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
?
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
?
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.