home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_593 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  2.8 KB  |  92 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import profile
  5. import pstats
  6. import hotshot.log as hotshot
  7. from hotshot.log import ENTER, EXIT
  8.  
  9. def load(filename):
  10.     return StatsLoader(filename).load()
  11.  
  12.  
  13. class StatsLoader:
  14.     
  15.     def __init__(self, logfn):
  16.         self._logfn = logfn
  17.         self._code = { }
  18.         self._stack = []
  19.         self.pop_frame = self._stack.pop
  20.  
  21.     
  22.     def load(self):
  23.         p = Profile()
  24.         p.get_time = _brokentimer
  25.         log = hotshot.log.LogReader(self._logfn)
  26.         taccum = 0
  27.         for event in log:
  28.             (filename, lineno, funcname) = (what,)
  29.             tdelta = event
  30.             if tdelta > 0:
  31.                 taccum += tdelta
  32.             
  33.             if what == ENTER:
  34.                 frame = self.new_frame(filename, lineno, funcname)
  35.                 p.trace_dispatch_call(frame, taccum * 1e-06)
  36.                 taccum = 0
  37.                 continue
  38.             if what == EXIT:
  39.                 frame = self.pop_frame()
  40.                 p.trace_dispatch_return(frame, taccum * 1e-06)
  41.                 taccum = 0
  42.                 continue
  43.         
  44.         return pstats.Stats(p)
  45.  
  46.     
  47.     def new_frame(self, *args):
  48.         
  49.         try:
  50.             code = self._code[args]
  51.         except KeyError:
  52.             code = FakeCode(*args)
  53.             self._code[args] = code
  54.  
  55.         if self._stack:
  56.             back = self._stack[-1]
  57.         else:
  58.             back = None
  59.         frame = FakeFrame(code, back)
  60.         self._stack.append(frame)
  61.         return frame
  62.  
  63.  
  64.  
  65. class Profile(profile.Profile):
  66.     
  67.     def simulate_cmd_complete(self):
  68.         pass
  69.  
  70.  
  71.  
  72. class FakeCode:
  73.     
  74.     def __init__(self, filename, firstlineno, funcname):
  75.         self.co_filename = filename
  76.         self.co_firstlineno = firstlineno
  77.         self.co_name = self.__name__ = funcname
  78.  
  79.  
  80.  
  81. class FakeFrame:
  82.     
  83.     def __init__(self, code, back):
  84.         self.f_back = back
  85.         self.f_code = code
  86.  
  87.  
  88.  
  89. def _brokentimer():
  90.     raise RuntimeError, 'this timer should not be called'
  91.  
  92.