-
Notifications
You must be signed in to change notification settings - Fork 175
/
meter.go
52 lines (45 loc) · 1.53 KB
/
meter.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
52
package meter
type MeterParameters struct {
ComputationMeterParameters
MemoryMeterParameters
EventMeterParameters
InteractionMeterParameters
}
func DefaultParameters() MeterParameters {
return MeterParameters{
ComputationMeterParameters: DefaultComputationMeterParameters(),
MemoryMeterParameters: DefaultMemoryParameters(),
EventMeterParameters: DefaultEventMeterParameters(),
InteractionMeterParameters: DefaultInteractionMeterParameters(),
}
}
// Meter collects memory and computation usage and enforces limits
// for any each memory/computation usage call it sums intensity multiplied by the weight of the intensity to the total
// memory/computation usage metrics and returns error if limits are not met.
type Meter struct {
MeterParameters
MemoryMeter
ComputationMeter
EventMeter
InteractionMeter
}
// NewMeter constructs a new Meter
func NewMeter(params MeterParameters) *Meter {
return &Meter{
MeterParameters: params,
ComputationMeter: NewComputationMeter(params.ComputationMeterParameters),
MemoryMeter: NewMemoryMeter(params.MemoryMeterParameters),
EventMeter: NewEventMeter(params.EventMeterParameters),
InteractionMeter: NewInteractionMeter(params.InteractionMeterParameters),
}
}
// MergeMeter merges the input meter into the current meter
func (m *Meter) MergeMeter(child *Meter) {
if child == nil {
return
}
m.ComputationMeter.Merge(child.ComputationMeter)
m.MemoryMeter.Merge(child.MemoryMeter)
m.EventMeter.Merge(child.EventMeter)
m.InteractionMeter.Merge(child.InteractionMeter)
}