3

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

CrazyArm
  • 356
  • 1
  • 3
  • 13

2 Answers2

4

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")
Vincent J
  • 4,968
  • 4
  • 40
  • 50
1

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.

taper
  • 528
  • 5
  • 22