Created
January 29, 2015 23:00
-
-
Save EricRahm/15aab9a903df3ef921ae to your computer and use it in GitHub Desktop.
about memory parser
This file contains 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
import json | |
import collections | |
import sys | |
import operator | |
from pprint import pprint | |
def path_total(data, path): | |
totals = collections.defaultdict(int) | |
totals_heap = collections.defaultdict(int) | |
totals_heap_allocated = collections.defaultdict(int) | |
for report in data["reports"]: | |
if report["path"].startswith(path): | |
totals[report["process"]] += report["amount"] | |
if report["kind"] == 1: | |
totals_heap[report["process"]] += report["amount"] | |
elif report["path"] == "heap-allocated": | |
totals_heap_allocated[report["process"]] = report["amount"] | |
if path == "explicit/": | |
for k, v in totals_heap.items(): | |
if k in totals_heap_allocated: | |
heap_unclassified = totals_heap_allocated[k] - totals_heap[k] | |
totals[k] += heap_unclassified | |
return totals | |
if __name__ == "__main__": | |
file_path = sys.argv[1] | |
tree_path = sys.argv[2] | |
json_data=open(file_path) | |
data = json.load(json_data) | |
json_data.close() | |
totals = path_total(data, tree_path); | |
sorted_totals = sorted(totals.iteritems(), key=lambda(k,v): (-v,k)) | |
for (k, v) in sorted_totals: | |
if v: | |
print "{0}\t".format(k), | |
print "" | |
for (k, v) in sorted_totals: | |
if v: | |
print "{0}\t".format(v), | |
print "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment