15
15
public class OngoingPowerMeasure extends ProcessorAware implements PowerMeasure {
16
16
private static final int DEFAULT_SIZE = 32 ;
17
17
private final SensorMetadata metadata ;
18
- private final long startedAt ;
19
18
private final BitSet nonZeroComponents ;
20
- private final double [][] measures ;
21
19
private final List <RegisteredSyntheticComponent > syntheticComponents ;
20
+ private final long samplePeriod ;
21
+ private double [][] measures ;
22
+ private long startedAt ;
22
23
private int samples ;
23
24
private long [] timestamps ;
24
- private long samplePeriod ;
25
25
26
26
public OngoingPowerMeasure (SensorMetadata metadata , SyntheticComponent ... syntheticComponents ) {
27
27
this (metadata , -1 , syntheticComponents );
@@ -30,11 +30,9 @@ public OngoingPowerMeasure(SensorMetadata metadata, SyntheticComponent... synthe
30
30
public OngoingPowerMeasure (SensorMetadata metadata , long samplePeriod , SyntheticComponent ... syntheticComponents ) {
31
31
super (Processors .empty );
32
32
33
- startedAt = System .currentTimeMillis ();
34
- final var numComponents = metadata .componentCardinality ();
35
- measures = new double [numComponents ][DEFAULT_SIZE ];
36
- nonZeroComponents = new BitSet (numComponents );
37
- timestamps = new long [DEFAULT_SIZE ];
33
+ final int componentCardinality = metadata .componentCardinality ();
34
+ nonZeroComponents = new BitSet (componentCardinality );
35
+ reset (componentCardinality );
38
36
this .samplePeriod = samplePeriod ;
39
37
40
38
if (syntheticComponents != null ) {
@@ -52,6 +50,18 @@ public OngoingPowerMeasure(SensorMetadata metadata, long samplePeriod, Synthetic
52
50
}
53
51
}
54
52
53
+ public void reset () {
54
+ reset (metadata .componentCardinality ());
55
+ }
56
+
57
+ private synchronized void reset (int componentCardinality ) {
58
+ startedAt = System .currentTimeMillis ();
59
+ nonZeroComponents .clear ();
60
+ measures = new double [componentCardinality ][DEFAULT_SIZE ];
61
+ timestamps = new long [DEFAULT_SIZE ];
62
+ samples = 0 ;
63
+ }
64
+
55
65
@ Override
56
66
public synchronized int numberOfSamples () {
57
67
return samples ;
0 commit comments