@@ -15,43 +15,33 @@ def __init__(self, sample_interval_usec):
15
15
lambda : collections .defaultdict (int )
16
16
)
17
17
18
- def collect (self , stack_frames ):
19
- for thread_id , frames in stack_frames :
20
- if not frames :
21
- continue
18
+ def _process_frames (self , frames ):
19
+ """Process a single thread's frame stack."""
20
+ if not frames :
21
+ return
22
22
23
- # Process each frame in the stack to track cumulative calls
24
- for frame in frames :
25
- location = (frame .filename , frame .lineno , frame .funcname )
26
- self .result [location ]["cumulative_calls" ] += 1
23
+ # Process each frame in the stack to track cumulative calls
24
+ for frame in frames :
25
+ location = (frame .filename , frame .lineno , frame .funcname )
26
+ self .result [location ]["cumulative_calls" ] += 1
27
27
28
- # The top frame gets counted as an inline call (directly executing)
29
- top_frame = frames [0 ]
30
- top_location = (
31
- top_frame .filename ,
32
- top_frame .lineno ,
33
- top_frame .funcname ,
34
- )
28
+ # The top frame gets counted as an inline call (directly executing)
29
+ top_location = (frames [0 ].filename , frames [0 ].lineno , frames [0 ].funcname )
30
+ self .result [top_location ]["direct_calls" ] += 1
35
31
36
- self .result [top_location ]["direct_calls" ] += 1
32
+ # Track caller-callee relationships for call graph
33
+ for i in range (1 , len (frames )):
34
+ callee_frame = frames [i - 1 ]
35
+ caller_frame = frames [i ]
37
36
38
- # Track caller-callee relationships for call graph
39
- for i in range (1 , len (frames )):
40
- callee_frame = frames [i - 1 ]
41
- caller_frame = frames [i ]
37
+ callee = (callee_frame .filename , callee_frame .lineno , callee_frame .funcname )
38
+ caller = (caller_frame .filename , caller_frame .lineno , caller_frame .funcname )
42
39
43
- callee = (
44
- callee_frame .filename ,
45
- callee_frame .lineno ,
46
- callee_frame .funcname ,
47
- )
48
- caller = (
49
- caller_frame .filename ,
50
- caller_frame .lineno ,
51
- caller_frame .funcname ,
52
- )
40
+ self .callers [callee ][caller ] += 1
53
41
54
- self .callers [callee ][caller ] += 1
42
+ def collect (self , stack_frames ):
43
+ for frames in self ._iter_all_frames (stack_frames ):
44
+ self ._process_frames (frames )
55
45
56
46
def export (self , filename ):
57
47
self .create_stats ()
0 commit comments