1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-12 19:10:19 +03:00
opentx/radio/util/lua_trace2plot.py
Damjan Adamic f0f3e35bf6 Lua memory (de)allocation tracer: (#5191)
* Lua memory (de)allocation tracer:

Usage:
 * turn on: `cmake -DLUA=YES -DLUA_ALLOCATOR_TRACER=YES -DDEBUG=YES -DNANO=NO`
 * get debug output and make plot data: `./simu 2>&1 | grep "^LT" | ../radio/util/lua_trace2plot.py > data.plot`
 * plot: `gnuplot  -e 'set xtics rotate;  plot "data.plot" using 2:xtic(1) ; pause mouse close'`

* Changes based on Bertrand comments
2017-11-11 09:41:05 +01:00

55 lines
1.3 KiB
Python
Executable file

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This script parses debug log events related to Lua memory (de)allocations ( lines
starting wiht "LT: ") and produces a data for gnuplot program
Usage:
./simu 2>&1 | grep "^LT" | ../radio/util/lua_trace2plot.py > data.plot
gnuplot -e 'set xtics rotate; plot "data.plot" using 2:xtic(1) ; pause mouse close'
"""
from __future__ import print_function
import sys
if len(sys.argv) > 1:
inputFile = sys.argv[1]
inp = open(inputFile, "r")
else:
inp = sys.stdin
x = 0
memUsed = 0
while True:
skip = True
line = inp.readline()
if len(line) == 0:
break
line = line.strip('\r\n')
if len(line) == 0:
skip = True
if line.startswith("LT:"):
skip = False
if not skip:
parts = line.split()
if len(parts) >= 3:
data = parts[1].strip("[").strip("]").split(",")
alloc = int(data[0])
free = int(data[1])
line = parts[2]
if alloc > 0:
memUsed += alloc
print("'%s'\t%d" % (line, memUsed))
x += 1
if free < 0:
memUsed += free
print("'%s'\t%d" % (line, memUsed))
x += 1
inp.close()