Skip to content

Conversation

@korniltsev
Copy link
Contributor

@korniltsev korniltsev commented Jul 30, 2025

Summary

This PR implements a new optional feature that adds thread names as pprof sample labels during JFR to pprof conversion.

Fixes: grafana/pyroscope#4331

Key Features

  • New Configuration Option: WithThreadNameLabels(bool) to enable thread name labels
  • Thread Name Extraction: Extracts thread names from JFR data with fallback hierarchy:
    • JavaName → OsName → "[thread]"
  • Sample Labels: Adds thread_name labels to pprof samples when enabled
  • Backward Compatibility: Feature is disabled by default

Implementation Details

  • Added GetThread() method to parser for accessing thread information
  • Enhanced ProfileBuilder with AddExternalSampleWithLabelsAndThread() method
  • All JFR event types now support thread name labels automatically
  • Thread name extraction follows the same pattern as the existing thread root frame feature

Testing

  • Added comprehensive test coverage with TestThreadNameLabels()
  • All existing tests pass, ensuring no regressions
  • Tests validate that thread names are correctly extracted and added as labels

🤖 Generated with Claude Code

korniltsev and others added 3 commits July 30, 2025 11:28
This commit implements a new optional feature that adds thread names as
pprof sample labels during JFR to pprof conversion.

Fixes: grafana/pyroscope#4331

Key changes:
- Added WithThreadNameLabels(bool) configuration option
- Enhanced ProfileBuilder to support thread name labels via new
  AddExternalSampleWithLabelsAndThread method
- Thread names extracted with fallback hierarchy: JavaName → OsName → "[thread]"
- Added GetThread() method to parser for thread information access
- All JFR event types now support thread name labels
- Comprehensive test coverage with TestThreadNameLabels()
- Feature is disabled by default for backward compatibility

Usage:
  profiles, err := pprof.ParseJFR(data, input, nil, pprof.WithThreadNameLabels(true))

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Extract getThreadName() helper function with fallback hierarchy
- Extract thread name only once if either thread root frame or thread name labels is enabled
- Improve efficiency by avoiding duplicate GetThread() calls and name resolution
- Maintain same functionality and behavior for both features

Co-Authored-By: Claude <[email protected]>
}

// getThreadName extracts thread name with fallback hierarchy: JavaName → OsName → "[thread]"
func (b *jfrPprofBuilders) getThreadName(threadRef types.ThreadRef) string {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should have an option to efficiently process/merge thread names, in case it has too much cardinality and it is a problem

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.

Support thread names in profiles converted from JFR

1 participant