Commit 990f3c11 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Make recording latency statistics optional.

parent bfe98501
...@@ -71,6 +71,7 @@ type MountState struct { ...@@ -71,6 +71,7 @@ type MountState struct {
// For efficient reads and writes. // For efficient reads and writes.
buffers *BufferPool buffers *BufferPool
RecordStatistics bool
statisticsMutex sync.Mutex statisticsMutex sync.Mutex
operationCounts map[string]int64 operationCounts map[string]int64
...@@ -186,21 +187,23 @@ func (me *MountState) discardRequest(req *request) { ...@@ -186,21 +187,23 @@ func (me *MountState) discardRequest(req *request) {
endNs := time.Nanoseconds() endNs := time.Nanoseconds()
dt := endNs - req.startNs dt := endNs - req.startNs
me.statisticsMutex.Lock() if me.RecordStatistics {
defer me.statisticsMutex.Unlock() me.statisticsMutex.Lock()
defer me.statisticsMutex.Unlock()
opname := operationName(req.inHeader.Opcode) opname := operationName(req.inHeader.Opcode)
key := opname key := opname
me.operationCounts[key] += 1 me.operationCounts[key] += 1
me.operationLatencies[key] += dt me.operationLatencies[key] += dt
key += "-dispatch" key += "-dispatch"
me.operationLatencies[key] += (req.dispatchNs - req.startNs) me.operationLatencies[key] += (req.dispatchNs - req.startNs)
me.operationCounts[key] += 1 me.operationCounts[key] += 1
key = opname + "-write" key = opname + "-write"
me.operationLatencies[key] += (endNs - req.preWriteNs) me.operationLatencies[key] += (endNs - req.preWriteNs)
me.operationCounts[key] += 1 me.operationCounts[key] += 1
}
me.buffers.FreeBuffer(req.inputBuf) me.buffers.FreeBuffer(req.inputBuf)
me.buffers.FreeBuffer(req.flatData) me.buffers.FreeBuffer(req.flatData)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment