Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python cprofile filename:lineno get full path

I use cprofile to get high offenders, however the filename:lineno is only listing the filename, but having the filepath listed would be more usefull to quickly open that path. Especially if there might be same module nams in different hierarchies.

ncalls    tottime    percall    cumtime    percall    filename:lineno(function)
1         0.000       0.000       3.922    display.py:599 (show)

Is there an option to turn that into fullpath?

like image 489
user1767754 Avatar asked Jun 06 '18 23:06

user1767754


2 Answers

I guess you format the output with "pstats.Stats" class and you have:

stats = Stats(profiler)
stats.strip_dirs()  # remove this
like image 140
user10916502 Avatar answered Oct 17 '22 21:10

user10916502


There doesn't seem to be a built in way but you can do this:

import cProfile                                                    
import pstats   
                                                   
p = cProfile.Profile()                      
s = p.run("1+1")     
pstats.Stats(s).sort_stats(2).print_stats()
like image 2
Timmmm Avatar answered Oct 17 '22 19:10

Timmmm