diff options
-rw-r--r-- | funcs.go | 6 | ||||
-rw-r--r-- | global.go | 1 | ||||
-rw-r--r-- | metrics.go | 7 | ||||
-rw-r--r-- | tx.go | 1 |
4 files changed, 14 insertions, 1 deletions
@@ -6,6 +6,7 @@ import ( var ( txPool = sync.Pool{New: func() interface{} { + expvars.Add("new txs", 1) tx := &Tx{ reads: make(map[*Var]uint64), writes: make(map[*Var]interface{}), @@ -17,6 +18,7 @@ var ( // Atomically executes the atomic function fn. func Atomically(fn func(*Tx)) interface{} { + expvars.Add("atomically", 1) // run the transaction tx := txPool.Get().(*Tx) retry: @@ -29,8 +31,10 @@ retry: return } if _ret, ok := r.(_return); ok { + expvars.Add("explicit returns", 1) ret = _ret.value } else if r == Retry { + expvars.Add("retries", 1) // wait for one of the variables we read to change before retrying tx.wait() retry = true @@ -47,11 +51,13 @@ retry: tx.lockAllVars() if !tx.verify() { tx.unlock() + expvars.Add("failed commits", 1) goto retry } // commit the write log and broadcast that variables have changed tx.commit() tx.unlock() + expvars.Add("commits", 1) tx.recycle() return ret } diff --git a/global.go b/global.go deleted file mode 100644 index 4974334..0000000 --- a/global.go +++ /dev/null @@ -1 +0,0 @@ -package stm diff --git a/metrics.go b/metrics.go new file mode 100644 index 0000000..b8563e2 --- /dev/null +++ b/metrics.go @@ -0,0 +1,7 @@ +package stm + +import ( + "expvar" +) + +var expvars = expvar.NewMap("stm") @@ -47,6 +47,7 @@ func (tx *Tx) wait() { } tx.mu.Lock() for tx.verify() { + expvars.Add("waits", 1) tx.cond.Wait() } tx.mu.Unlock() |