...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package profiler
16
17 import (
18 "fmt"
19
20 "cloud.google.com/go/profiler"
21 flag "github.com/spf13/pflag"
22 )
23
24 var profilerServiceName string
25
26 func AddFlag(flagSet *flag.FlagSet) {
27 flagSet.StringVar(&profilerServiceName, "profiler-service-name", "", "when specified, the profiler agent is enabled with a service name equal to the value. See https://cloud.google.com/profiler/docs/profiling-go#gke for details.")
28 }
29
30
31 func StartIfEnabled() error {
32 if profilerServiceName == "" {
33 return nil
34 }
35 return start()
36 }
37
38
39 func start() error {
40 cfg := profiler.Config{
41 Service: profilerServiceName,
42 DebugLogging: true,
43 }
44
45 if err := profiler.Start(cfg); err != nil {
46 return fmt.Errorf("error starting profiler: %v", err)
47 }
48 return nil
49 }
50
View as plain text