-
Notifications
You must be signed in to change notification settings - Fork 3
/
dbg.go
69 lines (59 loc) · 1.02 KB
/
dbg.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
package arbo
import "fmt"
// dbgStats is for debug purposes
type dbgStats struct {
hash int // TODO use atomics for all ints in dbgStats
dbGet int
dbPut int
}
func (t *Tree) dbgInit() {
t.dbg = newDbgStats()
}
func newDbgStats() *dbgStats {
return &dbgStats{
hash: 0,
dbGet: 0,
dbPut: 0,
}
}
func (d *dbgStats) incHash() {
if d == nil {
return
}
d.hash++
}
//nolint:unused
func (d *dbgStats) incDbGet() {
if d == nil {
return
}
d.dbGet++
}
//nolint:unused
func (d *dbgStats) incDbPut() {
if d == nil {
return
}
d.dbPut++
}
func (d *dbgStats) add(d2 *dbgStats) {
if d == nil || d2 == nil {
return
}
d.hash += d2.hash
d.dbGet += d2.dbGet
d.dbPut += d2.dbPut
}
func (d *dbgStats) print(prefix string) {
if d == nil {
return
}
fmt.Printf("%sdbgStats(hash: %s, dbGet: %s, dbPut: %s)\n",
prefix, formatK(d.hash), formatK(d.dbGet), formatK(d.dbPut))
}
func formatK(v int) string {
if v/1000 > 0 {
return fmt.Sprintf("%.3fk", float64(v)/1000) //nolint:gomnd
}
return fmt.Sprintf("%d", v)
}