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

谁说我不能喝 提交于 2020-01-01 07:42:33

问题


For example,

    def test():
        print "test"

I used perf record -g -p $pid, but the result was just all about PyEval_EvalFrameEx. How can I get the real name "test" or if can not by using perf?


回答1:


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.




回答2:


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.




回答3:


Maybe the traceback module will do the trick for you:

https://docs.python.org/2/library/traceback.html https://docs.python.org/3/library/traceback.html



来源:https://stackoverflow.com/questions/26902991/can-i-get-the-python-call-stack-with-the-linux-perf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!