Skip to content

Fix cumulative value calculation for recursive functions in Table view#6128

Open
secfree wants to merge 1 commit into
parca-dev:mainfrom
secfree:251225-fix-cumulative
Open

Fix cumulative value calculation for recursive functions in Table view#6128
secfree wants to merge 1 commit into
parca-dev:mainfrom
secfree:251225-fix-cumulative

Conversation

@secfree

@secfree secfree commented Dec 25, 2025

Copy link
Copy Markdown
Contributor

Problem

In the Table view, recursive functions (functions that appear multiple times in the same call stack) may display Cumulative (%) values greater than 100%. For example (tested with parca 0.25.0):

image

Root Cause

When building the table, the code iterates through each frame in a stacktrace and adds the sample value to that function's cumulative. When a function appears multiple times in the same stacktrace (due to recursion), its cumulative value gets counted multiple times.

Example:

Stacktrace: [A → B → A → D], value = 50

Before fix:
  Frame A: cumulative += 50  → 50
  Frame B: cumulative += 50  → 50
  Frame A: cumulative += 50  → 100  // Counted twice!
  Frame D: cumulative += 50  → 50

Function A Cumulative (%) = 100/50 = 200%  // Exceeds 100%

Solution

Track which table rows have been counted for each sample using a seenInSample map. Only add to cumulative for the first occurrence of a function in each sample, while still maintaining caller/callee relationships for all occurrences.

After fix:
  Frame A: first seen, +50     → cumulative = 50
  Frame B: first seen, +50     → cumulative = 50
  Frame A: already seen, SKIP  → cumulative = 50 (unchanged)
  Frame D: first seen, +50     → cumulative = 50

Function A Cumulative (%) = 50/50 = 100% 

@secfree secfree requested a review from a team as a code owner December 25, 2025 05:42
@secfree

secfree commented Jan 6, 2026

Copy link
Copy Markdown
Contributor Author

@brancz can you help take a look? Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant