Repository navigation
thermal_monitor: Add thermal monitor binary - #55
Merged
jimblacklercorp merged 6 commits intoNov 6, 2026
Merged
Conversation
Add thermal_monitor, a standalone Android executable that samples the framework thermal state via the NDK AThermal API while a capture is running, and writes it into the trace as atrace counters (ATrace_setCounter): - sherlock.thermal.status: AThermal_getCurrentThermalStatus() (Android 11+). - sherlock.thermal.headroom: AThermal_getThermalHeadroom(0) (Android 12+), multiplied by 1000 because atrace counters are integers. - sherlock.thermal.headroom.forecast: a 10-second headroom forecast (overridable via --forecast-seconds), sampled on alternate ticks because AThermal_getThermalHeadroom() is rate-limited to about 1 Hz whatever the horizon. A failed forecast tick emits no headroom rather than retrying the current headroom, and the forecast is dropped after 3 failures in a row, because a single NaN can just mean the call was rate-limited. - sherlock.thermal.headroom.threshold.<status>: the device-reported thresholds from AThermal_getThermalHeadroomThresholds() (Android 15+), re-emitted with every headroom sample because the monitor starts before tracing does. The monitor polls once a second (--poll-interval-ms can slow it down but not speed it up, because of the rate limit). Unknown arguments and malformed values are logged and ignored. The Android build now targets API 31 (Sherlock's minimum), so the AThermal calls link directly; AThermal_getThermalHeadroomThresholds() (API 35) is weakly linked and guarded by __builtin_available. Android Performance Analyzer ships the binary in its companion APK next to agi_launch_producer, and reads these counters in its trace viewer. It is built and installed to bin/ like agi_launch_producer. The sampling policy (ThermalCollector) has no Android dependencies, so it is built on the host too and unit tested with GoogleTest (test_thermal_collector).
jimblacklercorp
force-pushed
the
add-thermal-monitor
branch
from
November 4, 2026 11:59
1576fab to
205cac3
Compare
emrekultursay
left a comment
There was a problem hiding this comment.
Quick pass. I could not finish reviewing it.
emrekultursay
left a comment
There was a problem hiding this comment.
Quick pass. I could not finish reviewing it.
emrekultursay
left a comment
There was a problem hiding this comment.
Forgot to push? (I don't see Perfetto SDK changes)
- Return a ThermalStatus enum from ThermalSource::CurrentThermalStatus() instead of int. It mirrors AThermalStatus, which the host test build cannot include, and main.cpp static_asserts that the values match. Threshold maps and ThresholdCounterName() are keyed by it too. - Carry headroom as float, as the NDK returns it, instead of double. - Document the headroom range of ThermalSource::ThermalHeadroom(). - Reword the comment on AThermal_getThermalHeadroomThresholds() so it only describes what the monitor does on older Android versions. - Rename ThermalCollector's emit / emit_ to emitter / emitter_.
Write the thermal counters as Perfetto track event counters in a "SherlockThermal" category, in the same way as the device_memory_report layer, instead of with ATrace_setCounter(): - Counters are doubles, so headroom is written as the API's value rather than multiplied by 1000 and rounded. The float is written as the double nearest to its shortest decimal form, so that 0.8f shows as 0.8 rather than 0.800000011920929. - The trace no longer depends on atrace app tags being enabled for the monitor's process. - The headroom thresholds are written once at the start of each tracing session (from a TrackEventSessionObserver) instead of with every current headroom sample, so ThermalCollector reads them at construction and EmitThresholds() writes them. thermal_monitor links the Perfetto SDK from layersvt/perfetto, built as a separate static library so that the availability checks only apply to main.cpp. The stripped arm64 binary is now about 1.3 MB.
Use the NDK's AThermalStatus directly in ThermalSource, ThresholdCounterName() and the threshold maps, instead of the ThermalStatus enum that mirrored it. This drops the enum and the static_asserts in main.cpp that kept it in sync. The host build, which unit tests ThermalCollector, has no NDK, so it puts host_stubs/ on the include path. host_stubs/android/thermal.h declares only the AThermalStatus enum, with its NDK ABI values. Android builds use the real header.
Author
I didn't forget to push but what seems to happen is that GitHub sends the messages as soon as you write them (unlike Gerrit where they are set as drafts and everything sent together). I did see a way around this which is to click 'Start Review' in the Files Changed tab (even though I am replying not reviewing) but currently this is showing Submit Review, so IDK. |
…d-graphics#55 - Rename the Perfetto track event category from SherlockThermal to Thermals and reference ThermalConstants::kTrackEventCategory directly in Perfetto macros. - Log an error and exit with status 1 on unknown CLI flags or missing or malformed integer option values. - Call collector.EmitThresholds() unconditionally at startup and let Perfetto drop the events when the category is disabled. - Remove ToCounterValue() and pass float headroom values directly to the counter emitter.
jimblacklercorp
force-pushed
the
add-thermal-monitor
branch
from
November 6, 2026 13:18
c08b2a8 to
f70f55b
Compare
Author
|
PTAL |
emrekultursay
approved these changes
Nov 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add thermal_monitor, a standalone Android executable that samples the framework thermal state via the NDK AThermal API while a capture is running, and writes it into the trace as atrace counters (ATrace_setCounter):