OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # |
| 3 # Copyright 2009 the V8 project authors. All rights reserved. |
| 4 # Redistribution and use in source and binary forms, with or without |
| 5 # modification, are permitted provided that the following conditions are |
| 6 # met: |
| 7 # |
| 8 # * Redistributions of source code must retain the above copyright |
| 9 # notice, this list of conditions and the following disclaimer. |
| 10 # * Redistributions in binary form must reproduce the above |
| 11 # copyright notice, this list of conditions and the following |
| 12 # disclaimer in the documentation and/or other materials provided |
| 13 # with the distribution. |
| 14 # * Neither the name of Google Inc. nor the names of its |
| 15 # contributors may be used to endorse or promote products derived |
| 16 # from this software without specific prior written permission. |
| 17 # |
| 18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 |
| 30 # This is an utility for converting V8 heap logs into .hp files that can |
| 31 # be further processed using 'hp2ps' tool (bundled with GHC and Valgrind) |
| 32 # to produce heap usage histograms. |
| 33 |
| 34 # Sample usage: |
| 35 # $ ./shell --log-gc script.js |
| 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) |
| 38 |
| 39 import csv, sys, time |
| 40 |
| 41 def process_logfile(filename): |
| 42 sample_time = 0.0 |
| 43 sampling = False |
| 44 try: |
| 45 logfile = open(filename, 'rb') |
| 46 try: |
| 47 logreader = csv.reader(logfile) |
| 48 |
| 49 print('JOB "v8"') |
| 50 print('DATE "%s"' % time.asctime(time.localtime())) |
| 51 print('SAMPLE_UNIT "seconds"') |
| 52 print('VALUE_UNIT "bytes"') |
| 53 |
| 54 for row in logreader: |
| 55 if row[0] == 'heap-sample-begin' and row[1] == 'Heap': |
| 56 sample_time = float(row[3]) + float(row[4])/1000000.0 |
| 57 print('BEGIN_SAMPLE %.2f' % sample_time) |
| 58 sampling = True |
| 59 elif row[0] == 'heap-sample-end' and row[1] == 'Heap': |
| 60 print('END_SAMPLE %.2f' % sample_time) |
| 61 sampling = False |
| 62 elif row[0] == 'heap-sample-item' and sampling: |
| 63 print('%s %d' % (row[1], int(row[3]))) |
| 64 finally: |
| 65 logfile.close() |
| 66 except: |
| 67 sys.exit('can\'t open %s' % filename) |
| 68 |
| 69 process_logfile(sys.argv[1]) |
OLD | NEW |