APIHistogram: Use the new histogram parameter name
The use of mean and variance as histogram parameter names makes more sense. This also make it safe to use an empty histogram that holds no samples. Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
This commit is contained in:
parent
efc8d5c1e6
commit
9c7ab3fcf6
@ -551,11 +551,13 @@ public class APIClient {
|
||||
res.min = obj.getJsonNumber("min").longValue();
|
||||
res.sum = obj.getJsonNumber("sum").longValue();
|
||||
res.variance = obj.getJsonNumber("variance").doubleValue();
|
||||
res.svariance = obj.getJsonNumber("svariance").doubleValue();
|
||||
res.mean = obj.getJsonNumber("mean").doubleValue();
|
||||
JsonArray arr = obj.getJsonArray("sample");
|
||||
res.sample = new long[arr.size()];
|
||||
for (int i = 0; i < arr.size(); i++) {
|
||||
res.sample[i] = arr.getJsonNumber(i).longValue();
|
||||
if (arr != null) {
|
||||
res.sample = new long[arr.size()];
|
||||
for (int i = 0; i < arr.size(); i++) {
|
||||
res.sample[i] = arr.getJsonNumber(i).longValue();
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
@ -42,6 +42,12 @@ public class APIHistogram extends Histogram {
|
||||
sampleField.setAccessible(true);
|
||||
countField = Histogram.class.getDeclaredField("count");
|
||||
countField.setAccessible(true);
|
||||
try {
|
||||
getCount().set(0);
|
||||
} catch (IllegalArgumentException | IllegalAccessException e) {
|
||||
// There's no reason to get here
|
||||
// and there's nothing we can do even if we would
|
||||
}
|
||||
} catch (NoSuchFieldException | SecurityException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -104,16 +110,18 @@ public class APIHistogram extends Histogram {
|
||||
clear();
|
||||
HistogramValues vals = c.getHistogramValue(url);
|
||||
try {
|
||||
for (long v : vals.sample) {
|
||||
getSample().update(v);
|
||||
if (vals.sample != null) {
|
||||
for (long v : vals.sample) {
|
||||
getSample().update(v);
|
||||
}
|
||||
}
|
||||
getCount().set(vals.count);
|
||||
getMax().set(vals.max);
|
||||
getMin().set(vals.min);
|
||||
getSum().set(vals.sum);
|
||||
double[] newValue = new double[2];
|
||||
newValue[0] = vals.variance;
|
||||
newValue[1] = vals.svariance;
|
||||
newValue[0] = vals.mean;
|
||||
newValue[1] = vals.variance;
|
||||
getVariance().getAndSet(newValue);
|
||||
} catch (IllegalArgumentException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -6,6 +6,6 @@ public class HistogramValues {
|
||||
public long max;
|
||||
public long sum;
|
||||
public double variance;
|
||||
public double svariance;
|
||||
public double mean;
|
||||
public long sample[];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user