eric6/DebugClients/Python/PyProfile.py

changeset 7639
422fd05e9c91
parent 7637
c878e8255972
child 7690
a59680062837
equal deleted inserted replaced
7638:176145438b1e 7639:422fd05e9c91
8 8
9 import os 9 import os
10 import marshal 10 import marshal
11 import profile 11 import profile
12 import atexit 12 import atexit
13 import pickle # secok 13 import pickle
14 14
15 15
16 class PyProfile(profile.Profile): 16 class PyProfile(profile.Profile):
17 """ 17 """
18 Class extending the standard Python profiler with additional methods. 18 Class extending the standard Python profiler with additional methods.
54 try: 54 try:
55 cache = open(self.timingCache, 'rb') 55 cache = open(self.timingCache, 'rb')
56 timings = marshal.load(cache) # secok 56 timings = marshal.load(cache) # secok
57 if isinstance(timings, dict): 57 if isinstance(timings, dict):
58 self.timings = timings 58 self.timings = timings
59 except Exception: # secok 59 except (EnvironmentError, EOFError, ValueError, TypeError):
60 pass 60 pass
61 finally: 61 finally:
62 cache.close() 62 cache.close()
63 63
64 def save(self): 64 def save(self):
67 """ 67 """
68 # dump the raw timing data 68 # dump the raw timing data
69 try: 69 try:
70 cache = open(self.timingCache, 'wb') 70 cache = open(self.timingCache, 'wb')
71 marshal.dump(self.timings, cache) 71 marshal.dump(self.timings, cache)
72 except Exception: # secok 72 except EnvironmentError:
73 pass 73 pass
74 finally: 74 finally:
75 cache.close() 75 cache.close()
76 76
77 # dump the profile data 77 # dump the profile data
84 @param file name of the file to write to (string) 84 @param file name of the file to write to (string)
85 """ 85 """
86 try: 86 try:
87 f = open(file, 'wb') 87 f = open(file, 'wb')
88 self.create_stats() 88 self.create_stats()
89 pickle.dump(self.stats, f, 2) 89 pickle.dump(self.stats, f, 4)
90 except (EnvironmentError, pickle.PickleError): 90 except (EnvironmentError, pickle.PickleError):
91 pass 91 pass
92 finally: 92 finally:
93 f.close() 93 f.close()
94 94
176 "c_call": profile.Profile.trace_dispatch_c_call, 176 "c_call": profile.Profile.trace_dispatch_c_call,
177 "c_exception": profile.Profile.trace_dispatch_return, 177 "c_exception": profile.Profile.trace_dispatch_return,
178 # the C function returned 178 # the C function returned
179 "c_return": profile.Profile.trace_dispatch_return, 179 "c_return": profile.Profile.trace_dispatch_return,
180 } 180 }
181
182 #
183 # eflag: noqa = M702

eric ide

mercurial