refactor(options): measure options performance via the timing API
This will reduce the clutter in the console log.
Change-Id: Iab14f06595842dd0d37667abaa36b0c48f116172
diff --git a/src/common/options/optionsUtils.js b/src/common/options/optionsUtils.js
index 055e46b..7514643 100644
--- a/src/common/options/optionsUtils.js
+++ b/src/common/options/optionsUtils.js
@@ -71,8 +71,13 @@
// #!endif
export function getOptions(options, requireOptionalPermissions = true) {
// #!if !production
- let timeLabel = 'getOptions--' + randomId + '-' + (timerId++);
- console.time(timeLabel);
+ const timeLabel = 'getOptions--' + randomId + '-' + (timerId++);
+ const startMark = `mark_start_get_options_${timeLabel}`;
+ const grantedPermissionsCheckMark =
+ `mark_get_options_check_granted_permissions_${timeLabel}`;
+ const endMark = `mark_end_get_options_${timeLabel}`;
+ const measureName = `measure_get_options_${timeLabel}`;
+ window.performance.mark(startMark, {detail: {options}});
// #!endif
// Once we only target MV3, this can be greatly simplified.
return new Promise((resolve, reject) => {
@@ -117,9 +122,8 @@
// https://developer.chrome.com/docs/extensions/mv3/content_scripts/
// #!if !production
- console.debug(
- 'We are about to start checking granted permissions');
- console.timeLog(timeLabel);
+ window.performance.mark(
+ grantedPermissionsCheckMark, {detail: {options}});
// #!endif
if (!chrome.permissions) {
return chrome.runtime.sendMessage(
@@ -152,15 +156,21 @@
})
// #!if !production
.then(items => {
- console.group('getOptions(options); resolved; options: ', options);
- console.timeEnd(timeLabel);
- console.groupEnd();
+ window.performance.mark(endMark, {detail: {options}});
+ window.performance.measure(measureName, {
+ detail: {options},
+ start: startMark,
+ end: endMark,
+ });
return items;
})
.catch(err => {
- console.group('getOptions(options); rejected; options: ', options);
- console.timeEnd(timeLabel);
- console.groupEnd();
+ window.performance.mark(endMark, {detail: {options}});
+ window.performance.measure(measureName, {
+ detail: {options},
+ start: startMark,
+ end: endMark,
+ });
throw err;
})
// #!endif