Update AtomicTimeAbsoluteSamples.java and AtomicTimeIncrementalSamples.java
This commit is contained in:
parent
ddfeaade4f
commit
b805b8d02e
@ -88,23 +88,16 @@ public class AtomicTimeAbsoluteSamples implements AtomicTimeAbsoluteSamplesSnaps
|
|||||||
public synchronized double getAveragePerSecond(long timeRange) {
|
public synchronized double getAveragePerSecond(long timeRange) {
|
||||||
updateSamples();
|
updateSamples();
|
||||||
|
|
||||||
long currentTime = System.nanoTime() / 1000000L;
|
|
||||||
double preciseTimeRange = timeRange;
|
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
|
||||||
if (currentTime - preciseTimeRange < startTime) {
|
if (currentSampleStartTime - preciseTimeRange < startTime) {
|
||||||
preciseTimeRange = currentTime - startTime;
|
preciseTimeRange = currentSampleStartTime - startTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
double samplesCount = Math.min(Math.max(preciseTimeRange / sampleTime, 1d), samples.length);
|
double samplesCount = Math.min(Math.max(preciseTimeRange / sampleTime, 1d), samples.length);
|
||||||
double value = 0;
|
double value = 0;
|
||||||
for (int i = samplesCount == 1 ? 0 : 1; i < samplesCount; i++) {
|
for (int i = 1; i <= samplesCount; i++) {
|
||||||
double sampleValue;
|
value += samples[i];
|
||||||
if (i == 0) {
|
|
||||||
sampleValue = samples[i] * sampleTime / (double) (currentTime - currentSampleStartTime);
|
|
||||||
} else {
|
|
||||||
sampleValue = samples[i];
|
|
||||||
}
|
|
||||||
value += sampleValue;
|
|
||||||
}
|
}
|
||||||
return value / samplesCount;
|
return value / samplesCount;
|
||||||
}
|
}
|
||||||
|
@ -81,24 +81,17 @@ 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;
|
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
|
||||||
if (currentTime - preciseTimeRange < startTime) {
|
if (currentSampleStartTime - preciseTimeRange < startTime) {
|
||||||
preciseTimeRange = currentTime - startTime;
|
preciseTimeRange = currentSampleStartTime - startTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
double samplesCount = Math.min(Math.max(preciseTimeRange / sampleTime, 1d), samples.length);
|
double samplesCount = Math.min(Math.max(preciseTimeRange / sampleTime, 1d), samples.length);
|
||||||
double roundedTimeRange = samplesCount * sampleTime;
|
double roundedTimeRange = samplesCount * sampleTime;
|
||||||
double value = 0;
|
double value = 0;
|
||||||
for (int i = samplesCount == 1 ? 0 : 1; i < samplesCount; i++) {
|
for (int i = 1; i <= samplesCount; i++) {
|
||||||
double sampleValue;
|
value += samples[i];
|
||||||
if (i == 0) {
|
|
||||||
sampleValue = samples[i] * sampleTime / (double) (currentTime - currentSampleStartTime);
|
|
||||||
} else {
|
|
||||||
sampleValue = samples[i];
|
|
||||||
}
|
|
||||||
value += sampleValue;
|
|
||||||
}
|
}
|
||||||
return (value / roundedTimeRange) * 1000d;
|
return (value / roundedTimeRange) * 1000d;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user