From 4d62b488b7b39e19d6b35106d8db14df1ec47281 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 14 Aug 2014 10:52:24 -0700 Subject: [PATCH 1/2] Include memory usage in -diagnostics report --- src/compiler/sys.ts | 4 +++- src/compiler/tsc.ts | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index d6c19e61bb4..a5a3ec36fcc 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -234,7 +234,9 @@ var sys: System = (function () { return (process).cwd(); }, getMemoryUsage() { - global.gc(); + if (global.gc) { + global.gc(); + } return process.memoryUsage().heapUsed; }, exit(exitCode?: number): void { diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 054b76c55b2..ca5624875eb 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -337,12 +337,16 @@ module ts { reportDiagnostics(errors); if (commandLine.options.diagnostics) { + var memoryUsed = sys.getMemoryUsage(); reportCountStatistic("Files", program.getSourceFiles().length); reportCountStatistic("Lines", countLines(program)); reportCountStatistic("Nodes", checker ? checker.getNodeCount() : 0); reportCountStatistic("Identifiers", checker ? checker.getIdentifierCount() : 0); reportCountStatistic("Symbols", checker ? checker.getSymbolCount() : 0); reportCountStatistic("Types", checker ? checker.getTypeCount() : 0); + if (memoryUsed) { + reportStatisticalValue("Memory used", Math.round(memoryUsed / 1000) + "K"); + } reportTimeStatistic("Parse time", bindStart - parseStart); reportTimeStatistic("Bind time", checkStart - bindStart); reportTimeStatistic("Check time", emitStart - checkStart); From 7d3c00699229e2e793d3c73d0fd8803d38b6c165 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 14 Aug 2014 13:05:39 -0700 Subject: [PATCH 2/2] Making sys.getMemoryUsage optional. --- src/compiler/sys.ts | 5 +---- src/compiler/tsc.ts | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index a5a3ec36fcc..2f5ff604df3 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -14,7 +14,7 @@ interface System { createDirectory(directoryName: string): void; getExecutingFilePath(): string; getCurrentDirectory(): string; - getMemoryUsage(): number; + getMemoryUsage?(): number; exit(exitCode?: number): void; } @@ -128,9 +128,6 @@ var sys: System = (function () { getCurrentDirectory() { return new ActiveXObject("WScript.Shell").CurrentDirectory; }, - getMemoryUsage() { - return 0; - }, exit(exitCode?: number): void { try { WScript.Quit(exitCode); diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index ca5624875eb..af425c337aa 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -337,14 +337,14 @@ module ts { reportDiagnostics(errors); if (commandLine.options.diagnostics) { - var memoryUsed = sys.getMemoryUsage(); + var memoryUsed = sys.getMemoryUsage ? sys.getMemoryUsage() : -1; reportCountStatistic("Files", program.getSourceFiles().length); reportCountStatistic("Lines", countLines(program)); reportCountStatistic("Nodes", checker ? checker.getNodeCount() : 0); reportCountStatistic("Identifiers", checker ? checker.getIdentifierCount() : 0); reportCountStatistic("Symbols", checker ? checker.getSymbolCount() : 0); reportCountStatistic("Types", checker ? checker.getTypeCount() : 0); - if (memoryUsed) { + if (memoryUsed >= 0) { reportStatisticalValue("Memory used", Math.round(memoryUsed / 1000) + "K"); } reportTimeStatistic("Parse time", bindStart - parseStart);