Skip to content

device_memory_report: lazily initialize CounterTrack instances - #33

Merged
olehkuznetsov merged 6 commits into
android-graphics:mainfrom
jimblacklercorp:bugfix-device-memory-report-lazy-counter-tracks
Sep 17, 2026
Merged

olehkuznetsov merged 6 commits into
android-graphics:mainfrom
jimblacklercorp:bugfix-device-memory-report-lazy-counter-tracks

Conversation

@jimblacklercorp

Copy link
Copy Markdown

Static CounterTrack instances constructed at static initialization time lack process context (parent_uuid), which prevents Perfetto tracks from scoping under the process and being associated with the target application track group. Initializing tracks on first use inside GetCounterTrack ensures they properly bind to ProcessTrack::Current(). It also has the benefit of making the code much terser.

Static CounterTrack instances constructed at static initialization time
lack process context (parent_uuid), which prevents Perfetto tracks from
scoping under the process and being associated with the target application
track group. Initializing tracks on first use inside GetCounterTrack ensures
they properly bind to ProcessTrack::Current().
Add regression tests covering the lazy CounterTrack initialization fix.

Tracks constructed at static initialization time were created before
perfetto::Tracing::Initialize() assigned Track::process_uuid, so they ended
up with parent_uuid == 0 and were emitted as global tracks instead of being
scoped under the process.

@olehkuznetsov olehkuznetsov left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reviewed the lazy CounterTrack initialization and process-scoping tests.

Comment thread layersvt/test/test_devicememoryreport.cpp
Comment thread layersvt/device_memory_report/device_memory_report_perfetto.cpp
Comment thread layersvt/test/test_devicememoryreport.cpp Outdated
Run GetCounterTrackInitializesTracing in a fresh child process via
EXPECT_EXIT with threadsafe death test mode so it tests cold Perfetto
initialization from uninitialized static state.
…rdown

- Declare track_names before tracks to preserve LIFO static destruction order.
- Defer InitializeDeviceMemoryReportPerfetto() until cache miss to avoid std::call_once on fast path.
- Emplace string keys directly from string_view and pass const std::string& to DynamicString.
…g test

Now that static pre-registered tracks have been removed in favor of lazy
creation, remove the obsolete comment about pre-registered tracks.
@olehkuznetsov
olehkuznetsov merged commit d59c8d4 into android-graphics:main Sep 17, 2026
15 checks passed
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.

2 participants