-
Notifications
You must be signed in to change notification settings - Fork 0
/
cpu.go
51 lines (42 loc) · 2.25 KB
/
cpu.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
package devops
import (
"math/rand"
"time"
"github.com/timescale/tsbs/cmd/tsbs_generate_data/common"
"github.com/timescale/tsbs/cmd/tsbs_generate_data/serialize"
)
var (
labelCPU = []byte("cpu") // heap optimization
cpuFields = []labeledDistributionMaker{
{[]byte("usage_user"), func() common.Distribution { return common.CWD(cpuND, 0.0, 100.0, rand.Float64()*100.0) }},
{[]byte("usage_system"), func() common.Distribution { return common.CWD(cpuND, 0.0, 100.0, rand.Float64()*100.0) }},
{[]byte("usage_idle"), func() common.Distribution { return common.CWD(cpuND, 0.0, 100.0, rand.Float64()*100.0) }},
{[]byte("usage_nice"), func() common.Distribution { return common.CWD(cpuND, 0.0, 100.0, rand.Float64()*100.0) }},
{[]byte("usage_iowait"), func() common.Distribution { return common.CWD(cpuND, 0.0, 100.0, rand.Float64()*100.0) }},
{[]byte("usage_irq"), func() common.Distribution { return common.CWD(cpuND, 0.0, 100.0, rand.Float64()*100.0) }},
{[]byte("usage_softirq"), func() common.Distribution { return common.CWD(cpuND, 0.0, 100.0, rand.Float64()*100.0) }},
{[]byte("usage_steal"), func() common.Distribution { return common.CWD(cpuND, 0.0, 100.0, rand.Float64()*100.0) }},
{[]byte("usage_guest"), func() common.Distribution { return common.CWD(cpuND, 0.0, 100.0, rand.Float64()*100.0) }},
{[]byte("usage_guest_nice"), func() common.Distribution { return common.CWD(cpuND, 0.0, 100.0, rand.Float64()*100.0) }},
}
)
// Reuse NormalDistributions as arguments to other distributions. This is
// safe to do because the higher-level distribution advances the ND and
// immediately uses its value and saves the state
var cpuND = common.ND(0.0, 1.0)
type CPUMeasurement struct {
*subsystemMeasurement
}
func NewCPUMeasurement(start time.Time) *CPUMeasurement {
return newCPUMeasurementNumDistributions(start, len(cpuFields))
}
func newSingleCPUMeasurement(start time.Time) *CPUMeasurement {
return newCPUMeasurementNumDistributions(start, 1)
}
func newCPUMeasurementNumDistributions(start time.Time, numDistributions int) *CPUMeasurement {
sub := newSubsystemMeasurementWithDistributionMakers(start, cpuFields[:numDistributions])
return &CPUMeasurement{sub}
}
func (m *CPUMeasurement) ToPoint(p *serialize.Point) {
m.toPointAllInt64(p, labelCPU, cpuFields)
}