aboutsummaryrefslogtreecommitdiffstats
path: root/modules/graceful/manager_unix.go
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2022-03-25 12:47:12 +0000
committerGitHub <noreply@github.com>2022-03-25 12:47:12 +0000
commit5fe764b1eb7bf4da752b047c25794316f31b68d6 (patch)
treed043315969709a45b845c457c05c8b1dca6e27e1 /modules/graceful/manager_unix.go
parente48f3b05278db8b292a4211d8735913361eb27c7 (diff)
downloadgitea-5fe764b1eb7bf4da752b047c25794316f31b68d6.tar.gz
gitea-5fe764b1eb7bf4da752b047c25794316f31b68d6.zip
Add pprof labels in processes and for lifecycles (#19202)
Use pprof labelling to help identify goroutines with stacks. Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'modules/graceful/manager_unix.go')
-rw-r--r--modules/graceful/manager_unix.go17
1 files changed, 14 insertions, 3 deletions
diff --git a/modules/graceful/manager_unix.go b/modules/graceful/manager_unix.go
index 99e84d73e8..6fbb2bda29 100644
--- a/modules/graceful/manager_unix.go
+++ b/modules/graceful/manager_unix.go
@@ -12,6 +12,7 @@ import (
"errors"
"os"
"os/signal"
+ "runtime/pprof"
"sync"
"syscall"
"time"
@@ -29,11 +30,11 @@ type Manager struct {
shutdownCtx context.Context
hammerCtx context.Context
terminateCtx context.Context
- doneCtx context.Context
+ managerCtx context.Context
shutdownCtxCancel context.CancelFunc
hammerCtxCancel context.CancelFunc
terminateCtxCancel context.CancelFunc
- doneCtxCancel context.CancelFunc
+ managerCtxCancel context.CancelFunc
runningServerWaitGroup sync.WaitGroup
createServerWaitGroup sync.WaitGroup
terminateWaitGroup sync.WaitGroup
@@ -58,7 +59,17 @@ func (g *Manager) start(ctx context.Context) {
g.terminateCtx, g.terminateCtxCancel = context.WithCancel(ctx)
g.shutdownCtx, g.shutdownCtxCancel = context.WithCancel(ctx)
g.hammerCtx, g.hammerCtxCancel = context.WithCancel(ctx)
- g.doneCtx, g.doneCtxCancel = context.WithCancel(ctx)
+ g.managerCtx, g.managerCtxCancel = context.WithCancel(ctx)
+
+ // Next add pprof labels to these contexts
+ g.terminateCtx = pprof.WithLabels(g.terminateCtx, pprof.Labels("graceful-lifecycle", "with-terminate"))
+ g.shutdownCtx = pprof.WithLabels(g.shutdownCtx, pprof.Labels("graceful-lifecycle", "with-shutdown"))
+ g.hammerCtx = pprof.WithLabels(g.hammerCtx, pprof.Labels("graceful-lifecycle", "with-hammer"))
+ g.managerCtx = pprof.WithLabels(g.managerCtx, pprof.Labels("graceful-lifecycle", "with-manager"))
+
+ // Now label this and all goroutines created by this goroutine with the graceful-lifecycle manager
+ pprof.SetGoroutineLabels(g.managerCtx)
+ defer pprof.SetGoroutineLabels(ctx)
// Set the running state & handle signals
g.setState(stateRunning)