add metrics manifest to polyglot

This commit is contained in:
Jonathan Shook 2020-11-20 03:34:49 -06:00
parent 7e6aa1a2d8
commit 7b0e37ab3a
2 changed files with 19 additions and 4 deletions

View File

@ -18,13 +18,13 @@
package io.nosqlbench.engine.core.metrics;
import com.codahale.metrics.*;
import com.codahale.metrics.Timer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.graalvm.polyglot.Value;
import org.graalvm.polyglot.proxy.ProxyObject;
import java.util.ArrayList;
import java.util.Map;
import java.util.*;
/**
* A view of metrics objects as an object tree.
@ -136,7 +136,22 @@ public class PolyglotMetricRegistryBindings implements ProxyObject, MetricRegist
}
public Map<String, Metric> getMetrics() {
throw new RuntimeException("implement me");
return getMetrics(new LinkedHashMap<String, Metric>(), "metrics", metrics);
}
private Map<String, Metric> getMetrics(Map<String, Metric> totalMap, String prefix, MetricMap map) {
for (String key : map.getKeys()) {
Object o = map.get(key);
String name = prefix + "." + key;
if (o instanceof Metric) {
totalMap.put(name, (Metric) o);
} else if (o instanceof MetricMap) {
getMetrics(totalMap, name, (MetricMap) o);
} else {
throw new RuntimeException("entry value must be either a Metric or a MetricMap");
}
}
return totalMap;
}
// @Override

View File

@ -22,5 +22,5 @@ optimo.setObjectiveFunction(
var result = optimo.optimize();
print("optimized result was " + result);
print("map of result was " + result.getVarMap());
print("map of result was " + result.getMap());