src/eric7/DebugClients/Python/PyProfile.py

branch
eric7
changeset 10417
c6011e501282
parent 9653
e67609152c5e
child 10439
21c28b0f9e41
equal deleted inserted replaced
10416:5d807e997391 10417:c6011e501282
26 26
27 def __init__(self, basename, timer=None, bias=None): 27 def __init__(self, basename, timer=None, bias=None):
28 """ 28 """
29 Constructor 29 Constructor
30 30
31 @param basename name of the script to be profiled (string) 31 @param basename name of the script to be profiled
32 @type str
32 @param timer function defining the timing calculation 33 @param timer function defining the timing calculation
33 @param bias calibration value (float) 34 @type function
35 @param bias calibration value
36 @type float
34 """ 37 """
35 try: 38 try:
36 profile.Profile.__init__(self, timer, bias) 39 profile.Profile.__init__(self, timer, bias)
37 except TypeError: 40 except TypeError:
38 profile.Profile.__init__(self, timer) 41 profile.Profile.__init__(self, timer)
73 76
74 def dump_stats(self, file): 77 def dump_stats(self, file):
75 """ 78 """
76 Public method to dump the statistics data. 79 Public method to dump the statistics data.
77 80
78 @param file name of the file to write to (string) 81 @param file name of the file to write to
82 @type str
79 """ 83 """
80 self.create_stats() 84 self.create_stats()
81 with contextlib.suppress(OSError, pickle.PickleError), open(file, "wb") as f: 85 with contextlib.suppress(OSError, pickle.PickleError), open(file, "wb") as f:
82 pickle.dump(self.stats, f, 4) 86 pickle.dump(self.stats, f, 4)
83 87
89 if os.path.exists(self.timingCache): 93 if os.path.exists(self.timingCache):
90 os.remove(self.timingCache) 94 os.remove(self.timingCache)
91 95
92 def fix_frame_filename(self, frame): 96 def fix_frame_filename(self, frame):
93 """ 97 """
94 Public method used to fixup the filename for a given frame. 98 Public method used to fix up the filename for a given frame.
95 99
96 The logic employed here is that if a module was loaded 100 The logic employed here is that if a module was loaded
97 from a .pyc file, then the correct .py to operate with 101 from a .pyc file, then the correct .py to operate with
98 should be in the same path as the .pyc. The reason this 102 should be in the same path as the .pyc. The reason this
99 logic is needed is that when a .pyc file is generated, the 103 logic is needed is that when a .pyc file is generated, the
102 pyc is generated. If files are moved from machine to machine 106 pyc is generated. If files are moved from machine to machine
103 this can break debugging as the .pyc will refer to the .py 107 this can break debugging as the .pyc will refer to the .py
104 on the original machine. Another case might be sharing 108 on the original machine. Another case might be sharing
105 code over a network... This logic deals with that. 109 code over a network... This logic deals with that.
106 110
107 @param frame the frame object 111 @param frame frame object
108 @return fixed up file name (string) 112 @type frame
113 @return fixed up file name
114 @rtype str
109 """ 115 """
110 versionExt = ".py3" 116 versionExt = ".py3"
111 117
112 # get module name from __file__ 118 # get module name from __file__
113 if ( 119 if (
132 138
133 This is a variant of the one found in the standard Python 139 This is a variant of the one found in the standard Python
134 profile.py calling fix_frame_filename above. 140 profile.py calling fix_frame_filename above.
135 141
136 @param frame reference to the call frame 142 @param frame reference to the call frame
143 @type frame
137 @param t arguments 144 @param t arguments
138 @return flag indicating a successful handling (boolean) 145 @type list of Any
146 @return flag indicating a successful handling
147 @rtype int
139 """ 148 """
140 if self.cur and frame.f_back is not self.cur[-2]: 149 if self.cur and frame.f_back is not self.cur[-2]:
141 rpt, rit, ret, rfn, rframe, rcur = self.cur 150 rpt, rit, ret, rfn, rframe, rcur = self.cur
142 if not isinstance(rframe, profile.Profile.fake_frame): 151 if not isinstance(rframe, profile.Profile.fake_frame):
143 assert rframe.f_back is frame.f_back, ( # secok 152 assert rframe.f_back is frame.f_back, ( # secok

eric ide

mercurial