Skip to content

Commit

Permalink
set block profile after isProfiling=1
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Vaillancourt <[email protected]>
  • Loading branch information
timvaillancourt committed Dec 23, 2023
1 parent f361552 commit 560a0ec
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions go/logic/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (this *Server) runCPUProfile(args string) (string, error) {
duration := defaultCPUProfileDuration

var err error
var useGzip bool
var blockProfile, useGzip bool
if args != "" {
s := strings.Split(args, ",")
// a duration string must be the 1st field, if any
Expand All @@ -69,8 +69,7 @@ func (this *Server) runCPUProfile(args string) (string, error) {
for _, arg := range s[1:] {
switch arg {
case "block", "blocked", "blocking":
runtime.SetBlockProfileRate(1)
defer runtime.SetBlockProfileRate(0)
blockProfile = true
case "gzip":
useGzip = true
default:
Expand All @@ -84,6 +83,10 @@ func (this *Server) runCPUProfile(args string) (string, error) {

var buf bytes.Buffer
var writer io.Writer = &buf
if blockProfile {
runtime.SetBlockProfileRate(1)
defer runtime.SetBlockProfileRate(0)
}
if useGzip {
writer = gzip.NewWriter(&buf)
}
Expand Down

0 comments on commit 560a0ec

Please sign in to comment.