Skip to content

Commit 54b2afa

Browse files
committed
Add CounterDisplayConfig to counters in the processed profile format
Make counters self-describing in terms of rendering by adding `display` field of `CounterDisplayConfig` type. The value is derived from a counter's `category` and `name` fields. This data is sufficient to understand how a counter should be rendered allowing us to remove hardcoded logic for each counter. This is the first PR for issue #5752.
1 parent 66e023a commit 54b2afa

12 files changed

Lines changed: 197 additions & 27 deletions

File tree

docs-developer/CHANGELOG-formats.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ Note that this is not an exhaustive list. Processed profile format upgraders can
66

77
## Processed profile format
88

9+
### Version 62
10+
11+
A new `display` field of type `CounterDisplayConfig` was added to `RawCounter`.
12+
This metadata makes counters self-describing in terms of how they are rendered in the UI.
13+
For existing profiles, the display config is derived from the counter's `category` and `name`.
14+
915
### Version 61
1016

1117
The `SourceTable` in `profile.shared.sources` was updated:

src/app-logic/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const GECKO_PROFILE_VERSION = 34;
1212
// The current version of the "processed" profile format.
1313
// Please don't forget to update the processed profile format changelog in
1414
// `docs-developer/CHANGELOG-formats.md`.
15-
export const PROCESSED_PROFILE_VERSION = 61;
15+
export const PROCESSED_PROFILE_VERSION = 62;
1616

1717
// The following are the margin sizes for the left and right of the timeline. Independent
1818
// components need to share these values.

src/profile-logic/process-profile.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ import type {
9797
GeckoSourceTable,
9898
IndexIntoCategoryList,
9999
IndexIntoFrameTable,
100+
CounterDisplayConfig,
100101
} from 'firefox-profiler/types';
101102
import { decompress, isGzip } from 'firefox-profiler/utils/gz';
102103

@@ -972,6 +973,61 @@ function _processSamples(
972973
return samples;
973974
}
974975

976+
/**
977+
* Derive a CounterDisplayConfig from a counter's category and name.
978+
*/
979+
function _deriveCounterDisplay(
980+
category: string,
981+
name: string
982+
): CounterDisplayConfig {
983+
if (category === 'Memory') {
984+
return {
985+
graphType: 'line-accumulated',
986+
unit: 'bytes',
987+
color: 'orange',
988+
markerSchemaLocation: 'timeline-memory',
989+
sortOrder: 2,
990+
label: 'Memory',
991+
};
992+
} else if (category === 'power') {
993+
return {
994+
graphType: 'line-rate',
995+
unit: 'pWh',
996+
color: 'grey',
997+
markerSchemaLocation: null,
998+
sortOrder: 6,
999+
label: name,
1000+
};
1001+
} else if (category === 'Bandwidth') {
1002+
return {
1003+
graphType: 'line-rate',
1004+
unit: 'bytes',
1005+
color: 'blue',
1006+
markerSchemaLocation: null,
1007+
sortOrder: 8,
1008+
label: 'Bandwidth',
1009+
};
1010+
} else if (category === 'CPU' && name === 'processCPU') {
1011+
return {
1012+
graphType: 'line-rate',
1013+
unit: 'percent',
1014+
color: 'grey',
1015+
markerSchemaLocation: null,
1016+
sortOrder: 5,
1017+
label: 'Process CPU',
1018+
};
1019+
}
1020+
1021+
return {
1022+
graphType: 'line-rate',
1023+
unit: '',
1024+
color: 'grey',
1025+
markerSchemaLocation: null,
1026+
sortOrder: 9,
1027+
label: name,
1028+
};
1029+
}
1030+
9751031
/**
9761032
* Converts the Gecko list of counters into the processed format.
9771033
*/
@@ -1031,6 +1087,7 @@ function _processCounters(
10311087
pid: mainThreadPid,
10321088
mainThreadIndex,
10331089
samples: adjustTableTimeDeltas(processedCounterSamples, delta),
1090+
display: _deriveCounterDisplay(category, name),
10341091
});
10351092
return result;
10361093
},

src/profile-logic/processed-profile-versioning.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3049,6 +3049,66 @@ const _upgraders: {
30493049
}
30503050
},
30513051

3052+
[62]: (profile: any) => {
3053+
// Added CounterDisplayConfig to counters. This metadata controls how a
3054+
// counter is rendered (graph type, color, unit, etc.).
3055+
// Derive defaults from the counter's category and name.
3056+
if (profile.counters) {
3057+
for (const counter of profile.counters) {
3058+
if (counter.display !== undefined) {
3059+
continue;
3060+
}
3061+
const { category, name } = counter;
3062+
if (category === 'Memory') {
3063+
counter.display = {
3064+
graphType: 'line-accumulated',
3065+
unit: 'bytes',
3066+
color: 'orange',
3067+
markerSchemaLocation: 'timeline-memory',
3068+
sortOrder: 2,
3069+
label: 'Memory',
3070+
};
3071+
} else if (category === 'power') {
3072+
counter.display = {
3073+
graphType: 'line-rate',
3074+
unit: 'pWh',
3075+
color: 'grey',
3076+
markerSchemaLocation: null,
3077+
sortOrder: 6,
3078+
label: name,
3079+
};
3080+
} else if (category === 'Bandwidth') {
3081+
counter.display = {
3082+
graphType: 'line-rate',
3083+
unit: 'bytes',
3084+
color: 'blue',
3085+
markerSchemaLocation: null,
3086+
sortOrder: 8,
3087+
label: 'Bandwidth',
3088+
};
3089+
} else if (category === 'CPU' && name === 'processCPU') {
3090+
counter.display = {
3091+
graphType: 'line-rate',
3092+
unit: 'percent',
3093+
color: 'grey',
3094+
markerSchemaLocation: null,
3095+
sortOrder: 5,
3096+
label: 'Process CPU',
3097+
};
3098+
} else {
3099+
counter.display = {
3100+
graphType: 'line-rate',
3101+
unit: '',
3102+
color: 'grey',
3103+
markerSchemaLocation: null,
3104+
sortOrder: 9,
3105+
label: name,
3106+
};
3107+
}
3108+
}
3109+
}
3110+
},
3111+
30523112
// If you add a new upgrader here, please document the change in
30533113
// `docs-developer/CHANGELOG-formats.md`.
30543114
};

src/profile-logic/profile-data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2307,7 +2307,7 @@ export function processCounter(rawCounter: RawCounter): Counter {
23072307
color: rawCounter.color,
23082308
pid: rawCounter.pid,
23092309
mainThreadIndex: rawCounter.mainThreadIndex,
2310-
2310+
display: rawCounter.display,
23112311
samples,
23122312
};
23132313

src/test/fixtures/profiles/processed-profile.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import type {
3333
CategoryList,
3434
JsTracerTable,
3535
RawCounter,
36+
CounterDisplayConfig,
3637
TabID,
3738
MarkerPayload,
3839
NetworkPayload,
@@ -1479,6 +1480,18 @@ export function getProfileWithJsTracerEvents(
14791480
return profile;
14801481
}
14811482

1483+
/**
1484+
* Default display configuration for test counters.
1485+
*/
1486+
const DEFAULT_TEST_COUNTER_DISPLAY: CounterDisplayConfig = {
1487+
graphType: 'line-rate',
1488+
unit: '',
1489+
color: 'grey',
1490+
markerSchemaLocation: null,
1491+
sortOrder: 9,
1492+
label: 'My Counter',
1493+
};
1494+
14821495
/**
14831496
* Creates a Counter fixture for a given thread.
14841497
*/
@@ -1504,6 +1517,7 @@ export function getCounterForThread(
15041517
count: sampleTimes.map((_, i) => Math.sin(i)),
15051518
length: thread.samples.length,
15061519
},
1520+
display: DEFAULT_TEST_COUNTER_DISPLAY,
15071521
};
15081522
return counter;
15091523
}
@@ -1541,6 +1555,7 @@ export function getCounterForThreadWithSamples(
15411555
pid: thread.pid,
15421556
mainThreadIndex,
15431557
samples: newSamples,
1558+
display: DEFAULT_TEST_COUNTER_DISPLAY,
15441559
};
15451560
return counter;
15461561
}

src/test/integration/symbolicator-cli/__snapshots__/symbolicator-cli.test.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Object {
8787
"markerSchema": Array [],
8888
"oscpu": "macOS 14.6.1",
8989
"pausedRanges": Array [],
90-
"preprocessedProfileVersion": 61,
90+
"preprocessedProfileVersion": 62,
9191
"processType": 0,
9292
"product": "a.out",
9393
"sampleUnits": Object {
@@ -1415,7 +1415,7 @@ Object {
14151415
"markerSchema": Array [],
14161416
"oscpu": "macOS 14.6.1",
14171417
"pausedRanges": Array [],
1418-
"preprocessedProfileVersion": 61,
1418+
"preprocessedProfileVersion": 62,
14191419
"processType": 0,
14201420
"product": "a.out",
14211421
"sampleUnits": Object {

src/test/store/__snapshots__/profile-view.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ Object {
418418
"oscpu": "",
419419
"physicalCPUs": 0,
420420
"platform": "",
421-
"preprocessedProfileVersion": 61,
421+
"preprocessedProfileVersion": 62,
422422
"processType": 0,
423423
"product": "Firefox",
424424
"sourceURL": "",

0 commit comments

Comments
 (0)