Skip to content

Commit 3189a8f

Browse files
committed
eh, just copy from heatmap
1 parent 192e54b commit 3189a8f

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

Lib/profiling/sampling/jsonl_collector.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def __init__(self, sample_interval_usec, *, skip_idle=False, mode=None):
4343
self._frame_self = Counter()
4444
self._frame_cumulative = Counter()
4545
self._samples_total = 0
46+
self._seen_frame_ids = set()
4647

4748
self._mode = mode
4849

@@ -51,17 +52,21 @@ def process_frames(self, frames, _thread_id, weight=1):
5152
return
5253

5354
self._samples_total += weight
55+
self._seen_frame_ids.clear()
5456

55-
frame_ids = [
56-
self._get_or_create_frame_id(filename, location, funcname)
57-
for filename, location, funcname, _opcode in frames
58-
]
59-
leaf_frame_id = frame_ids[0]
57+
for i, (filename, location, funcname, _opcode) in enumerate(frames):
58+
frame_id = self._get_or_create_frame_id(filename, location, funcname)
59+
is_leaf = (i == 0)
60+
count_cumulative = frame_id not in self._seen_frame_ids
6061

61-
self._frame_self[leaf_frame_id] += weight
62+
if count_cumulative:
63+
self._seen_frame_ids.add(frame_id)
6264

63-
for frame_id in set(frame_ids):
64-
self._frame_cumulative[frame_id] += weight
65+
if is_leaf:
66+
self._frame_self[frame_id] += weight
67+
68+
if count_cumulative:
69+
self._frame_cumulative[frame_id] += weight
6570

6671
def export(self, filename):
6772
with open(filename, "w", encoding="utf-8") as output:

0 commit comments

Comments
 (0)