Skip to content

Commit 114a519

Browse files
authored
Merge pull request #164 from RaiVaibhav/add_support_to_show_hide_the_full_file_path
Add: support to hide/show the full path of file
2 parents 96fc29d + ca4f4f5 commit 114a519

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

pytest-profiling/pytest_profiling.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,16 @@ class Profiling(object):
2727
svg = False
2828
svg_name = None
2929
profs = []
30+
stripdirs = False
3031
combined = None
3132
svg_err = None
3233
dot_cmd = None
3334
gprof2dot_cmd = None
3435

35-
def __init__(self, svg, dir=None, element_number=20):
36+
def __init__(self, svg, dir=None, element_number=20, stripdirs=False):
3637
self.svg = svg
3738
self.dir = 'prof' if dir is None else dir[0]
39+
self.stripdirs = stripdirs
3840
self.element_number = element_number
3941
self.profs = []
4042
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
8688
def pytest_terminal_summary(self, terminalreporter):
8789
if self.combined:
8890
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)
9095
if self.svg_name:
9196
if not self.svg_err:
9297
# 0 - SUCCESS
@@ -140,6 +145,8 @@ def pytest_addoption(parser):
140145
help="configure the dump directory of profile data files")
141146
group.addoption("--element-number", action="store", type="int", default=20,
142147
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")
143150

144151

145152
def pytest_configure(config):
@@ -148,4 +155,5 @@ def pytest_configure(config):
148155
if profile_enable:
149156
config.pluginmanager.register(Profiling(config.getvalue('profile_svg'),
150157
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

Comments
 (0)