Commit f1e3a827 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Use LatencyMap to signal whether to record stats.

parent 2e0db5ff
...@@ -73,7 +73,7 @@ func main() { ...@@ -73,7 +73,7 @@ func main() {
state.Debug = *debug state.Debug = *debug
if *latencies { if *latencies {
state.RecordStatistics = true state.SetRecordStatistics(true)
debugFs.AddMountState(state) debugFs.AddMountState(state)
debugFs.AddFileSystemConnector(conn) debugFs.AddFileSystemConnector(conn)
} }
......
...@@ -44,7 +44,7 @@ func main() { ...@@ -44,7 +44,7 @@ func main() {
} }
mountPoint := flag.Arg(0) mountPoint := flag.Arg(0)
state.RecordStatistics = *latencies state.SetRecordStatistics(*latencies)
state.Debug = *debug state.Debug = *debug
state.Mount(mountPoint) state.Mount(mountPoint)
......
...@@ -70,7 +70,6 @@ type MountState struct { ...@@ -70,7 +70,6 @@ type MountState struct {
// For efficient reads and writes. // For efficient reads and writes.
buffers *BufferPool buffers *BufferPool
RecordStatistics bool
*LatencyMap *LatencyMap
} }
...@@ -82,10 +81,17 @@ func (me *MountState) Mount(mountPoint string) os.Error { ...@@ -82,10 +81,17 @@ func (me *MountState) Mount(mountPoint string) os.Error {
} }
me.mountPoint = mp me.mountPoint = mp
me.mountFile = file me.mountFile = file
me.LatencyMap = NewLatencyMap()
return nil return nil
} }
func (me *MountState) SetRecordStatistics(record bool) {
if record {
me.LatencyMap = NewLatencyMap()
} else {
me.LatencyMap = nil
}
}
func (me *MountState) Unmount() os.Error { func (me *MountState) Unmount() os.Error {
// Todo: flush/release all files/dirs? // Todo: flush/release all files/dirs?
result := unmount(me.mountPoint) result := unmount(me.mountPoint)
...@@ -96,7 +102,7 @@ func (me *MountState) Unmount() os.Error { ...@@ -96,7 +102,7 @@ func (me *MountState) Unmount() os.Error {
} }
func (me *MountState) Write(req *request) { func (me *MountState) Write(req *request) {
if me.RecordStatistics { if me.LatencyMap != nil {
req.preWriteNs = time.Nanoseconds() req.preWriteNs = time.Nanoseconds()
} }
...@@ -153,7 +159,7 @@ func (me *MountState) readRequest(req *request) os.Error { ...@@ -153,7 +159,7 @@ func (me *MountState) readRequest(req *request) os.Error {
n, err := me.mountFile.Read(req.inputBuf) n, err := me.mountFile.Read(req.inputBuf)
// If we start timing before the read, we may take into // If we start timing before the read, we may take into
// account waiting for input into the timing. // account waiting for input into the timing.
if me.RecordStatistics { if me.LatencyMap != nil {
req.startNs = time.Nanoseconds() req.startNs = time.Nanoseconds()
} }
req.inputBuf = req.inputBuf[0:n] req.inputBuf = req.inputBuf[0:n]
...@@ -161,7 +167,7 @@ func (me *MountState) readRequest(req *request) os.Error { ...@@ -161,7 +167,7 @@ func (me *MountState) readRequest(req *request) os.Error {
} }
func (me *MountState) discardRequest(req *request) { func (me *MountState) discardRequest(req *request) {
if me.RecordStatistics { if me.LatencyMap != nil {
endNs := time.Nanoseconds() endNs := time.Nanoseconds()
dt := endNs - req.startNs dt := endNs - req.startNs
...@@ -273,7 +279,7 @@ func (me *MountState) handle(req *request) { ...@@ -273,7 +279,7 @@ func (me *MountState) handle(req *request) {
} }
func (me *MountState) dispatch(req *request, handler *operationHandler) { func (me *MountState) dispatch(req *request, handler *operationHandler) {
if me.RecordStatistics { if me.LatencyMap != nil {
req.dispatchNs = time.Nanoseconds() req.dispatchNs = time.Nanoseconds()
} }
......
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