Fix ar9x compile/boot (#7102)
[opentx.git] / radio / util / lua_trace2plot.py
blob2327a047555d1daa69e59a4eb57426e20965aec6
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
4 """
5 This script parses debug log events related to Lua memory (de)allocations ( lines
6 starting wiht "LT: ") and produces a data for gnuplot program
8 Usage:
10 ./simu 2>&1 | grep "^LT" | ../radio/util/lua_trace2plot.py > data.plot
11 gnuplot -e 'set xtics rotate; plot "data.plot" using 2:xtic(1) ; pause mouse close'
12 """
14 from __future__ import print_function
16 import sys
19 if len(sys.argv) > 1:
20 inputFile = sys.argv[1]
21 inp = open(inputFile, "r")
22 else:
23 inp = sys.stdin
26 x = 0
27 memUsed = 0
28 while True:
29 skip = True
30 line = inp.readline()
31 if len(line) == 0:
32 break
33 line = line.strip('\r\n')
34 if len(line) == 0:
35 skip = True
36 if line.startswith("LT:"):
37 skip = False
39 if not skip:
40 parts = line.split()
41 if len(parts) >= 3:
42 data = parts[1].strip("[").strip("]").split(",")
43 alloc = int(data[0])
44 free = int(data[1])
45 line = parts[2]
46 if alloc > 0:
47 memUsed += alloc
48 print("'%s'\t%d" % (line, memUsed))
49 x += 1
50 if free < 0:
51 memUsed += free
52 print("'%s'\t%d" % (line, memUsed))
53 x += 1
55 inp.close()