google / google/perfetto

[heapprofd] Add thread ID (tid) to heap profile samples

Open
#6,526 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
6.5k
Forks
868
Avg merge
2d 1h
Merged PRs (30d)
218

Description

## Problem

heapprofd aggregates allocations at process (pid) granularity only, with no thread information.

When different business modules run on dedicated threads and call into shared libraries (e.g., protobuf, image decoding, compression), the flamegraph merges all allocations into one view. There is no way to attribute memory
usage to a specific thread without modifying application code.

## Use Case

Thread "VideoDecoder": decode() → utils::decompress() → malloc
Thread "AudioEngine": process() → utils::decompress() → malloc
Thread "NetworkSync": sync() → utils::decompress() → malloc

All three threads produce identical callstacks from `utils::decompress()` downward. The flamegraph shows a large allocation on `utils::decompress`, but it is impossible to determine which business module is the primary
consumer.

## Why existing approaches don't work

| Approach | Limitation |
|----------|-----------|
| Callstack root frame inference | Fails when threads share entry points (e.g., `WorkerThread::run`) |
| Custom Heap API | Requires wrapping every allocation site; cannot track allocations inside third-party libraries or STL containers |
| `traced_perf` (PerfSample has tid) | CPU sampling, not memory semantics — no bytes allocated/freed |
| heapprofd + `linux.process_stats` | No join key between the two — allocations cannot be correlated to threads |

Contributor guide

Open the contributing guide

Research direction

Start with heapprofd's allocation aggregation and heap-profile sample paths, then compare them with traced_perf's PerfSample, which the issue identifies as carrying a tid. Determine how thread identity could be retained and exposed alongside allocation data; done means shared callstacks can be attributed to individual threads without application-side allocation wrappers.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
observability, performance
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.