1 """Statistics analyzer for HotShot."""
8 from hotshot
.log
import ENTER
, EXIT
12 return StatsLoader(filename
).load()
16 def __init__(self
, logfn
):
20 self
.pop_frame
= self
._stack
.pop
23 # The timer selected by the profiler should never be used, so make
24 # sure it doesn't work:
26 p
.get_time
= _brokentimer
27 log
= hotshot
.log
.LogReader(self
._logfn
)
30 what
, (filename
, lineno
, funcname
), tdelta
= event
34 # We multiply taccum to convert from the microseconds we
35 # have to the seconds that the profile/pstats module work
36 # with; this allows the numbers to have some basis in
37 # reality (ignoring calibration issues for now).
40 frame
= self
.new_frame(filename
, lineno
, funcname
)
41 p
.trace_dispatch_call(frame
, taccum
* .000001)
45 frame
= self
.pop_frame()
46 p
.trace_dispatch_return(frame
, taccum
* .000001)
49 # no further work for line events
51 assert not self
._stack
52 return pstats
.Stats(p
)
54 def new_frame(self
, *args
):
55 # args must be filename, firstlineno, funcname
56 # our code objects are cached since we don't need to create
59 code
= self
._code
[args
]
61 code
= FakeCode(*args
)
62 self
._code
[args
] = code
63 # frame objects are create fresh, since the back pointer will
66 back
= self
._stack
[-1]
69 frame
= FakeFrame(code
, back
)
70 self
._stack
.append(frame
)
74 class Profile(profile
.Profile
):
75 def simulate_cmd_complete(self
):
80 def __init__(self
, filename
, firstlineno
, funcname
):
81 self
.co_filename
= filename
82 self
.co_firstlineno
= firstlineno
83 self
.co_name
= self
.__name
__ = funcname
87 def __init__(self
, code
, back
):
93 raise RuntimeError, "this timer should not be called"