Skip to content

Commit

Permalink
cmd/go: add span for modload.LoadBuildList
Browse files Browse the repository at this point in the history
This change adds context, and a span to modload.LoadBuildList and
propagates context into modload.BuildList. It's the start
of a run of CLs to add trace spans for module operations.

Updates #38714

Change-Id: I0d58dd394051526338092dc9a5ec29a9e087e4e4
Reviewed-on: https://go-review.googlesource.com/c/go/+/248325
Run-TryBot: Michael Matloob <[email protected]>
Reviewed-by: Bryan C. Mills <[email protected]>
  • Loading branch information
matloob committed Aug 17, 2020
1 parent ebccba7 commit 2ac4bf3
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/cmd/go/internal/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,9 +413,9 @@ func runList(ctx context.Context, cmd *base.Command, args []string) {
}
}

modload.LoadBuildList()
modload.LoadBuildList(ctx)

mods := modload.ListModules(args, *listU, *listVersions)
mods := modload.ListModules(ctx, args, *listU, *listVersions)
if !*listE {
for _, m := range mods {
if m.Error != nil {
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/go/internal/modcmd/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func runDownload(ctx context.Context, cmd *base.Command, args []string) {
var work par.Work
listU := false
listVersions := false
for _, info := range modload.ListModules(args, listU, listVersions) {
for _, info := range modload.ListModules(ctx, args, listU, listVersions) {
if info.Replace != nil {
info = info.Replace
}
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/go/internal/modcmd/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func runGraph(ctx context.Context, cmd *base.Command, args []string) {
base.Fatalf("go: cannot find main module; see 'go help modules'")
}
}
modload.LoadBuildList()
modload.LoadBuildList(ctx)

reqs := modload.MinReqs()
format := func(m module.Version) string {
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/go/internal/modcmd/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func runVerify(ctx context.Context, cmd *base.Command, args []string) {
sem := make(chan token, runtime.GOMAXPROCS(0))

// Use a slice of result channels, so that the output is deterministic.
mods := modload.LoadBuildList()[1:]
mods := modload.LoadBuildList(ctx)[1:]
errsChans := make([]<-chan []error, len(mods))

for i, mod := range mods {
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/go/internal/modcmd/why.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func runWhy(ctx context.Context, cmd *base.Command, args []string) {
base.Fatalf("go mod why: module query not allowed")
}
}
mods := modload.ListModules(args, listU, listVersions)
mods := modload.ListModules(ctx, args, listU, listVersions)
byModule := make(map[module.Version][]string)
for _, path := range loadALL() {
m := modload.PackageModule(path)
Expand Down
8 changes: 4 additions & 4 deletions src/cmd/go/internal/modget/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func runGet(ctx context.Context, cmd *base.Command, args []string) {
}
modload.LoadTests = *getT

buildList := modload.LoadBuildList()
buildList := modload.LoadBuildList(ctx)
buildList = buildList[:len(buildList):len(buildList)] // copy on append
versionByPath := make(map[string]string)
for _, m := range buildList {
Expand Down Expand Up @@ -444,7 +444,7 @@ func runGet(ctx context.Context, cmd *base.Command, args []string) {
// packages in unknown modules can't be expanded. This also avoids looking
// up new modules while loading packages, only to downgrade later.
queryCache := make(map[querySpec]*query)
byPath := runQueries(queryCache, queries, nil)
byPath := runQueries(ctx, queryCache, queries, nil)

// Add missing modules to the build list.
// We call SetBuildList here and elsewhere, since newUpgrader,
Expand Down Expand Up @@ -586,7 +586,7 @@ func runGet(ctx context.Context, cmd *base.Command, args []string) {

// Query target versions for modules providing packages matched by
// command line arguments.
byPath = runQueries(queryCache, queries, modOnly)
byPath = runQueries(ctx, queryCache, queries, modOnly)

// Handle upgrades. This is needed for arguments that didn't match
// modules or matched different modules from a previous iteration. It
Expand Down Expand Up @@ -724,7 +724,7 @@ func runGet(ctx context.Context, cmd *base.Command, args []string) {
// versions (including earlier queries in the modOnly map), an error will be
// reported. A map from module paths to queries is returned, which includes
// queries and modOnly.
func runQueries(cache map[querySpec]*query, queries []*query, modOnly map[string]*query) map[string]*query {
func runQueries(ctx context.Context, cache map[querySpec]*query, queries []*query, modOnly map[string]*query) map[string]*query {
var lookup par.Work
for _, q := range queries {
if cached := cache[q.querySpec]; cached != nil {
Expand Down
9 changes: 5 additions & 4 deletions src/cmd/go/internal/modload/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package modload

import (
"context"
"errors"
"fmt"
"os"
Expand All @@ -19,8 +20,8 @@ import (
"golang.org/x/mod/module"
)

func ListModules(args []string, listU, listVersions bool) []*modinfo.ModulePublic {
mods := listModules(args, listVersions)
func ListModules(ctx context.Context, args []string, listU, listVersions bool) []*modinfo.ModulePublic {
mods := listModules(ctx, args, listVersions)
if listU || listVersions {
var work par.Work
for _, m := range mods {
Expand All @@ -42,8 +43,8 @@ func ListModules(args []string, listU, listVersions bool) []*modinfo.ModulePubli
return mods
}

func listModules(args []string, listVersions bool) []*modinfo.ModulePublic {
LoadBuildList()
func listModules(ctx context.Context, args []string, listVersions bool) []*modinfo.ModulePublic {
LoadBuildList(ctx)
if len(args) == 0 {
return []*modinfo.ModulePublic{moduleInfo(buildList[0], true)}
}
Expand Down
23 changes: 14 additions & 9 deletions src/cmd/go/internal/modload/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,7 @@ package modload

import (
"bytes"
"cmd/go/internal/base"
"cmd/go/internal/cfg"
"cmd/go/internal/imports"
"cmd/go/internal/modfetch"
"cmd/go/internal/mvs"
"cmd/go/internal/par"
"cmd/go/internal/search"
"cmd/go/internal/str"
"context"
"errors"
"fmt"
"go/build"
Expand All @@ -24,6 +17,16 @@ import (
"sort"
"strings"

"cmd/go/internal/base"
"cmd/go/internal/cfg"
"cmd/go/internal/imports"
"cmd/go/internal/modfetch"
"cmd/go/internal/mvs"
"cmd/go/internal/par"
"cmd/go/internal/search"
"cmd/go/internal/str"
"cmd/go/internal/trace"

"golang.org/x/mod/module"
)

Expand Down Expand Up @@ -385,7 +388,9 @@ func DirImportPath(dir string) string {
// LoadBuildList need only be called if ImportPaths is not
// (typically in commands that care about the module but
// no particular package).
func LoadBuildList() []module.Version {
func LoadBuildList(ctx context.Context) []module.Version {
ctx, span := trace.StartSpan(ctx, "LoadBuildList")
defer span.Done()
InitMod()
ReloadBuildList()
WriteGoMod()
Expand Down

0 comments on commit 2ac4bf3

Please sign in to comment.