Created
February 5, 2018 16:19
-
-
Save jakelandis/c6802ef723db222cf764863a9ba1712c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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