Skip to content

Commit ee31cab

Browse files
committed
up
1 parent 32197d8 commit ee31cab

6 files changed

Lines changed: 14 additions & 54 deletions

File tree

‎Lib/profiling/sampling/collector.py‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,27 @@ def normalize_location(location):
2020
"""Normalize location to a 4-tuple format.
2121
2222
Args:
23-
location: tuple (lineno, end_lineno, col_offset, end_col_offset),
24-
an integer line number, or None
23+
location: tuple (lineno, end_lineno, col_offset, end_col_offset) or None
2524
2625
Returns:
2726
tuple: (lineno, end_lineno, col_offset, end_col_offset)
2827
"""
2928
if location is None:
3029
return DEFAULT_LOCATION
31-
if isinstance(location, int):
32-
return (location, location, -1, -1)
3330
return location
3431

3532

3633
def extract_lineno(location):
3734
"""Extract lineno from location.
3835
3936
Args:
40-
location: tuple (lineno, end_lineno, col_offset, end_col_offset),
41-
an integer line number, or None
37+
location: tuple (lineno, end_lineno, col_offset, end_col_offset) or None
4238
4339
Returns:
4440
int: The line number (0 for synthetic frames)
4541
"""
4642
if location is None:
4743
return 0
48-
if isinstance(location, int):
49-
return location
5044
return location[0]
5145

5246
def _is_internal_frame(frame):

‎Lib/profiling/sampling/gecko_collector.py‎

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -368,11 +368,10 @@ def _record_stack_sample(self, thread_data, frames, tid, times, first_time):
368368
if self.opcodes_enabled and frames:
369369
leaf_frame = frames[0]
370370
filename, location, funcname, opcode = leaf_frame
371-
if isinstance(location, tuple):
372-
lineno, _, col_offset, _ = location
371+
if location is None:
372+
lineno, col_offset = None, -1
373373
else:
374-
lineno = location
375-
col_offset = -1
374+
lineno, _, col_offset, _ = location
376375

377376
current_state = (opcode, lineno, col_offset, funcname, filename)
378377

@@ -541,15 +540,11 @@ def _process_stack(self, thread_data, frames):
541540

542541
for frame_tuple in reversed(frames):
543542
# frame_tuple is (filename, location, funcname, opcode)
544-
# location is (lineno, end_lineno, col_offset, end_col_offset) or just lineno
545543
filename, location, funcname, opcode = frame_tuple
546-
if isinstance(location, tuple):
547-
lineno, end_lineno, col_offset, end_col_offset = location
544+
if location is None:
545+
lineno, col_offset = None, -1
548546
else:
549-
# Legacy format: location is just lineno
550-
lineno = location
551-
col_offset = -1
552-
end_col_offset = -1
547+
lineno, _, col_offset, _ = location
553548

554549
# Get or create function
555550
func_idx = self._get_or_create_func(

‎Lib/profiling/sampling/live_collector/collector.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,6 @@ def process_frames(self, frames, thread_id=None):
313313
self._seen_locations.clear()
314314

315315
# Process each frame in the stack to track cumulative calls
316-
# frame.location is (lineno, end_lineno, col_offset, end_col_offset), int, or None
317316
for frame in frames:
318317
lineno = extract_lineno(frame.location)
319318
location = (frame.filename, lineno, frame.funcname)

‎Lib/profiling/sampling/pstats_collector.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ def _process_frames(self, frames, weight=1):
3030
self._seen_locations.clear()
3131

3232
# Process each frame in the stack to track cumulative calls
33-
# frame.location is int, tuple (lineno, end_lineno, col_offset, end_col_offset), or None
3433
for frame in frames:
3534
lineno = extract_lineno(frame.location)
3635
location = (frame.filename, lineno, frame.funcname)

‎Lib/test/test_profiling/test_sampling_profiler/test_binary_format.py‎

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -63,29 +63,16 @@ def make_interpreter(interp_id, threads):
6363
return InterpreterInfo((interp_id, threads))
6464

6565

66-
def extract_lineno(location):
67-
"""Extract line number from location (tuple or int or None)."""
68-
if location is None:
69-
return 0 # Treat None as 0
70-
if isinstance(location, tuple):
71-
return location[0] if location[0] is not None else 0
72-
return location
73-
74-
7566
def extract_location(location):
7667
"""Extract full location info as dict from location tuple or None."""
7768
if location is None:
7869
return {"lineno": 0, "end_lineno": 0, "column": 0, "end_column": 0}
79-
if isinstance(location, tuple) and len(location) >= 4:
80-
return {
81-
"lineno": location[0] if location[0] is not None else 0,
82-
"end_lineno": location[1] if location[1] is not None else 0,
83-
"column": location[2] if location[2] is not None else 0,
84-
"end_column": location[3] if location[3] is not None else 0,
85-
}
86-
# Fallback for old-style location
87-
lineno = location[0] if isinstance(location, tuple) else location
88-
return {"lineno": lineno or 0, "end_lineno": lineno or 0, "column": 0, "end_column": 0}
70+
return {
71+
"lineno": location[0],
72+
"end_lineno": location[1],
73+
"column": location[2],
74+
"end_column": location[3],
75+
}
8976

9077

9178
def frame_to_dict(frame):

‎Lib/test/test_profiling/test_sampling_profiler/test_collectors.py‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2957,20 +2957,6 @@ def test_extract_lineno_from_none(self):
29572957
"""Test extracting lineno from None (synthetic frames)."""
29582958
self.assertEqual(extract_lineno(None), 0)
29592959

2960-
def test_extract_lineno_from_int(self):
2961-
"""Test extracting lineno from a bare integer line number.
2962-
2963-
Mirrors normalize_location's int contract so callers like the
2964-
collapsed/flamegraph collectors do not crash on a bare-int location.
2965-
"""
2966-
self.assertEqual(extract_lineno(42), 42)
2967-
self.assertEqual(extract_lineno(0), 0)
2968-
2969-
def test_normalize_location_with_int(self):
2970-
"""Test normalize_location expands a legacy integer line number."""
2971-
result = normalize_location(42)
2972-
self.assertEqual(result, (42, 42, -1, -1))
2973-
29742960
def test_normalize_location_with_location_info(self):
29752961
"""Test normalize_location passes through LocationInfo."""
29762962
loc = LocationInfo(10, 15, 0, 5)

0 commit comments

Comments
 (0)