Skip to content

Fix cdbstack parser dropping last sample and missing metrics#2329

Merged
brianrob merged 3 commits intomainfrom
copilot/fix-last-sample-issue
Nov 12, 2025
Merged

Fix cdbstack parser dropping last sample and missing metrics#2329
brianrob merged 3 commits intomainfrom
copilot/fix-last-sample-issue

Conversation

Copy link
Contributor

Copilot AI commented Nov 12, 2025

Fix for cdbstack - last sample is dropped (Issue)

Plan

  • Explore repository and understand the issue
  • Understand the bug: last sample in file not added when EOF is reached
  • Create test case to demonstrate the bug
  • Fix the bug by adding code after the for loop to handle the last sample
  • Ensure sample.Metric = 1 is set (related to issue No metrics in cdbstacks #1009)
  • Build and test the changes (TraceEvent builds successfully)
  • Manual code review completed
  • Logic verification completed
  • Refactor to extract helper method (addressing code review feedback)
  • Finalize and complete

Changes Made

  1. Extracted helper method: Created AddSampleFromStack() method to eliminate code duplication
  2. Line 113 & 124: Both call sites now use the helper method
  3. Test file: Comprehensive test cases in DebuggerStackSourceTests.cs

Refactoring Details

  • Created AddSampleFromStack() helper method that encapsulates the logic for:
    • Building the call stack from accumulated frames
    • Setting sample.Metric = 1
    • Setting sample properties (StackIndex, TimeRelativeMSec)
    • Adding the sample
  • Both locations (line 94 and line 118 in original) now call this helper
  • Eliminates ~15 lines of duplicated code

Issue Resolution

This PR fully resolves the reported issue where the last sample in a cdbstack file was being dropped at EOF, and addresses the code review feedback to eliminate duplication.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: brianrob <6210322+brianrob@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix last sample not being added in cdbstack Fix cdbstack parser dropping last sample and missing metrics Nov 12, 2025
Copilot AI requested a review from brianrob November 12, 2025 04:28
Copy link
Member

@brianrob brianrob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot, please address this comment.

…cation

Co-authored-by: brianrob <6210322+brianrob@users.noreply.github.com>
@brianrob
Copy link
Member

Copilot Post-Mortem:

  • Bonus points for detecting that there was another issue in the same area (it was referenced) and fixing them both together.

@brianrob brianrob marked this pull request as ready for review November 12, 2025 04:59
Copy link
Collaborator

@leculver leculver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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.

3 participants

Comments