Skip to content

Instantly share code, notes, and snippets.

@egonelbre
Created March 8, 2016 14:55
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 egonelbre/72b5a88cf5b65e8035f4 to your computer and use it in GitHub Desktop.
Save egonelbre/72b5a88cf5b65e8035f4 to your computer and use it in GitHub Desktop.
use as
go build -gantt <project> 2> build.html
then add <table> and </table> to the beginning and end of build.html
diff --git a/src/cmd/go/build.go b/src/cmd/go/build.go
index 5977828..41fc630 100644
--- a/src/cmd/go/build.go
+++ b/src/cmd/go/build.go
@@ -76,6 +76,7 @@ and test commands:
and only with Clang/LLVM as the host C compiler.
-v
print the names of packages as they are compiled.
+ -gantt
-work
print the name of the temporary work directory and
do not delete it when exiting.
@@ -163,6 +164,7 @@ var buildA bool // -a flag
var buildN bool // -n flag
var buildP = runtime.NumCPU() // -p flag
var buildV bool // -v flag
+var buildGantt bool // -gantt flag
var buildX bool // -x flag
var buildI bool // -i flag
var buildO = cmdBuild.Flag.String("o", "", "output file")
@@ -220,6 +222,7 @@ func addBuildFlags(cmd *Command) {
cmd.Flag.BoolVar(&buildN, "n", false, "")
cmd.Flag.IntVar(&buildP, "p", buildP, "")
cmd.Flag.BoolVar(&buildV, "v", false, "")
+ cmd.Flag.BoolVar(&buildGantt, "gantt", false, "")
cmd.Flag.BoolVar(&buildX, "x", false, "")
cmd.Flag.Var((*stringsFlag)(&buildAsmflags), "asmflags", "")
@@ -1334,6 +1337,12 @@ func hasString(strings []string, s string) bool {
return false
}
+var globalStart time.Time
+
+func init() {
+ globalStart = time.Now()
+}
+
// build is the action for building a single package or command.
func (b *builder) build(a *action) (err error) {
// Return an error if the package has CXX files but it's not using
@@ -1370,6 +1379,19 @@ func (b *builder) build(a *action) (err error) {
if buildV {
b.print(a.p.ImportPath + "\n")
}
+ if buildGantt {
+ start := time.Now()
+ defer func() {
+ finish := time.Now()
+ begin := start.Sub(globalStart)
+ total := finish.Sub(start)
+
+ title := fmt.Sprintf("<td>%v</td>", a.p.ImportPath)
+ time := fmt.Sprintf("<td>%v</td>", total)
+ block := fmt.Sprintf("<td><div style='margin-left:%vpx; width:%vpx; background: #f88;'>&nbsp;</div></td>", begin.Seconds()*20, total.Seconds()*20)
+ b.print("<tr>" + title + time + block + "</tr>")
+ }()
+ }
// Make build directory.
obj := a.objdir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment