]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: add span for modload.LoadBuildList
authorMichael Matloob <matloob@golang.org>
Wed, 24 Jun 2020 19:58:47 +0000 (15:58 -0400)
committerMichael Matloob <matloob@golang.org>
Mon, 17 Aug 2020 18:32:28 +0000 (18:32 +0000)
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 <matloob@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
src/cmd/go/internal/list/list.go
src/cmd/go/internal/modcmd/download.go
src/cmd/go/internal/modcmd/graph.go
src/cmd/go/internal/modcmd/verify.go
src/cmd/go/internal/modcmd/why.go
src/cmd/go/internal/modget/get.go
src/cmd/go/internal/modload/list.go
src/cmd/go/internal/modload/load.go

index 7747e730ae91723cad6840b8ffa91d9c38349065..7303e6c86650fa0344fd05a778e60ed46f88e18f 100644 (file)
@@ -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 {
index b43c32be5a6b4f016985577d4001157d677b9055..946e8ed3cfb3ad0d847e2582ee329567a85dc91c 100644 (file)
@@ -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
                }
index fff5b02626630bd25c1867c898da6003da3d549b..4853503fd453087a062af392d68d96b8f4b7285d 100644 (file)
@@ -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 {
index 570e5710491229d6988a67998634e03d411d152b..73ab714d101a12a6f588931c82a000acd9c3db04 100644 (file)
@@ -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 {
index 3f9cf0f12016edb42c99a705e84e8f6c7e0de8f8..f400339b25c32cde0e2c1eb41f3474d53553d807 100644 (file)
@@ -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)
index b2171969317f70c8ce1a0c21311e39dffbc9f04b..93a6bb54d5f12bb6eebdf55216035bb89ce661b5 100644 (file)
@@ -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 {
@@ -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,
@@ -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
@@ -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 {
index 9400793bcb253b3e7547ea7e6773b22f9d3c4bfb..4768516e90f03911051e0b0364b85ab668f5aca7 100644 (file)
@@ -5,6 +5,7 @@
 package modload
 
 import (
+       "context"
        "errors"
        "fmt"
        "os"
@@ -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 {
@@ -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)}
        }
index 30992e0cc233efac2bbd8e7936fc6eaff3eb6dff..8190009b23ecf41f48a26133ac480324ee79ba87 100644 (file)
@@ -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"
@@ -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"
 )
 
@@ -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()