Skip to content

Commit 028e3a8

Browse files
authored
python: PyPerf: Allow passing 0 for --pyperf-user-stacks-pages (#172)
1 parent 8896cce commit 028e3a8

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

gprofiler/gprofiler_types.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,15 @@
1313
UserArgs = Dict[str, Tuple[int, bool, str]]
1414

1515

16-
def positive_integer(value):
16+
def positive_integer(value) -> int:
1717
value = int(value)
1818
if value <= 0:
1919
raise configargparse.ArgumentTypeError("invalid positive integer value: {!r}".format(value))
2020
return value
21+
22+
23+
def nonnegative_integer(value) -> int:
24+
value = int(value)
25+
if value < 0:
26+
raise configargparse.ArgumentTypeError("invalid non-negative integer value: {!r}".format(value))
27+
return value

gprofiler/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def start(self):
214214
raise
215215

216216
# others - are ignored, with a warning.
217-
logger.warning(f"Failed to start {prof.__class__.__name__}, continuing without it")
217+
logger.warning(f"Failed to start {prof.__class__.__name__}, continuing without it", exc_info=True)
218218
self.process_profilers.remove(prof)
219219

220220
def stop(self):

gprofiler/profilers/python.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from psutil import NoSuchProcess, Process
1414

1515
from gprofiler.exceptions import CalledProcessError, ProcessStoppedException, StopEventSetException
16-
from gprofiler.gprofiler_types import ProcessToStackSampleCounters, StackToSampleCount, positive_integer
16+
from gprofiler.gprofiler_types import ProcessToStackSampleCounters, StackToSampleCount, nonnegative_integer
1717
from gprofiler.log import get_logger_adapter
1818
from gprofiler.merge import parse_and_remove_one_collapsed, parse_many_collapsed
1919
from gprofiler.metadata.system_metadata import get_arch
@@ -215,7 +215,7 @@ def start(self):
215215
]
216216

217217
if self.user_stacks_pages is not None:
218-
cmd.extend(["--user-stacks-pages", self.user_stacks_pages])
218+
cmd.extend(["--user-stacks-pages", str(self.user_stacks_pages)])
219219

220220
process = start_process(cmd, via_staticx=True)
221221
# wait until the transient data file appears - because once returning from here, PyPerf may
@@ -289,7 +289,12 @@ def stop(self):
289289
" or disabled (no runtime profilers for Python).",
290290
profiler_arguments=[
291291
ProfilerArgument(
292-
"--pyperf-user-stacks-pages", dest="python_pyperf_user_stacks_pages", default=None, type=positive_integer
292+
"--pyperf-user-stacks-pages",
293+
dest="python_pyperf_user_stacks_pages",
294+
default=None,
295+
type=nonnegative_integer,
296+
help="Number of user stack-pages that PyPerf will collect, this controls the maximum stack depth of native"
297+
" user frames. Pass 0 to disable user native stacks altogether.",
293298
)
294299
],
295300
)

0 commit comments

Comments
 (0)