diff --git a/cmd/zoekt-git-index/main.go b/cmd/zoekt-git-index/main.go index c1aa5d1a..39ab33fc 100644 --- a/cmd/zoekt-git-index/main.go +++ b/cmd/zoekt-git-index/main.go @@ -22,6 +22,8 @@ import ( "runtime/pprof" "strings" + "github.com/sourcegraph/zoekt" + "github.com/sourcegraph/zoekt/internal/profiler" "go.uber.org/automaxprocs/maxprocs" "github.com/sourcegraph/zoekt/cmd" @@ -70,6 +72,7 @@ func run() int { } *repoCacheDir = dir } + opts := cmd.OptionsFromFlags() opts.IsDelta = *isDelta opts.DocumentRanksPath = *offlineRanking @@ -107,6 +110,7 @@ func run() int { opts.LanguageMap[m[0]] = ctags.StringToParser(m[1]) } + profiler.InitLightweight("zoekt-git-index", zoekt.Version) exitStatus := 0 for dir, name := range gitRepos { opts.RepositoryDescription.Name = name diff --git a/cmd/zoekt-sourcegraph-indexserver/main.go b/cmd/zoekt-sourcegraph-indexserver/main.go index 671e3de9..e89073b4 100644 --- a/cmd/zoekt-sourcegraph-indexserver/main.go +++ b/cmd/zoekt-sourcegraph-indexserver/main.go @@ -1277,7 +1277,7 @@ func startServer(conf rootConfig) error { return err } - profiler.Init("zoekt-sourcegraph-indexserver", zoekt.Version, conf.blockProfileRate) + profiler.Init("zoekt-sourcegraph-indexserver", zoekt.Version) setCompoundShardCounter(s.IndexDir) if conf.listen != "" { diff --git a/cmd/zoekt-webserver/main.go b/cmd/zoekt-webserver/main.go index 5503dd3c..d66ac33d 100644 --- a/cmd/zoekt-webserver/main.go +++ b/cmd/zoekt-webserver/main.go @@ -177,7 +177,7 @@ func main() { liblog := sglog.Init(resource) defer liblog.Sync() tracer.Init(resource) - profiler.Init("zoekt-webserver", zoekt.Version, -1) + profiler.Init("zoekt-webserver", zoekt.Version) if *logDir != "" { if fi, err := os.Lstat(*logDir); err != nil || !fi.IsDir() { diff --git a/internal/profiler/profiler.go b/internal/profiler/profiler.go index 194fc9b4..0d18bf2c 100644 --- a/internal/profiler/profiler.go +++ b/internal/profiler/profiler.go @@ -8,7 +8,7 @@ import ( ) // Init starts the supported profilers IFF the environment variable is set. -func Init(svcName, version string, blockProfileRate int) { +func Init(svcName, version string) { if os.Getenv("GOOGLE_CLOUD_PROFILER_ENABLED") != "" { err := profiler.Start(profiler.Config{ Service: svcName, @@ -21,3 +21,17 @@ func Init(svcName, version string, blockProfileRate int) { } } } + +// InitLightweight starts the supported profilers IFF the environment variable is set. +// Compared to Init, it disables mutex profiling and forced GC to reduce its overhead. +func InitLightweight(svcName, version string) { + if os.Getenv("GOOGLE_CLOUD_PROFILER_ENABLED") != "" { + err := profiler.Start(profiler.Config{ + Service: svcName, + ServiceVersion: version, + }) + if err != nil { + log.Printf("could not initialize profiler: %s", err.Error()) + } + } +}