sumerc / yappi

Yet Another Python Profiler, but this time multithreading, asyncio and gevent aware.
MIT License
1.46k stars 72 forks source link

Full path not printed #154

Closed chookity-pokk closed 10 months ago

chookity-pokk commented 10 months ago

When trying to print out my profile I get the below output which trims off most of the path making it hard to find certain functions without just searching the codebase manually.

name                                  ncall  tsub      ttot      tavg                                                                                                                                                                           
..rofiler_test.py:16 pytorch_profile  1      0.018081  15.32734  15.32734                                                                                                                                                                       
..ng.py:21 calibrate_pulse_efficient  1      0.000092  15.30926  15.30926                                                                                                                                                                       
.._testing.py:89 get_tomography_data  1      8.447636  13.99318  13.99318                                                                                                                                                                       
..rch.py:57 DirectOptimizer.optimize  1      0.000108  1.178290  1.178290                                                                                                                                                                       
..ess.py:729 ProcessPoolExecutor.map  1      0.000018  1.174164  1.174164                                                                                                                                                                       
..ase.py:573 ProcessPoolExecutor.map  1      0.000010  1.174146  1.174146                                                                                                                                                                       
..nt/futures/_base.py:598 <listcomp>  1      0.000121  1.174135  1.174135                                                                                                                                                                       
...py:704 ProcessPoolExecutor.submit  40     0.000389  1.166747  0.029169                                                                                                                                                                       
..tor._start_executor_manager_thread  40     0.000115  1.164310  0.029108        

The code I am using is just


yappi.set_clock_type("cpu") # Use set_clock_type("wall") for wall time
yappi.start()
my_profile()
yappi.get_func_stats().print_all()
yappi.get_thread_stats().print_all()
sumerc commented 10 months ago

You can play with column lengths like:

yappi.get_func_stats().print_all(columns={
            0: ("name", 36),
            1: ("ncall", 5),
            2: ("tsub", 8),
            3: ("ttot", 8),
            4: ("tavg", 8)
        })

I must admit also that it is a bit weird API but not easy to change without backward compact.

Usually ppl. that would like to play with stats, just enumerate them like:

for x in yappi.get_func_stats():
     pass

or just save it to a file.

chookity-pokk commented 10 months ago

Thanks for the help!