@@ -117,13 +117,13 @@ private [profile] object RealProfiler {
117117}
118118
119119private [profile] class RealProfiler (reporter : ProfileReporter , val settings : Settings ) extends Profiler with NotificationListener {
120-
120+ private val mainThread = Thread .currentThread()
121121 val tracePath = {
122122 if (settings.YprofileDestination .isSetByUser) new File (new java.io.File (settings.YprofileDestination .value)).changeExtension(" trace" ).jfile.toPath
123123 else Files .createTempFile(" scalac-" , " .trace" )
124124 }
125125 private val chromeTrace = new ChromeTrace (tracePath)
126- chromeTrace.traceAsyncEventStart(" scalac" , 0 , " 0" )
126+ chromeTrace.traceAsyncEventStart(" scalac- " + mainThread.getId, mainThread.getId , " 0" )
127127
128128 def completeBackground (threadRange : ProfileRange ): Unit = {
129129 reporter.reportBackground(this , threadRange)
@@ -139,7 +139,6 @@ private [profile] class RealProfiler(reporter : ProfileReporter, val settings: S
139139
140140 val active = RealProfiler .allPlugins map (_.generate(this , settings))
141141
142- private val mainThread = Thread .currentThread()
143142
144143 private [profile] def snapThread ( idleTimeNanos: Long ): ProfileSnap = {
145144 import RealProfiler ._
@@ -180,7 +179,7 @@ private [profile] class RealProfiler(reporter : ProfileReporter, val settings: S
180179 val startNanos = gcEvent.endNanos - durationNanos
181180 chromeTrace.traceDurationEvent(gcEvent.name, startNanos, durationNanos, GcThreadId )
182181 }
183- chromeTrace.traceAsyncEventEnd(" scalac" , 0 , " 0" )
182+ chromeTrace.traceAsyncEventEnd(" scalac- " + mainThread.getId , 0 , " 0" )
184183
185184 println(" Trace file: " + tracePath)
186185 chromeTrace.close()
@@ -214,6 +213,21 @@ private [profile] class RealProfiler(reporter : ProfileReporter, val settings: S
214213 }
215214 }
216215
216+ override def beforePhase (phase : Phase ): ProfileSnap = {
217+ assert(mainThread eq Thread .currentThread())
218+ chromeTrace.traceAsyncEventStart(phase.name, mainThread.getId, " 0" )
219+ if (settings.YprofileRunGcBetweenPhases .containsPhase(phase))
220+ doGC
221+ if (settings.YprofileExternalTool .containsPhase(phase)) {
222+ println(" Profile hook start" )
223+ ExternalToolHook .before()
224+ }
225+ active foreach {_.beforePhase(phase)}
226+ val snap = snapThread(0 )
227+ if (phase.prev eq null ) baseline = snap
228+ snap
229+ }
230+
217231 override def afterPhase (phase : Phase , snapBefore : ProfileSnap ): Unit = {
218232 assert(mainThread eq Thread .currentThread())
219233 val initialSnap = snapThread(0 )
@@ -226,21 +240,21 @@ private [profile] class RealProfiler(reporter : ProfileReporter, val settings: S
226240 doGC
227241 initialSnap.updateHeap(readHeapUsage())
228242 } else initialSnap
229- chromeTrace.traceAsyncEventEnd(phase.name, 0 , " 0" )
243+ chromeTrace.traceAsyncEventEnd(phase.name, mainThread.getId , " 0" )
230244
231245 reporter.reportForeground(this , ProfileRange (snapBefore, finalSnap, phase, " " , 0 , Thread .currentThread))
232246 }
233247
234248 override def beforeUnit (phase : Phase , file : AbstractFile ): ProfileSnap = {
235249 assert(mainThread eq Thread .currentThread())
236- chromeTrace.traceAsyncEventStart(file.name, 0 , " 0" )
250+ chromeTrace.traceAsyncEventStart(file.name, mainThread.getId , " 0" )
237251 snapThread(0 )
238252 }
239253
240254 override def afterUnit (phase : Phase , file : AbstractFile , snapBefore : ProfileSnap ): Unit = {
241255 assert(mainThread eq Thread .currentThread())
242256 val initialSnap = snapThread(0 )
243- chromeTrace.traceAsyncEventEnd(file.name, 0 , " 0" )
257+ chromeTrace.traceAsyncEventEnd(file.name, mainThread.getId , " 0" )
244258 chromeTrace.traceCounterEvent(" allocBytes" , " allocBytes" , initialSnap.allocatedBytes - this .baseline.allocatedBytes)
245259 chromeTrace.traceCounterEvent(" heapBytes" , " heapBytes" , initialSnap.heapBytes - this .baseline.heapBytes)
246260 chromeTrace.traceCounterEvent(" classesLoaded" , " classesLoaded" , initialSnap.totalClassesLoaded - this .baseline.totalClassesLoaded)
@@ -252,27 +266,11 @@ private [profile] class RealProfiler(reporter : ProfileReporter, val settings: S
252266
253267 private var baseline : ProfileSnap = _
254268
255- override def beforePhase (phase : Phase ): ProfileSnap = {
256- assert(mainThread eq Thread .currentThread())
257- chromeTrace.traceAsyncEventStart(phase.name, 0 , " 0" )
258- if (settings.YprofileRunGcBetweenPhases .containsPhase(phase))
259- doGC
260- if (settings.YprofileExternalTool .containsPhase(phase)) {
261- println(" Profile hook start" )
262- ExternalToolHook .before()
263- }
264- active foreach {_.beforePhase(phase)}
265- val snap = snapThread(0 )
266- if (phase.prev eq null ) baseline = snap
267- snap
268- }
269-
270269 private val completingStack = new mutable.ArrayStack [Global # Symbol ]
271270 private val stringsOf = (0 to 128 ).map(_.toString).toArray
272271 def intToString (i : Int ) = if (i < 128 ) stringsOf(i) else i.toString
273272
274- import scala .reflect .internal .util .ChromeTrace
275- private def traceId = if (completingStack.isEmpty) 0 else completingStack.top.id
273+ private def traceId = if (completingStack.isEmpty) mainThread.getId else mainThread.getId << 32 | (completingStack.top.id.toLong & 0xffffffffL)
276274 override def beforeTypedImplDef (sym : Global # Symbol ): Unit = {
277275 chromeTrace.traceAsyncEventStart(sym.rawname.toString, traceId, intToString(completingStack.length))
278276 }
@@ -281,23 +279,23 @@ private [profile] class RealProfiler(reporter : ProfileReporter, val settings: S
281279 }
282280
283281 override def beforeImplicitSearch (pt : Global # Symbol ): Unit = {
284- chromeTrace.traceAsyncEventStart(" <implicit> " + pt.rawname, traceId, intToString(completingStack.length))
282+ chromeTrace.traceAsyncEventStart(" <implicit> " + pt.rawname, traceId, intToString(completingStack.length), colour = " yellow " )
285283 }
286284
287285 override def afterImplicitSearch (pt : Global # Symbol ): Unit = {
288- chromeTrace.traceAsyncEventEnd(" <implicit> " + pt.rawname, traceId, intToString(completingStack.length))
286+ chromeTrace.traceAsyncEventEnd(" <implicit> " + pt.rawname, traceId, intToString(completingStack.length), colour = " yellow " )
289287 }
290288
291289 override def beforeMacroExpansion (macroSym : Global # Symbol ): Unit = {
292- chromeTrace.traceAsyncEventStart(" <macro> " + macroSym.rawname, traceId, intToString(completingStack.length))
290+ chromeTrace.traceAsyncEventStart(" <macro> " + macroSym.rawname, traceId, intToString(completingStack.length), colour = " olive " )
293291 }
294292
295293 override def afterMacroExpansion (macroSym : Global # Symbol ): Unit = {
296- chromeTrace.traceAsyncEventEnd(" <macro> " + macroSym.rawname, traceId, intToString(completingStack.length))
294+ chromeTrace.traceAsyncEventEnd(" <macro> " + macroSym.rawname, traceId, intToString(completingStack.length), colour = " olive " )
297295 }
298296
299297 override def beforeCompletion (root : Global # Symbol ): Unit = {
300- chromeTrace.traceAsyncEventStart(" <wait>" , traceId, intToString(completingStack.length))
298+ chromeTrace.traceAsyncEventStart(" <wait>" , traceId, intToString(completingStack.length), colour = " thread_state_sleeping " )
301299 completingStack.push(root)
302300 chromeTrace.traceAsyncEventStart(" <completion>" , traceId, intToString(completingStack.length))
303301 chromeTrace.traceAsyncEventStart(root.rawname.toString, traceId, intToString(completingStack.length))
0 commit comments