File tree Expand file tree Collapse file tree
packages/angular/build/src/tools Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import { createRequire } from 'node:module';
1212import { MessageChannel } from 'node:worker_threads' ;
1313import type { SourceFile } from 'typescript' ;
1414import { WorkerPool } from '../../../utils/worker-pool' ;
15+ import { mergeCumulativeDurations } from '../../esbuild/profiling' ;
1516import type { AngularHostOptions } from '../angular-host' ;
1617import { AngularCompilation , DiagnosticModes , EmitFileResult } from './angular-compilation' ;
1718
@@ -124,10 +125,15 @@ export class ParallelCompilation extends AngularCompilation {
124125 throw new Error ( 'Not implemented in ParallelCompilation.' ) ;
125126 }
126127
127- override diagnoseFiles (
128+ override async diagnoseFiles (
128129 modes = DiagnosticModes . All ,
129130 ) : Promise < { errors ?: PartialMessage [ ] ; warnings ?: PartialMessage [ ] } > {
130- return this . #worker. run ( modes , { name : 'diagnose' } ) ;
131+ const { timings, ...result } = await this . #worker. run ( modes , { name : 'diagnose' } ) ;
132+ if ( timings ) {
133+ mergeCumulativeDurations ( timings ) ;
134+ }
135+
136+ return result ;
131137 }
132138
133139 override emitAffectedFiles ( ) : Promise < Iterable < EmitFileResult > > {
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import assert from 'node:assert';
1111import { randomUUID } from 'node:crypto' ;
1212import { type MessagePort , receiveMessageOnPort } from 'node:worker_threads' ;
1313import { SourceFileCache } from '../../esbuild/angular/source-file-cache' ;
14+ import { getAndClearCumulativeDurations } from '../../esbuild/profiling' ;
1415import type { AngularCompilation , DiagnosticModes } from './angular-compilation' ;
1516import { AotCompilation } from './aot-compilation' ;
1617import { JitCompilation } from './jit-compilation' ;
@@ -121,12 +122,17 @@ export async function initialize(request: InitRequest) {
121122export async function diagnose ( modes : DiagnosticModes ) : Promise < {
122123 errors ?: PartialMessage [ ] ;
123124 warnings ?: PartialMessage [ ] ;
125+ timings ?: Record < string , number [ ] > ;
124126} > {
125127 assert ( compilation ) ;
126128
127129 const diagnostics = await compilation . diagnoseFiles ( modes ) ;
130+ const timings = getAndClearCumulativeDurations ( ) ;
128131
129- return diagnostics ;
132+ return {
133+ ...diagnostics ,
134+ timings,
135+ } ;
130136}
131137
132138export async function emit ( ) {
Original file line number Diff line number Diff line change @@ -14,6 +14,32 @@ export function resetCumulativeDurations(): void {
1414 cumulativeDurations ?. clear ( ) ;
1515}
1616
17+ export function getAndClearCumulativeDurations ( ) : Record < string , number [ ] > | undefined {
18+ if ( ! cumulativeDurations || cumulativeDurations . size === 0 ) {
19+ return undefined ;
20+ }
21+
22+ const data = Object . fromEntries ( cumulativeDurations ) ;
23+
24+ cumulativeDurations . clear ( ) ;
25+
26+ return data ;
27+ }
28+
29+ export function mergeCumulativeDurations ( data : Record < string , number [ ] > ) : void {
30+ cumulativeDurations ??= new Map ( ) ;
31+
32+ for ( const [ name , durations ] of Object . entries ( data ) ) {
33+ let existing = cumulativeDurations . get ( name ) ;
34+ if ( ! existing ) {
35+ existing = [ ] ;
36+ cumulativeDurations . set ( name , existing ) ;
37+ }
38+
39+ existing . push ( ...durations ) ;
40+ }
41+ }
42+
1743export function logCumulativeDurations ( ) : void {
1844 if ( ! debugPerformance || ! cumulativeDurations ) {
1945 return ;
You can’t perform that action at this time.
0 commit comments