func (self *IoRate) Increment(other *IoRate) {
	self.Read.Increment(other.Read)
	self.Write.Increment(other.Write)
}
Increment this rate by another.
package core
import (
	"math"
	"time"
)
type IoStats struct {
	Total   IoAmount `json:"total,omitempty"`
	RateMax IoRate   `json:"max,omitempty"`
	RateDev IoRate   `json:"dev,omitempty"`
}
type IoStatsBuilder struct {
	IoStats
	lastPids map[int]*IoAmount
	deadUsage IoAmount
	weightedSumSquared IoRate
	lastMeasurement    time.Time
	start              time.Time
}
func NewIoStatsBuilder() *IoStatsBuilder {
	t := time.Now()
	return &IoStatsBuilder{
		lastPids:        make(map[int]*IoAmount),
		lastMeasurement: t,
		start:           t,
	}
}
func (self *IoStatsBuilder) Update(current map[int]*IoAmount, now time.Time) {
	seconds := now.Sub(self.lastMeasurement).Seconds()
	var total IoAmount
	for pid, amt := range current {
		total.Increment(amt)
		delete(self.lastPids, pid)
	}
	for _, amt := range self.lastPids {
		self.deadUsage.Increment(amt)
	}
	total.Increment(&self.deadUsage)
	self.lastPids = current
	self.lastMeasurement = now
	diff := self.Total.update(&total)
	if seconds > 0 {
		rate := diff.rate(seconds)
		self.RateMax.TakeMax(rate)
		rate.weightSquared(seconds)
		self.weightedSumSquared.Increment(rate)
		if t := now.Sub(self.start).Seconds(); t > 0 {
			self.RateDev = self.weightedSumSquared.computeStdDev(
				&self.Total, t)
		}
	}
}
type IoAmount struct {
	Read  IoValues `json:"read"`
	Write IoValues `json:"write"`
}
func (self *IoAmount) Increment(other *IoAmount) {
	self.Read.Increment(other.Read)
	self.Write.Increment(other.Write)
}
func (self *IoAmount) update(other *IoAmount) (diff IoAmount) {
	self.Read.update(other.Read, &diff.Read)
	self.Write.update(other.Write, &diff.Write)
	return diff
}
func (self *IoAmount) rate(seconds float64) *IoRate {
	if seconds <= 0 {
		return new(IoRate)
	}
	return &IoRate{
		Read:  self.Read.rate(seconds),
		Write: self.Write.rate(seconds),
	}
}
type IoValues struct {
	Syscalls int64 `json:"sysc"`
	BlockBytes int64 `json:"bytes"`
}
func (self *IoValues) update(other IoValues, diff *IoValues) {
	diff.Syscalls += (other.Syscalls - self.Syscalls)
	self.Syscalls = other.Syscalls
	diff.BlockBytes += (other.BlockBytes - self.BlockBytes)
	self.BlockBytes = other.BlockBytes
}
func (self *IoValues) rate(seconds float64) IoRateValues {
	if seconds <= 0 {
		return IoRateValues{}
	}
	return IoRateValues{
		Syscalls:   float64(self.Syscalls) / seconds,
		BlockBytes: float64(self.BlockBytes) / seconds,
	}
}
func (self *IoValues) Increment(other IoValues) {
	self.Syscalls += other.Syscalls
	self.BlockBytes += other.BlockBytes
}
type IoRate struct {
	Read  IoRateValues `json:"read"`
	Write IoRateValues `json:"write"`
}