我可以使用linux perf获得python调用堆栈吗? [英] Can I get the python call stack with the linux perf?
问题描述
例如,
def test():
print "test"
我使用了perf record -g -p $pid
,但是结果只是关于PyEval_EvalFrameEx
的全部.我该如何获得真实姓名"test",或者如果不能使用perf来获得实名?
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?
推荐答案
截至2018年,perf
根本不支持读取Python堆栈框架(请参阅
As of 2018, perf
simply doesn't have support for reading the Python stack frames (cf. a 2014 Python mailinglist discussion).
Python 3.6支持 Dtrace和Systemtap .
Python 3.6 has some support for Dtrace and Systemtap.
另一种替代方法是 Pyflame,一种用于Python的随机探查器,可通过
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.
在Pyflame中使用--threads
选项时,您会看到调用C/C ++扩展的Python行,尽管堆栈跟踪在最后一个Python帧处停止.但这也许足以满足您的用例.
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.
这篇关于我可以使用linux perf获得python调用堆栈吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!