-
Notifications
You must be signed in to change notification settings - Fork 1
/
stats.go
105 lines (88 loc) · 2.68 KB
/
stats.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package bstore
// StatsKV represent operations on the underlying BoltDB key/value store.
type StatsKV struct {
Get uint
Put uint // For Stats.Bucket, this counts calls of CreateBucket.
Delete uint
Cursor uint // Any cursor operation: Seek/First/Last/Next/Prev.
}
// Stats tracks DB/Tx/Query statistics, mostly counters.
type Stats struct {
// Number of read-only or writable transactions. Set for DB only.
Reads uint
Writes uint
Bucket StatsKV // Use of buckets.
Records StatsKV // Use of records bucket for types.
Index StatsKV // Use of index buckets for types.
// Operations that modify the database. Each record is counted, e.g.
// for a query that updates/deletes multiple records.
Get uint
Insert uint
Update uint
Delete uint
Queries uint // Total queries executed.
PlanTableScan uint // Full table scans.
PlanPK uint // Primary key get.
PlanUnique uint // Full key Unique index get.
PlanPKScan uint // Scan over primary keys.
PlanIndexScan uint // Scan over index.
Sort uint // In-memory collect and sort.
LastType string // Last type queried.
LastIndex string // Last index for LastType used for a query, or empty.
LastOrdered bool // Whether last scan (PK or index) use was ordered, e.g. for sorting or because of a comparison filter.
LastAsc bool // If ordered, whether last index scan was ascending.
}
func (skv *StatsKV) add(n StatsKV) {
skv.Get += n.Get
skv.Put += n.Put
skv.Delete += n.Delete
skv.Cursor += n.Cursor
}
func (skv *StatsKV) sub(n StatsKV) {
skv.Get -= n.Get
skv.Put -= n.Put
skv.Delete -= n.Delete
skv.Cursor -= n.Cursor
}
func (st *Stats) add(n Stats) {
st.Reads += n.Reads
st.Writes += n.Writes
st.Bucket.add(n.Bucket)
st.Records.add(n.Records)
st.Index.add(n.Index)
st.Get += n.Get
st.Insert += n.Insert
st.Update += n.Update
st.Delete += n.Delete
st.Queries += n.Queries
st.PlanTableScan += n.PlanTableScan
st.PlanPK += n.PlanPK
st.PlanUnique += n.PlanUnique
st.PlanPKScan += n.PlanPKScan
st.PlanIndexScan += n.PlanIndexScan
st.Sort += n.Sort
st.LastType = n.LastType
st.LastIndex = n.LastIndex
st.LastOrdered = n.LastOrdered
st.LastAsc = n.LastAsc
}
// Sub returns st with the counters from o subtracted.
func (st Stats) Sub(o Stats) Stats {
st.Reads -= o.Reads
st.Writes -= o.Writes
st.Bucket.sub(o.Bucket)
st.Records.sub(o.Records)
st.Index.sub(o.Index)
st.Get -= o.Get
st.Insert -= o.Insert
st.Update -= o.Update
st.Delete -= o.Delete
st.Queries -= o.Queries
st.PlanTableScan -= o.PlanTableScan
st.PlanPK -= o.PlanPK
st.PlanUnique -= o.PlanUnique
st.PlanPKScan -= o.PlanPKScan
st.PlanIndexScan -= o.PlanIndexScan
st.Sort -= o.Sort
return st
}