Skip to content

Expose counter information in profiler-cli#6084

Open
fatadel wants to merge 1 commit into
firefox-devtools:mainfrom
fatadel:issue-6040-1
Open

Expose counter information in profiler-cli#6084
fatadel wants to merge 1 commit into
firefox-devtools:mainfrom
fatadel:issue-6040-1

Conversation

@fatadel

@fatadel fatadel commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Add counter list and counter info <handle> commands, and list each counter under its process in profile info, to inspect any counter track from the terminal. Counters get stable c-N handles, like threads and functions.

Per-counter stats come from the counter's own tooltip schema, reusing the timeline tooltips' labels and formatters so the CLI and UI agree. Stats respect the current zoom.

This is only the first iteration for #6040.


Usage examples

➜  profiler git:(issue-6040-1) pq counter list
[Thread: t-7 (GeckoMain) | View: Full profile | Full: 3.449s]

Counters (22):
  c-0: Bandwidth (Bandwidth) - Data transferred in the visible range: 182KB (0.020 g CO₂e) [67 samples]
  c-1: Process CPU (CPU) [345 samples]
...
➜  profiler git:(issue-6040-1) pq counter info c-1
[Thread: t-7 (GeckoMain) | View: Full profile | Full: 3.449s]

Counter c-1: Process CPU
  Name: processCPU
  Category: CPU
  Description: Process CPU utilization
  Unit: percent
  Graph type: line-rate
  Main thread: t-0 (GeckoMain)
  Samples: 345 total, 345 in current range
  Time span: 2h9m → 2h9m
[Thread: t-7 (GeckoMain) | View: Full profile | Full: 3.449s]

Name: Firefox 150 – macOS 26.5.0
Platform: macOS 26.5.0

This profile contains 8 threads across 7 processes.

Top processes and threads by CPU usage:
  p-0: Parent Process [pid 1999] [ts<12W → end] - 297.869ms
    t-0: GeckoMain [tid 16337] - 297.869ms
    c-0: Bandwidth - Data transferred in the visible range: 182KB (0.020 g CO₂e) [67 samples]
    c-1: Process CPU [345 samples]
    c-2: Memory - memory range in graph: 13.7MB [322 samples]
    c-3: Process Power - Energy used in the visible range: 185 µWh (0.088 mg CO₂e) [345 samples]
...

CPU activity over time:
- 22% for 769.4ms: [ts-1 → ts-z] (14.371ms - 3.438s)
  - 60% for 62.0ms: [ts-1 → ts-3] (14.371ms - 117.22ms)
...

@fatadel fatadel requested review from canova and mstange June 4, 2026 12:30
@codecov

codecov Bot commented Jun 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0.86207% with 115 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.43%. Comparing base (a99497b) to head (ec80263).
⚠️ Report is 107 commits behind head on main.

Files with missing lines Patch % Lines
src/profile-query/formatters/counter-info.ts 1.12% 88 Missing ⚠️
src/profile-query/counter-map.ts 0.00% 13 Missing ⚠️
src/profile-query/formatters/profile-info.ts 0.00% 7 Missing ⚠️
src/profile-query/index.ts 0.00% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6084      +/-   ##
==========================================
- Coverage   83.82%   83.43%   -0.39%     
==========================================
  Files         330      339       +9     
  Lines       34682    35690    +1008     
  Branches     9703    10017     +314     
==========================================
+ Hits        29072    29779     +707     
- Misses       5181     5483     +302     
+ Partials      429      428       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@canova

canova commented Jun 4, 2026

Copy link
Copy Markdown
Member

pq profile info --counters: I don't think we should have --counters, we should directly put the counters into the list. Similar to how we have a track list in the profiler UI.

Add `counter list` and `counter info <handle>` commands, and list each
counter under its process in `profile info`, to inspect any counter
track from the terminal. Counters get stable `c-N` handles, like threads
and functions.

Per-counter stats come from the counter's own tooltip schema, reusing
the timeline tooltips' labels and formatters so the CLI and UI agree.
Stats respect the current zoom.

Part of firefox-devtools#6040
@fatadel

fatadel commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

@canova makes sense, updated.

@canova canova left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the PR! Looks great to me with some nits!

One thing I noticed is that I think we don't currently use the sortWeight in the pq profile info command. It would be good to use that so it matches the web frontend. It can be also done as a follow-up.

This is only the first iteration for #6040.

Currently we show the counters in the profile info and get info of them with pq counter info. I think it would be great to get more information of the counter values, similar to "CPU activity over time" section that we have in the pq profile info as a follow-up. What do you think?

const countersByPid = new Map<string, CounterSummary[]>();
(getCounters(state) ?? []).forEach((_, index) => {
const counter = collectCounterSummary(store, threadMap, index);
const pid = String(profile.threads[counter.mainThreadIndex].pid);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

counter has a pid already, we can do counter.pid directly. Also, pids should be string already, no need to do String().

cpuMs: thread.cpuMs,
})),
remainingThreads: processItem.remainingThreads,
counters: countersByPid.get(String(processItem.pid)),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same, I think no need to wrap it with a String.

export type CounterStat = {
source: CounterTooltipDataSource;
label: string;
labelKey?: string;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need labelKey? It was for localization, right? I think we can just remove it as we don't have any i18n in the cli.

start: number,
end: number
): number {
const [begin, finish] = getSampleIndexRangeForSelection(samples, start, end);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: Hm, it would be good to get committedRangeCounterSampleSum from a counter selector instead of computing all the time.

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