github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/kbfs/ldbutils/meter_snapshot.go (about) 1 // Copied from github.com/rcrowley/go-metrics so that we can populate 2 // unexported fields. 3 // 4 // Copyright 2012 Richard Crowley. All rights reserved. 5 // 6 // Redistribution and use in source and binary forms, with or without 7 // modification, are permitted provided that the following conditions are 8 // met: 9 // 10 // 1. Redistributions of source code must retain the above copyright 11 // notice, this list of conditions and the following disclaimer. 12 // 13 // 2. Redistributions in binary form must reproduce the above 14 // copyright notice, this list of conditions and the following 15 // disclaimer in the documentation and/or other materials provided 16 // with the distribution. 17 // 18 // THIS SOFTWARE IS PROVIDED BY RICHARD CROWLEY ``AS IS'' AND ANY EXPRESS 19 // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 // DISCLAIMED. IN NO EVENT SHALL RICHARD CROWLEY OR CONTRIBUTORS BE LIABLE 22 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28 // THE POSSIBILITY OF SUCH DAMAGE. 29 // 30 // The views and conclusions contained in the software and documentation 31 // are those of the authors and should not be interpreted as representing 32 // official policies, either expressed or implied, of Richard Crowley. 33 34 package ldbutils 35 36 import metrics "github.com/rcrowley/go-metrics" 37 38 // MeterSnapshot is a read-only copy of another Meter. 39 type MeterSnapshot struct { 40 count int64 41 rate1, rate5, rate15, rateMean float64 42 } 43 44 var _ metrics.Meter = (*MeterSnapshot)(nil) 45 46 // Count returns the count of events at the time the snapshot was taken. 47 func (m *MeterSnapshot) Count() int64 { return m.count } 48 49 // Mark panics. 50 func (*MeterSnapshot) Mark(n int64) { 51 panic("Mark called on a MeterSnapshot") 52 } 53 54 // Rate1 returns the one-minute moving average rate of events per second at the 55 // time the snapshot was taken. 56 func (m *MeterSnapshot) Rate1() float64 { return m.rate1 } 57 58 // Rate5 returns the five-minute moving average rate of events per second at 59 // the time the snapshot was taken. 60 func (m *MeterSnapshot) Rate5() float64 { return m.rate5 } 61 62 // Rate15 returns the fifteen-minute moving average rate of events per second 63 // at the time the snapshot was taken. 64 func (m *MeterSnapshot) Rate15() float64 { return m.rate15 } 65 66 // RateMean returns the meter's mean rate of events per second at the time the 67 // snapshot was taken. 68 func (m *MeterSnapshot) RateMean() float64 { return m.rateMean } 69 70 // Snapshot returns the snapshot. 71 func (m *MeterSnapshot) Snapshot() metrics.Meter { return m }