擅长:python、mysql、java
<p>这看起来像是一个bug或限制。嵌套探查器不工作。这里有个建议:</p>
<pre><code>import cProfile
import pstats
import time
import cStringIO as StringIO
def do():
for i in range(100):
time.sleep(0.01)
def do_more():
for i in range(100):
time.sleep(0.01)
def do_all():
all_profiler = cProfile.Profile()
all_profiler.enable()
profiler = cProfile.Profile()
profiler.enable()
do()
profiler.disable()
strio = StringIO.StringIO()
stats = pstats.Stats(profiler, stream=strio)
stats.sort_stats("cumulative")
stats.print_stats(10)
print "do profile:\n{}".format(strio.getvalue())
do_more()
all_profiler.disable()
strio = StringIO.StringIO()
stats = pstats.Stats(all_profiler, stream=strio)
stats.sort_stats("cumulative")
stats.print_stats(10)
print "all profile:\n{}".format(strio.getvalue())
do_all()
</code></pre>
<p>添加到临时股东大会在shell中运行,输出为:</p>
^{pr2}$
<p>请注意,“all_profiler”只显示另一个profiler。在</p>
<p>编辑:这可能只是摘要打印的问题。例如,我没有尝试将统计数据转储到配置文件查看器中,例如转换为使用kCachegrind。在</p>