Commit 13c8c87c authored by Kirill Smelkov's avatar Kirill Smelkov

pymprof: Tool to collect memory profile of a running Python process

parent f9ae1831
# pyrasite payload to collect memory profile for <t> seconds
t = 10
from golang import go
import tracemalloc, time, sys
def mprof(t):
print("\nmprof start ...")
tracemalloc.start()
time.sleep(t)
snapshot = tracemalloc.take_snapshot()
tracemalloc.stop()
top_stats = snapshot.statistics('lineno')
print('\nmprof: [ Top 10 ]')
for stat in top_stats[:10]:
print(stat)
sys.stdout.flush()
go(mprof, t)
#!/bin/sh
# pymprof <pid> -- collect/print memory profile from a running Python program
#
# The output is collected in a spawned thread in the target process and then is
# sent to program's stdout. Pymprof only spawns that thread and does not wait
# for its completion.
#
# see also pyinject.gdb
pyrasite $1 mprof.py
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment