Skip to content

Commit

Permalink
cmd/go: process -debug-trace flag for cmd/test and cmd/vet
Browse files Browse the repository at this point in the history
These commands are build-like commands that do their own flag
processing, so the value of debug-trace isn't available until
the command starts running. Start tracing in the cmd's run
function.

Updates #38714

Change-Id: I4d633e6ee907bf09feac52c2aff3daceb9b20e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/248324
Run-TryBot: Michael Matloob <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Bryan C. Mills <[email protected]>
  • Loading branch information
matloob committed Aug 17, 2020
1 parent 38fea3a commit ebccba7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
18 changes: 18 additions & 0 deletions src/cmd/go/internal/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"cmd/go/internal/lockedfile"
"cmd/go/internal/modload"
"cmd/go/internal/str"
"cmd/go/internal/trace"
"cmd/go/internal/work"
"cmd/internal/test2json"
)
Expand Down Expand Up @@ -571,6 +572,23 @@ func runTest(ctx context.Context, cmd *base.Command, args []string) {

pkgArgs, testArgs = testFlags(args)

if cfg.DebugTrace != "" {
var close func() error
var err error
ctx, close, err = trace.Start(ctx, cfg.DebugTrace)
if err != nil {
base.Fatalf("failed to start trace: %v", err)
}
defer func() {
if err := close(); err != nil {
base.Fatalf("failed to stop trace: %v", err)
}
}()
}

ctx, span := trace.StartSpan(ctx, fmt.Sprint("Running ", cmd.Name(), " command"))
defer span.Done()

work.FindExecCmd() // initialize cached result

work.BuildInit()
Expand Down
25 changes: 23 additions & 2 deletions src/cmd/go/internal/vet/vet.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@
package vet

import (
"context"
"fmt"
"path/filepath"

"cmd/go/internal/base"
"cmd/go/internal/cfg"
"cmd/go/internal/load"
"cmd/go/internal/modload"
"cmd/go/internal/trace"
"cmd/go/internal/work"
"context"
"path/filepath"
)

// Break init loop.
Expand Down Expand Up @@ -54,6 +58,23 @@ func runVet(ctx context.Context, cmd *base.Command, args []string) {

vetFlags, pkgArgs := vetFlags(args)

if cfg.DebugTrace != "" {
var close func() error
var err error
ctx, close, err = trace.Start(ctx, cfg.DebugTrace)
if err != nil {
base.Fatalf("failed to start trace: %v", err)
}
defer func() {
if err := close(); err != nil {
base.Fatalf("failed to stop trace: %v", err)
}
}()
}

ctx, span := trace.StartSpan(ctx, fmt.Sprint("Running ", cmd.Name(), " command"))
defer span.Done()

work.BuildInit()
work.VetFlags = vetFlags
if len(vetFlags) > 0 {
Expand Down

0 comments on commit ebccba7

Please sign in to comment.