-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats.go
115 lines (96 loc) · 2.3 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
106
107
108
109
110
111
112
113
114
115
package rindex
import "sync"
// IndexStats is returned every time an new document is indexed or when
// the indexing process finishes.
type IndexStats struct {
// Files that did not pass the filter (not indexed)
Mismatch uint64
// Number of nodes (files or directories) scanned
ScannedNodes uint64
// Number of files indexed
IndexedFiles uint64
// Number of snapshots visited for indexing
ScannedSnapshots uint64
// Number of files previously indexed
AlreadyIndexed uint64
// Number of files scanned
ScannedFiles uint64
// Errors found while scanning or indexing files
Errors []error
// Last file indexed
LastMatch string
// Snapshots that will be scanned
MissingSnapshots uint64
// List of files in every snapshot
SnapshotFiles map[string]uint64
// Number of files scanned in the current snapshot
CurrentSnapshotFiles uint64
// Total number of files in the snapshot being scanned
CurrentSnapshotTotalFiles uint64
// Total number of snapshots
TotalSnapshots uint64
m *sync.Mutex
}
func NewStats() IndexStats {
return IndexStats{Errors: []error{}, SnapshotFiles: map[string]uint64{}, m: &sync.Mutex{}}
}
func (s *IndexStats) ErrorsAdd(err error) {
s.m.Lock()
s.Errors = append(s.Errors, err)
s.m.Unlock()
}
func (s *IndexStats) ScannedSnapshotsInc() {
s.m.Lock()
s.ScannedSnapshots++
s.m.Unlock()
}
func (s *IndexStats) ScannedNodesInc() {
s.m.Lock()
s.ScannedNodes++
s.m.Unlock()
}
func (s *IndexStats) IndexedFilesInc() {
s.m.Lock()
s.IndexedFiles++
s.m.Unlock()
}
func (s *IndexStats) MismatchInc() {
s.m.Lock()
s.Mismatch++
s.m.Unlock()
}
func (s *IndexStats) ScannedFilesInc() {
s.m.Lock()
s.ScannedFiles++
s.m.Unlock()
}
func (s *IndexStats) AlreadyIndexedInc() {
s.m.Lock()
s.AlreadyIndexed++
s.m.Unlock()
}
func (s *IndexStats) SetMissingSnapshots(count uint64) {
s.m.Lock()
s.MissingSnapshots = count
s.m.Unlock()
}
func (s *IndexStats) SetSnapshotFiles(id string, count uint64) {
s.m.Lock()
s.SnapshotFiles[id] = count
s.m.Unlock()
}
func (s *IndexStats) SetCurrentSnapshotTotalFiles(count uint64) {
s.m.Lock()
s.CurrentSnapshotTotalFiles = count
s.m.Unlock()
}
func (s *IndexStats) CurrentSnapshotFilesInc() {
s.m.Lock()
s.CurrentSnapshotFiles++
s.m.Unlock()
}
func (s *IndexStats) SetTotalSnapshots(count uint64) {
s.m.Lock()
s.TotalSnapshots = count
s.m.Unlock()
}