Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Snakeviz only showing one function

I am trying to use Snakeviz to profile my python code. I use

if __name__ == "__main__":
    # main()
    cProfile.run('main()', "stats.prof")

to start the profiling. The issue I am having is that Snakeviz is only showing one overall function "built-in method builtins.exec". Anyone know what could be causing this? The function I am profiling calls many sub-functions. Snakeviz sees this, as shown in the table excerpt below the image, it just doesn't show up in the visualisation.

snakeviz example

like image 332
CrazyArm Avatar asked Nov 02 '25 09:11

CrazyArm


2 Answers

cProfile.run does not seem to add callers data to the file.

Instead of using cProfile.run('main()', "stats.prof") try this:

pr = cProfile.Profile()
pr.enable()
main()
pr.disable()
pr.dump_stats("stats.prof")
like image 64
Vincent J Avatar answered Nov 04 '25 01:11

Vincent J


Consider directly running cProfile from command line:

python -m cProfile -o output_file script_to_run.py

This will allow cProfile to understand your script's running time better.

like image 27
taper Avatar answered Nov 04 '25 00:11

taper



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!