1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-13 11:29:51 +03:00

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
This commit is contained in:
Damjan Adamic 2017-11-11 09:41:05 +01:00 committed by Bertrand Songis
parent c30ff28f85
commit f0f3e35bf6
6 changed files with 161 additions and 8 deletions

55
radio/util/lua_trace2plot.py Executable file
View file

@ -0,0 +1,55 @@
#!/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()