use of org.iobserve.analysis.behavior.models.extended.EntryCallNode in project iobserve-analysis by research-iobserve.
the class SessionToBehaviorModelTransformation method createNode.
private EntryCallNode createNode(final PayloadAwareEntryCallEvent event) {
final String signature = event.getOperationSignature();
final EntryCallNode node = new EntryCallNode(signature);
final String[] parameters = event.getParameters();
final String[] values = event.getValues();
for (int i = 0; i < parameters.length; i++) {
node.mergeCallInformation(new CallInformation(parameters[i], values[i]));
}
return node;
}
use of org.iobserve.analysis.behavior.models.extended.EntryCallNode in project iobserve-analysis by research-iobserve.
the class GeneralStructureMetric method caclulateNodeDistance.
/**
* Calculate node distance.
*
* @param a
* first model
* @param b
* second model
*/
private double caclulateNodeDistance(final BehaviorModel a, final BehaviorModel b) {
// Get amount of shared nodes
double sharedNodes = 0;
for (final EntryCallNode nodeA : a.getNodes()) {
for (final EntryCallNode nodeB : b.getNodes()) {
if (nodeA.equals(nodeB)) {
sharedNodes++;
// There cannot be multiple nodes with the same signature in a model
break;
}
}
}
final double nodesInA = a.getNodes().size();
final double nodesInB = b.getNodes().size();
return (nodesInA + nodesInB - sharedNodes) / (nodesInA + nodesInB);
}
use of org.iobserve.analysis.behavior.models.extended.EntryCallNode in project iobserve-analysis by research-iobserve.
the class ComparisonOutputStage method execute.
@Override
protected void execute(final ComparisonResult result) throws IOException {
final BufferedWriter writer = Files.newBufferedWriter(this.outputFile.toPath(), StandardCharsets.UTF_8, StandardOpenOption.WRITE);
final int baselineNodeCount = result.getBaselineNodes().size();
final int testModelNodeCount = result.getTestModelNodes().size();
final int missingNodeCount = result.getMissingNodes().size();
final int additionalNodeCount = result.getAdditionalNodes().size();
final int baselineEdgeCount = result.getBaselineEdges().size();
final int testModelEdgeCount = result.getTestModelEdges().size();
final int missingEdgeCount = result.getMissingEdgeCount();
final int additionalEdgeCount = result.getAdditionalEdgeCount();
writer.write("CP;" + this.outputFile.getName() + ";" + baselineNodeCount + ";" + baselineEdgeCount + ";" + testModelNodeCount + ";" + testModelEdgeCount + ";" + missingNodeCount + ";" + additionalNodeCount + ";" + missingEdgeCount + ";" + additionalEdgeCount + ";" + (double) missingNodeCount / (double) baselineNodeCount + ";" + (double) additionalNodeCount / (double) baselineNodeCount + ";" + (double) missingEdgeCount / (double) baselineEdgeCount + ";" + (double) additionalEdgeCount / (double) baselineEdgeCount + "\n");
final List<EntryCallNode> allNodes = this.createAllNodesList(result.getBaselineNodes(), result.getTestModelNodes());
final List<EntryCallEdge> allEdges = this.createAllEdgesList(result.getBaselineEdges(), result.getTestModelEdges());
this.generateNodeCallInformation(writer, "baseline;" + this.outputFile.getName() + ";", allNodes, result.getBaselineNodes());
this.generateNodeCallInformation(writer, "compared;" + this.outputFile.getName() + ";", allNodes, result.getTestModelNodes());
writer.write("baseline;------------------------------------------ edges\n");
writer.write("compared;------------------------------------------ edges\n");
this.generateEdges(writer, "baseline;" + this.outputFile.getName() + ";", allEdges, result.getBaselineEdges());
this.generateEdges(writer, "compared;" + this.outputFile.getName() + ";", allEdges, result.getTestModelEdges());
writer.write("Nodes:\n\tmissing=" + result.getMissingNodes().size() + "\n\tadditional=" + result.getAdditionalNodes().size() + "\n");
for (final EntryCallNode node : result.getMissingNodes()) {
writer.write("\t - " + node.getSignature() + "\n");
}
for (final EntryCallNode node : result.getAdditionalNodes()) {
writer.write("\t + " + node.getSignature() + "\n");
}
for (final EntryCallNode node : result.getSimilarNodes()) {
writer.write("\t = " + node.getSignature() + "\n");
}
writer.write("Edges:\n\tmissing=" + result.getMissingEdgeCount() + "\n\tadditional=" + result.getAdditionalEdgeCount() + "\n");
writer.write("Node differences:\n");
for (final NodeDifference difference : result.getNodeDifferences()) {
writer.write("\tNode " + difference.getReferenceNode().getSignature() + "\n");
writer.write("\t\tMissing");
String separator = "=";
for (final CallInformation callInformation : difference.getMissingInformation()) {
writer.write(separator + callInformation);
separator = ", ";
}
writer.write("\n");
writer.write("\t\tAdditional");
separator = "=";
for (final CallInformation callInformation : difference.getMissingInformation()) {
writer.write(separator + callInformation);
separator = ", ";
}
writer.write("\n");
}
writer.close();
}
use of org.iobserve.analysis.behavior.models.extended.EntryCallNode 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.EntryCallNode 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());
}
}
Aggregations