Skip to content

[WIP] Emit detailed compiler trace under -Yprofile #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from

Conversation

retronym
Copy link
Owner

@retronym retronym commented Oct 4, 2018

Suitable for viewing directly in chrome://tracing, or manipulation
with the underlying tooling at:

https://github.com/catapult-project/catapult/tree/master/tracing

  • Time spent completing lazy types is excluded from the callsite,
    and instead attributed to the symbol being completed itself.
  • The top-most implicit search is tracked.
  • macro expansions are tracked the trace

TODO:

@retronym
Copy link
Owner Author

retronym commented Oct 4, 2018

profile.trace file generated with this PR.

image

image

@retronym retronym force-pushed the topic/statify-chrome-trace branch 8 times, most recently from 72cae64 to 088eb2d Compare October 4, 2018 07:04
@retronym retronym changed the title Emit detailed compiler trace under -Yprofile WIP Emit detailed compiler trace under -Yprofile Oct 4, 2018
@retronym retronym changed the title WIP Emit detailed compiler trace under -Yprofile [WIP] Emit detailed compiler trace under -Yprofile Oct 4, 2018
@retronym retronym force-pushed the topic/statify-chrome-trace branch 2 times, most recently from be989fd to 4c77697 Compare October 5, 2018 03:53
@retronym
Copy link
Owner Author

retronym commented Oct 5, 2018

How to test this yourself:

Publish this PR locally

$ sbt
> set scala.build.ScriptCommands.enableOptimizer ++ scala.build.ScriptCommands.noDocs ++ ((baseVersionSuffix in Global := "SHA"):: Nil)
[info] Defining */*:baseVersionSuffix, {.}/compile:packageDoc::publishArtifact, {.}/compile:scalacOptions
[info] The new values will be used by */*:versionProperties, bootstrap/*:artifacts and 33 others.
[info] 	Run `last` for details.
[info] Reapplying settings...
[info] *** Welcome to the sbt build definition for Scala! ***
[info] Check README.md for more information.
> publishLocal

...
[info] 	published scala-compiler to /Users/jz/.ivy2/local/org.scala-lang/scala-compiler/2.12.8-bin-4c77697/jars/scala-compiler.jar
[info] 	published ivy to /Users/jz/.ivy2/local/org.scala-lang/scala-compiler/2.12.8-bin-4c77697/ivys/ivy.xml

Modify a project to add the compiler options and to depend on this version:

/code/guardian-frontend on master*
$ git diff head -U2
diff --git a/project/ProjectSettings.scala b/project/ProjectSettings.scala
index f8ffd13797..cf823f4443 100644
--- a/project/ProjectSettings.scala
+++ b/project/ProjectSettings.scala
@@ -26,5 +26,5 @@ object ProjectSettings {
     sources in (Compile,doc) := Seq.empty,
     doc in Compile := target.map(_ / "none").value,
-    scalaVersion := "2.12.7",
+    scalaVersion := "2.12.8-bin-4c77697",
     initialize := {
       val _ = initialize.value
@@ -36,4 +36,6 @@ object ProjectSettings {
       clean.all(allProjects)
     }.value
+  ) ++ Seq(Compile, Test).map(config =>
+    scalacOptions in config := List("-Yprofile-enabled", "-Yprofile-destination", target.value / config.toString + ".csv")
   )

Build

$ sbt -J-Xmx1G clean test:compile clean test:compile
...
Trace file: /Users/jz/code/guardian-frontend/sport/target/test.trace
[info] Done compiling.
Trace file: /Users/jz/code/guardian-frontend/applications/target/test.trace
[info] Done compiling.
[success] Total time: 65 s, completed 05/10/2018 2:19:11 PM

Sample .trace files

View in Chrome

Enter chrome://tracing, and open a .trace file.

Combine Trace Files (optional)

$ (echo '{"traceEvents": [ {"name": "process_name", "ph": "M", "pid": -1, "tid": 2347,"args": {"name": "dummy"}}'; (for f in $(find . -name '*.trace'); do cat $f | perl -pne 's/{"traceEvents": \[\n/,/' |  perl -pne 's/]}//'; done) | egrep -v '^,$'; echo ']}') > /tmp/combined.trace

Generates combined.trace.zip

@retronym
Copy link
Owner Author

retronym commented Oct 6, 2018

I'm working on the post-processing tool https://github.com/retronym/chrome-trace-to-flamegraph

This tool should be able:

  • Split traces that span a stop-the-world GC event into a pre- and post- span that exclude the time that the JVM was inactive.
  • When a type completor starts: stop the in-progress span and pretend that the recursive frames of the completer where the base of the stack. When we pop out of the completion, re-start the stopped enclosing frame.
  • output to a compressed Chrome Trace format, collapsing begin/end events into complete events for compression
    • maybe further compressing by symbolizing stack trace elements
  • output Flamegraph collapsed stack format
  • output speedscope format

@retronym
Copy link
Owner Author

retronym commented Oct 9, 2018

I've made a bit of progress in the post-processing tool. Here's the latest output:

https://drive.google.com/drive/folders/1EJJb7Yy52gpu6wNjOgPfh39D4V2MOihC?usp=sharing

@retronym retronym force-pushed the topic/statify-chrome-trace branch 2 times, most recently from 1520e83 to 39913e7 Compare October 11, 2018 03:30
psilospore and others added 2 commits October 17, 2018 14:46
modules loaded by classpath, and created tests.
10786 setting privateWithin for java protected inner classes
a small handful of optimizations for 2.12
@retronym retronym force-pushed the topic/statify-chrome-trace branch 3 times, most recently from a88b4ec to 3c0f632 Compare October 23, 2018 05:18
Suitable for viewing directly in chrome://tracing, or post processing
with https://github.com/retronym/chrome-trace-to-flamegraph

Co-Authored-By: Mike Skells <[email protected]>
@retronym retronym force-pushed the topic/statify-chrome-trace branch from 3c0f632 to 583c3ef Compare October 23, 2018 23:22
@retronym
Copy link
Owner Author

Moved to scala#7364

@retronym retronym closed this Oct 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants