Support for profiling imported c modules
Now only the functions in the script that is profiled are added to the log. It would be really great to also know what takes time in functions from other modules imported by the profiled script.
This profiler should profile functions inside imported python modules. If you can give me an example where it isn't doing this I'll be happy to investigate.
Ok, maybe I'm just missing something.
Let's look at a simle script test.py:
#!/usr/bin/env python
import math
def calculate_something(lst):
for element in lst:
math.sqrt(element)
calculate_something([x for x in xrange(1,10000000)])
When I run something like that:
python -m flamegraph -o perf.log test.py
I just get:
MainThread`_run_code;MainThread`<module>;MainThread`main;MainThread`<module> 484
MainThread`_run_code;MainThread`<module>;MainThread`main;MainThread`<module>;MainThread`calculate_something 35
MainThread`_run_code;MainThread`<module>;MainThread`main;MainThread`start;MainThread`wait;MainThread`wait 1
Where is the number for math.sqrt? Hot to get it?
It looks like you're on to something, it looks like my approach is unable to sample stackframes inside native c modules.
This module should work ok on pure python, but I need to figure out an approach for native code...
Take a look at Aaron Solowski's version: https://github.com/asokoloski/python-flamegraph
He's added support using signal.setitimer that will profile inside of c modules. The downside is you lose thread information, but depending on your use-case that's probably a good trade-off.
Any progress?
No, haven't been working in python recently. Pull requests would be considered. Have you checked out Aaron Solowski's version (linked in Jul 21 comment)?