mirror of
https://github.com/coder/coder.git
synced 2025-07-09 11:45:56 +00:00
feat: Add support for pprof in coder agent
(#1985)
* feat: Allow USR1 signal to start pprof
This commit is contained in:
committed by
GitHub
parent
0ac37b146d
commit
59a6826920
38
cli/agent_unix.go
Normal file
38
cli/agent_unix.go
Normal file
@ -0,0 +1,38 @@
|
||||
//go:build !windows
|
||||
|
||||
package cli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"cdr.dev/slog"
|
||||
)
|
||||
|
||||
func agentStartPPROFOnUSR1(ctx context.Context, logger slog.Logger, pprofAddress string) (srvClose func()) {
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
|
||||
usr1 := make(chan os.Signal, 1)
|
||||
signal.Notify(usr1, syscall.SIGUSR1)
|
||||
go func() {
|
||||
defer close(usr1)
|
||||
defer signal.Stop(usr1)
|
||||
|
||||
select {
|
||||
case <-usr1:
|
||||
signal.Stop(usr1)
|
||||
srvClose := serveHandler(ctx, logger, nil, pprofAddress, "pprof")
|
||||
defer srvClose()
|
||||
case <-ctx.Done():
|
||||
return
|
||||
}
|
||||
<-ctx.Done() // Prevent defer close until done.
|
||||
}()
|
||||
|
||||
return func() {
|
||||
cancel()
|
||||
<-usr1 // Wait until usr1 is closed, ensures srvClose was run.
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user