简体   繁体   中英

Can I get the python call stack with the linux perf?

For example,

    def test():
        print "test"

As of 2018, perf simply doesn't have support for reading the Python stack frames (cf. a 2014 Python mailinglist discussion ).

Python 3.6 has some support for Dtrace and Systemtap .

An alternative to this is Pyflame, a stochastic profiler for Python that samples python call stacks via ptrace() . In contrast to Dtrace/Systemtap you don't need extra permissions and it also works with Python versions that are compiled without instrumentalization support.

When you use the --threads option with Pyflame you see Python lines that call into C/C++ extensions, although the stack-trace stops at the last Python frame. But perhaps this is sufficient for your use case.

You won't be able to do this with perf, that's specifically built to interface the Linux process model, decode those stack frames, etc. It's doing what it's supposed to by telling you that it was executing the function PyEval_EvalFrameEx. It would have to be extended with python-specific information to be able to actually decode Python's frame information, which isn't going to happen. Unfortunately I haven't found a really good way to debug both Python and C/C++ modules easily. It's generally pdb for one and gdb for the other.

Austin 3.3 has a where<\/code> option which allows you to emit the current stack trace of a running Python process

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM