0

GSoC 2018: How to profile a piece of code

As suggested by my mentor Konstantin, a person can use 3 below tools to profile a piece of code:

  • Vmprof, which includes a lot of add-ons that can be used with!
  • Profilehooks, and snakeviz to visualize the result
  • Statprof-smarkets

They are really useful in visualizing the run time of each functions call stack -> recognize the functions that take a lot of time so that it might be easier to know the functions that can be improved

 

Use all 3 of the profiling tools so that we can have a more precise result to look at.

 

For vmprof, the advantage is that we have a lot of views to look at. However, the most useful one is the flamegraph, which shows % of the time a function takes to process; but it does not show exactly how much time it takes to run a function. The 4 numbers on the top of the web results shows the information in order: the % time this function takes compared to the time the profiled python code ran, the time that this function takes everywhere in the profiled python code (a function can be called multiple times within a piece of code), the % of time spent on this function at the current location (exclude the functions it calls), the % of time spent on this function (exclude the functions it calls) everywhere in the profiled python code.

 

For profilehooks, since it is a cprofiler, it shows the times that a function is called when running the profiled python script. In addition, it also shows how much time spent in the function in second. For the .prof file result, we can use snakeviz to visualize the data faster

 

Statprof-smarkets shares the same functionality as other statistical profiler like vmprof!

 

Special thanks to Konstantin for showing me all of this 🙂