@@ -27,14 +27,16 @@ class Profiling(object):
27
27
svg = False
28
28
svg_name = None
29
29
profs = []
30
+ stripdirs = False
30
31
combined = None
31
32
svg_err = None
32
33
dot_cmd = None
33
34
gprof2dot_cmd = None
34
35
35
- def __init__ (self , svg , dir = None , element_number = 20 ):
36
+ def __init__ (self , svg , dir = None , element_number = 20 , stripdirs = False ):
36
37
self .svg = svg
37
38
self .dir = 'prof' if dir is None else dir [0 ]
39
+ self .stripdirs = stripdirs
38
40
self .element_number = element_number
39
41
self .profs = []
40
42
self .gprof2dot = os .path .abspath (os .path .join (os .path .dirname (sys .executable ), 'gprof2dot' ))
@@ -86,7 +88,10 @@ def pytest_sessionfinish(self, session, exitstatus): # @UnusedVariable
86
88
def pytest_terminal_summary (self , terminalreporter ):
87
89
if self .combined :
88
90
terminalreporter .write ("Profiling (from {prof}):\n " .format (prof = self .combined ))
89
- pstats .Stats (self .combined , stream = terminalreporter ).strip_dirs ().sort_stats ('cumulative' ).print_stats (self .element_number )
91
+ stats = pstats .Stats (self .combined , stream = terminalreporter )
92
+ if self .stripdirs :
93
+ stats .strip_dirs ()
94
+ stats .sort_stats ('cumulative' ).print_stats (self .element_number )
90
95
if self .svg_name :
91
96
if not self .svg_err :
92
97
# 0 - SUCCESS
@@ -140,6 +145,8 @@ def pytest_addoption(parser):
140
145
help = "configure the dump directory of profile data files" )
141
146
group .addoption ("--element-number" , action = "store" , type = "int" , default = 20 ,
142
147
help = "defines how many elements will display in a result" )
148
+ group .addoption ("--strip-dirs" , action = "store_true" ,
149
+ help = "configure to show/hide the leading path information from file names" )
143
150
144
151
145
152
def pytest_configure (config ):
@@ -148,4 +155,5 @@ def pytest_configure(config):
148
155
if profile_enable :
149
156
config .pluginmanager .register (Profiling (config .getvalue ('profile_svg' ),
150
157
config .getvalue ('pstats_dir' ),
151
- element_number = config .getvalue ('element_number' )))
158
+ element_number = config .getvalue ('element_number' ),
159
+ stripdirs = config .getvalue ('strip_dirs' )))
0 commit comments