pyroscope icon indicating copy to clipboard operation
pyroscope copied to clipboard

feat: Add ability to GroupBy Samples by line number and relative line number to function start

Open simonswine opened this issue 3 weeks ago • 0 comments

Feature Request

Summary

Add the ability to group profiling samples by more granular code location attributes, specifically:

  • Absolute line number within a file
  • Relative line number from function start

Motivation

Currently, samples are primarily grouped by function/method names. However, for complex functions with multiple code paths, it would be valuable to analyze performance at a more granular level by grouping samples by specific line numbers within those functions.

This would enable users to:

  • Identify performance hotspots within large functions
  • Analyze specific code paths or branches more precisely
  • Understand which lines within a function consume the most resources
  • Compare performance across different sections of the same function

Prior Art: pprof Granularity Options

The pprof tool already supports multiple granularity levels for aggregation:

granularity
  -functions       Aggregate at the function level.
  -filefunctions   Aggregate at the function level.
  -files           Aggregate at the file level.
  -lines           Aggregate at the source code line level.
  -addresses       Aggregate at the address level.

Pyroscope could provide similar GroupBy options, particularly implementing the -lines equivalent for line-level aggregation.

Use Cases

  1. Long function optimization: Identify which sections of a large function are the bottleneck
  2. Loop analysis: See which iterations or branches within loops consume the most time
  3. Conditional path analysis: Understand performance differences between if/else branches
  4. Source code correlation: Make it easier to map profiling data directly to specific source lines

Additional Considerations

  • UI/UX considerations for displaying line-level granularity
  • Performance implications of querying at line-level granularity
  • Could also consider file-level and address-level grouping similar to pprof

simonswine avatar Dec 04 '25 09:12 simonswine