Skip to content

Commit f79a78c

Browse files
authored
Merge pull request #41498 from amcasey/RemoveBeginEnd
Fold tracing.begin and end into push and pop
2 parents a5606ec + e8996a3 commit f79a78c

File tree

5 files changed

+33
-41
lines changed

5 files changed

+33
-41
lines changed

src/compiler/binder.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,14 @@ namespace ts {
174174
const binder = createBinder();
175175

176176
export function bindSourceFile(file: SourceFile, options: CompilerOptions) {
177-
const tracingData: tracing.EventData = [tracing.Phase.Bind, "bindSourceFile", { path: file.path }];
178-
tracing.begin(...tracingData);
177+
tracing.push(tracing.Phase.Bind, "bindSourceFile", { path: file.path }, /*separateBeginAndEnd*/ true);
179178
performance.mark("beforeBind");
180179
perfLogger.logStartBindFile("" + file.fileName);
181180
binder(file, options);
182181
perfLogger.logStopBindFile();
183182
performance.mark("afterBind");
184183
performance.measure("Bind", "beforeBind", "afterBind");
185-
tracing.end(...tracingData);
184+
tracing.pop();
186185
}
187186

188187
function createBinder(): (file: SourceFile, options: CompilerOptions) => void {

src/compiler/checker.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36997,13 +36997,12 @@ namespace ts {
3699736997
}
3699836998

3699936999
function checkSourceFile(node: SourceFile) {
37000-
const tracingData: tracing.EventData = [tracing.Phase.Check, "checkSourceFile", { path: node.path }];
37001-
tracing.begin(...tracingData);
37000+
tracing.push(tracing.Phase.Check, "checkSourceFile", { path: node.path }, /*separateBeginAndEnd*/ true);
3700237001
performance.mark("beforeCheck");
3700337002
checkSourceFileWorker(node);
3700437003
performance.mark("afterCheck");
3700537004
performance.measure("Check", "beforeCheck", "afterCheck");
37006-
tracing.end(...tracingData);
37005+
tracing.pop();
3700737006
}
3700837007

3700937008
function unusedIsError(kind: UnusedKind, isAmbient: boolean): boolean {

src/compiler/parser.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -614,8 +614,7 @@ namespace ts {
614614
}
615615

616616
export function createSourceFile(fileName: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes = false, scriptKind?: ScriptKind): SourceFile {
617-
const tracingData: tracing.EventData = [tracing.Phase.Parse, "createSourceFile", { path: fileName }];
618-
tracing.begin(...tracingData);
617+
tracing.push(tracing.Phase.Parse, "createSourceFile", { path: fileName }, /*separateBeginAndEnd*/ true);
619618
performance.mark("beforeParse");
620619
let result: SourceFile;
621620

@@ -630,7 +629,7 @@ namespace ts {
630629

631630
performance.mark("afterParse");
632631
performance.measure("Parse", "beforeParse", "afterParse");
633-
tracing.end(...tracingData);
632+
tracing.pop();
634633
return result;
635634
}
636635

src/compiler/program.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -780,8 +780,7 @@ namespace ts {
780780
// Track source files that are source files found by searching under node_modules, as these shouldn't be compiled.
781781
const sourceFilesFoundSearchingNodeModules = new Map<string, boolean>();
782782

783-
const tracingData: tracing.EventData = [tracing.Phase.Program, "createProgram"];
784-
tracing.begin(...tracingData);
783+
tracing.push(tracing.Phase.Program, "createProgram", {}, /*separateBeginAndEnd*/ true);
785784
performance.mark("beforeProgram");
786785

787786
const host = createProgramOptions.host || createCompilerHost(options);
@@ -1041,7 +1040,7 @@ namespace ts {
10411040
verifyCompilerOptions();
10421041
performance.mark("afterProgram");
10431042
performance.measure("Program", "beforeProgram", "afterProgram");
1044-
tracing.end(...tracingData);
1043+
tracing.pop();
10451044

10461045
return program;
10471046

@@ -1603,8 +1602,7 @@ namespace ts {
16031602

16041603
function emitBuildInfo(writeFileCallback?: WriteFileCallback): EmitResult {
16051604
Debug.assert(!outFile(options));
1606-
const tracingData: tracing.EventData = [tracing.Phase.Emit, "emitBuildInfo"];
1607-
tracing.begin(...tracingData);
1605+
tracing.push(tracing.Phase.Emit, "emitBuildInfo", {}, /*separateBeginAndEnd*/ true);
16081606
performance.mark("beforeEmit");
16091607
const emitResult = emitFiles(
16101608
notImplementedResolver,
@@ -1617,7 +1615,7 @@ namespace ts {
16171615

16181616
performance.mark("afterEmit");
16191617
performance.measure("Emit", "beforeEmit", "afterEmit");
1620-
tracing.end(...tracingData);
1618+
tracing.pop();
16211619
return emitResult;
16221620
}
16231621

@@ -1678,10 +1676,9 @@ namespace ts {
16781676
}
16791677

16801678
function emit(sourceFile?: SourceFile, writeFileCallback?: WriteFileCallback, cancellationToken?: CancellationToken, emitOnlyDtsFiles?: boolean, transformers?: CustomTransformers, forceDtsEmit?: boolean): EmitResult {
1681-
const tracingData: tracing.EventData = [tracing.Phase.Emit, "emit", { path: sourceFile?.path }];
1682-
tracing.begin(...tracingData);
1679+
tracing.push(tracing.Phase.Emit, "emit", { path: sourceFile?.path }, /*separateBeginAndEnd*/ true);
16831680
const result = runWithCancellationToken(() => emitWorker(program, sourceFile, writeFileCallback, cancellationToken, emitOnlyDtsFiles, transformers, forceDtsEmit));
1684-
tracing.end(...tracingData);
1681+
tracing.pop();
16851682
return result;
16861683
}
16871684

src/compiler/tracing.ts

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -92,40 +92,38 @@ namespace ts.tracing {
9292
Emit = "emit",
9393
}
9494

95-
export type EventData = [phase: Phase, name: string, args?: object];
96-
97-
/** Note: `push`/`pop` should be used by default.
98-
* `begin`/`end` are for special cases where we need the data point even if the event never
99-
* terminates (typically for reducing a scenario too big to trace to one that can be completed).
100-
* In the future we might implement an exit handler to dump unfinished events which would
101-
* deprecate these operations.
102-
*/
103-
export function begin(phase: Phase, name: string, args?: object) {
104-
if (!traceFd) return;
105-
writeEvent("B", phase, name, args);
106-
}
107-
export function end(phase: Phase, name: string, args?: object) {
108-
if (!traceFd) return;
109-
writeEvent("E", phase, name, args);
110-
}
111-
11295
export function instant(phase: Phase, name: string, args?: object) {
11396
if (!traceFd) return;
11497
writeEvent("I", phase, name, args, `"s":"g"`);
11598
}
11699

117100
// Used for "Complete" (ph:"X") events
118-
const completeEvents: { phase: Phase, name: string, args?: object, time: number }[] = [];
119-
export function push(phase: Phase, name: string, args?: object) {
101+
const completeEvents: { phase: Phase, name: string, args?: object, time: number, separateBeginAndEnd: boolean }[] = [];
102+
103+
/**
104+
* @param separateBeginAndEnd - used for special cases where we need the trace point even if the event
105+
* never terminates (typically for reducing a scenario too big to trace to one that can be completed).
106+
* In the future we might implement an exit handler to dump unfinished events which would deprecate
107+
* these operations.
108+
*/
109+
export function push(phase: Phase, name: string, args?: object, separateBeginAndEnd = false) {
120110
if (!traceFd) return;
121-
completeEvents.push({ phase, name, args, time: 1000 * timestamp() });
111+
if (separateBeginAndEnd) {
112+
writeEvent("B", phase, name, args);
113+
}
114+
completeEvents.push({ phase, name, args, time: 1000 * timestamp(), separateBeginAndEnd });
122115
}
123116
export function pop() {
124117
if (!traceFd) return;
125118
Debug.assert(completeEvents.length > 0);
126-
const { phase, name, args, time } = completeEvents.pop()!;
127-
const dur = 1000 * timestamp() - time;
128-
writeEvent("X", phase, name, args, `"dur":${dur}`, time);
119+
const { phase, name, args, time, separateBeginAndEnd } = completeEvents.pop()!;
120+
if (separateBeginAndEnd) {
121+
writeEvent("E", phase, name, args);
122+
}
123+
else {
124+
const dur = 1000 * timestamp() - time;
125+
writeEvent("X", phase, name, args, `"dur":${dur}`, time);
126+
}
129127
}
130128

131129
function writeEvent(eventType: string, phase: Phase, name: string, args: object | undefined, extras?: string,

0 commit comments

Comments
 (0)