File: log2gnuplot.py

package info (click to toggle)
duktape 2.7.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 21,160 kB
  • sloc: ansic: 215,359; python: 5,961; javascript: 4,555; makefile: 477; cpp: 205
file content (41 lines) | stat: -rw-r--r-- 1,041 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python2
#
#  Analyze allocator logs and write total-bytes-in-use after every
#  operation to stdout.  The output can be gnuplotted as:
#
#  $ python log2gnuplot.py </tmp/duk-alloc-log.txt >/tmp/output.txt
#  $ gnuplot
#  > plot "output.txt" with lines
#

import os
import sys

def main():
    allocated = 0

    for line in sys.stdin:
        line = line.strip()
        parts = line.split(' ')

        # A ptr/NULL/FAIL size
        # F ptr/NULL size
        # R ptr/NULL oldsize ptr/NULL/FAIL newsize

        # Note: duk-low doesn't log oldsize (uses -1 instead)

        if parts[0] == 'A':
            if parts[1] != 'NULL' and parts[1] != 'FAIL':
                allocated += long(parts[2])
        elif parts[0] == 'F':
            allocated -= long(parts[2])
        elif parts[0] == 'R':
            allocated -= long(parts[2])
            if parts[3] != 'NULL' and parts[3] != 'FAIL':
                allocated += long(parts[4])
        print(allocated)

    print(allocated)

if __name__ == '__main__':
    main()