@@ -208,6 +208,7 @@ private [profile] class RealProfiler(reporter : ProfileReporter)(using Context)
208208 }
209209
210210 reporter.header(this )
211+ traceCounters()
211212
212213 override def finished (): Unit = {
213214 // we may miss a GC event if gc is occurring as we call this
@@ -253,11 +254,11 @@ private [profile] class RealProfiler(reporter : ProfileReporter)(using Context)
253254 override def afterPhase (event : TracedEventId , phase : Phase , snapBefore : ProfileSnap ): Unit = {
254255 assert(mainThread eq Thread .currentThread())
255256 val initialSnap = RealProfiler .snapThread(0 )
256- if (ctx.settings.YprofileExternalTool .value.contains(phase.toString )) {
257+ if (ctx.settings.YprofileExternalTool .value.contains(phase.phaseName )) {
257258 println(" Profile hook stop" )
258259 ExternalToolHook .after()
259260 }
260- val finalSnap = if (ctx.settings.YprofileRunGcBetweenPhases .value.contains(phase.toString )) {
261+ val finalSnap = if (ctx.settings.YprofileRunGcBetweenPhases .value.contains(phase.phaseName )) {
261262 doGC()
262263 initialSnap.updateHeap(RealProfiler .readHeapUsage())
263264 }
@@ -270,9 +271,9 @@ private [profile] class RealProfiler(reporter : ProfileReporter)(using Context)
270271 override def beforePhase (phase : Phase ): (TracedEventId , ProfileSnap ) = {
271272 assert(mainThread eq Thread .currentThread())
272273 val eventId = traceDurationStart(Category .Phase , phase.phaseName)
273- if (ctx.settings.YprofileRunGcBetweenPhases .value.contains(phase.toString ))
274+ if (ctx.settings.YprofileRunGcBetweenPhases .value.contains(phase.phaseName ))
274275 doGC()
275- if (ctx.settings.YprofileExternalTool .value.contains(phase.toString )) {
276+ if (ctx.settings.YprofileExternalTool .value.contains(phase.phaseName )) {
276277 println(" Profile hook start" )
277278 ExternalToolHook .before()
278279 }
@@ -290,17 +291,20 @@ private [profile] class RealProfiler(reporter : ProfileReporter)(using Context)
290291 val now = System .nanoTime()
291292 traceDurationEnd(Category .File , event)
292293 if now > nextAfterUnitSnap then
293- val initialSnap = RealProfiler .snapThread(0 )
294- chromeTrace.traceCounterEvent(" allocBytes" , " allocBytes" , initialSnap.allocatedBytes, processWide = false )
295- chromeTrace.traceCounterEvent(" heapBytes" , " heapBytes" , initialSnap.heapBytes, processWide = true )
296- chromeTrace.traceCounterEvent(" classesLoaded" , " classesLoaded" , initialSnap.totalClassesLoaded, processWide = true )
297- chromeTrace.traceCounterEvent(" jitCompilationTime" , " jitCompilationTime" , initialSnap.totalJITCompilationTime, processWide = true )
298- chromeTrace.traceCounterEvent(" userTime" , " userTime" , initialSnap.userTimeNanos, processWide = false )
299- chromeTrace.traceCounterEvent(" cpuTime" , " cpuTime" , initialSnap.cpuTimeNanos, processWide = false )
300- chromeTrace.traceCounterEvent(" idleTime" , " idleTime" , initialSnap.idleTimeNanos, processWide = false )
294+ traceCounters()
301295 nextAfterUnitSnap = System .nanoTime() + 10 * 1000 * 1000
302296 }
303297
298+ private def traceCounters (): Unit = if chromeTrace != null then
299+ val snap = RealProfiler .snapThread(0 )
300+ chromeTrace.traceCounterEvent(" allocBytes" , " allocBytes" , snap.allocatedBytes, processWide = false )
301+ chromeTrace.traceCounterEvent(" heapBytes" , " heapBytes" , snap.heapBytes, processWide = true )
302+ chromeTrace.traceCounterEvent(" classesLoaded" , " classesLoaded" , snap.totalClassesLoaded, processWide = true )
303+ chromeTrace.traceCounterEvent(" jitCompilationTime" , " jitCompilationTime" , snap.totalJITCompilationTime, processWide = true )
304+ chromeTrace.traceCounterEvent(" userTime" , " userTime" , snap.userTimeNanos, processWide = false )
305+ chromeTrace.traceCounterEvent(" cpuTime" , " cpuTime" , snap.cpuTimeNanos, processWide = false )
306+ chromeTrace.traceCounterEvent(" idleTime" , " idleTime" , snap.idleTimeNanos, processWide = false )
307+
304308 override def beforeTypedDef (sym : Symbol ): TracedEventId = traceDurationStart(Category .TypeCheck , symbolName(sym))
305309 override def afterTypedDef (event : TracedEventId ): Unit = traceDurationEnd(Category .TypeCheck , event)
306310
0 commit comments