4

I need to capture some python profiling data and generate a report.

While most of this component runs Python 3.5, to support a couple of legacy modules, we still have part of the system that runs 2.7.

In this instance, 3.5 invokes 2.7 via subprocess.Popen() and captures both stdout and stderr (which serve as data and log respectively).

I'm able to run cProfile inside the 2.7 process, write the resulting data to disk, and load it into pStats.

At this point, I can sort/filter and print to console. Unfortunately, as stdout/stderr are already in use, this isn't much help.

I'd also prefer a chance to format, inject source code snippets, etc.

So I need to interrogate the pStats class programmatically, build up a suitable report and then store it in our messaging system.

The documentation doesn't seem to indicate any way to extract data other that writing to console.

the .stats property looks promising but only contains an array of 3-tuples which omit lots of information.

How can I browse the data in pStats programmatically?

Specifically, I want to extract as a minimum:

  • Source file/line number
  • Cumulative time
  • Exclusive time

1 Answer 1

1

Not strictly a complete answer, but you might want to check out the SnakeViz library (with which I am not affiliated). They do some visualisations of cProfile output, which presumably means they have a parser you might be able to hijack.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, that got me to this... github.com/jiffyclub/snakeviz/blob/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.