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();
}
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());
}
}
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;
}
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);
}
}
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;
}
Aggregations