Skip to content

Commit 2775fc2

Browse files
committed
Merge pull request #453 from Microsoft/reportMemoryUsage
Include memory usage in -diagnostics report
2 parents f622cb4 + 7d3c006 commit 2775fc2

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/compiler/sys.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface System {
1414
createDirectory(directoryName: string): void;
1515
getExecutingFilePath(): string;
1616
getCurrentDirectory(): string;
17-
getMemoryUsage(): number;
17+
getMemoryUsage?(): number;
1818
exit(exitCode?: number): void;
1919
}
2020

@@ -128,9 +128,6 @@ var sys: System = (function () {
128128
getCurrentDirectory() {
129129
return new ActiveXObject("WScript.Shell").CurrentDirectory;
130130
},
131-
getMemoryUsage() {
132-
return 0;
133-
},
134131
exit(exitCode?: number): void {
135132
try {
136133
WScript.Quit(exitCode);
@@ -234,7 +231,9 @@ var sys: System = (function () {
234231
return (<any>process).cwd();
235232
},
236233
getMemoryUsage() {
237-
global.gc();
234+
if (global.gc) {
235+
global.gc();
236+
}
238237
return process.memoryUsage().heapUsed;
239238
},
240239
exit(exitCode?: number): void {

src/compiler/tsc.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,12 +337,16 @@ module ts {
337337

338338
reportDiagnostics(errors);
339339
if (commandLine.options.diagnostics) {
340+
var memoryUsed = sys.getMemoryUsage ? sys.getMemoryUsage() : -1;
340341
reportCountStatistic("Files", program.getSourceFiles().length);
341342
reportCountStatistic("Lines", countLines(program));
342343
reportCountStatistic("Nodes", checker ? checker.getNodeCount() : 0);
343344
reportCountStatistic("Identifiers", checker ? checker.getIdentifierCount() : 0);
344345
reportCountStatistic("Symbols", checker ? checker.getSymbolCount() : 0);
345346
reportCountStatistic("Types", checker ? checker.getTypeCount() : 0);
347+
if (memoryUsed >= 0) {
348+
reportStatisticalValue("Memory used", Math.round(memoryUsed / 1000) + "K");
349+
}
346350
reportTimeStatistic("Parse time", bindStart - parseStart);
347351
reportTimeStatistic("Bind time", checkStart - bindStart);
348352
reportTimeStatistic("Check time", emitStart - checkStart);

0 commit comments

Comments
 (0)