Skip to content

Commit 2b27679

Browse files
committed
refactor(@angular-devkit/build-angular): show more cumulative metrics for esbuild perf debug output
When the `NG_BUILD_DEBUG_PERF` environment variable is used to debug performance of the experimental esbuild-based browser application builder, additional information will be logged for cumulative profiling actions. This includes the count, minimum, maximum, and average.
1 parent 1c87de6 commit 2b27679

File tree

1 file changed

+25
-6
lines changed
  • packages/angular_devkit/build_angular/src/builders/browser-esbuild

1 file changed

+25
-6
lines changed

packages/angular_devkit/build_angular/src/builders/browser-esbuild/profiling.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import { debugPerformance } from '../../utils/environment-options';
1010

11-
let cumulativeDurations: Map<string, number> | undefined;
11+
let cumulativeDurations: Map<string, number[]> | undefined;
1212

1313
export function resetCumulativeDurations(): void {
1414
cumulativeDurations?.clear();
@@ -19,20 +19,39 @@ export function logCumulativeDurations(): void {
1919
return;
2020
}
2121

22-
for (const [name, duration] of cumulativeDurations) {
22+
for (const [name, durations] of cumulativeDurations) {
23+
let total = 0;
24+
let min;
25+
let max;
26+
for (const duration of durations) {
27+
total += duration;
28+
if (min === undefined || duration < min) {
29+
min = duration;
30+
}
31+
if (max === undefined || duration > max) {
32+
max = duration;
33+
}
34+
}
35+
const average = total / durations.length;
2336
// eslint-disable-next-line no-console
24-
console.log(`DURATION[${name}]: ${duration.toFixed(9)} seconds`);
37+
console.log(
38+
`DURATION[${name}]: ${total.toFixed(9)}s [count: ${durations.length}; avg: ${average.toFixed(
39+
9,
40+
)}s; min: ${min?.toFixed(9)}s; max: ${max?.toFixed(9)}s]`,
41+
);
2542
}
2643
}
2744

2845
function recordDuration(name: string, startTime: bigint, cumulative?: boolean): void {
2946
const duration = Number(process.hrtime.bigint() - startTime) / 10 ** 9;
3047
if (cumulative) {
31-
cumulativeDurations ??= new Map<string, number>();
32-
cumulativeDurations.set(name, (cumulativeDurations.get(name) ?? 0) + duration);
48+
cumulativeDurations ??= new Map<string, number[]>();
49+
const durations = cumulativeDurations.get(name) ?? [];
50+
durations.push(duration);
51+
cumulativeDurations.set(name, durations);
3352
} else {
3453
// eslint-disable-next-line no-console
35-
console.log(`DURATION[${name}]: ${duration.toFixed(9)} seconds`);
54+
console.log(`DURATION[${name}]: ${duration.toFixed(9)}s`);
3655
}
3756
}
3857

0 commit comments

Comments
 (0)