【问题标题】:Profiling only user defined functions pstats仅分析用户定义的函数 pstats
【发布时间】:2016-08-06 17:17:01
【问题描述】:

我正在尝试使用 pstats 模块中的 Stats():

    p = Profile()
    p.runcall(wrangle_file,input_filename="test.csv",output_file="solution.csv",metrics=True)
    stats = Stats(p)
    stats.strip_dirs()
    stats.sort_stats('cumulative')
    stats.print_stats()

但是,当我执行 print_stats 时,我也会收到对库函数的调用。有没有办法可以过滤这些以仅打印对我的函数的调用?

【问题讨论】:

    标签: python profiling pstats


    【解决方案1】:

    您可以通过在print_stats() 函数中传递模块名称来过滤模块。

    假设您的 Python 文件的名称是 my_python.py,那么您应该使用 print_stats("my_python")

    你也可以传入函数名。

    【讨论】:

      猜你喜欢
      • 2011-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-31
      • 1970-01-01
      • 2017-07-21
      • 2011-07-23
      • 2012-07-25
      相关资源
      最近更新 更多