diff options
| author | Paul Bütow <pbuetow@mimecast.com> | 2020-01-26 11:26:53 +0000 |
|---|---|---|
| committer | Paul Bütow <pbuetow@mimecast.com> | 2020-02-07 13:31:15 +0000 |
| commit | 0945da8dfefcbb723eecea0e5f4eafff63398253 (patch) | |
| tree | f06dab4d2bf21d25d176b23d5baeca588d27f5d7 /internal/fs/stats.go | |
| parent | 2a8e5de265a0e0a31a5834909d6879f5c9941467 (diff) | |
Introduce drun command, refactor code to use context package
Diffstat (limited to 'internal/fs/stats.go')
| -rw-r--r-- | internal/fs/stats.go | 69 |
1 files changed, 0 insertions, 69 deletions
diff --git a/internal/fs/stats.go b/internal/fs/stats.go deleted file mode 100644 index 4121ff7..0000000 --- a/internal/fs/stats.go +++ /dev/null @@ -1,69 +0,0 @@ -package fs - -// Used to calculate how many log lines matched the regular expression -// and how many log files could be transmitted from the server to the client. -// Hit and transmit percentage takes only the last 100 log lines into calculation. -type stats struct { - pos int - lineCount uint64 - matched [100]bool - matchCount uint64 - transmitted [100]bool - transmitCount int -} - -// Return the total line count. -func (f *stats) totalLineCount() uint64 { - return f.lineCount -} - -// Calculate the percentage of log lines transmitted to the client. -func (f *stats) transmittedPerc() int { - return int(percentOf(float64(f.matchCount), float64(f.transmitCount))) -} - -// Update bucket position. We only take into consideration the last 100 -// lines for stats. -func (f *stats) updatePosition() { - f.pos = (f.pos + 1) % 100 - f.lineCount++ -} - -// Increment match counter. -func (f *stats) updateLineMatched() { - if !f.matched[f.pos] { - f.matchCount++ - f.matched[f.pos] = true - } -} - -// Increment transmitted counter. -func (f *stats) updateLineTransmitted() { - if !f.transmitted[f.pos] { - f.transmitCount++ - f.transmitted[f.pos] = true - } -} - -// Decrement match counter. -func (f *stats) updateLineNotMatched() { - if f.matched[f.pos] { - f.matchCount-- - f.matched[f.pos] = false - } -} - -// Decrement transmitted counter. -func (f *stats) updateLineNotTransmitted() { - if f.transmitted[f.pos] { - f.transmitCount-- - f.transmitted[f.pos] = false - } -} - -func percentOf(total float64, value float64) float64 { - if total == 0 || total == value { - return 100 - } - return value / (total / 100.0) -} |
