rkern / line_profiler

(OLD REPO) Line-by-line profiling for Python - Current repo ->
https://github.com/pyutils/line_profiler
Other
3.6k stars 256 forks source link

Strange .lprof file encoding #155

Open andresespinosapc opened 5 years ago

andresespinosapc commented 5 years ago

How can I open the .lprof file? If I open it with nano or other common text editor I get non-understandable symbols, like these:

�^D��^@^@^@^@^@^@^@�^N_line_profiler�� LineStats���)��}�(�^Gtimings�}��^Pvisualization.py�K��^KshowImgAtts���]�(K�K^AK^E��K�K^AK^A��K�K^

Hanaasagi commented 5 years ago

It is a Python object after serialization.

In [8]: import pickle

In [9]: pickle.load(open('t.py.lprof', 'rb'))
Out[9]: <_line_profiler.LineStats at 0x7fade8531e10>

Or just run

$ python -m line_profiler t.py.lprof
Timer unit: 1e-06 s

Total time: 1.00207 s
File: t.py
Function: f at line 2

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
     2                                           @profile
     3                                           def f():
     4         1    1002074.0 1002074.0    100.0      time.sleep(1)