Skip to content

Instantly share code, notes, and snippets.

@jakelandis
Created February 5, 2018 16:19
Show Gist options
  • Save jakelandis/c6802ef723db222cf764863a9ba1712c to your computer and use it in GitHub Desktop.
Save jakelandis/c6802ef723db222cf764863a9ba1712c to your computer and use it in GitHub Desktop.
var countByValue = {};
var sizeByValue = {};
// Scroll the strings
heap.forEachObject(
function(strObject) {
var key = strObject.metaClass.realClass.cachedName;
if (key) {
key = key.toString();
} else {
key = "unknown";
}
var count = countByValue[key];
var size = sizeByValue[key] ? sizeByValue[key] : 0;
countByValue[key] = count ? count + 1 : 1;
sizeByValue[key] = size + sizeof(strObject);
},
"org.jruby.RubyObject",
false
);
// Transform the map into array
var mapEntries = [];
for (var i = 0, keys = Object.keys(countByValue), total = keys.length; i < total; i++) {
mapEntries.push({
count : countByValue[keys[i]],
string : keys[i],
shallow_size : sizeByValue[keys[i]]
});
}
// Sort by counts
//sort(mapEntries, 'rhs.count - lhs.count');
//Sort by size
sort(mapEntries, 'rhs.shallow_size - lhs.shallow_size');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment