OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright 2009 the V8 project authors. All rights reserved. | 3 # Copyright 2009 the V8 project authors. All rights reserved. |
4 # Redistribution and use in source and binary forms, with or without | 4 # Redistribution and use in source and binary forms, with or without |
5 # modification, are permitted provided that the following conditions are | 5 # modification, are permitted provided that the following conditions are |
6 # met: | 6 # met: |
7 # | 7 # |
8 # * Redistributions of source code must retain the above copyright | 8 # * Redistributions of source code must retain the above copyright |
9 # notice, this list of conditions and the following disclaimer. | 9 # notice, this list of conditions and the following disclaimer. |
10 # * Redistributions in binary form must reproduce the above | 10 # * Redistributions in binary form must reproduce the above |
(...skipping 21 matching lines...) Expand all Loading... |
32 # to produce heap usage histograms. | 32 # to produce heap usage histograms. |
33 | 33 |
34 # Sample usage: | 34 # Sample usage: |
35 # $ ./shell --log-gc script.js | 35 # $ ./shell --log-gc script.js |
36 # $ tools/process-heap-prof.py v8.log | hp2ps -c > script-heap-graph.ps | 36 # $ tools/process-heap-prof.py v8.log | hp2ps -c > script-heap-graph.ps |
37 # ('-c' enables color, see hp2ps manual page for more options) | 37 # ('-c' enables color, see hp2ps manual page for more options) |
38 | 38 |
39 import csv, sys, time | 39 import csv, sys, time |
40 | 40 |
41 def process_logfile(filename): | 41 def process_logfile(filename): |
| 42 first_call_time = None |
42 sample_time = 0.0 | 43 sample_time = 0.0 |
43 sampling = False | 44 sampling = False |
44 try: | 45 try: |
45 logfile = open(filename, 'rb') | 46 logfile = open(filename, 'rb') |
46 try: | 47 try: |
47 logreader = csv.reader(logfile) | 48 logreader = csv.reader(logfile) |
48 | 49 |
49 print('JOB "v8"') | 50 print('JOB "v8"') |
50 print('DATE "%s"' % time.asctime(time.localtime())) | 51 print('DATE "%s"' % time.asctime(time.localtime())) |
51 print('SAMPLE_UNIT "seconds"') | 52 print('SAMPLE_UNIT "seconds"') |
52 print('VALUE_UNIT "bytes"') | 53 print('VALUE_UNIT "bytes"') |
53 | 54 |
54 for row in logreader: | 55 for row in logreader: |
55 if row[0] == 'heap-sample-begin' and row[1] == 'Heap': | 56 if row[0] == 'heap-sample-begin' and row[1] == 'Heap': |
56 sample_time = float(row[3]) + float(row[4])/1000000.0 | 57 sample_time = float(row[3])/1000.0 |
| 58 if first_call_time == None: |
| 59 first_call_time = sample_time |
| 60 sample_time -= first_call_time |
57 print('BEGIN_SAMPLE %.2f' % sample_time) | 61 print('BEGIN_SAMPLE %.2f' % sample_time) |
58 sampling = True | 62 sampling = True |
59 elif row[0] == 'heap-sample-end' and row[1] == 'Heap': | 63 elif row[0] == 'heap-sample-end' and row[1] == 'Heap': |
60 print('END_SAMPLE %.2f' % sample_time) | 64 print('END_SAMPLE %.2f' % sample_time) |
61 sampling = False | 65 sampling = False |
62 elif row[0] == 'heap-sample-item' and sampling: | 66 elif row[0] == 'heap-sample-item' and sampling: |
63 print('%s %d' % (row[1], int(row[3]))) | 67 print('%s %d' % (row[1], int(row[3]))) |
64 finally: | 68 finally: |
65 logfile.close() | 69 logfile.close() |
66 except: | 70 except: |
67 sys.exit('can\'t open %s' % filename) | 71 sys.exit('can\'t open %s' % filename) |
68 | 72 |
69 process_logfile(sys.argv[1]) | 73 process_logfile(sys.argv[1]) |
OLD | NEW |