-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(@angular-devkit/build-angular): add debug profiling support …
…to esbuild angular compiler plugin When using the experimental esbuild-based browser application builder, initial debug performance profiling information can now be output to the console by using the `NG_BUILD_DEBUG_PERF` environment variable. When enabled, duration information for elements of the Angular build pipeline will be shown on the console. Certain elements marked with an asterisk postfix represent the total parallel execution time and will not correlate directly to the total build time. This information is useful for both experimentation with build process improvements as well as diagnosing slow builds.
- Loading branch information
1 parent
8ccf873
commit 0d97c05
Showing
3 changed files
with
194 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
packages/angular_devkit/build_angular/src/builders/browser-esbuild/profiling.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import { debugPerformance } from '../../utils/environment-options'; | ||
|
||
let cumulativeDurations: Map<string, number> | undefined; | ||
|
||
export function resetCumulativeDurations(): void { | ||
cumulativeDurations?.clear(); | ||
} | ||
|
||
export function logCumulativeDurations(): void { | ||
if (!debugPerformance || !cumulativeDurations) { | ||
return; | ||
} | ||
|
||
for (const [name, duration] of cumulativeDurations) { | ||
// eslint-disable-next-line no-console | ||
console.log(`DURATION[${name}]: ${duration} seconds`); | ||
} | ||
} | ||
|
||
function recordDuration(name: string, startTime: bigint, cumulative?: boolean): void { | ||
const duration = Number(process.hrtime.bigint() - startTime) / 10 ** 9; | ||
if (cumulative) { | ||
cumulativeDurations ??= new Map<string, number>(); | ||
cumulativeDurations.set(name, (cumulativeDurations.get(name) ?? 0) + duration); | ||
} else { | ||
// eslint-disable-next-line no-console | ||
console.log(`DURATION[${name}]: ${duration} seconds`); | ||
} | ||
} | ||
|
||
export async function profileAsync<T>( | ||
name: string, | ||
action: () => Promise<T>, | ||
cumulative?: boolean, | ||
): Promise<T> { | ||
if (!debugPerformance) { | ||
return action(); | ||
} | ||
|
||
const startTime = process.hrtime.bigint(); | ||
try { | ||
return await action(); | ||
} finally { | ||
recordDuration(name, startTime, cumulative); | ||
} | ||
} | ||
|
||
export function profileSync<T>(name: string, action: () => T, cumulative?: boolean): T { | ||
if (!debugPerformance) { | ||
return action(); | ||
} | ||
|
||
const startTime = process.hrtime.bigint(); | ||
try { | ||
return action(); | ||
} finally { | ||
recordDuration(name, startTime, cumulative); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters