|
12 | 12 | PROFILING_MODE_GIL, |
13 | 13 | PROFILING_MODE_WALL, |
14 | 14 | ) |
| 15 | +from .collector import normalize_location |
15 | 16 | from .stack_collector import StackTraceCollector |
16 | 17 |
|
17 | 18 |
|
@@ -117,7 +118,7 @@ def _build_end_record(self): |
117 | 118 |
|
118 | 119 | def _get_or_create_frame_id(self, filename, location, funcname): |
119 | 120 | synthetic = location is None |
120 | | - location_fields = self._normalize_export_location(location) |
| 121 | + location_fields = self._location_to_export_fields(location) |
121 | 122 | func_str_id = self._intern_string(funcname) |
122 | 123 | path_str_id = self._intern_string(filename) |
123 | 124 |
|
@@ -160,34 +161,19 @@ def _intern_string(self, value): |
160 | 161 | return string_id |
161 | 162 |
|
162 | 163 | @staticmethod |
163 | | - def _normalize_export_location(location): |
164 | | - if location is None: |
165 | | - return {"line": 0} |
166 | | - |
167 | | - if isinstance(location, int): |
168 | | - return {"line": max(location, 0)} |
169 | | - |
170 | | - if not isinstance(location, tuple): |
171 | | - lineno = getattr(location, "lineno", 0) |
172 | | - location = ( |
173 | | - lineno, |
174 | | - getattr(location, "end_lineno", lineno), |
175 | | - getattr(location, "col_offset", -1), |
176 | | - getattr(location, "end_col_offset", -1), |
177 | | - ) |
| 164 | + def _location_to_export_fields(location): |
| 165 | + lineno, end_lineno, col_offset, end_col_offset = normalize_location( |
| 166 | + location |
| 167 | + ) |
178 | 168 |
|
179 | | - lineno, end_lineno, col_offset, end_col_offset = location |
180 | | - if not isinstance(lineno, int) or lineno <= 0: |
181 | | - return {"line": 0} |
182 | | - |
183 | | - normalized = {"line": lineno} |
184 | | - if isinstance(end_lineno, int) and end_lineno > 0: |
185 | | - normalized["end_line"] = end_lineno |
186 | | - if isinstance(col_offset, int) and col_offset >= 0: |
187 | | - normalized["col"] = col_offset |
188 | | - if isinstance(end_col_offset, int) and end_col_offset >= 0: |
189 | | - normalized["end_col"] = end_col_offset |
190 | | - return normalized |
| 169 | + fields = {"line": lineno} |
| 170 | + if end_lineno > 0: |
| 171 | + fields["end_line"] = end_lineno |
| 172 | + if col_offset >= 0: |
| 173 | + fields["col"] = col_offset |
| 174 | + if end_col_offset >= 0: |
| 175 | + fields["end_col"] = end_col_offset |
| 176 | + return fields |
191 | 177 |
|
192 | 178 | def _iter_final_agg_entries(self): |
193 | 179 | for frame_record in self._frames: |
|
0 commit comments