From 8ab6a8449b2406e14dd323988acf52d59dbd0b7e Mon Sep 17 00:00:00 2001 From: Julie Tibshirani Date: Fri, 6 Sep 2024 13:17:30 -0700 Subject: [PATCH 1/3] Report GCP profiles from zoekt-git-index --- cmd/zoekt-git-index/main.go | 4 ++++ cmd/zoekt-sourcegraph-indexserver/main.go | 2 +- cmd/zoekt-webserver/main.go | 2 +- internal/profiler/profiler.go | 16 +++++++++++++++- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/cmd/zoekt-git-index/main.go b/cmd/zoekt-git-index/main.go index c1aa5d1ad..39ab33fce 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 671e3de91..e89073b44 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 5503dd3c8..d66ac33df 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 194fc9b4b..0d18bf2c6 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()) + } + } +} From 080d0b9234d7fb8701c1ae1c0be6f1e05ee9901c Mon Sep 17 00:00:00 2001 From: Julie Tibshirani Date: Mon, 9 Sep 2024 09:45:27 -0700 Subject: [PATCH 2/3] Remove version arg --- cmd/zoekt-git-index/main.go | 3 +-- cmd/zoekt-sourcegraph-indexserver/main.go | 2 +- cmd/zoekt-webserver/main.go | 2 +- internal/profiler/profiler.go | 9 +++++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cmd/zoekt-git-index/main.go b/cmd/zoekt-git-index/main.go index 39ab33fce..f41fa101e 100644 --- a/cmd/zoekt-git-index/main.go +++ b/cmd/zoekt-git-index/main.go @@ -22,7 +22,6 @@ import ( "runtime/pprof" "strings" - "github.com/sourcegraph/zoekt" "github.com/sourcegraph/zoekt/internal/profiler" "go.uber.org/automaxprocs/maxprocs" @@ -110,7 +109,7 @@ func run() int { opts.LanguageMap[m[0]] = ctags.StringToParser(m[1]) } - profiler.InitLightweight("zoekt-git-index", zoekt.Version) + profiler.InitLightweight("zoekt-git-index") 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 e89073b44..d5c513bfb 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) + profiler.Init("zoekt-sourcegraph-indexserver") setCompoundShardCounter(s.IndexDir) if conf.listen != "" { diff --git a/cmd/zoekt-webserver/main.go b/cmd/zoekt-webserver/main.go index d66ac33df..49fb923d2 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) + profiler.Init("zoekt-webserver") 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 0d18bf2c6..0762e3562 100644 --- a/internal/profiler/profiler.go +++ b/internal/profiler/profiler.go @@ -5,14 +5,15 @@ import ( "os" "cloud.google.com/go/profiler" + "github.com/sourcegraph/zoekt" ) // Init starts the supported profilers IFF the environment variable is set. -func Init(svcName, version string) { +func Init(svcName string) { if os.Getenv("GOOGLE_CLOUD_PROFILER_ENABLED") != "" { err := profiler.Start(profiler.Config{ Service: svcName, - ServiceVersion: version, + ServiceVersion: zoekt.Version, MutexProfiling: true, AllocForceGC: true, }) @@ -24,11 +25,11 @@ func Init(svcName, version string) { // 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) { +func InitLightweight(svcName string) { if os.Getenv("GOOGLE_CLOUD_PROFILER_ENABLED") != "" { err := profiler.Start(profiler.Config{ Service: svcName, - ServiceVersion: version, + ServiceVersion: zoekt.Version, }) if err != nil { log.Printf("could not initialize profiler: %s", err.Error()) From be99dcf76afe1c70a32d6ed4f37e3916cdc78ef5 Mon Sep 17 00:00:00 2001 From: Julie Tibshirani Date: Mon, 9 Sep 2024 10:35:13 -0700 Subject: [PATCH 3/3] Remove lightweight init --- cmd/zoekt-git-index/main.go | 2 +- internal/profiler/profiler.go | 14 -------------- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/cmd/zoekt-git-index/main.go b/cmd/zoekt-git-index/main.go index f41fa101e..5ba4bc38f 100644 --- a/cmd/zoekt-git-index/main.go +++ b/cmd/zoekt-git-index/main.go @@ -109,7 +109,7 @@ func run() int { opts.LanguageMap[m[0]] = ctags.StringToParser(m[1]) } - profiler.InitLightweight("zoekt-git-index") + profiler.Init("zoekt-git-index") exitStatus := 0 for dir, name := range gitRepos { opts.RepositoryDescription.Name = name diff --git a/internal/profiler/profiler.go b/internal/profiler/profiler.go index 0762e3562..84039ac92 100644 --- a/internal/profiler/profiler.go +++ b/internal/profiler/profiler.go @@ -22,17 +22,3 @@ func Init(svcName string) { } } } - -// 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 string) { - if os.Getenv("GOOGLE_CLOUD_PROFILER_ENABLED") != "" { - err := profiler.Start(profiler.Config{ - Service: svcName, - ServiceVersion: zoekt.Version, - }) - if err != nil { - log.Printf("could not initialize profiler: %s", err.Error()) - } - } -}