Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python2..../hotshot
File: stats.py
"""Statistics analyzer for HotShot."""
[0] Fix | Delete
[1] Fix | Delete
import profile
[2] Fix | Delete
import pstats
[3] Fix | Delete
[4] Fix | Delete
import hotshot.log
[5] Fix | Delete
[6] Fix | Delete
from hotshot.log import ENTER, EXIT
[7] Fix | Delete
[8] Fix | Delete
[9] Fix | Delete
def load(filename):
[10] Fix | Delete
return StatsLoader(filename).load()
[11] Fix | Delete
[12] Fix | Delete
[13] Fix | Delete
class StatsLoader:
[14] Fix | Delete
def __init__(self, logfn):
[15] Fix | Delete
self._logfn = logfn
[16] Fix | Delete
self._code = {}
[17] Fix | Delete
self._stack = []
[18] Fix | Delete
self.pop_frame = self._stack.pop
[19] Fix | Delete
[20] Fix | Delete
def load(self):
[21] Fix | Delete
# The timer selected by the profiler should never be used, so make
[22] Fix | Delete
# sure it doesn't work:
[23] Fix | Delete
p = Profile()
[24] Fix | Delete
p.get_time = _brokentimer
[25] Fix | Delete
log = hotshot.log.LogReader(self._logfn)
[26] Fix | Delete
taccum = 0
[27] Fix | Delete
for event in log:
[28] Fix | Delete
what, (filename, lineno, funcname), tdelta = event
[29] Fix | Delete
if tdelta > 0:
[30] Fix | Delete
taccum += tdelta
[31] Fix | Delete
[32] Fix | Delete
# We multiply taccum to convert from the microseconds we
[33] Fix | Delete
# have to the seconds that the profile/pstats module work
[34] Fix | Delete
# with; this allows the numbers to have some basis in
[35] Fix | Delete
# reality (ignoring calibration issues for now).
[36] Fix | Delete
[37] Fix | Delete
if what == ENTER:
[38] Fix | Delete
frame = self.new_frame(filename, lineno, funcname)
[39] Fix | Delete
p.trace_dispatch_call(frame, taccum * .000001)
[40] Fix | Delete
taccum = 0
[41] Fix | Delete
[42] Fix | Delete
elif what == EXIT:
[43] Fix | Delete
frame = self.pop_frame()
[44] Fix | Delete
p.trace_dispatch_return(frame, taccum * .000001)
[45] Fix | Delete
taccum = 0
[46] Fix | Delete
[47] Fix | Delete
# no further work for line events
[48] Fix | Delete
[49] Fix | Delete
assert not self._stack
[50] Fix | Delete
return pstats.Stats(p)
[51] Fix | Delete
[52] Fix | Delete
def new_frame(self, *args):
[53] Fix | Delete
# args must be filename, firstlineno, funcname
[54] Fix | Delete
# our code objects are cached since we don't need to create
[55] Fix | Delete
# new ones every time
[56] Fix | Delete
try:
[57] Fix | Delete
code = self._code[args]
[58] Fix | Delete
except KeyError:
[59] Fix | Delete
code = FakeCode(*args)
[60] Fix | Delete
self._code[args] = code
[61] Fix | Delete
# frame objects are create fresh, since the back pointer will
[62] Fix | Delete
# vary considerably
[63] Fix | Delete
if self._stack:
[64] Fix | Delete
back = self._stack[-1]
[65] Fix | Delete
else:
[66] Fix | Delete
back = None
[67] Fix | Delete
frame = FakeFrame(code, back)
[68] Fix | Delete
self._stack.append(frame)
[69] Fix | Delete
return frame
[70] Fix | Delete
[71] Fix | Delete
[72] Fix | Delete
class Profile(profile.Profile):
[73] Fix | Delete
def simulate_cmd_complete(self):
[74] Fix | Delete
pass
[75] Fix | Delete
[76] Fix | Delete
[77] Fix | Delete
class FakeCode:
[78] Fix | Delete
def __init__(self, filename, firstlineno, funcname):
[79] Fix | Delete
self.co_filename = filename
[80] Fix | Delete
self.co_firstlineno = firstlineno
[81] Fix | Delete
self.co_name = self.__name__ = funcname
[82] Fix | Delete
[83] Fix | Delete
[84] Fix | Delete
class FakeFrame:
[85] Fix | Delete
def __init__(self, code, back):
[86] Fix | Delete
self.f_back = back
[87] Fix | Delete
self.f_code = code
[88] Fix | Delete
[89] Fix | Delete
[90] Fix | Delete
def _brokentimer():
[91] Fix | Delete
raise RuntimeError, "this timer should not be called"
[92] Fix | Delete
[93] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function