Skip to content

Commit f72d6c5

Browse files
committed
feat: support WERF_PRINT_STACK_TRACES=1 env var for period stack traces
Signed-off-by: Ilya Lesikov <ilya@lesikov.com>
1 parent 0049ae8 commit f72d6c5

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

Diff for: cmd/werf/main.go

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import (
1919
func main() {
2020
ctx := common.GetContextWithLogger()
2121

22+
root.PrintStackTraces()
23+
2224
shouldTerminate, err := common.ContainerBackendProcessStartupHook()
2325
if err != nil {
2426
common.TerminateWithError(err.Error(), 1)

Diff for: cmd/werf/root/root.go

+27
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import (
55
"fmt"
66
"os"
77
"path/filepath"
8+
"runtime"
9+
"strconv"
10+
"time"
811

912
"github.com/spf13/cobra"
1013

@@ -256,3 +259,27 @@ func SetupTelemetryInit(rootCmd *cobra.Command) {
256259
}
257260
}
258261
}
262+
263+
func PrintStackTraces() {
264+
if os.Getenv("WERF_PRINT_STACK_TRACES") != "1" {
265+
return
266+
}
267+
268+
period := 5
269+
if prd := os.Getenv("WERF_PRINT_STACK_TRACES_PERIOD"); prd != "" {
270+
p, err := strconv.Atoi(prd)
271+
if err == nil {
272+
period = p
273+
}
274+
}
275+
276+
go func() {
277+
for {
278+
buf := make([]byte, 1<<16)
279+
runtime.Stack(buf, true)
280+
fmt.Printf("%s", buf)
281+
282+
time.Sleep(time.Second * time.Duration(period))
283+
}
284+
}()
285+
}

0 commit comments

Comments
 (0)