@@ -31,11 +31,12 @@ class Profiling(object):
3131 dot_cmd = None
3232 gprof2dot_cmd = None
3333
34- def __init__ (self , svg , dir = None , element_number = 20 , stripdirs = False ):
34+ def __init__ (self , svg , dir = None , element_number = 20 , stripdirs = False , element_regex = None ):
3535 self .svg = svg
3636 self .dir = 'prof' if dir is None else dir [0 ]
3737 self .stripdirs = stripdirs
3838 self .element_number = element_number
39+ self .element_regex = element_regex
3940 self .profs = []
4041 self .gprof2dot = os .path .abspath (os .path .join (os .path .dirname (sys .executable ), 'gprof2dot' ))
4142 if not os .path .isfile (self .gprof2dot ):
@@ -98,7 +99,12 @@ def pytest_terminal_summary(self, terminalreporter):
9899 stats = pstats .Stats (self .combined , stream = terminalreporter )
99100 if self .stripdirs :
100101 stats .strip_dirs ()
101- stats .sort_stats ('cumulative' ).print_stats (self .element_number )
102+ if self .element_regex :
103+ print_args = self .element_regex , self .element_number
104+ else :
105+ print_args = (self .element_number ,)
106+ stats .sort_stats ('cumulative' )
107+ stats .print_stats (* print_args )
102108 if self .svg_name :
103109 if not self .exit_code :
104110 # 0 - SUCCESS
@@ -144,6 +150,8 @@ def pytest_addoption(parser):
144150 help = "generate profiling graph (using gprof2dot and dot -Tsvg)" )
145151 group .addoption ("--pstats-dir" , nargs = 1 ,
146152 help = "configure the dump directory of profile data files" )
153+ group .addoption ("--profile-element-regex" , type = str , default = None ,
154+ help = "filters elements displayed using regex" )
147155 group .addoption ("--element-number" , action = "store" , type = int , default = 20 ,
148156 help = "defines how many elements will display in a result" )
149157 group .addoption ("--strip-dirs" , action = "store_true" ,
@@ -157,4 +165,5 @@ def pytest_configure(config):
157165 config .pluginmanager .register (Profiling (config .getvalue ('profile_svg' ),
158166 config .getvalue ('pstats_dir' ),
159167 element_number = config .getvalue ('element_number' ),
160- stripdirs = config .getvalue ('strip_dirs' )))
168+ stripdirs = config .getvalue ('strip_dirs' ),
169+ element_regex = config .getvalue ('profile_element_regex' )))
0 commit comments