Skip to content

Commit 16fd7ef

Browse files
committed
Clarify category + subcategory format requirements.
1 parent aa8354e commit 16fd7ef

File tree

2 files changed

+50
-6
lines changed

2 files changed

+50
-6
lines changed

src/profile-logic/import/simpleperf.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { PROCESSED_PROFILE_VERSION } from 'firefox-profiler/app-logic/constants'
66
import type { Milliseconds } from 'firefox-profiler/types/units';
77
import type {
88
CategoryList,
9+
CategoryColor,
910
FrameTable,
1011
FuncTable,
1112
IndexIntoCategoryList,
@@ -64,7 +65,10 @@ class Categories {
6465
return this.categoryList;
6566
}
6667

67-
static createCategory(name: string, color: string): IndexIntoCategoryList {
68+
static createCategory(
69+
name: string,
70+
color: CategoryColor
71+
): IndexIntoCategoryList {
6872
const index = this.categoryList.length;
6973
this.categoryList.push({ name, color, subcategories: ['Other'] });
7074

src/types/profile.js

+45-5
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,21 @@ export type FrameTable = {|
258258
// nativeSymbol, but each has a different func and line.
259259
inlineDepth: number[],
260260

261+
// The category of the frame. This is used to calculate the category of the stack nodes
262+
// which use this frame:
263+
// - If the frame has a null category, the stack node inherits its parent node's category
264+
// and subcategory. If there is no parent node, we use the "default category" (see ProfileMeta.categories).
265+
// - If the frame has a non-null category, this category and subcategory is used for the stack node.
261266
category: (IndexIntoCategoryList | null)[],
267+
268+
// The subcategory of a frame. This is used to calculate the subcategory of the stack nodes
269+
// which use this frame.
270+
// Must be non-null if the frame's category is non-null.
271+
// Ignored if the frame's category is null.
272+
// 0 is always a valid value and refers to the "Other" subcategory (see Category.subcategories).
262273
subcategory: (IndexIntoSubcategoryListForCategory | null)[],
274+
275+
// The frame's function.
263276
func: IndexIntoFuncTable[],
264277

265278
// The symbol index (referring into this thread's nativeSymbols table) corresponding
@@ -391,9 +404,36 @@ export type Lib = {|
391404
codeId: string | null, // e.g. "6132B96B70fd000"
392405
|};
393406

407+
// The list of available category colors.
408+
//
409+
// We don't accept just any CSS color so that the front-end has more freedom about
410+
// picking colors, for example to ensure contrast or to adjust to light/dark modes.
411+
export type CategoryColor =
412+
| 'transparent' // used for "idle" frames / stacks
413+
| 'purple'
414+
| 'green'
415+
| 'orange'
416+
| 'yellow'
417+
| 'lightblue'
418+
| 'blue'
419+
| 'brown'
420+
| 'magenta'
421+
| 'red'
422+
| 'lightred'
423+
| 'darkgrey'
424+
| 'grey'; // <-- "grey" marks the default category
425+
426+
// A category in profile.meta.categories, used for stack frames and call nodes.
394427
export type Category = {|
428+
// The category name.
395429
name: string,
396-
color: string,
430+
431+
// The category color. Must be picked from the CategoryColor list. At least one
432+
// category with color "grey" must be present in the category list.
433+
color: CategoryColor,
434+
435+
// The list of subcategories. Must always have at least one element; subcategory
436+
// zero must be the "Other" subcategory and is used to refer to the category itself.
397437
subcategories: string[],
398438
|};
399439

@@ -739,10 +779,10 @@ export type ProfileMeta = {|
739779
// The extensions property landed in Firefox 60, and is only optional because older
740780
// processed profile versions may not have it. No upgrader was written for this change.
741781
extensions?: ExtensionTable,
742-
// The list of categories as provided by the platform. The categories are present for
743-
// all Firefox profiles, but imported profiles may not include any category support.
744-
// The front-end will provide a default list of categories, but the saved profile
745-
// will not include them.
782+
// The list of categories used in this profile. If present, it must contain at least the
783+
// "default category" which is defined as the first category whose color is "grey" - this
784+
// category usually has the name "Other".
785+
// If meta.categories is not present, a default list is substituted.
746786
categories?: CategoryList,
747787
// The name of the product, most likely "Firefox".
748788
product: 'Firefox' | string,

0 commit comments

Comments
 (0)