mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
metrics: apply suggestions from review
This commit is contained in:
parent
c8e1767e33
commit
267656019b
5 changed files with 15 additions and 15 deletions
|
|
@ -82,7 +82,6 @@ func (c counterSnapshot) Count() int64 { return int64(c) }
|
|||
// NilCounter is a no-op Counter.
|
||||
type NilCounter struct{}
|
||||
|
||||
// Clear is a no-op.
|
||||
func (NilCounter) Clear() {}
|
||||
func (NilCounter) Dec(i int64) {}
|
||||
func (NilCounter) Inc(i int64) {}
|
||||
|
|
|
|||
|
|
@ -39,12 +39,12 @@ func NewEWMA15() EWMA {
|
|||
return NewEWMA(1 - math.Exp(-5.0/60.0/15))
|
||||
}
|
||||
|
||||
// eWMASnapshot is a read-only copy of another EWMA.
|
||||
type eWMASnapshot float64
|
||||
// ewmaSnapshot is a read-only copy of another EWMA.
|
||||
type ewmaSnapshot float64
|
||||
|
||||
// Rate returns the rate of events per second at the time the snapshot was
|
||||
// taken.
|
||||
func (a eWMASnapshot) Rate() float64 { return float64(a) }
|
||||
func (a ewmaSnapshot) Rate() float64 { return float64(a) }
|
||||
|
||||
// NilEWMA is a no-op EWMA.
|
||||
type NilEWMA struct{}
|
||||
|
|
@ -67,7 +67,7 @@ type StandardEWMA struct {
|
|||
// Snapshot returns a read-only copy of the EWMA.
|
||||
func (a *StandardEWMA) Snapshot() EWMASnapshot {
|
||||
r := math.Float64frombits(a.rate.Load()) * float64(time.Second)
|
||||
return eWMASnapshot(r)
|
||||
return ewmaSnapshot(r)
|
||||
}
|
||||
|
||||
// Tick ticks the clock to update the moving average. It assumes it is called
|
||||
|
|
|
|||
|
|
@ -76,8 +76,14 @@ func (g *StandardGauge) Update(v int64) {
|
|||
|
||||
// Update updates the gauge's value if v is larger then the current valie.
|
||||
func (g *StandardGauge) UpdateIfGt(v int64) {
|
||||
if g.value.Load() < v {
|
||||
g.value.Store(v)
|
||||
for {
|
||||
exist := g.value.Load()
|
||||
if exist >= v {
|
||||
break
|
||||
}
|
||||
if g.value.CompareAndSwap(exist, v) {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -51,13 +51,8 @@ func (g gaugeFloat64Snapshot) Value() float64 { return float64(g) }
|
|||
// NilGauge is a no-op Gauge.
|
||||
type NilGaugeFloat64 struct{}
|
||||
|
||||
// Snapshot is a no-op.
|
||||
func (NilGaugeFloat64) Snapshot() GaugeFloat64Snapshot { return NilGaugeFloat64{} }
|
||||
|
||||
// Update is a no-op.
|
||||
func (NilGaugeFloat64) Update(v float64) {}
|
||||
|
||||
// Value is a no-op.
|
||||
func (NilGaugeFloat64) Value() float64 { return 0.0 }
|
||||
|
||||
// StandardGaugeFloat64 is the standard implementation of a GaugeFloat64 and uses
|
||||
|
|
|
|||
|
|
@ -148,7 +148,7 @@ func (NilSample) Clear() {}
|
|||
func (NilSample) Snapshot() SampleSnapshot { return (*emptySnapshot)(nil) }
|
||||
func (NilSample) Update(v int64) {}
|
||||
|
||||
// CalculatePercentiles returns an arbitrary percentile of the slice of int64.
|
||||
// SamplePercentiles returns an arbitrary percentile of the slice of int64.
|
||||
func SamplePercentile(values []int64, p float64) float64 {
|
||||
return CalculatePercentiles(values, []float64{p})[0]
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue