-
Notifications
You must be signed in to change notification settings - Fork 0
/
monitoring.go
53 lines (43 loc) · 1.08 KB
/
monitoring.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
package edb
import (
"encoding/json"
"reflect"
)
type TableStats struct {
Rows int
IndexRows int
DataSize int
DataAlloc int
IndexSize int
IndexAlloc int
}
func (ts *TableStats) TotalSize() int {
return ts.DataSize + ts.IndexSize
}
func (ts *TableStats) TotalAlloc() int {
return ts.DataAlloc + ts.IndexAlloc
}
func (tx *Tx) TableStats(tbl *Table) TableStats {
tableBuck := nonNil(tx.btx.Bucket(tbl.buck.Raw()))
dataBuck := nonNil(tableBuck.Bucket(dataBucket.Raw()))
bs := dataBuck.Stats()
result := TableStats{
Rows: bs.KeyN,
DataSize: bs.LeafInuse,
DataAlloc: bs.BranchAlloc + bs.LeafAlloc,
}
for _, idx := range tbl.indices {
indexBuck := nonNil(tableBuck.Bucket(idx.buck.Raw()))
bs = indexBuck.Stats()
result.IndexRows += bs.KeyN
result.IndexSize += bs.LeafInuse
result.IndexAlloc += bs.BranchAlloc + bs.LeafAlloc
}
return result
}
func loggableRowVal(rowVal reflect.Value) string {
return string(must(json.Marshal(rowVal.Interface())))
}
func loggableVal(rowVal reflect.Value) string {
return string(must(json.Marshal(rowVal.Interface())))
}