Skip to content

Commit bbc3082

Browse files
author
Tomás Senart
authored
profiler: Introduce a profiler package and use it in repo-updater (#16656)
* profiler: Introduce a profiler package and use it in repo-updater This commit introduces a profiler package, similar to tracer and logging, that is shim to Google Cloud Profiler, which we aim to use to get continuous profiling information (every minute) on repo-updater. Fixes #16655 * fixup! go mod tidy
1 parent d090e82 commit bbc3082

4 files changed

Lines changed: 32 additions & 0 deletions

File tree

cmd/repo-updater/shared/main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"github.com/sourcegraph/sourcegraph/internal/httpcli"
3535
"github.com/sourcegraph/sourcegraph/internal/httpserver"
3636
"github.com/sourcegraph/sourcegraph/internal/logging"
37+
"github.com/sourcegraph/sourcegraph/internal/profiler"
3738
"github.com/sourcegraph/sourcegraph/internal/ratelimit"
3839
"github.com/sourcegraph/sourcegraph/internal/repos"
3940
"github.com/sourcegraph/sourcegraph/internal/trace"
@@ -52,6 +53,11 @@ func Main(enterpriseInit EnterpriseInit) {
5253
ctx := context.Background()
5354
env.Lock()
5455
env.HandleHelpFlag()
56+
57+
if err := profiler.Init(); err != nil {
58+
log.Fatalf("failed to start profiler: %v", err)
59+
}
60+
5561
logging.Init()
5662
tracer.Init()
5763
trace.Init(true)

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/sourcegraph/sourcegraph
33
go 1.14
44

55
require (
6+
cloud.google.com/go v0.56.0
67
cloud.google.com/go/bigquery v1.6.0 // indirect
78
cloud.google.com/go/pubsub v1.3.1
89
cloud.google.com/go/storage v1.6.0

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,7 @@ github.com/golang/mock v1.3.1 h1:qGJ6qTW+x6xX/my+8YUVl4WNpX9B7+/l2tRsHGZ7f2s=
531531
github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y=
532532
github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
533533
github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
534+
github.com/golang/mock v1.4.3 h1:GV+pQPG/EUUbkh47niozDcADz6go/dUwhVzdUQHIVRw=
534535
github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
535536
github.com/golang/protobuf v1.3.5 h1:F768QJ1E9tib+q5Sc8MkdJi1RxLTbRcTf8LJV56aRls=
536537
github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk=

internal/profiler/profiler.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package profiler
2+
3+
import (
4+
"cloud.google.com/go/profiler"
5+
6+
"github.com/sourcegraph/sourcegraph/cmd/frontend/envvar"
7+
"github.com/sourcegraph/sourcegraph/internal/env"
8+
"github.com/sourcegraph/sourcegraph/internal/version"
9+
)
10+
11+
// Init starts the Google Cloud Profiler when in sourcegraph.com mode.
12+
// https://cloud.google.com/profiler/docs/profiling-go
13+
func Init() error {
14+
if !envvar.SourcegraphDotComMode() {
15+
return nil
16+
}
17+
18+
return profiler.Start(profiler.Config{
19+
Service: env.MyName,
20+
ServiceVersion: version.Version(),
21+
MutexProfiling: true,
22+
AllocForceGC: true,
23+
})
24+
}

0 commit comments

Comments
 (0)