我可以使用linux perf获得python调用堆栈吗? [英] Can I get the python call stack with the linux perf?

查看:433
本文介绍了我可以使用linux perf获得python调用堆栈吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,

    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的随机探查器,可通过.与Dtrace/Systemtap相比,您不需要额外的权限,它也适用于在没有工具支持的情况下编译的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆