Is there a Python profiler that preserves function arguments?

Go Luhng goluhng at gmail.com
Wed Mar 11 17:09:49 EDT 2020


I'm profiling a Python function `foo()` that takes a single argument,
but that argument makes a huge difference in what the function
actually does.

Currently I'm using `cProfile`, which records every call to `foo()` as
if it was the same, preventing me from figuring out what's going on.

Is there a way to get `cProfile`, or any other Python profiler, to
preserve function call arguments, so when I look at the call stack
later (especially using a visualizer like SnakeViz) I can distinguish
between `foo('bar')` and `foo('qux')`?

P.S. arguably this is a code design issue: since `foo('bar')` and
`foo('qux')` do very different things, they should be distinctly-named
separate functions, like `foo_bar()` and `foo_qux()`. However, the
question is whether I can profile them as-is, without refactoring.


More information about the Python-list mailing list