Skip to content

Commit

Permalink
Report GCP profiles from zoekt-git-index
Browse files Browse the repository at this point in the history
  • Loading branch information
jtibshirani committed Sep 6, 2024
1 parent 35dda3e commit 8ab6a84
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
4 changes: 4 additions & 0 deletions cmd/zoekt-git-index/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -70,6 +72,7 @@ func run() int {
}
*repoCacheDir = dir
}

opts := cmd.OptionsFromFlags()
opts.IsDelta = *isDelta
opts.DocumentRanksPath = *offlineRanking
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cmd/zoekt-sourcegraph-indexserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down
2 changes: 1 addition & 1 deletion cmd/zoekt-webserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
16 changes: 15 additions & 1 deletion internal/profiler/profiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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())
}
}
}

0 comments on commit 8ab6a84

Please sign in to comment.