Skip to content

Instantly share code, notes, and snippets.

@josharian
Created June 13, 2019 20:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josharian/7cf7b96c447efc4f01b8b4642bbe64ba to your computer and use it in GitHub Desktop.
Save josharian/7cf7b96c447efc4f01b8b4642bbe64ba to your computer and use it in GitHub Desktop.
attempt to instrument the compiler for causal profiling
diff --git a/src/cmd/compile/internal/gc/main.go b/src/cmd/compile/internal/gc/main.go
index dc3fb64e27..21e211e339 100644
--- a/src/cmd/compile/internal/gc/main.go
+++ b/src/cmd/compile/internal/gc/main.go
@@ -27,6 +27,7 @@ import (
"path"
"regexp"
"runtime"
+ "runtime/causalprof"
"strconv"
"strings"
)
@@ -129,6 +130,18 @@ var nowritebarrierrecCheck *nowritebarrierrecChecker
// arguments, type-checks the parsed Go package, compiles functions to machine
// code, and finally writes the compiled package definition to disk.
func Main(archInit func(*Arch)) {
+ cpfile := os.Getenv("CPFILE")
+ if cpfile != "" {
+ f, err := os.Create(cpfile)
+ if err != nil {
+ Fatalf("%v", err)
+ }
+ if err := causalprof.Start(f); err != nil {
+ Fatalf("%v", err)
+ }
+ atExit(causalprof.Stop)
+ }
+
timings.Start("fe", "init")
defer hidePanic()
@@ -682,7 +695,9 @@ func Main(archInit func(*Arch)) {
fninit(xtop)
}
+ progress := causalprof.StartProgress()
compileFunctions()
+ progress.Stop()
if nowritebarrierrecCheck != nil {
// Write barriers are now known. Check the
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment