@@ -15,43 +15,33 @@ def __init__(self, sample_interval_usec):
1515 lambda : collections .defaultdict (int )
1616 )
1717
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
2222
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
2727
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
3531
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 ]
3736
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 )
4239
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
5341
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 )
5545
5646 def export (self , filename ):
5747 self .create_stats ()
0 commit comments