@@ -27,9 +27,10 @@ class Profiling(object):
27
27
profs = []
28
28
combined = None
29
29
30
- def __init__ (self , svg , dir ):
30
+ def __init__ (self , svg , dir , element_number ):
31
31
self .svg = svg
32
32
self .dir = 'prof' if dir is None else dir [0 ]
33
+ self .element_number = element_number
33
34
self .profs = []
34
35
self .gprof2dot = os .path .abspath (os .path .join (os .path .dirname (sys .executable ), 'gprof2dot' ))
35
36
if not os .path .isfile (self .gprof2dot ):
@@ -59,7 +60,7 @@ def pytest_sessionfinish(self, session, exitstatus): # @UnusedVariable
59
60
def pytest_terminal_summary (self , terminalreporter ):
60
61
if self .combined :
61
62
terminalreporter .write ("Profiling (from {prof}):\n " .format (prof = self .combined ))
62
- pstats .Stats (self .combined , stream = terminalreporter ).strip_dirs ().sort_stats ('cumulative' ).print_stats (20 )
63
+ pstats .Stats (self .combined , stream = terminalreporter ).strip_dirs ().sort_stats ('cumulative' ).print_stats (int ( self . element_number ) )
63
64
if self .svg_name :
64
65
terminalreporter .write ("SVG profile in {svg}.\n " .format (svg = self .svg_name ))
65
66
@@ -98,11 +99,14 @@ def pytest_addoption(parser):
98
99
help = "generate profiling graph (using gprof2dot and dot -Tsvg)" )
99
100
group .addoption ("--pstats-dir" , nargs = 1 ,
100
101
help = "configure the dump directory of profile data files" )
102
+ group .addoption ("--element-number" , action = "store" , default = "20" ,
103
+ help = "defines how many elements will display in a result" )
101
104
102
105
103
106
def pytest_configure (config ):
104
107
"""pytest_configure hook for profiling plugin"""
105
108
profile_enable = any (config .getvalue (x ) for x in ('profile' , 'profile_svg' ))
106
109
if profile_enable :
107
110
config .pluginmanager .register (Profiling (config .getvalue ('profile_svg' ),
108
- config .getvalue ('pstats_dir' )))
111
+ config .getvalue ('pstats_dir' ),
112
+ config .getvalue ('element_number' )))
0 commit comments