Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for profiling imported c modules #5

Open
test-account-0 opened this issue Feb 15, 2016 · 6 comments
Open

Support for profiling imported c modules #5

test-account-0 opened this issue Feb 15, 2016 · 6 comments

Comments

@test-account-0
Copy link

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.

@evanhempel
Copy link
Owner

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.

@test-account-0
Copy link
Author

test-account-0 commented Apr 21, 2016

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?

@evanhempel
Copy link
Owner

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 evanhempel reopened this Apr 26, 2016
@evanhempel evanhempel changed the title Support for profiling imported modules Support for profiling imported c modules May 9, 2016
@evanhempel
Copy link
Owner

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.

@jcea
Copy link

jcea commented Aug 21, 2017

Any progress?

@evanhempel
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants