python-flamegraph icon indicating copy to clipboard operation
python-flamegraph copied to clipboard

Support for profiling imported c modules

Open test-account-0 opened this issue 10 years ago • 6 comments

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.

test-account-0 avatar Feb 15 '16 11:02 test-account-0

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.

evanhempel avatar Apr 21 '16 00:04 evanhempel

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?

test-account-0 avatar Apr 21 '16 19:04 test-account-0

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...

evanhempel avatar Apr 26 '16 01:04 evanhempel

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.

evanhempel avatar Jul 21 '17 23:07 evanhempel

Any progress?

jcea avatar Aug 21 '17 00:08 jcea

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)?

evanhempel avatar Aug 29 '17 01:08 evanhempel