MCPcopy
hub / github.com/github/gh-ost / runCPUProfile

Method runCPUProfile

go/logic/server.go:54–100  ·  view source on GitHub ↗
(args string)

Source from the content-addressed store, hash-verified

52}
53
54func (srv *Server) runCPUProfile(args string) (io.Reader, error) {
55 duration := defaultCPUProfileDuration
56
57 var err error
58 var blockProfile, useGzip bool
59 if args != "" {
60 s := strings.Split(args, ",")
61 // a duration string must be the 1st field, if any
62 if duration, err = time.ParseDuration(s[0]); err != nil {
63 return nil, err
64 }
65 for _, arg := range s[1:] {
66 switch arg {
67 case "block", "blocked", "blocking":
68 blockProfile = true
69 case "gzip":
70 useGzip = true
71 default:
72 return nil, ErrCPUProfilingBadOption
73 }
74 }
75 }
76
77 if atomic.LoadInt64(&srv.isCPUProfiling) > 0 {
78 return nil, ErrCPUProfilingInProgress
79 }
80 atomic.StoreInt64(&srv.isCPUProfiling, 1)
81 defer atomic.StoreInt64(&srv.isCPUProfiling, 0)
82
83 var buf bytes.Buffer
84 var writer io.Writer = &buf
85 if blockProfile {
86 runtime.SetBlockProfileRate(1)
87 defer runtime.SetBlockProfileRate(0)
88 }
89 if useGzip {
90 writer = gzip.NewWriter(writer)
91 }
92 if err = pprof.StartCPUProfile(writer); err != nil {
93 return nil, err
94 }
95
96 time.Sleep(duration)
97 pprof.StopCPUProfile()
98 srv.migrationContext.Log.Infof("Captured %d byte runtime/pprof CPU profile (gzip=%v)", buf.Len(), useGzip)
99 return &buf, nil
100}
101
102func (srv *Server) createPostponeCutOverFlagFile(filePath string) (err error) {
103 if !base.FileExists(filePath) {

Callers 2

applyServerCommandMethod · 0.95
TestServerRunCPUProfileFunction · 0.95

Calls 2

InfofMethod · 0.65
LenMethod · 0.45

Tested by 1

TestServerRunCPUProfileFunction · 0.76