Update AtomicTimeAbsoluteSamples.java and AtomicTimeIncrementalSamples.java
This commit is contained in:
parent
fbabebbf13
commit
f0f7e609c0
@ -88,18 +88,25 @@ public class AtomicTimeAbsoluteSamples implements AtomicTimeAbsoluteSamplesSnaps
|
|||||||
public synchronized double getAveragePerSecond(long timeRange) {
|
public synchronized double getAveragePerSecond(long timeRange) {
|
||||||
updateSamples();
|
updateSamples();
|
||||||
|
|
||||||
// Fix if the time range is bigger than the collected data since start
|
|
||||||
long currentTime = System.nanoTime() / 1000000L;
|
long currentTime = System.nanoTime() / 1000000L;
|
||||||
if (currentTime - timeRange < startTime) {
|
double preciseTimeRange = timeRange;
|
||||||
timeRange = currentTime - startTime;
|
// Fix if the time range is bigger than the collected data since start
|
||||||
|
if (currentTime - preciseTimeRange < startTime) {
|
||||||
|
preciseTimeRange = currentTime - startTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
long samplesCount = Math.min(Math.max(timeRange / sampleTime, 1L), samples.length);
|
double samplesCount = Math.min(Math.max(preciseTimeRange / sampleTime, 1d), samples.length);
|
||||||
long value = 0;
|
double value = 0;
|
||||||
for (int i = 0; i < samplesCount; i++) {
|
for (int i = 0; i < samplesCount; i++) {
|
||||||
value += samples[i];
|
double sampleValue;
|
||||||
|
if (i == 0) {
|
||||||
|
sampleValue = samples[i] * sampleTime / (double) (currentTime - currentSampleStartTime);
|
||||||
|
} else {
|
||||||
|
sampleValue = samples[i];
|
||||||
|
}
|
||||||
|
value += sampleValue;
|
||||||
}
|
}
|
||||||
return ((double) value) / ((double) samplesCount);
|
return value / samplesCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -81,19 +81,26 @@ public class AtomicTimeIncrementalSamples implements AtomicTimeIncrementalSample
|
|||||||
public synchronized double getAveragePerSecond(long timeRange) {
|
public synchronized double getAveragePerSecond(long timeRange) {
|
||||||
updateSamples();
|
updateSamples();
|
||||||
|
|
||||||
|
long currentTime = System.nanoTime() / 1000000L;
|
||||||
|
double preciseTimeRange = timeRange;
|
||||||
// Fix if the time range is bigger than the collected data since start
|
// Fix if the time range is bigger than the collected data since start
|
||||||
long currentTime = currentSampleStartTime;
|
if (currentTime - preciseTimeRange < startTime) {
|
||||||
if (currentTime - timeRange < startTime) {
|
preciseTimeRange = currentTime - startTime;
|
||||||
timeRange = currentTime - startTime;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
long samplesCount = Math.min(Math.max(timeRange / sampleTime, 1L), samples.length);
|
double samplesCount = Math.min(Math.max(preciseTimeRange / sampleTime, 1d), samples.length);
|
||||||
long roundedTimeRange = samplesCount * sampleTime;
|
double roundedTimeRange = samplesCount * sampleTime;
|
||||||
long value = 0;
|
double value = 0;
|
||||||
for (int i = 0; i < samplesCount; i++) {
|
for (int i = 0; i < samplesCount; i++) {
|
||||||
value += samples[i];
|
double sampleValue;
|
||||||
|
if (i == 0) {
|
||||||
|
sampleValue = samples[i] * sampleTime / (double) (currentTime - currentSampleStartTime);
|
||||||
|
} else {
|
||||||
|
sampleValue = samples[i];
|
||||||
|
}
|
||||||
|
value += sampleValue;
|
||||||
}
|
}
|
||||||
return ((double) value) / ((double) roundedTimeRange / 1000D);
|
return (value / roundedTimeRange) * 1000d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user