Skip to content

Commit

Permalink
Merge "ui: recording v2, fix serialization of chrome categories" into…
Browse files Browse the repository at this point in the history
… main
  • Loading branch information
primiano authored and Gerrit Code Review committed Jan 21, 2025
2 parents 7b500ef + 67bdbf6 commit 6105dd9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions ui/src/plugins/dev.perfetto.RecordTraceV2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export default class implements PerfettoPlugin {
);
recMgr.restorePluginStateFromLocalstorage();
}
(window as {} as {recordingMgr: unknown}).recordingMgr = this.recordingMgr;
return this.recordingMgr;
}
}
22 changes: 19 additions & 3 deletions ui/src/plugins/dev.perfetto.RecordTraceV2/pages/chrome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,30 @@ const DISAB_PREFIX = 'disabled-by-default-';

export class ChromeCategoriesWidget implements ProbeSetting {
private options = new Array<MultiSelectOption>();
private fetchedRuntimeCategories = false;

constructor(private chromeCategoryGetter: ChromeCatFunction) {
// Initialize first with the static list of builtin categories (in case
// something goes wrong with the extension).
this.initializeCategories(BUILTIN_CATEGORIES);
// But then try to fetch the updated list from the Tracing Extension and use
// that instead if available.
this.fetchRuntimeCategoriesIfNeeded();
}

private async fetchRuntimeCategoriesIfNeeded() {
if (this.fetchedRuntimeCategories) return;
const runtimeCategories = await this.chromeCategoryGetter();
this.initializeCategories(runtimeCategories);
this.fetchedRuntimeCategories = true;
}

private initializeCategories(cats: string[]) {
this.options = cats
.map((cat) => ({
id: cat,
name: cat.replace(DISAB_PREFIX, ''),
checked: false,
checked: this.options.find((o) => o.id === cat)?.checked ?? false,
}))
.sort((a, b) => a.name.toLowerCase().localeCompare(b.name.toLowerCase()));
}
Expand Down Expand Up @@ -187,8 +200,11 @@ export class ChromeCategoriesWidget implements ProbeSetting {
return m(
'div.chrome-categories',
{
oninit: async () =>
this.initializeCategories(await this.chromeCategoryGetter()),
// This shouldn't be necessary in most cases. It's only needed:
// 1. The first time the user installs the extension.
// 2. In rare cases if the extension fails to respond to the call in the
// constructor, to deal with its flakiness.
oninit: () => this.fetchRuntimeCategoriesIfNeeded(),
},
m(
Section,
Expand Down

0 comments on commit 6105dd9

Please sign in to comment.