-
Notifications
You must be signed in to change notification settings - Fork 21
[Fix #114] Add leak suspect retained heap top consumers #115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: Kevin Grigorenko <kevin.grigorenko@us.ibm.com>
@jasonk000 or @krumts: if one of you can please review when you have a chance, thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Directionally looks good, some changes required though.
Long sumHeapSize = sumHeapSizes.get(name); | ||
if (sumHeapSize == null) | ||
{ | ||
sumHeapSize = 0L; | ||
} | ||
sumHeapSize += snapshot.getHeapSize(objectId); | ||
sumHeapSizes.put(name, sumHeapSize); | ||
|
||
Integer count = counts.get(name); | ||
if (count == null) | ||
{ | ||
count = 0; | ||
} | ||
count++; | ||
counts.put(name, count); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could be simplified
IObject object = snapshot.getObject(objectId);
String name = snapshot.isClass(objectId)
? ((IClass) object).getName()
: object.getClazz().getName();
sumHeapSizes.merge(name, snapshot.getHeapSize(objectId), Long::sum);
counts.merge(name, 1, Integer::sum);
StringBuilder result = new StringBuilder(); | ||
List<Entry<String, Long>> list = new ArrayList<>(sumHeapSizes.entrySet()); | ||
list.sort((e1, e2) -> e2.getValue().compareTo(e1.getValue())); | ||
List<Entry<String, Long>> finalList = list.subList(0, Math.min(list.size(), topItems)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
8000
I think this might be a slow way to sort for large counts - not sure how significant, what about something like a PriorityQueue
to do the top-N sort? Probably not a huge deal.
entry.getKey(), count, bytesFormatter.format(entry.getValue()))); | ||
} | ||
} | ||
return HTMLUtils.escapeText(result.toString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops. I added escaping to fix some tests (classes with <
and >
in them) but then I forgot to run it again visually to see this.
Signed-off-by: Kevin Grigorenko <kevin.grigorenko@us.ibm.com>
As per #114, add a new second sentence (in bold below) that lists up to the top 3 consumers of the suspect's retained heap; for example: