Lock tracing, fixes

This commit is contained in:
Jakob Borg 2013-12-24 20:31:25 -05:00
parent 4151972d3e
commit cf04e101b9
2 changed files with 46 additions and 9 deletions

43
locktrace.go Normal file
View File

@ -0,0 +1,43 @@
//+build locktrace
package main
import (
"log"
"path"
"runtime"
"time"
)
var (
lockTime time.Time
)
func (m *Model) Lock() {
_, file, line, _ := runtime.Caller(1)
log.Printf("%s:%d: Lock()...", path.Base(file), line)
blockTime := time.Now()
m.RWMutex.Lock()
lockTime = time.Now()
log.Printf("%s:%d: ...Lock() [%.04f ms]", path.Base(file), line, time.Since(blockTime).Seconds()*1000)
}
func (m *Model) Unlock() {
_, file, line, _ := runtime.Caller(1)
m.RWMutex.Unlock()
log.Printf("%s:%d: Unlock() [%.04f ms]", path.Base(file), line, time.Since(lockTime).Seconds()*1000)
}
func (m *Model) RLock() {
_, file, line, _ := runtime.Caller(1)
log.Printf("%s:%d: RLock()...", path.Base(file), line)
blockTime := time.Now()
m.RWMutex.RLock()
log.Printf("%s:%d: ...RLock() [%.04f ms]", path.Base(file), line, time.Since(blockTime).Seconds()*1000)
}
func (m *Model) RUnlock() {
_, file, line, _ := runtime.Caller(1)
m.RWMutex.RUnlock()
log.Printf("%s:%d: RUnlock()", path.Base(file), line)
}

View File

@ -233,16 +233,10 @@ func (m *Model) ReplaceLocal(fs []File) {
m.recomputeGlobal() m.recomputeGlobal()
m.recomputeNeed() m.recomputeNeed()
m.updated = time.Now().Unix() m.updated = time.Now().Unix()
m.broadcastIndex() m.lastIdxBcastRequest = time.Now()
} }
} }
func (m *Model) broadcastIndex() {
m.Lock()
defer m.Unlock()
m.lastIdxBcastRequest = time.Now()
}
func (m *Model) broadcastIndexLoop() { func (m *Model) broadcastIndexLoop() {
for { for {
m.RLock() m.RLock()
@ -263,7 +257,7 @@ func (m *Model) broadcastIndexLoop() {
m.lastIdxBcast = time.Now() m.lastIdxBcast = time.Now()
} }
m.RUnlock() m.RUnlock()
time.Sleep(idxBcastHoldtime) time.Sleep(idxBcastHoldtime / 2)
} }
} }
@ -300,7 +294,7 @@ func (m *Model) UpdateLocal(f File) {
m.recomputeGlobal() m.recomputeGlobal()
m.recomputeNeed() m.recomputeNeed()
m.updated = time.Now().Unix() m.updated = time.Now().Unix()
m.broadcastIndex() m.lastIdxBcastRequest = time.Now()
} }
} }