Skip to content

Commit 61ca27a

Browse files
committed
Collect statistics without printing them
This change adds a new flag `-Ycollect-statistics` that enables the same statistics gathering as `-Ystatistics` but without dumping all the statistics to the console. This is useful for build tools that want to collect statistics via a compiler plugin without interfering with the console output or the operation of `-Ystatistics` (if specified explicitly by the user). Note that there is an internal `YstatisticsEnabled` setting that may appear to do this already, but in fact it controls both collecting and printing together. Even if you switched it on internally (without enabling any phase statistics via `-Ystatistics` / `-Yhot-statistics`) you would still get at least the phase timings summary.
1 parent 2429854 commit 61ca27a

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/compiler/scala/tools/nsc/Global.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,7 +1326,7 @@ class Global(var currentSettings: Settings, reporter0: Reporter)
13261326
checkPhaseSettings(including = false, exclusions.map(_.value): _*)
13271327

13281328
// Report the overhead of statistics measurements per every run
1329-
if (settings.areStatisticsEnabled)
1329+
if (settings.areStatisticsEnabled && settings.Ystatistics.value.nonEmpty)
13301330
statistics.reportStatisticsOverhead(reporter)
13311331

13321332
phase = first //parserPhase
@@ -1628,7 +1628,7 @@ class Global(var currentSettings: Settings, reporter0: Reporter)
16281628
}
16291629
symSource.keys foreach (x => resetPackageClass(x.owner))
16301630

1631-
if (timePhases) {
1631+
if (timePhases && settings.Ystatistics.value.nonEmpty) {
16321632
statistics.stopTimer(totalCompileTime, startTotal)
16331633
informTime("total", totalCompileTime.nanos)
16341634
inform("*** Cumulative timers for phases")

src/compiler/scala/tools/nsc/settings/ScalaSettings.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -607,12 +607,14 @@ trait ScalaSettings extends StandardScalaSettings with Warnings { _: MutableSett
607607
.withAbbreviation("-Yshow-symkinds")
608608
val Yshowsymowners = BooleanSetting ("-Vshow-symowners", "Print owner identifiers next to symbol names.")
609609
.withAbbreviation("-Yshow-symowners")
610-
val Ystatistics = PhasesSetting("-Vstatistics", "Print compiler statistics for specific phases", "parser,typer,patmat,erasure,cleanup,jvm")
611-
.withPostSetHook(s => YstatisticsEnabled.value = s.value.nonEmpty)
610+
val Ystatistics = PhasesSetting("-Vstatistics", "Print compiler statistics for specific phases (implies `-Ycollect-statistics`)", "parser,typer,patmat,erasure,cleanup,jvm")
611+
.withPostSetHook(s => if (s.value.nonEmpty) YstatisticsEnabled.value = true)
612612
.withAbbreviation("-Ystatistics")
613613
val YstatisticsEnabled = BooleanSetting("-Ystatistics-enabled", "Internal setting, indicating that statistics are enabled for some phase.").internalOnly().withPostSetHook(s => if (s.value) StatisticsStatics.enableColdStatsAndDeoptimize())
614614
val YhotStatisticsEnabled = BooleanSetting("-Vhot-statistics", s"Enable `${Ystatistics.name}` to also print hot statistics.")
615615
.withAbbreviation("-Yhot-statistics").withPostSetHook(s => if (s.value && YstatisticsEnabled.value) StatisticsStatics.enableHotStatsAndDeoptimize())
616+
val YcollectStatistics = BooleanSetting("-Ycollect-statistics", "Collect cold statistics (quietly, unless `-Vstatistics` is set)")
617+
.withPostSetHook(s => if (s.value) YstatisticsEnabled.value = true)
616618
val Yshowsyms = BooleanSetting("-Vsymbols", "Print the AST symbol hierarchy after each phase.") withAbbreviation "-Yshow-syms"
617619
val Ytyperdebug = BooleanSetting("-Vtyper", "Trace type assignments.") withAbbreviation "-Ytyper-debug"
618620
val Vimplicits = BooleanSetting("-Vimplicits", "Print dependent missing implicits.").withAbbreviation("-Xlog-implicits")

0 commit comments

Comments
 (0)