Skip to content

Comments

fix: enhance native flamegraph to handle empty sample counts#647

Open
harp-intel wants to merge 1 commit intomainfrom
flame-resiliency
Open

fix: enhance native flamegraph to handle empty sample counts#647
harp-intel wants to merge 1 commit intomainfrom
flame-resiliency

Conversation

@harp-intel
Copy link
Contributor

This pull request improves the handling of empty input cases in the mergeSystemFolded function and adds comprehensive unit tests to verify the new behaviors. The changes ensure that the function gracefully handles scenarios where either or both of the input folded stack traces are empty, and provides better logging and error messages.

Enhanced error handling and logging:

  • Updated mergeSystemFolded in flamegraph_tables.go to:
    • Return a specific error only when both the fp and dwarf sample counts are zero, with a clearer error message.
    • Fall back to using the non-empty input when only one of the inputs is empty, and log a warning indicating which source is being used.

Testing improvements:

  • Added flamegraph_tables_test.go with tests for:
    • Using the dwarf stacks when the fp input is empty.
    • Using the fp stacks when the dwarf input is empty.
    • Returning an error when both inputs are empty.

…tests

Signed-off-by: Harper, Jason M <jason.m.harper@intel.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request enhances the mergeSystemFolded function in the flamegraph command to gracefully handle empty input scenarios. Previously, the function would error if either input was empty; now it only errors when both inputs are empty, and falls back to using whichever input is available when only one is empty. This is a practical improvement for real-world scenarios where one profiling method might fail or produce no samples while the other succeeds.

Changes:

  • Modified error handling in mergeSystemFolded to only error when both fp and dwarf sample counts are zero
  • Added fallback logic to use dwarf stacks when fp is empty, and vice versa, with appropriate warning logs
  • Added comprehensive unit tests covering all three edge cases: fp empty, dwarf empty, and both empty

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
cmd/flamegraph/flamegraph_tables.go Enhanced mergeSystemFolded to handle empty inputs with fallback logic and clearer error messages
cmd/flamegraph/flamegraph_tables_test.go Added new test file with tests for empty input scenarios and helper function for parsing folded stacks

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