Skip to content

Commit

Permalink
Allow PPROFLISTEN on all builds
Browse files Browse the repository at this point in the history
  • Loading branch information
neilalexander committed Oct 21, 2023
1 parent 6a94937 commit 80e56ea
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions src/core/debug.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
//go:build debug
// +build debug

package core

import (
"fmt"
"net/http"
_ "net/http/pprof"
"os"
"runtime"

"github.com/gologme/log"
)

// Start the profiler in debug builds, if the required environment variable is set.
// Start the profiler if the required environment variable is set.
func init() {
envVarName := "PPROFLISTEN"
hostPort := os.Getenv(envVarName)
Expand All @@ -22,14 +16,6 @@ func init() {
fmt.Fprintf(os.Stderr, "DEBUG: %s not set, profiler not started.\n", envVarName)
default:
fmt.Fprintf(os.Stderr, "DEBUG: Starting pprof on %s\n", hostPort)
go func() { fmt.Println(http.ListenAndServe(hostPort, nil)) }()
go fmt.Println(http.ListenAndServe(hostPort, nil))
}
}

// Starts the function profiler. This is only supported when built with
// '-tags build'.
func StartProfiler(log *log.Logger) error {
runtime.SetBlockProfileRate(1)
go func() { log.Println(http.ListenAndServe("localhost:6060", nil)) }()
return nil
}

0 comments on commit 80e56ea

Please sign in to comment.