Python stats: how do I write it to a (human readable) file

后端 未结 5 1388
小蘑菇
小蘑菇 2021-02-07 00:39

I am using Python\'s hotshot profiler: http://docs.python.org/2/library/hotshot.html

It shows how to print the stats:

stats.print_stats(20)
5条回答
  •  攒了一身酷
    2021-02-07 00:59

    You can use the library: pstats_print2list https://pypi.python.org/pypi/pstats_print2list

    pip install pstats_print2list And usage:

    from pstats_print2list import get_pstats_print2list, print_pstats_list
    fname_stats = 'my_profiling_out.stats'
    pstats_list = get_pstats_print2list(
        os.path.expanduser(fname_stats),
        filter_fnames=['myfile1.py', 'myfile2.py', 'root_path1'],
        exclude_fnames=['dontshow.py', 'path_dont_show'],
        sort='cumulative',
        limit=5,
    )
    print_pstats_list(pstats_list)
    

提交回复
热议问题