From fa82a64ce23231da85315e0757e2c0db8ef5ed1d Mon Sep 17 00:00:00 2001 From: Yi Duan Date: Tue, 14 Feb 2023 14:48:22 +0800 Subject: [PATCH] feat: add env option `SONIC_STOP_PROFILING` to stop traceback on demands (#361) --- internal/rt/asm_amd64.s | 4 ++++ internal/rt/gcwb.go | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/internal/rt/asm_amd64.s b/internal/rt/asm_amd64.s index d7abffd..8250e38 100644 --- a/internal/rt/asm_amd64.s +++ b/internal/rt/asm_amd64.s @@ -22,6 +22,8 @@ _stack_grow: TEXT ·StopProf(SB), NOSPLIT, $0-0 NO_LOCAL_POINTERS + CMPB github·com∕bytedance∕sonic∕internal∕rt·StopProfiling(SB), $0 + JEQ _ret_1 MOVL $1, AX LEAQ github·com∕bytedance∕sonic∕internal∕rt·yieldCount(SB), CX LOCK @@ -37,6 +39,8 @@ _ret_1: TEXT ·StartProf(SB), NOSPLIT, $0-0 NO_LOCAL_POINTERS + CMPB github·com∕bytedance∕sonic∕internal∕rt·StopProfiling(SB), $0 + JEQ _ret_2 MOVL $-1, AX LEAQ github·com∕bytedance∕sonic∕internal∕rt·yieldCount(SB), CX LOCK diff --git a/internal/rt/gcwb.go b/internal/rt/gcwb.go index 2cec9df..c3217c8 100644 --- a/internal/rt/gcwb.go +++ b/internal/rt/gcwb.go @@ -17,6 +17,7 @@ package rt import ( + `os` `sync/atomic` `unsafe` @@ -75,6 +76,11 @@ func GcwbAddr() uintptr { } } +// StopProfiling is used to stop traceback introduced by SIGPROF while native code is running. +// WARN: this option is only a workaround for traceback issue (https://github.com/bytedance/sonic/issues/310), +// and will be dropped when the issue is fixed. +var StopProfiling = os.Getenv("SONIC_STOP_PROFILING") != "" + // WARN: must be aligned with runtime.Prof // type Prof struct { // signalLock uint32