Skip to content

Commit c4b0302

Browse files
committed
Clean up diagnostic timers and -diagnostic output
1 parent f747e5a commit c4b0302

File tree

2 files changed

+41
-44
lines changed

2 files changed

+41
-44
lines changed

src/compiler/program.ts

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
/// <reference path="emitter.ts" />
33

44
module ts {
5+
/* @internal */ export var programTime = 0;
56
/* @internal */ export var emitTime = 0;
67
/* @internal */ export var ioReadTime = 0;
8+
/* @internal */ export var ioWriteTime = 0;
79

810
/** The version of the TypeScript compiler release */
911
export var version = "1.5.0.0";
@@ -35,33 +37,34 @@ module ts {
3537
}
3638
text = "";
3739
}
38-
3940
return text !== undefined ? createSourceFile(fileName, text, languageVersion) : undefined;
4041
}
4142

42-
function writeFile(fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void) {
43-
function directoryExists(directoryPath: string): boolean {
44-
if (hasProperty(existingDirectories, directoryPath)) {
45-
return true;
46-
}
47-
if (sys.directoryExists(directoryPath)) {
48-
existingDirectories[directoryPath] = true;
49-
return true;
50-
}
51-
return false;
43+
function directoryExists(directoryPath: string): boolean {
44+
if (hasProperty(existingDirectories, directoryPath)) {
45+
return true;
46+
}
47+
if (sys.directoryExists(directoryPath)) {
48+
existingDirectories[directoryPath] = true;
49+
return true;
5250
}
51+
return false;
52+
}
5353

54-
function ensureDirectoriesExist(directoryPath: string) {
55-
if (directoryPath.length > getRootLength(directoryPath) && !directoryExists(directoryPath)) {
56-
var parentDirectory = getDirectoryPath(directoryPath);
57-
ensureDirectoriesExist(parentDirectory);
58-
sys.createDirectory(directoryPath);
59-
}
54+
function ensureDirectoriesExist(directoryPath: string) {
55+
if (directoryPath.length > getRootLength(directoryPath) && !directoryExists(directoryPath)) {
56+
var parentDirectory = getDirectoryPath(directoryPath);
57+
ensureDirectoriesExist(parentDirectory);
58+
sys.createDirectory(directoryPath);
6059
}
60+
}
6161

62+
function writeFile(fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void) {
6263
try {
64+
var start = new Date().getTime();
6365
ensureDirectoriesExist(getDirectoryPath(normalizePath(fileName)));
6466
sys.writeFile(fileName, data, writeByteOrderMark);
67+
ioWriteTime += new Date().getTime() - start;
6568
}
6669
catch (e) {
6770
if (onError) {
@@ -119,16 +122,19 @@ module ts {
119122
var diagnostics = createDiagnosticCollection();
120123
var seenNoDefaultLib = options.noLib;
121124
var commonSourceDirectory: string;
125+
var diagnosticsProducingTypeChecker: TypeChecker;
126+
var noDiagnosticsTypeChecker: TypeChecker;
127+
122128
host = host || createCompilerHost(options);
123129

130+
var start = new Date().getTime();
124131
forEach(rootNames, name => processRootFile(name, false));
125132
if (!seenNoDefaultLib) {
126133
processRootFile(host.getDefaultLibFileName(options), true);
127134
}
128-
verifyCompilerOptions();
135+
programTime += new Date().getTime() - start;
129136

130-
var diagnosticsProducingTypeChecker: TypeChecker;
131-
var noDiagnosticsTypeChecker: TypeChecker;
137+
verifyCompilerOptions();
132138

133139
program = {
134140
getSourceFile: getSourceFile,

src/compiler/tsc.ts

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -320,22 +320,16 @@ module ts {
320320
}
321321

322322
function compile(fileNames: string[], compilerOptions: CompilerOptions, compilerHost: CompilerHost) {
323-
ts.ioReadTime = 0;
324-
ts.parseTime = 0;
325-
ts.bindTime = 0;
326-
ts.checkTime = 0;
327-
ts.emitTime = 0;
328-
329-
var start = new Date().getTime();
323+
ioReadTime = 0;
324+
ioWriteTime = 0;
325+
programTime = 0;
326+
bindTime = 0;
327+
checkTime = 0;
328+
emitTime = 0;
330329

331330
var program = createProgram(fileNames, compilerOptions, compilerHost);
332-
var programTime = new Date().getTime() - start;
333-
334331
var exitStatus = compileProgram();
335332

336-
var end = new Date().getTime() - start;
337-
var compileTime = end - programTime;
338-
339333
if (compilerOptions.listFiles) {
340334
forEach(program.getSourceFiles(), file => {
341335
sys.write(file.fileName + sys.newLine);
@@ -356,19 +350,16 @@ module ts {
356350
}
357351

358352
// Individual component times.
359-
// Note: we output 'programTime' as parseTime to match the tsc 1.3 behavior. tsc 1.3
360-
// measured parse time along with read IO as a single counter. We preserve that
361-
// behavior so we can accurately compare times. For actual parse times (in isolation)
362-
// is reported below.
353+
// Note: To match the behavior of previous versions of the compiler, the reported parse time includes
354+
// I/O read time and processing time for triple-slash references and module imports, and the reported
355+
// emit time includes I/O write time. We preserve this behavior so we can accurately compare times.
356+
reportTimeStatistic("I/O read", ioReadTime);
357+
reportTimeStatistic("I/O write", ioWriteTime);
363358
reportTimeStatistic("Parse time", programTime);
364-
reportTimeStatistic("Bind time", ts.bindTime);
365-
reportTimeStatistic("Check time", ts.checkTime);
366-
reportTimeStatistic("Emit time", ts.emitTime);
367-
368-
reportTimeStatistic("Parse time w/o IO", ts.parseTime);
369-
reportTimeStatistic("IO read", ts.ioReadTime);
370-
reportTimeStatistic("Compile time", compileTime);
371-
reportTimeStatistic("Total time", end);
359+
reportTimeStatistic("Bind time", bindTime);
360+
reportTimeStatistic("Check time", checkTime);
361+
reportTimeStatistic("Emit time", emitTime);
362+
reportTimeStatistic("Total time", programTime + bindTime + checkTime + emitTime);
372363
}
373364

374365
return { program, exitStatus };

0 commit comments

Comments
 (0)