How can I analyze a file created with pstats.dump_stats(filename) off line?

后端 未结 2 1212
盖世英雄少女心
盖世英雄少女心 2021-02-18 18:50

I have essentially done the following:

import cProfile, pstats, StringIO
pr = cProfile.Profile()
pr.enable()
# ... my code did something ...
pr.disable()
s = Str         


        
2条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-18 19:21

    You can try snakeviz https://jiffyclub.github.io/snakeviz

    It is a browser based graphical viewer for the output of Python’s cProfile module and an alternative to using the standard library pstats module.

    # to install it with pip
    pip install snakeviz
    
    # once installed, you can use snakeviz to view the file
    snakeviz /path/to/your/dump/pstat/file
    

    Here is a sample image for a visualized pstat file you can dump like above.

提交回复
热议问题