Skip to content

Commit 4518799

Browse files
authored
Merge pull request microsoft#41261 from amcasey/TracingPerf
Stop doing tracing work when tracing is disabled
2 parents 261d03b + e712d42 commit 4518799

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/compiler/tracing.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,22 +101,27 @@ namespace ts.tracing {
101101
* deprecate these operations.
102102
*/
103103
export function begin(phase: Phase, name: string, args?: object) {
104+
if (!traceFd) return;
104105
writeEvent("B", phase, name, args);
105106
}
106107
export function end(phase: Phase, name: string, args?: object) {
108+
if (!traceFd) return;
107109
writeEvent("E", phase, name, args);
108110
}
109111

110112
export function instant(phase: Phase, name: string, args?: object) {
113+
if (!traceFd) return;
111114
writeEvent("I", phase, name, args, `"s":"g"`);
112115
}
113116

114117
// Used for "Complete" (ph:"X") events
115118
const completeEvents: { phase: Phase, name: string, args?: object, time: number }[] = [];
116119
export function push(phase: Phase, name: string, args?: object) {
120+
if (!traceFd) return;
117121
completeEvents.push({ phase, name, args, time: 1000 * timestamp() });
118122
}
119123
export function pop() {
124+
if (!traceFd) return;
120125
Debug.assert(completeEvents.length > 0);
121126
const { phase, name, args, time } = completeEvents.pop()!;
122127
const dur = 1000 * timestamp() - time;
@@ -125,7 +130,7 @@ namespace ts.tracing {
125130

126131
function writeEvent(eventType: string, phase: Phase, name: string, args: object | undefined, extras?: string,
127132
time: number = 1000 * timestamp()) {
128-
if (!traceFd) return;
133+
Debug.assert(traceFd);
129134
Debug.assert(fs);
130135
performance.mark("beginTracing");
131136
fs.writeSync(traceFd, `,\n{"pid":1,"tid":1,"ph":"${eventType}","cat":"${phase}","ts":${time},"name":"${name}"`);

0 commit comments

Comments
 (0)