Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disable tracking lock stack traces by default #481

Merged
merged 1 commit into from
Sep 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions utils/lock_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
var lockTrackerEnabled = false
var enableLockTrackerOnce sync.Once
var lowResTime uint32 = uint32(time.Now().Unix())
var enableLockTrackerStackTrace uint32

// EnableLockTracker enable lock tracking background worker. This should be
// called during init
Expand All @@ -36,6 +37,14 @@ func EnableLockTracker() {
})
}

func ToggleLockTrackerStackTraces(enable bool) {
var v uint32
if enable {
v = 1
}
atomic.StoreUint32(&enableLockTrackerStackTrace, v)
}

func updateLowResTime() {
ticker := time.NewTicker(time.Second)
for t := range ticker.C {
Expand Down Expand Up @@ -151,13 +160,15 @@ func (t *lockTracker) trackLock() {
if atomic.AddInt32(&t.held, 1) == 1 {
atomic.StoreUint32(&t.ts, atomic.LoadUint32(&lowResTime))

for {
n := runtime.Stack(t.stack[:cap(t.stack)], false)
if n < cap(t.stack) {
t.stack = t.stack[:n]
break
if atomic.LoadUint32(&enableLockTrackerStackTrace) == 1 {
for {
n := runtime.Stack(t.stack[:cap(t.stack)], false)
if n < cap(t.stack) {
t.stack = t.stack[:n]
break
}
t.stack = make([]byte, len(t.stack)*2)
}
t.stack = make([]byte, len(t.stack)*2)
}
}
}
Expand Down
Loading