DebugClients/Python/PyProfile.py

changeset 945
8cd4d08fa9f6
parent 791
9ec2ac20e54e
child 1509
c0b5e693b0eb
equal deleted inserted replaced
944:1b59c4ba121e 945:8cd4d08fa9f6
10 import marshal 10 import marshal
11 import profile 11 import profile
12 import atexit 12 import atexit
13 import pickle 13 import pickle
14 14
15
15 class PyProfile(profile.Profile): 16 class PyProfile(profile.Profile):
16 """ 17 """
17 Class extending the standard Python profiler with additional methods. 18 Class extending the standard Python profiler with additional methods.
18 19
19 This class extends the standard Python profiler by the functionality to 20 This class extends the standard Python profiler by the functionality to
20 save the collected timing data in a timing cache, to restore these data 21 save the collected timing data in a timing cache, to restore these data
21 on subsequent calls, to store a profile dump to a standard filename and 22 on subsequent calls, to store a profile dump to a standard filename and
22 to erase these caches. 23 to erase these caches.
23 """ 24 """
24 def __init__(self, basename, timer=None, bias=None): 25 def __init__(self, basename, timer=None, bias=None):
25 """ 26 """
26 Constructor 27 Constructor
111 112
112 @param frame the frame object 113 @param frame the frame object
113 """ 114 """
114 # get module name from __file__ 115 # get module name from __file__
115 if not isinstance(frame, profile.Profile.fake_frame) and \ 116 if not isinstance(frame, profile.Profile.fake_frame) and \
116 frame.f_globals.has_key('__file__'): 117 '__file__' in frame.f_globals:
117 root, ext = os.path.splitext(frame.f_globals['__file__']) 118 root, ext = os.path.splitext(frame.f_globals['__file__'])
118 if ext == '.pyc' or ext == '.py': 119 if ext == '.pyc' or ext == '.py':
119 fixedName = root + '.py' 120 fixedName = root + '.py'
120 if os.path.exists(fixedName): 121 if os.path.exists(fixedName):
121 return fixedName 122 return fixedName
142 fcode = frame.f_code 143 fcode = frame.f_code
143 fn = (self.fix_frame_filename(frame), 144 fn = (self.fix_frame_filename(frame),
144 fcode.co_firstlineno, fcode.co_name) 145 fcode.co_firstlineno, fcode.co_name)
145 self.cur = (t, 0, 0, fn, frame, self.cur) 146 self.cur = (t, 0, 0, fn, frame, self.cur)
146 timings = self.timings 147 timings = self.timings
147 if timings.has_key(fn): 148 if fn in timings:
148 cc, ns, tt, ct, callers = timings[fn] 149 cc, ns, tt, ct, callers = timings[fn]
149 timings[fn] = cc, ns + 1, tt, ct, callers 150 timings[fn] = cc, ns + 1, tt, ct, callers
150 else: 151 else:
151 timings[fn] = 0, 0, 0, 0, {} 152 timings[fn] = 0, 0, 0, 0, {}
152 return 1 153 return 1

eric ide

mercurial