Skip to content

Commit

Permalink
disable tracking lock stack traces by default (#481)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulwe authored Sep 23, 2023
1 parent 821c244 commit 9087b5d
Showing 1 changed file with 17 additions and 6 deletions.
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

0 comments on commit 9087b5d

Please sign in to comment.