Skip to content

Commit

Permalink
Report GCP profiles from zoekt-git-index (#816)
Browse files Browse the repository at this point in the history
This PR initializes the GCP profiler in the `zoekt-git-index` process so we can
examine CPU and memory usage for the indexing process itself.
  • Loading branch information
jtibshirani authored Sep 9, 2024
1 parent 35dda3e commit 1ceac75
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
3 changes: 3 additions & 0 deletions cmd/zoekt-git-index/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"runtime/pprof"
"strings"

"github.com/sourcegraph/zoekt/internal/profiler"
"go.uber.org/automaxprocs/maxprocs"

"github.com/sourcegraph/zoekt/cmd"
Expand Down Expand Up @@ -70,6 +71,7 @@ func run() int {
}
*repoCacheDir = dir
}

opts := cmd.OptionsFromFlags()
opts.IsDelta = *isDelta
opts.DocumentRanksPath = *offlineRanking
Expand Down Expand Up @@ -107,6 +109,7 @@ func run() int {
opts.LanguageMap[m[0]] = ctags.StringToParser(m[1])
}

profiler.Init("zoekt-git-index")
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")
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")

if *logDir != "" {
if fi, err := os.Lstat(*logDir); err != nil || !fi.IsDir() {
Expand Down
5 changes: 3 additions & 2 deletions internal/profiler/profiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, blockProfileRate int) {
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,
})
Expand Down

0 comments on commit 1ceac75

Please sign in to comment.