Search in sources :

Example 1 with PolyglotMetricRegistryBindings

use of io.nosqlbench.engine.core.metrics.PolyglotMetricRegistryBindings in project nosqlbench by nosqlbench.

the class MetricsMapper method metricsDetail.

public static String metricsDetail(String activitySpec) {
    // StringBuilder metricsDetail = new StringBuilder();
    List<String> metricsDetails = new ArrayList<>();
    ActivityDef activityDef = ActivityDef.parseActivityDef(activitySpec);
    logger.info("introspecting metric names for " + activitySpec);
    Optional<ActivityType> activityType = new ActivityTypeLoader().load(activityDef);
    if (!activityType.isPresent()) {
        throw new RuntimeException("Activity type '" + activityDef.getActivityType() + "' does not exist in this runtime.");
    }
    Activity activity = activityType.get().getAssembledActivity(activityDef, new HashMap<>());
    PolyglotMetricRegistryBindings nashornMetricRegistryBindings = new PolyglotMetricRegistryBindings(ActivityMetrics.getMetricRegistry());
    activity.initActivity();
    activity.getInputDispenserDelegate().getInput(0);
    activity.getActionDispenserDelegate().getAction(0);
    activity.getMotorDispenserDelegate().getMotor(activityDef, 0);
    Map<String, Metric> metricMap = nashornMetricRegistryBindings.getMetrics();
    for (Map.Entry<String, Metric> metricEntry : metricMap.entrySet()) {
        String metricName = metricEntry.getKey();
        Metric metricValue = metricEntry.getValue();
        Map<String, String> getterSummary = getGetterSummary(metricValue);
        // details.put(metricName,getterSummary);
        List<String> methodDetails = getterSummary.entrySet().stream().map(es -> metricName + es.getKey() + "  " + es.getValue()).collect(Collectors.toList());
        methodDetails.sort(String::compareTo);
        String getterText = methodDetails.stream().collect(Collectors.joining("\n"));
        metricsDetails.add(metricName + "\n" + getterText);
    }
    return metricsDetails.stream().collect(Collectors.joining("\n"));
}
Also used : java.util(java.util) ActivityDef(io.nosqlbench.engine.api.activityimpl.ActivityDef) Predicate(java.util.function.Predicate) Timer(java.util.Timer) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) ActivityMetrics(io.nosqlbench.engine.api.metrics.ActivityMetrics) ActivityTypeLoader(io.nosqlbench.engine.core.lifecycle.ActivityTypeLoader) Logger(org.apache.logging.log4j.Logger) com.codahale.metrics(com.codahale.metrics) Activity(io.nosqlbench.engine.api.activityapi.core.Activity) PolyglotMetricRegistryBindings(io.nosqlbench.engine.core.metrics.PolyglotMetricRegistryBindings) LogManager(org.apache.logging.log4j.LogManager) Method(java.lang.reflect.Method) ActivityType(io.nosqlbench.engine.api.activityapi.core.ActivityType) ActivityType(io.nosqlbench.engine.api.activityapi.core.ActivityType) Activity(io.nosqlbench.engine.api.activityapi.core.Activity) ActivityDef(io.nosqlbench.engine.api.activityimpl.ActivityDef) PolyglotMetricRegistryBindings(io.nosqlbench.engine.core.metrics.PolyglotMetricRegistryBindings) ActivityTypeLoader(io.nosqlbench.engine.core.lifecycle.ActivityTypeLoader)

Example 2 with PolyglotMetricRegistryBindings

use of io.nosqlbench.engine.core.metrics.PolyglotMetricRegistryBindings in project nosqlbench by nosqlbench.

the class Scenario method init.

private void init() {
    logger.debug("Using engine " + engine.toString());
    MetricRegistry metricRegistry = ActivityMetrics.getMetricRegistry();
    switch(engine) {
        case Nashorn:
            throw new RuntimeException("The nashorn engine has been deprecated in this version of NoSQLBench.");
        case Graalvm:
            Context.Builder contextSettings = Context.newBuilder("js").allowHostAccess(HostAccess.ALL).allowNativeAccess(true).allowCreateThread(true).allowIO(true).allowHostClassLookup(s -> true).allowHostClassLoading(true).allowCreateProcess(true).allowAllAccess(true).allowEnvironmentAccess(EnvironmentAccess.INHERIT).allowPolyglotAccess(PolyglotAccess.ALL).option("js.ecmascript-version", "2020").option("js.nashorn-compat", "true");
            // TODO: add in, out, err for this scenario
            this.scriptEngine = GraalJSScriptEngine.create(null, contextSettings);
            break;
    }
    scenarioController = new ScenarioController(this.scenarioName, minMaturity);
    if (!progressInterval.equals("disabled")) {
        activityProgressIndicator = new ActivityProgressIndicator(scenarioController, progressInterval);
    }
    scriptEnv = new ScenarioContext(scenarioController);
    scriptEngine.setContext(scriptEnv);
    scriptEngine.put("params", scenarioScriptParams);
    if (engine == Engine.Graalvm) {
        // https://github.com/graalvm/graaljs/blob/master/docs/user/JavaInterop.md
        if (wantsGraaljsCompatMode) {
            scriptEngine.put("scenario", scenarioController);
            scriptEngine.put("metrics", new PolyglotMetricRegistryBindings(metricRegistry));
            scriptEngine.put("activities", new NashornActivityBindings(scenarioController));
        } else {
            scriptEngine.put("scenario", new PolyglotScenarioController(scenarioController));
            scriptEngine.put("metrics", new PolyglotMetricRegistryBindings(metricRegistry));
            scriptEngine.put("activities", new NashornActivityBindings(scenarioController));
        }
    } else if (engine == Engine.Nashorn) {
        throw new RuntimeException("The Nashorn engine has been deprecated in this version of NoSQLBench.");
    } else {
        throw new RuntimeException("Unsupported engine: " + engine);
    }
    for (ScriptingPluginInfo<?> extensionDescriptor : SandboxExtensionFinder.findAll()) {
        if (!extensionDescriptor.isAutoLoading()) {
            logger.info("Not loading " + extensionDescriptor + ", autoloading is false");
            continue;
        }
        Logger extensionLogger = LogManager.getLogger("extensions." + extensionDescriptor.getBaseVariableName());
        Object extensionObject = extensionDescriptor.getExtensionObject(extensionLogger, metricRegistry, scriptEnv);
        ScenarioMetadataAware.apply(extensionObject, getScenarioMetadata());
        logger.trace("Adding extension object:  name=" + extensionDescriptor.getBaseVariableName() + " class=" + extensionObject.getClass().getSimpleName());
        scriptEngine.put(extensionDescriptor.getBaseVariableName(), extensionObject);
    }
}
Also used : Context(org.graalvm.polyglot.Context) GraalJSScriptEngine(com.oracle.truffle.js.scriptengine.GraalJSScriptEngine) Maturity(io.nosqlbench.nb.annotations.Maturity) Callable(java.util.concurrent.Callable) Annotation(io.nosqlbench.nb.api.annotations.Annotation) ByteBuffer(java.nio.ByteBuffer) ArrayList(java.util.ArrayList) PolyglotScenarioController(io.nosqlbench.engine.core.lifecycle.PolyglotScenarioController) Charset(java.nio.charset.Charset) Map(java.util.Map) ScenarioController(io.nosqlbench.engine.core.lifecycle.ScenarioController) Path(java.nio.file.Path) Compilable(javax.script.Compilable) MetricRegistry(com.codahale.metrics.MetricRegistry) ScenarioResult(io.nosqlbench.engine.core.lifecycle.ScenarioResult) Files(java.nio.file.Files) SystemId(io.nosqlbench.nb.api.metadata.SystemId) ActivityProgressIndicator(io.nosqlbench.engine.core.lifecycle.ActivityProgressIndicator) StandardOpenOption(java.nio.file.StandardOpenOption) ScriptEngineManager(javax.script.ScriptEngineManager) ScriptEnvBuffer(io.nosqlbench.engine.api.scripting.ScriptEnvBuffer) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) ActivityMetrics(io.nosqlbench.engine.api.metrics.ActivityMetrics) ScenarioMetadata(io.nosqlbench.nb.api.metadata.ScenarioMetadata) ScenarioMetadataAware(io.nosqlbench.nb.api.metadata.ScenarioMetadataAware) List(java.util.List) Logger(org.apache.logging.log4j.Logger) HostAccess(org.graalvm.polyglot.HostAccess) java.io(java.io) PolyglotAccess(org.graalvm.polyglot.PolyglotAccess) Paths(java.nio.file.Paths) EnvironmentAccess(org.graalvm.polyglot.EnvironmentAccess) ScriptingPluginInfo(io.nosqlbench.engine.api.extensions.ScriptingPluginInfo) CompiledScript(javax.script.CompiledScript) ScriptEngine(javax.script.ScriptEngine) Optional(java.util.Optional) Annotators(io.nosqlbench.engine.core.annotation.Annotators) Context(org.graalvm.polyglot.Context) PolyglotMetricRegistryBindings(io.nosqlbench.engine.core.metrics.PolyglotMetricRegistryBindings) LogManager(org.apache.logging.log4j.LogManager) Layer(io.nosqlbench.nb.api.annotations.Layer) PolyglotScenarioController(io.nosqlbench.engine.core.lifecycle.PolyglotScenarioController) ScenarioController(io.nosqlbench.engine.core.lifecycle.ScenarioController) MetricRegistry(com.codahale.metrics.MetricRegistry) Logger(org.apache.logging.log4j.Logger) PolyglotMetricRegistryBindings(io.nosqlbench.engine.core.metrics.PolyglotMetricRegistryBindings) PolyglotScenarioController(io.nosqlbench.engine.core.lifecycle.PolyglotScenarioController) ActivityProgressIndicator(io.nosqlbench.engine.core.lifecycle.ActivityProgressIndicator)

Aggregations

ActivityMetrics (io.nosqlbench.engine.api.metrics.ActivityMetrics)2 PolyglotMetricRegistryBindings (io.nosqlbench.engine.core.metrics.PolyglotMetricRegistryBindings)2 Collectors (java.util.stream.Collectors)2 LogManager (org.apache.logging.log4j.LogManager)2 Logger (org.apache.logging.log4j.Logger)2 com.codahale.metrics (com.codahale.metrics)1 MetricRegistry (com.codahale.metrics.MetricRegistry)1 GraalJSScriptEngine (com.oracle.truffle.js.scriptengine.GraalJSScriptEngine)1 Activity (io.nosqlbench.engine.api.activityapi.core.Activity)1 ActivityType (io.nosqlbench.engine.api.activityapi.core.ActivityType)1 ActivityDef (io.nosqlbench.engine.api.activityimpl.ActivityDef)1 ScriptingPluginInfo (io.nosqlbench.engine.api.extensions.ScriptingPluginInfo)1 ScriptEnvBuffer (io.nosqlbench.engine.api.scripting.ScriptEnvBuffer)1 Annotators (io.nosqlbench.engine.core.annotation.Annotators)1 ActivityProgressIndicator (io.nosqlbench.engine.core.lifecycle.ActivityProgressIndicator)1 ActivityTypeLoader (io.nosqlbench.engine.core.lifecycle.ActivityTypeLoader)1 PolyglotScenarioController (io.nosqlbench.engine.core.lifecycle.PolyglotScenarioController)1 ScenarioController (io.nosqlbench.engine.core.lifecycle.ScenarioController)1 ScenarioResult (io.nosqlbench.engine.core.lifecycle.ScenarioResult)1 Maturity (io.nosqlbench.nb.annotations.Maturity)1