ui: Arm telemetry cpu manager, telemetry plugin, and page to load cpus
Add the com.arm.ArmTelemetry UI plugin for loading Arm CPU telemetry specifications and generating derived CPU metric tracks from PMU counter data.
This change adds a Support > Arm CPU page where users can load Arm CPU specification files, inspect the loaded specs in a tree view. Loaded specs are stored in a persistent plugin setting so they survive page reloads.
The plugin uses those specs during trace load to identify supported CPU metrics, create the required intermediate tables/views, compute metric values from PMU counters, and register per-CPU metric tracks under the Hardware workspace group.
Key Changes:
Add Arm telemetry CPU spec parsing and validation. Add a persistent plugin setting for loaded CPU specs. Add the Support > Arm CPU page for loading, viewing, and clearing specs. Add trace-load processing for Arm telemetry metrics. Create CPU activity and PMU counter views needed for metric computation. Generate per-CPU metric tables from spec formulas. Register metric counter tracks in the workspace.
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).
View this failed invocation of the CLA check for more information.
For the most up to date status, view the checks section at the bottom of the pull request.
@primiano Thanks for the comments. I will work on the layering of the code.
Hi @primiano I have re-architectured the code by splitting it into focused plugins
com.arm.ArmTelemetrySpec: owns the shared Arm telemetry spec manager/registry, including parsing, validation, registration, and lookup of loaded CPU specs.com.arm.ArmCpuPage: provides the UI page under Support for loading and browsing Arm CPU specs. It depends onArmTelemetrySpecand updates the shared spec registry through that plugin.com.arm.ArmTelemetry: consumes the shared spec registry to expose trace-side Arm telemetry and derived metric functionality.com.arm.ArmPmuRecorder: also depends onArmTelemetrySpecand consumes the shared registry to drive PMU recording configuration from the loaded CPU specs (This is in #5286 )
Can you please look at this?
Hey thanks, looks much better. a few questions, see comments above
My main high level questions:
- What is that Spec thing doing? it's not a real plugin.
- The plugin ID should match the directory name, like the others
- The injection of that static seems a bit weird. why isn't that jinjected
A lot of that injection can be largely avoided using the ctx.plugins.getPlugin(ClassName) That returns an instance of the per-trace plugin instantiation, which avoid all the plumbing through the static member you are doing.
See other precedent for using ctx.plugins.getPlugin in the codebase
also add OWNERS
Hi @primiano You’re right about ArmTelemetrySpec: it should not really be a separate plugin. It could be folded into ArmCpuPage.
The intent was to initialize the telemetry manager when that functionality is enabled. That manager then needs to be shared across multiple consumers, such as PmuRecorder and ArmTelemetry.
This cannot be trace-scoped, because both PmuRecorder and ArmCpuPage need access to it before any trace is loaded. So the real question is what the right pattern is for app-scoped shared state here: should ArmCpuPage initialize a global registry/service that other plugins can read and update, or is there a more idiomatic way in this codebase to expose shared app-level state across plugins?
Hi @primiano You’re right about ArmTelemetrySpec: it should not really be a separate plugin. It could be folded into ArmCpuPage.
The intent was to initialize the telemetry manager when that functionality is enabled. That manager then needs to be shared across multiple consumers, such as PmuRecorder and ArmTelemetry.
This cannot be trace-scoped, because both PmuRecorder and ArmCpuPage need access to it before any trace is loaded. So the real question is what the right pattern is for app-scoped shared state here: should ArmCpuPage initialize a global registry/service that other plugins can read and update, or is there a more idiomatic way in this codebase to expose shared app-level state across plugins?
Can you explain a bit your design and what you are intending to do? sorry it's a bit hard to reverse engineer from your code
can hyou give a clear indication on:
- what needs to be app scoped (what does it do and when)
- what needs to be trace scoped
it's fine to have app-scoped thing into a static member of your plugin class, if it's truly app-scoped.
but then you are doing all that seemingly to just call this.app.raf.scheduleFullRedraw();, where instead you could just call m.redraw()
I think that would largely simplify your architecture
Below are thre functional pieces in the current design. Among them, ArmTelemetrySpec is not clearly a “real plugin” in the usual sense.
ArmTelemetrySpec
ArmTelemetrySpec is currently just the holder/initializer for the shared telemetry-spec manager which parses, stores, updates, and serves CPU telemetry specs to other consumers. This is why it feels less like a real plugin and more like app-scoped shared infrastructure. ArmCpuPage and ArmPmuRecorder are app-level consumers of a shared CPU telemetry spec manager.
ArmCpuPage
This is an app-level UI/plugin. Its job is to register the /cpu page, and then render the CPU-spec browser UI for the user. It is the UI entry point for loading and inspecting CPU telemetry specs. It reads/writes telemetry-spec manager's spec registry. This plugin exists before any trace is loaded.
ArmPmuRecorder
This is also app-level. It integrates into the record UI by registering a PMU subpage during onActivate(), so it exists before any trace is loaded. It reads the shared telemetry manager's spec registry, and uses those specs to build the perf event config for recording. It listens for spec changes, and can also load/update CPU spec files from the recorder UI itself.
ArmTelemetry
ArmTelemetry is the trace-level consumer that uses those specs to derive metrics and create tracks for the currently loaded trace.
And underneath those, we have:
ArmTelemetryManager
This is the real shared data structure. It parses JSON specs, validates them, stores them by CPU id, and notifies listeners when specs change. That is the app-scoped shared state the other pieces are using.
So the intended split is:
App-scoped/shared: the telemetry spec manager and the features that use it before trace load (ArmCpuPage, ArmPmuRecorder). Trace-scoped: ArmTelemetry, which consumes the shared specs together with the current trace to build tracks.
Below are thre functional pieces in the current design. Among them, ArmTelemetrySpec is not clearly a “real plugin” in the usual sense.
ArmTelemetrySpecArmTelemetrySpec is currently just the holder/initializer for the shared telemetry-spec manager which parses, stores, updates, and serves CPU telemetry specs to other consumers. This is why it feels less like a real plugin and more like app-scoped shared infrastructure.ArmCpuPageandArmPmuRecorderare app-level consumers of a shared CPU telemetry spec manager.
ArmCpuPageThis is an app-level UI/plugin. Its job is to register the /cpu page, and then render the CPU-spec browser UI for the user. It is the UI entry point for loading and inspecting CPU telemetry specs. It reads/writes telemetry-spec manager's spec registry. This plugin exists before any trace is loaded.
ArmPmuRecorderThis is also app-level. It integrates into the record UI by registering a PMU subpage during onActivate(), so it exists before any trace is loaded. It reads the shared telemetry manager's spec registry, and uses those specs to build the perf event config for recording. It listens for spec changes, and can also load/update CPU spec files from the recorder UI itself.
ArmTelemetryArmTelemetry is the trace-level consumer that uses those specs to derive metrics and create tracks for the currently loaded trace.And underneath those, we have:
ArmTelemetryManagerThis is the real shared data structure. It parses JSON specs, validates them, stores them by CPU id, and notifies listeners when specs change. That is the app-scoped shared state the other pieces are using.So the intended split is:
App-scoped/shared: the telemetry spec manager and the features that use it before trace load (ArmCpuPage, ArmPmuRecorder). Trace-scoped: ArmTelemetry, which consumes the shared specs together with the current trace to build tracks.
Thanks for the explanation. My main reaction to all this is: why are you breaking it down into so many plugins? It feels to me that a lot of the architectural complexity here is self-induced by the fact that you are breaking down code that is rather tightly coupled (so much that you felt the need to create a "ArmTelemetrySpec shared infrastructure holder") into N plugins. Frankly a lot of these problems would go away if... this was just a plugin, because you would have one clean context that you can use OnActivate.
Also from a user viewpoint, if you split things into N plugins, you'll need to remember to ask people that want to use your solution to enable N plugins, which is going to be inconvenient for your users.
I really don't see a big value into splitting your works in plugins that need each other to operate.
is there a good reason why this is not one ArmTelemetry plugin?
Thanks for the explanation. My main reaction to all this is: why are you breaking it down into so many plugins? It feels to me that a lot of the architectural complexity here is self-induced by the fact that you are breaking down code that is rather tightly coupled (so much that you felt the need to create a "ArmTelemetrySpec shared infrastructure holder") into N plugins. Frankly a lot of these problems would go away if... this was just a plugin, because you would have one clean context that you can use OnActivate.
Also from a user viewpoint, if you split things into N plugins, you'll need to remember to ask people that want to use your solution to enable N plugins, which is going to be inconvenient for your users.
I really don't see a big value into splitting your works in plugins that need each other to operate.
is there a good reason why this is not one ArmTelemetry plugin?
Yes, the current split is probably over-architected. My original intent was to separate the recording UI, the CPU spec browsing/loading UI, and the trace-analysis logic, mainly to keep each piece smaller and conceptually focused, but it makes things complex. So I will work on making it a single ArmTelemetry plugin, with: app-scoped initialization in onActivate() for the shared telemetry spec registry and any pre-trace UI such as CPU page / recorder integration. trace-scoped work in onTraceLoad() for the actual metric derivation and track creation.
@primiano Folded everything into one plugin - ArmTelemetry.
Btw on top of my comments above (please look at them), I suggest using AI agents to self-review.
THey spot a lot of stuff TBH.
This is what I got within 5 minutes with /review PR #5284
Don't take everything as gold as it exaggerated / got too pendantic in various places (e.g. the sql injection, doesn't seem a real risk). But worth having an overall look
Outstanding from prior review
- OWNERS file is still missing — primiano explicitly asked for one in the last
round.
- private static manager (index.ts:481). primiano questioned this
static-injection pattern. With everything in one plugin, this can just be a
regular instance field (or moved to be created lazily). The manager outlives
the trace, but the plugin singleton outlives the trace too — there is no need
for static. The static also makes it impossible to test the plugin in
isolation.
- app.raf.scheduleFullRedraw() inside the manager
(arm_telemetry_spec_manager_impl.ts:241,250). primiano suggested m.redraw().
Since the manager only exists to push UI updates on registry changes, dropping
the App injection and using m.redraw() would let the manager be a plain class
with no app coupling.
Correctness / bugs
- AsyncDisposableStack reuse bug (index.ts:725). Once asyncDispose() is
called, subsequent defer() throws. The code disposes _metricsThrash then
immediately calls _metricsThrash!.defer(...) on the same instance at lines 754
and 1014. After the second updateMetricTracks invocation, those defer calls
will throw. You need to assign a fresh new AsyncDisposableStack() after
disposing.
- SQL injection / breakage via counter name (index.ts:660-684). tableName goes
through sqlNameSafe(), but ${counterName} is interpolated raw three times
(the _counter column alias, the bare delta column alias, and name like
'${counterName}'). Counter names come from perf_counter_track.name in the
trace; a name containing a quote, space, or SQL keyword breaks the query.
Either sanitize the column aliases the same way, or quote the column with "…"
and use = with parameter binding (or at minimum quote-escape). Also, like
should be = — wildcard matching is almost certainly not intended and LIKE is
slower.
- Re-entry race in updateMetricTracks (index.ts:694-795). Two concurrent
triggers can both observe _updating == false between awaits. The "captured
ctx" check helps but doesn't fully serialize. Consider a single inflight
promise (this._pendingUpdate = this._pendingUpdate?.then(...) ?? doUpdate()).
- update() doesn't fire 'REMOVE' (arm_telemetry_spec_manager_impl.ts:243-254).
The old desc is disposed and replaced — listeners get only 'UPDATE', fine —
but the callback type also includes 'REMOVE' which is never emitted by any
code path. Either implement remove() or drop the variant.
- Querying input by global selector (cpu_page.ts:397).
document.querySelector('input.cpu_file') will collide if the page is mounted
twice or if any other widget uses that class. Use
m.vnode.dom.querySelector(...) or a closure-local ref.
- Throwing inside FileReader.onloadend (cpu_page.ts:367-380). Exceptions in
async event handlers are swallowed; the user gets no feedback for malformed
JSON. Surface a UI error (toast / inline banner) instead.
- Validation O(n²) (arm_telemetry_spec_manager_impl.ts:164-209).
eventNames.includes(...) inside .every(...) over potentially-large dicts.
Convert to Set once.
- getCpuId collision risk (arm_telemetry_spec.ts:87). implementer +
part_num.toString(16) without a separator means implementer "0x4" + part
0x1d8d and implementer "0x41" + part 0xd8d produce the same id. Either
zero-pad or join with a delimiter. (SME2_SPEC_CPUID = '0x41d8d' in
index.ts:458 shows the same flat encoding — pick one canonical form and use it
everywhere.)
- UNION vs UNION ALL (index.ts:969,1003,1006). UNION deduplicates by sorting
all rows. The idle/busy partitions are disjoint by (ts, cpu), and metrics
across CPUs are disjoint by cpu. Use UNION ALL — significant perf win on large
traces.
Style / minor
- Dead comment // minimal: false, at cpu_page.ts:391.
- Typos: _metricsThrash should be _metricsTrash (it mirrors the ctx.trash
API); "asociated" (index.ts:550); "begining" (index.ts:589, cpu_page.ts
summary); "pendng" (index.ts:692).
- == vs === at index.ts:854,855,943,944.
- Number(desc.product_configuration.part_num).toString(16)
(arm_telemetry_spec.ts:90) — part_num is already typed as string in the
schema; either coerce in the schema or document that it accepts hex strings.
- The line in index.ts:514: (_change: 'ADD' | 'REMOVE' | 'UPDATE', _desc:
ArmTelemetryCpuSpec) => { setTimeout(() => this.updateMetricTracks(), 0); } —
the setTimeout 0 is a manual deferral; if used to break a sync re-entrant
call, document it. Otherwise, drop it.
- License headers say 2026; cpu_page.ts says 2025. Pick one.
- Counter name passed straight into SQL also is not just an injection issue —
counter names with hyphens/dots like l1d-cache-load-miss (common in perf) are
not valid SQL identifiers and will fail today even before any malicious input.
Worth confirming this works with real Arm perf counter names.
Tests
No tests. At minimum, a unit test for validateArmTelemetrySpec (covering
missing-event-in-metric, missing-metric-in-group, etc.) would be cheap and
high-value, since that's the bulk of pure logic in the PR.
Risks
- The whole metric pipeline executes spec-supplied formulas verbatim as SQL
fragments. That's by design (the formulas are SQL), but it means a malicious
- Defines a zod schema for an Arm CPU telemetry spec (events, metrics, methodologies) — arm_telemetry_spec.ts.
- Provides an app-scoped registry that parses, validates, stores, and notifies on changes — arm_telemetry_spec_manager{,_impl}.ts.
- Adds a sidebar page under "Support" with a JSON file uploader and a tree view of loaded specs — cpu_page.ts.
- On trace load, builds per-counter SQL views joined with CPU-busy slices, derives metric tables from spec formulas, and creates MetricCounterTrack entries under Hardware/CPU metrics — index.ts.
The latest revision folds everything into one plugin (per the prior review thread). High level architecture is now reasonable; most outstanding issues are inside index.ts.
Outstanding from prior review
- OWNERS file is still missing — primiano explicitly asked for one in the last round.
- private static manager (index.ts:481). primiano questioned this static-injection pattern. With everything in one plugin, this can just be a regular instance field (or moved to be created lazily). The manager outlives the trace, but the
plugin singleton outlives the trace too — there is no need for static. The static also makes it impossible to test the plugin in isolation.
- app.raf.scheduleFullRedraw() inside the manager (arm_telemetry_spec_manager_impl.ts:241,250). primiano suggested m.redraw(). Since the manager only exists to push UI updates on registry changes, dropping the App injection and using
m.redraw() would let the manager be a plain class with no app coupling.
Correctness / bugs
- AsyncDisposableStack reuse bug (index.ts:725). Once asyncDispose() is called, subsequent defer() throws. The code disposes _metricsThrash then immediately calls _metricsThrash!.defer(...) on the same instance at lines 754 and 1014.
After the second updateMetricTracks invocation, those defer calls will throw. You need to assign a fresh new AsyncDisposableStack() after disposing.
- SQL injection / breakage via counter name (index.ts:660-684). tableName goes through sqlNameSafe(), but ${counterName} is interpolated raw three times (the _counter column alias, the bare delta column alias, and name like
'${counterName}'). Counter names come from perf_counter_track.name in the trace; a name containing a quote, space, or SQL keyword breaks the query. Either sanitize the column aliases the same way, or quote the column with "…" and use =
with parameter binding (or at minimum quote-escape). Also, like should be = — wildcard matching is almost certainly not intended and LIKE is slower.
- Re-entry race in updateMetricTracks (index.ts:694-795). Two concurrent triggers can both observe _updating == false between awaits. The "captured ctx" check helps but doesn't fully serialize. Consider a single inflight promise
(this._pendingUpdate = this._pendingUpdate?.then(...) ?? doUpdate()).
- update() doesn't fire 'REMOVE' (arm_telemetry_spec_manager_impl.ts:243-254). The old desc is disposed and replaced — listeners get only 'UPDATE', fine — but the callback type also includes 'REMOVE' which is never emitted by any code
path. Either implement remove() or drop the variant.
- Querying input by global selector (cpu_page.ts:397). document.querySelector('input.cpu_file') will collide if the page is mounted twice or if any other widget uses that class. Use m.vnode.dom.querySelector(...) or a closure-local ref.
- Throwing inside FileReader.onloadend (cpu_page.ts:367-380). Exceptions in async event handlers are swallowed; the user gets no feedback for malformed JSON. Surface a UI error (toast / inline banner) instead.
- Validation O(n²) (arm_telemetry_spec_manager_impl.ts:164-209). eventNames.includes(...) inside .every(...) over potentially-large dicts. Convert to Set once.
- getCpuId collision risk (arm_telemetry_spec.ts:87). implementer + part_num.toString(16) without a separator means implementer "0x4" + part 0x1d8d and implementer "0x41" + part 0xd8d produce the same id. Either zero-pad or join with a
delimiter. (SME2_SPEC_CPUID = '0x41d8d' in index.ts:458 shows the same flat encoding — pick one canonical form and use it everywhere.)
- UNION vs UNION ALL (index.ts:969,1003,1006). UNION deduplicates by sorting all rows. The idle/busy partitions are disjoint by (ts, cpu), and metrics across CPUs are disjoint by cpu. Use UNION ALL — significant perf win on large traces.
Style / minor
- Dead comment // minimal: false, at cpu_page.ts:391.
- Typos: _metricsThrash should be _metricsTrash (it mirrors the ctx.trash API); "asociated" (index.ts:550); "begining" (index.ts:589, cpu_page.ts summary); "pendng" (index.ts:692).
- == vs === at index.ts:854,855,943,944.
- Number(desc.product_configuration.part_num).toString(16) (arm_telemetry_spec.ts:90) — part_num is already typed as string in the schema; either coerce in the schema or document that it accepts hex strings.
- The line in index.ts:514: (_change: 'ADD' | 'REMOVE' | 'UPDATE', _desc: ArmTelemetryCpuSpec) => { setTimeout(() => this.updateMetricTracks(), 0); } — the setTimeout 0 is a manual deferral; if used to break a sync re-entrant call,
document it. Otherwise, drop it.
- License headers say 2026; cpu_page.ts says 2025. Pick one.
- Counter name passed straight into SQL also is not just an injection issue — counter names with hyphens/dots like l1d-cache-load-miss (common in perf) are not valid SQL identifiers and will fail today even before any malicious input.
Worth confirming this works with real Arm perf counter names.
I'm still trying to understand exactly how this plugin is indented to be used to bear with me.
From what I understand, the main user journey is something like this:
- Load a spec sheet (before or after a trace is loaded).
- Load a trace.
- Depending on the content of the spec, this can affect which tracks show up in the timeline.
- If the user changes the spec sheet while a trace is loaded, this will immediately update the list of tracks.
I have a few questions:
- Is this flow correct?
- It seems like a pain to have to load a spec sheet every time you load up the UI, would it make more sense to keep the spec sheet(s) loaded in a persistent setting?
- How important is it that loading a new spec sheet while a trace is loaded also updates the track list in the timeline? E.g. are spec sheets expected to change often for the same trace?
The reason for asking about 3 in particular is that it seems a lot of the complexity in this plugin is handling changing spec sheets on the fly for a given trace. Perfetto is not really designed to have dynamic tracks in this way. Typically, plugins will inspect a trace at trace load time and add whatever tracks it thinks are relevant, and the user should be able to filter those tracks using the timeline filtering and searching mechanisms.
If this requirement were to be dropped, the plugin would become dead simple. We could load one or more spec sheets into a plugin setting (probably before loading a trace) then every time a trace loads, the plugin consults the spec sheet setting, cross references it with the content of the trace, creates the necessary views and tables, and adds the necessary tracks. If you want to change spec sheets, you modify the setting which prompts you to reload the page, and reload the page, which reloads the trace.
If this approach works for you, this will make the plugin a lot simpler. if not, please let me know and hopefully we can work something out.
Hi @stevegolton You are correct about the flow. It is fair to drop the requirement of changing specs on the while a trace is loaded as that would greately reduce the complexity. I will make these changes. It would also make sense to keep spec in the persistent memory. Regarding this, I have a question - Can we include the currently released specifications in the plugin so users don't have to load them manually?
Hi @stevegolton You are correct about the flow. It is fair to drop the requirement of changing specs on the while a trace is loaded as that would greately reduce the complexity. I will make these changes.
Great - thanks for confirming!
It would also make sense to keep spec in the persistent memory.
Great! You can use the settings API to store the spec sheets persistently - https://perfetto.dev/docs/contributing/ui-plugins#custom-settings. You edit the settings manually from your new page, or you can implement a little widget in that shows up in the settings page to allow editing them there (or both?).
Regarding this, I have a question - Can we include the currently released specifications in the plugin so users don't have to load them manually?
If they're small and can be inlined in the plugin than that should be OK. If they're larger than a few KB then please leave them out. You could always pull them from an external URL, even an external github repo, via a fetch on plugin startup?
Made changes:
- Use settings API to store cpu specs persistently.
- There is no more automatic update of tracks when the specs are updated.
Note on the plugin setting for cpu specs: the setting is edited from the Arm CPU page rather than the global Settings page. The setting page shows a warning about this. Please confirm if this is acceptable.
Hi Team, just a friendly ping on this review. When you get a chance, could someone please take another look and restart the review process?
Hi Team, just a friendly ping on this review. When you get a chance, could someone please take another look and restart the review process?
Apologies for the delay - taking a look this morning.
@stevegolton Thanks for the review. #5286 (pmu recording page) was created as part of this project. This has not been updated for a while, because I was waiting for the architectural changes to be completed and approved. I will update it soon.
@stevegolton Thanks for the review. #5286 (pmu recording page) was created as part of this project. This has not been updated for a while, because I was waiting for the architectural changes to be completed and approved. I will update it soon.
Ah, I was just wondering about that PR. Thanks for letting me know!
Edit: Happy to land as-is (I just need to find you a second stamp), but let me know if you want to land now or address anything first?
@stevegolton Thanks! I’d like to address some of the review comments before landing this. Once these changes are merged, I’ll continue with #5286 and get it updated accordingly.