joerick / pyinstrument

🚴 Call stack profiler for Python. Shows you why your code is slow!
https://pyinstrument.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
6.63k stars 232 forks source link

No information about the number of calls #85

Closed ftrofin closed 4 years ago

ftrofin commented 4 years ago

Thank you for writing this profiler it brings a bit of fresh air. I tested it on one of my scripts with the HTMl renderer and while I love the fact that I can collapse/expand the nodes, I really need to see more information (besides total time). At a minimum I'd like to see:

carterbox commented 4 years ago

Number of calls

pyinstrument is a statistical profiler; computing the number of calls of each function was traded for less profiling overhead. In other words, pyinstrument doesn't record every function call and the time it takes to return, it samples the state of the stack at regular intervals. Using this method, it is not possible to know whether two consecutive measures of the same function are from the same call.

Child time

Time spend it children vs self is already reported. pyinstrument reports total time in a function, time spent in [self], and time spend in each child. In the example below, the time spent in line_search children vs itself would be (190 - 116) / 190 ms.

   β”‚  β”‚     β”œβ”€ 0.190 line_search  tike/opt.py:12
   β”‚  β”‚     β”‚  β”œβ”€ 0.116 [self]  
   β”‚  β”‚     β”‚  └─ 0.074 cost_function  tike/ptycho/solvers.py:111
   β”‚  β”‚     β”‚     └─ 0.069 _gaussian_cost  libtike/cufft/_propagation.py:44
   β”‚  β”‚     β”‚        └─ 0.042 array  cupy/creation/from_data.py:7

If you don't see [self] that means the amount of time spent in self was too small to be measured.

joerick commented 4 years ago

@carterbox agree to all of this, thanks for responding!

line number where the call originated (not a big deal, I can infer it by looking up that function in the source code of the parent but most profilers give you that)

This is something I'm considering adding actually, so feel free to prod me about it as a standalone issue if it's important for your use case!