Skip to content

Commit 84f2b50

Browse files
committed
ci metrics collection issues
1 parent caeb94f commit 84f2b50

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

packages/replay/metrics/configs/ci/collect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function checkStdDev(stats: MetricsStats, name: string, provider: NumberProvider
1818
return true;
1919
}
2020

21-
const collector = new MetricsCollector({ headless: true });
21+
const collector = new MetricsCollector({ headless: true, cpuThrottling: 2 });
2222
const result = await collector.execute({
2323
name: 'jank',
2424
a: new JankTestScenario(false),

packages/replay/metrics/configs/dev/collect.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Metrics, MetricsCollector } from '../../src/collector.js';
22
import { MetricsStats } from '../../src/results/metrics-stats.js';
33
import { JankTestScenario } from '../../src/scenarios.js';
4+
import { printStats } from '../../src/util/console.js';
45
import { latestResultFile } from './env.js';
56

67
const collector = new MetricsCollector();
@@ -12,6 +13,8 @@ const result = await collector.execute({
1213
tries: 1,
1314
async shouldAccept(results: Metrics[]): Promise<boolean> {
1415
const stats = new MetricsStats(results);
16+
printStats(stats);
17+
1518
const cpuUsage = stats.mean(MetricsStats.cpu)!;
1619
if (cpuUsage > 0.9) {
1720
console.error(`CPU usage too high to be accurate: ${(cpuUsage * 100).toFixed(2)} %.`,

packages/replay/metrics/src/collector.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { Scenario, TestCase } from './scenarios.js';
99
import { consoleGroup } from './util/console.js';
1010
import { WebVitals, WebVitalsCollector } from './vitals/index.js';
1111

12-
const cpuThrottling = 4;
1312
const networkConditions = 'Fast 3G';
1413

1514
// Same as puppeteer-core PredefinedNetworkConditions
@@ -42,6 +41,7 @@ export class Metrics {
4241

4342
export interface MetricsCollectorOptions {
4443
headless: boolean;
44+
cpuThrottling: number;
4545
}
4646

4747
export class MetricsCollector {
@@ -50,6 +50,7 @@ export class MetricsCollector {
5050
constructor(options?: Partial<MetricsCollectorOptions>) {
5151
this._options = {
5252
headless: false,
53+
cpuThrottling: 4,
5354
...options
5455
};
5556
}
@@ -59,7 +60,7 @@ export class MetricsCollector {
5960
return consoleGroup(async () => {
6061
const aResults = await this._collect(testCase, 'A', testCase.a);
6162
const bResults = await this._collect(testCase, 'B', testCase.b);
62-
return new Result(testCase.name, cpuThrottling, networkConditions, aResults, bResults);
63+
return new Result(testCase.name, this._options.cpuThrottling, networkConditions, aResults, bResults);
6364
});
6465
}
6566

@@ -119,7 +120,7 @@ export class MetricsCollector {
119120
uploadThroughput: PredefinedNetworkConditions[networkConditions].upload,
120121
downloadThroughput: PredefinedNetworkConditions[networkConditions].download,
121122
});
122-
await cdp.send('Emulation.setCPUThrottlingRate', { rate: cpuThrottling });
123+
await cdp.send('Emulation.setCPUThrottlingRate', { rate: this._options.cpuThrottling });
123124

124125
// Collect CPU and memory info 10 times per second.
125126
const perfSampler = await PerfMetricsSampler.create(cdp, 100);

packages/replay/metrics/src/util/console.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ type PrintableTable = { [k: string]: any };
1313

1414
export function printStats(stats: MetricsStats): void {
1515
console.table({
16-
lcp: `${stats.mean(MetricsStats.lcp)?.toFixed(2)} %`,
17-
cls: `${stats.mean(MetricsStats.cls)?.toFixed(2)} %`,
16+
lcp: `${stats.mean(MetricsStats.lcp)?.toFixed(2)} ms`,
17+
cls: `${stats.mean(MetricsStats.cls)?.toFixed(2)} ms`,
1818
cpu: `${((stats.mean(MetricsStats.cpu) || 0) * 100).toFixed(2)} %`,
1919
memoryMean: filesize(stats.mean(MetricsStats.memoryMean)),
2020
memoryMax: filesize(stats.max(MetricsStats.memoryMax)),

0 commit comments

Comments
 (0)