Search in sources :

Example 11 with EntryCallEdge

use of org.iobserve.analysis.behavior.models.extended.EntryCallEdge in project iobserve-analysis by research-iobserve.

the class BehaviorModelJSONReader method execute.

@Override
protected void execute() throws Exception {
    final ObjectMapper mapper = new ObjectMapper();
    /**
     * Have to read the model by hand
     */
    final JsonNode tree = mapper.readTree(this.inputFile);
    if (!(tree instanceof ObjectNode)) {
        throw new IOException("Wrong format while reading model.");
    }
    final ObjectNode modelNode = (ObjectNode) tree;
    final BehaviorModel model = new BehaviorModel();
    /**
     * Read name.
     */
    final JsonNode name = modelNode.get("name");
    if (name.isTextual()) {
        model.setName(name.textValue());
    }
    // Read nodes
    final JsonNode nodesNode = modelNode.get("nodes");
    if (nodesNode.isArray()) {
        final ArrayNode nodesArray = (ArrayNode) nodesNode;
        final Iterator<JsonNode> nodesIter = nodesArray.elements();
        while (nodesIter.hasNext()) {
            final EntryCallNode newECNode = new EntryCallNode();
            final ObjectNode node = (ObjectNode) nodesIter.next();
            newECNode.setSignature(node.get("signature").textValue());
            final ArrayNode callInfos = (ArrayNode) node.get("entryCallInformation");
            final Iterator<JsonNode> callInfoIter = callInfos.elements();
            while (callInfoIter.hasNext()) {
                final ObjectNode ciNode = (ObjectNode) callInfoIter.next();
                final CallInformation info = new CallInformation(ciNode.get("informationSignature").textValue(), ciNode.get("informationCode").textValue(), ciNode.get("count").asInt());
                newECNode.mergeCallInformation(info);
            }
            model.addNode(newECNode, false);
        }
    }
    final ArrayNode edgesNode = (ArrayNode) modelNode.findValue("edges");
    final Iterator<JsonNode> edgesIter = edgesNode.elements();
    while (edgesIter.hasNext()) {
        final ObjectNode edge = (ObjectNode) edgesIter.next();
        final ObjectNode source = (ObjectNode) edge.get("source");
        final ObjectNode target = (ObjectNode) edge.get("target");
        final EntryCallNode sourceECNode = model.findNode(source.get("signature").textValue()).get();
        final EntryCallNode targetECNode = model.findNode(target.get("signature").textValue()).get();
        final EntryCallEdge newECEdge = new EntryCallEdge(sourceECNode, targetECNode, edge.get("calls").asInt());
        model.addEdge(newECEdge, false);
    }
    this.outputPort.send(model);
    this.workCompleted();
}
Also used : CallInformation(org.iobserve.analysis.behavior.models.extended.CallInformation) EntryCallEdge(org.iobserve.analysis.behavior.models.extended.EntryCallEdge) EntryCallNode(org.iobserve.analysis.behavior.models.extended.EntryCallNode) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) BehaviorModel(org.iobserve.analysis.behavior.models.extended.BehaviorModel) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 12 with EntryCallEdge

use of org.iobserve.analysis.behavior.models.extended.EntryCallEdge in project iobserve-analysis by research-iobserve.

the class UsageModelToBehaviorModelStage method traverseAction.

private Map<EntryCallNode, Double> traverseAction(final BehaviorModel behaviorModel, final Optional<Map<EntryCallNode, Double>> optPreviousNodes, final AbstractUserAction action) {
    if (action instanceof Branch) {
        final Branch branch = (Branch) action;
        return this.traverseBranch(behaviorModel, optPreviousNodes, branch);
    } else if (action instanceof Loop) {
        final Loop loop = (Loop) action;
        return this.traverseLoop(behaviorModel, optPreviousNodes, loop);
    } else if (action instanceof EntryLevelSystemCall) {
        final Map<EntryCallNode, Double> endNodes = new HashMap<>();
        final EntryLevelSystemCall entryLevelSystemCall = (EntryLevelSystemCall) action;
        final EntryCallNode entryCallNode = this.createEntryCallNode(entryLevelSystemCall);
        behaviorModel.addNode(entryCallNode, true);
        if (optPreviousNodes.isPresent()) {
            optPreviousNodes.get().keySet().stream().map(previousNode -> new EntryCallEdge(previousNode, entryCallNode, optPreviousNodes.get().get(previousNode))).forEach(node -> behaviorModel.addEdge(node, true));
        }
        endNodes.put(entryCallNode, 1.0);
        return this.traverseAction(behaviorModel, Optional.of(endNodes), action.getSuccessor());
    } else if (action instanceof Stop) {
        return optPreviousNodes.isPresent() ? optPreviousNodes.get() : new HashMap<>();
    } else {
        // skip action
        return this.traverseAction(behaviorModel, optPreviousNodes, action.getSuccessor());
    }
}
Also used : Loop(org.palladiosimulator.pcm.usagemodel.Loop) BehaviorModel(org.iobserve.analysis.behavior.models.extended.BehaviorModel) BranchTransition(org.palladiosimulator.pcm.usagemodel.BranchTransition) UsageScenario(org.palladiosimulator.pcm.usagemodel.UsageScenario) EntryLevelSystemCall(org.palladiosimulator.pcm.usagemodel.EntryLevelSystemCall) HashMap(java.util.HashMap) OutputPort(teetime.framework.OutputPort) AbstractUserAction(org.palladiosimulator.pcm.usagemodel.AbstractUserAction) List(java.util.List) SingleOrNoneCollector(org.iobserve.analysis.behavior.SingleOrNoneCollector) AbstractConsumerStage(teetime.framework.AbstractConsumerStage) Map(java.util.Map) Optional(java.util.Optional) EntryCallNode(org.iobserve.analysis.behavior.models.extended.EntryCallNode) UsageModel(org.palladiosimulator.pcm.usagemodel.UsageModel) EntryCallEdge(org.iobserve.analysis.behavior.models.extended.EntryCallEdge) Branch(org.palladiosimulator.pcm.usagemodel.Branch) Start(org.palladiosimulator.pcm.usagemodel.Start) Loop(org.palladiosimulator.pcm.usagemodel.Loop) ScenarioBehaviour(org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour) Stop(org.palladiosimulator.pcm.usagemodel.Stop) EntryCallEdge(org.iobserve.analysis.behavior.models.extended.EntryCallEdge) EntryLevelSystemCall(org.palladiosimulator.pcm.usagemodel.EntryLevelSystemCall) EntryCallNode(org.iobserve.analysis.behavior.models.extended.EntryCallNode) HashMap(java.util.HashMap) Stop(org.palladiosimulator.pcm.usagemodel.Stop) Branch(org.palladiosimulator.pcm.usagemodel.Branch)

Example 13 with EntryCallEdge

use of org.iobserve.analysis.behavior.models.extended.EntryCallEdge in project iobserve-analysis by research-iobserve.

the class UnionModelGenerationStrategy method generateModel.

@Override
public BehaviorModel generateModel(final BehaviorModel[] models) {
    final BehaviorModel newModel = new BehaviorModel();
    for (final BehaviorModel model : models) {
        /**
         * We add nodes first so we don't get duplicate nodes from the same model
         */
        for (final EntryCallNode node : model.getNodes()) {
            final Optional<EntryCallNode> matchingNode = newModel.findNode(node.getSignature());
            if (matchingNode.isPresent()) {
                Optional<CallInformation> matchingInfo;
                for (final CallInformation info : node.getEntryCallInformation()) {
                    matchingInfo = matchingNode.get().findCallInformation(info.getInformationSignature(), info.getInformationParameter());
                    if (matchingInfo.isPresent()) {
                        final int newCount = Math.max(info.getCount(), matchingInfo.get().getCount());
                        matchingInfo.get().setCount(newCount);
                    } else {
                        matchingNode.get().mergeCallInformation(new CallInformation(info.getInformationSignature(), info.getInformationParameter(), info.getCount()));
                    }
                }
            } else {
                // Copy node and add it
                final EntryCallNode newNode = new EntryCallNode();
                newNode.setSignature(node.getSignature());
                for (final CallInformation info : node.getEntryCallInformation()) {
                    final CallInformation newInfo = new CallInformation(info.getInformationSignature(), info.getInformationParameter(), info.getCount());
                    newNode.mergeCallInformation(newInfo);
                }
                newModel.addNode(newNode, false);
            }
        }
        for (final EntryCallEdge edge : model.getEdges()) {
            final Optional<EntryCallEdge> matchingEdge = newModel.findEdge(edge.getSource().getSignature(), edge.getTarget().getSignature());
            if (matchingEdge.isPresent()) {
                matchingEdge.get().setCalls(Math.max(matchingEdge.get().getCalls(), edge.getCalls()));
            } else {
                newModel.addEdge(new EntryCallEdge(edge.getSource(), edge.getTarget(), edge.getCalls()), false);
            }
        }
    }
    return newModel;
}
Also used : CallInformation(org.iobserve.analysis.behavior.models.extended.CallInformation) EntryCallEdge(org.iobserve.analysis.behavior.models.extended.EntryCallEdge) EntryCallNode(org.iobserve.analysis.behavior.models.extended.EntryCallNode) BehaviorModel(org.iobserve.analysis.behavior.models.extended.BehaviorModel)

Example 14 with EntryCallEdge

use of org.iobserve.analysis.behavior.models.extended.EntryCallEdge in project iobserve-analysis by research-iobserve.

the class ModelComparisonStage method execute.

/*
     * (non-Javadoc)
     *
     * @see teetime.framework.AbstractStage#execute()
     */
@Override
protected void execute() throws Exception {
    /**
     * We cannot use else if here, as (a) there could be an input at each input port, (b) there
     * could be a model at testModel but not at the referenceModel input, in an if-then-else
     * style, the test model would not be received until we have a reference model, which
     * unnecessarily would imply a sequence between both ports.
     */
    if (this.referenceModel == null) {
        this.referenceModel = this.referenceModelInputPort.receive();
    }
    if (this.testModel == null) {
        this.testModel = this.testModelInputPort.receive();
    }
    /**
     * We still have to check both, as there could be nothing a both ports.
     */
    if ((this.referenceModel != null) && (this.testModel != null)) {
        final ComparisonResult result = new ComparisonResult();
        result.getBaselineNodes().addAll(this.referenceModel.getNodes());
        result.getBaselineEdges().addAll(this.referenceModel.getEdges());
        result.getTestModelNodes().addAll(this.testModel.getNodes());
        result.getTestModelEdges().addAll(this.testModel.getEdges());
        /**
         * Missing nodes.
         */
        for (final EntryCallNode baselineNode : this.referenceModel.getNodes()) {
            final EntryCallNode testModelNode = this.findMatchingModelNode(this.testModel.getNodes(), baselineNode);
            if (testModelNode == null) {
                result.getMissingNodes().add(baselineNode);
            } else {
                result.getSimilarNodes().add(baselineNode);
                /**
                 * Compute mismatch in call information.
                 */
                final List<CallInformation> missingInformation = this.computeAdditionalInformation(baselineNode.getEntryCallInformation(), testModelNode.getEntryCallInformation());
                final List<CallInformation> additionalInformation = this.computeAdditionalInformation(testModelNode.getEntryCallInformation(), baselineNode.getEntryCallInformation());
                result.getNodeDifferences().add(new NodeDifference(baselineNode, testModelNode, missingInformation, additionalInformation));
            }
        }
        /**
         * Additional nodes.
         */
        for (final EntryCallNode testModelNode : this.testModel.getNodes()) {
            final EntryCallNode baselineNode = this.findMatchingModelNode(this.referenceModel.getNodes(), testModelNode);
            if (baselineNode == null) {
                result.getAdditionalNodes().add(testModelNode);
            }
        }
        /**
         * Missing edges.
         */
        int missingEdgeCount = 0;
        for (final EntryCallEdge baselineEdge : this.referenceModel.getEdges()) {
            final EntryCallEdge testModelEdge = this.findMatchingModelEdge(this.testModel.getEdges(), baselineEdge);
            if (testModelEdge == null) {
                missingEdgeCount += (int) baselineEdge.getCalls();
            } else {
                missingEdgeCount += Math.abs((int) (baselineEdge.getCalls() - testModelEdge.getCalls()));
            }
        }
        result.setMissingEdgeCount(missingEdgeCount);
        /**
         * Additional edges.
         */
        int additionalEdgeCount = 0;
        for (final EntryCallEdge testModelEdge : this.testModel.getEdges()) {
            final EntryCallEdge baselineEdge = this.findMatchingModelEdge(this.referenceModel.getEdges(), testModelEdge);
            if (baselineEdge == null) {
                additionalEdgeCount += (int) testModelEdge.getCalls();
            } else {
                additionalEdgeCount += Math.abs((int) (baselineEdge.getCalls() - testModelEdge.getCalls()));
            }
        }
        result.setAdditionalEdgeCount(additionalEdgeCount);
        /**
         * Forget models after processing to be able to process the next elements.
         */
        // NOPMD necessary to forget data
        this.referenceModel = null;
        // NOPMD necessary to forget data
        this.testModel = null;
        /**
         * Add baseline and testModelNodes
         */
        this.resultPort.send(result);
    }
}
Also used : CallInformation(org.iobserve.analysis.behavior.models.extended.CallInformation) EntryCallEdge(org.iobserve.analysis.behavior.models.extended.EntryCallEdge) EntryCallNode(org.iobserve.analysis.behavior.models.extended.EntryCallNode) NodeDifference(org.iobserve.evaluation.data.NodeDifference) ComparisonResult(org.iobserve.evaluation.data.ComparisonResult)

Example 15 with EntryCallEdge

use of org.iobserve.analysis.behavior.models.extended.EntryCallEdge in project iobserve-analysis by research-iobserve.

the class ModelComparisonStageTest method createReferenceModel.

private BehaviorModel createReferenceModel() {
    final BehaviorModel model = new BehaviorModel();
    model.addNode(this.nodeA, false);
    model.addNode(this.nodeB, false);
    model.addNode(this.nodeC, false);
    final EntryCallEdge edgeAB = new EntryCallEdge(this.nodeA, this.nodeB);
    edgeAB.addCalls(4);
    model.addEdge(edgeAB, false);
    final EntryCallEdge edgeBA = new EntryCallEdge(this.nodeB, this.nodeA);
    edgeBA.addCalls(3);
    model.addEdge(edgeBA, false);
    final EntryCallEdge edgeBC = new EntryCallEdge(this.nodeB, this.nodeC);
    edgeBA.addCalls(1);
    model.addEdge(edgeBC, false);
    return model;
}
Also used : EntryCallEdge(org.iobserve.analysis.behavior.models.extended.EntryCallEdge) BehaviorModel(org.iobserve.analysis.behavior.models.extended.BehaviorModel)

Aggregations

EntryCallEdge (org.iobserve.analysis.behavior.models.extended.EntryCallEdge)15 BehaviorModel (org.iobserve.analysis.behavior.models.extended.BehaviorModel)8 EntryCallNode (org.iobserve.analysis.behavior.models.extended.EntryCallNode)8 CallInformation (org.iobserve.analysis.behavior.models.extended.CallInformation)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 Optional (java.util.Optional)2 NodeDifference (org.iobserve.evaluation.data.NodeDifference)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 BufferedWriter (java.io.BufferedWriter)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 SingleOrNoneCollector (org.iobserve.analysis.behavior.SingleOrNoneCollector)1 ComparisonResult (org.iobserve.evaluation.data.ComparisonResult)1 EntryCallEvent (org.iobserve.stages.general.data.EntryCallEvent)1 PayloadAwareEntryCallEvent (org.iobserve.stages.general.data.PayloadAwareEntryCallEvent)1