mirror of
https://github.com/bitwarden/browser
synced 2025-12-06 00:13:28 +00:00
[PM-22544] Add Performance measurement tools (#15475)
Adds logService.mark and logService.measure which are wrappers around performance.mark and performance.measure with extra debug logging for more visibility outside the performance tool.
This commit is contained in:
@@ -54,4 +54,43 @@ export class ConsoleLogService implements LogService {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
measure(
|
||||
start: DOMHighResTimeStamp,
|
||||
trackGroup: string,
|
||||
track: string,
|
||||
name?: string,
|
||||
properties?: [string, any][],
|
||||
): PerformanceMeasure {
|
||||
const measureName = `[${track}]: ${name}`;
|
||||
|
||||
const measure = performance.measure(measureName, {
|
||||
start: start,
|
||||
detail: {
|
||||
devtools: {
|
||||
dataType: "track-entry",
|
||||
track,
|
||||
trackGroup,
|
||||
properties,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
this.info(`${measureName} took ${measure.duration}`, properties);
|
||||
return measure;
|
||||
}
|
||||
|
||||
mark(name: string): PerformanceMark {
|
||||
const mark = performance.mark(name, {
|
||||
detail: {
|
||||
devtools: {
|
||||
dataType: "marker",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
this.info(mark.name, new Date().toISOString());
|
||||
|
||||
return mark;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,4 +6,28 @@ export abstract class LogService {
|
||||
abstract warning(message?: any, ...optionalParams: any[]): void;
|
||||
abstract error(message?: any, ...optionalParams: any[]): void;
|
||||
abstract write(level: LogLevel, message?: any, ...optionalParams: any[]): void;
|
||||
|
||||
/**
|
||||
* Helper wrapper around `performance.measure` to log a measurement. Should also debug-log the data.
|
||||
*
|
||||
* @param start Start time of the measurement.
|
||||
* @param trackGroup A track-group for the measurement, should generally be the team owning the domain.
|
||||
* @param track A track for the measurement, should generally be the class name.
|
||||
* @param measureName A descriptive name for the measurement.
|
||||
* @param properties Additional properties to include.
|
||||
*/
|
||||
abstract measure(
|
||||
start: DOMHighResTimeStamp,
|
||||
trackGroup: string,
|
||||
track: string,
|
||||
measureName: string,
|
||||
properties?: [string, any][],
|
||||
): PerformanceMeasure;
|
||||
|
||||
/**
|
||||
* Helper wrapper around `performance.mark` to log a mark. Should also debug-log the data.
|
||||
*
|
||||
* @param name Name of the mark to create.
|
||||
*/
|
||||
abstract mark(name: string): PerformanceMark;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user