Index: tools/process-heap-prof.py
|
===================================================================
|
--- tools/process-heap-prof.py (revision 3252)
|
+++ tools/process-heap-prof.py (working copy)
|
@@ -40,9 +40,14 @@
|
# to get JS constructor profile
|
|
|
-import csv, sys, time
|
+import csv, sys, time, optparse
|
|
-def process_logfile(filename, itemname):
|
+def ProcessLogFile(filename, options):
|
+ if options.js_cons_profile:
|
+ itemname = 'heap-js-cons-item'
|
+ else:
|
+ itemname = 'heap-sample-item'
|
+
|
first_call_time = None
|
sample_time = 0.0
|
sampling = False
|
@@ -68,13 +73,48 @@
|
print('END_SAMPLE %.2f' % sample_time)
|
sampling = False
|
elif row[0] == itemname and sampling:
|
- print('%s %d' % (row[1], int(row[3])))
|
+ print(row[1]),
|
+ if options.count:
|
+ print('%d' % (int(row[2]))),
|
+ if options.size:
|
+ print('%d' % (int(row[3]))),
|
+ print
|
finally:
|
logfile.close()
|
except:
|
sys.exit('can\'t open %s' % filename)
|
|
-if sys.argv[1] == '--js-cons-profile':
|
- process_logfile(sys.argv[2], 'heap-js-cons-item')
|
-else:
|
- process_logfile(sys.argv[1], 'heap-sample-item')
|
+
|
+def BuildOptions():
|
+ result = optparse.OptionParser()
|
+ result.add_option("--js_cons_profile", help="Constructor profile",
|
+ default=False, action="store_true")
|
+ result.add_option("--size", help="Report object size",
|
+ default=False, action="store_true")
|
+ result.add_option("--count", help="Report object count",
|
+ default=False, action="store_true")
|
+ return result
|
+
|
+
|
+def ProcessOptions(options):
|
+ if not options.size and not options.count:
|
+ options.size = True
|
+ return True
|
+
|
+
|
+def Main():
|
+ parser = BuildOptions()
|
+ (options, args) = parser.parse_args()
|
+ if not ProcessOptions(options):
|
+ parser.print_help()
|
+ sys.exit();
|
+
|
+ if not args:
|
+ print "Missing logfile"
|
+ sys.exit();
|
+
|
+ ProcessLogFile(args[0], options)
|
+
|
+
|
+if __name__ == '__main__':
|
+ sys.exit(Main())
|
|