From a2335b65b2ccf7e6ffc440ca3d61dd6bec9e9163 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Wed, 8 Apr 2026 22:23:55 +0300 Subject: Task e: gate debug signal handlers behind build tag --- README.md | 4 +++- internal/debug/signals.go | 2 +- internal/debug/signals_disabled.go | 10 ++++++++++ internal/debug/signals_test.go | 5 +++-- 4 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 internal/debug/signals_disabled.go diff --git a/README.md b/README.md index 94359f8..1e4753a 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ If Task Samurai appears to hang or freeze, you can capture runtime diagnostics u ### Signal Handlers (Unix/Linux/macOS only) -Task Samurai supports two debugging signals: +Task Samurai supports two debugging signals when built with the `debugsignals` build tag: #### SIGUSR1 - Quick Goroutine Dump @@ -100,6 +100,8 @@ This creates multiple files: - `tasksamurai-TIMESTAMP-cpu.pprof` - CPU profile (5 second sample) - `tasksamurai-TIMESTAMP-block.pprof` - Lock contention events +Build with `-tags debugsignals` to enable these handlers in a local or debug build. + ### Analyzing Profiles Use Go's pprof tool to analyze the binary profile files: diff --git a/internal/debug/signals.go b/internal/debug/signals.go index 20a463a..adcfb01 100644 --- a/internal/debug/signals.go +++ b/internal/debug/signals.go @@ -1,4 +1,4 @@ -//go:build !windows +//go:build debugsignals && !windows package debug diff --git a/internal/debug/signals_disabled.go b/internal/debug/signals_disabled.go new file mode 100644 index 0000000..2c9b65e --- /dev/null +++ b/internal/debug/signals_disabled.go @@ -0,0 +1,10 @@ +//go:build !debugsignals && !windows + +package debug + +// SetDebugDir sets the directory where debug output files will be written. +// In production builds, runtime signal diagnostics are disabled. +func SetDebugDir(dir string) {} + +// InitSignalHandlers is a no-op in production builds. +func InitSignalHandlers() {} diff --git a/internal/debug/signals_test.go b/internal/debug/signals_test.go index d7b0d2d..641e638 100644 --- a/internal/debug/signals_test.go +++ b/internal/debug/signals_test.go @@ -1,4 +1,5 @@ -// +build !windows +//go:build debugsignals && !windows +// +build debugsignals,!windows package debug @@ -55,7 +56,7 @@ func TestDumpGoroutines(t *testing.T) { func TestWriteProfile(t *testing.T) { tmpDir := t.TempDir() - + // Test goroutine profile (text format) goroutineFile := filepath.Join(tmpDir, "test-goroutine.txt") if err := writeProfile(goroutineFile, "goroutine", 1); err != nil { -- cgit v1.2.3