0

If I do something like

python -m cProfile -o profile.prof myprogram.py

Can one reconstruct the source code from have access to profile.prof?

John Allard
  • 3,564
  • 5
  • 23
  • 42

1 Answers1

0

All the .prof file contains is a marshal serialisation of the very same stats you see when you don't use -o (and thus print the stats).

It's basically a dictionary keyed on function 'label', with per function call stats, aggregated. A function label is defined as:

def label(code):
    if isinstance(code, str):
        return ('~', 0, code)    # built-in functions ('~' sorts at the end)
    else:
        return (code.co_filename, code.co_firstlineno, code.co_name)

So only the filename, line number and function name are recorded, nothing else. You can't reconstruct a full program from this.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343