playwright-performance-reporter
Version:
Measure and publish performance metrics from browser dev-tools when running playwright
47 lines (46 loc) • 1.49 kB
JavaScript
import { nativeChromiumPlugins, } from '../plugins/index.js';
import { enhanceGarbageCollectionPlugin, } from '../../../helpers/index.js';
export class HeapProfilerSampling {
options;
name = 'heapProfilerSampling';
plugins = [
nativeChromiumPlugins.heapProfilerDomainPlugin,
];
constructor(options) {
this.options = options;
enhanceGarbageCollectionPlugin(nativeChromiumPlugins.heapGarbageCollectorPlugin, this, this.options);
}
/**
* @inheritdoc
*/
async onStart(accumulator, developmentTools) {
return new Promise(async (resolve, reject) => {
try {
await developmentTools.HeapProfiler.startSampling();
}
catch {
reject(new Error('HeapProfiler.startSampling command failed'));
}
resolve();
});
}
/**
* @inheritdoc
*/
async onSampling(accumulator, developmentTools) { }
/**
* @inheritdoc
*/
async onStop(accumulator, developmentTools) {
return new Promise(async (resolve, reject) => {
try {
const stopSamplingResponse = await developmentTools.HeapProfiler.stopSampling();
accumulator.heapProfilerSampling = JSON.stringify(stopSamplingResponse.profile);
}
catch {
reject(new Error('HeapProfiler.stopSampling command failed'));
}
resolve();
});
}
}