第十六章:开发工具-profile和pstats:性能分析-调用者被调用者图

it2022-05-05  131

16.8.5 调用者/被调用者图 stats还包括一些方法可以打印函数的调用者和被调用者。

import cProfile as profile import pstats from profile_fibonacci_memoized import fib,fib_seq # Read all 5 stats files into a single object. stats = pstats.Stats('profile_stats_0.stats') for i in range(1,5): stats.add('profile_stats_{}.stats'.format(i)) stats.strip_dirs() stats.sort_stats('cumulative') print('INCOMING CALLERS:') stats.print_callers('\(fib') print('OUTGOING CALLEES:') stats.print_callees('\(fib')

print_callers()和print_callees()的参数与print_stats()的现在参数类似。输出会显示调用者、调用数以及累积时间。


最新回复(0)