use of org.eclipse.tracecompass.analysis.graph.core.building.TmfGraphBuilderModule in project tracecompass by tracecompass.
the class TmfGraphBuilderModuleTest method testBuildGraph.
/**
* Test the graph builder execution
*/
@Test
public void testBuildGraph() {
TmfXmlTraceStub trace = TmfXmlTraceStubNs.setupTrace(Activator.getAbsoluteFilePath(STUB_TRACE_FILE));
TmfGraphBuilderModule module = getModule(trace);
module.schedule();
module.waitForCompletion();
TmfGraph graph = module.getGraph();
assertNotNull(graph);
assertEquals(2, graph.getWorkers().size());
assertEquals(9, graph.size());
List<TmfVertex> vertices = graph.getNodesOf(new TestGraphWorker(1));
assertEquals(5, vertices.size());
long[] timestamps1 = { 1, 2, 5, 7, 12 };
boolean[][] hasEdges1 = { { false, true, false, false }, { true, false, false, true }, { false, true, true, false }, { true, false, false, false }, { false, false, true, false } };
for (int i = 0; i < vertices.size(); i++) {
TmfVertex v = vertices.get(i);
assertEquals(timestamps1[i], v.getTs());
assertEquals(hasEdges1[i][0], v.getEdge(EdgeDirection.INCOMING_HORIZONTAL_EDGE) != null);
assertEquals(hasEdges1[i][1], v.getEdge(EdgeDirection.OUTGOING_HORIZONTAL_EDGE) != null);
assertEquals(hasEdges1[i][2], v.getEdge(EdgeDirection.INCOMING_VERTICAL_EDGE) != null);
assertEquals(hasEdges1[i][3], v.getEdge(EdgeDirection.OUTGOING_VERTICAL_EDGE) != null);
}
vertices = graph.getNodesOf(new TestGraphWorker(2));
assertEquals(4, vertices.size());
long[] timestamps2 = { 2, 5, 10, 12 };
boolean[][] hasEdges2 = { { false, true, true, false }, { true, false, false, true }, { false, true, false, false }, { true, false, false, true } };
for (int i = 0; i < vertices.size(); i++) {
TmfVertex v = vertices.get(i);
assertEquals(timestamps2[i], v.getTs());
assertEquals(hasEdges2[i][0], v.getEdge(EdgeDirection.INCOMING_HORIZONTAL_EDGE) != null);
assertEquals(hasEdges2[i][1], v.getEdge(EdgeDirection.OUTGOING_HORIZONTAL_EDGE) != null);
assertEquals(hasEdges2[i][2], v.getEdge(EdgeDirection.INCOMING_VERTICAL_EDGE) != null);
assertEquals(hasEdges2[i][3], v.getEdge(EdgeDirection.OUTGOING_VERTICAL_EDGE) != null);
}
trace.dispose();
}
use of org.eclipse.tracecompass.analysis.graph.core.building.TmfGraphBuilderModule in project tracecompass by tracecompass.
the class CriticalPathModule method executeAnalysis.
@Override
protected boolean executeAnalysis(final IProgressMonitor monitor) throws TmfAnalysisException {
/* Get the worker id */
Object workerObj = getParameter(PARAM_WORKER);
if (workerObj == null) {
return false;
}
if (!(workerObj instanceof IGraphWorker)) {
// $NON-NLS-1$
throw new IllegalStateException("Worker parameter must be an IGraphWorker");
}
IGraphWorker worker = (IGraphWorker) workerObj;
/* Get the graph */
TmfGraphBuilderModule graphModule = fGraphModule;
graphModule.schedule();
monitor.setTaskName(NLS.bind(Messages.CriticalPathModule_waitingForGraph, graphModule.getName()));
if (!graphModule.waitForCompletion(monitor)) {
// $NON-NLS-1$
Activator.getInstance().logInfo("Critical path execution: graph building was cancelled. Results may not be accurate.");
return false;
}
TmfGraph graph = graphModule.getGraph();
if (graph == null) {
// $NON-NLS-1$//$NON-NLS-2$
throw new TmfAnalysisException("Critical Path analysis: graph " + graphModule.getName() + " is null");
}
TmfVertex head = graph.getHead(worker);
if (head == null) {
/* Nothing happens with this worker, return an empty graph */
fCriticalPath = new TmfGraph();
return true;
}
ICriticalPathAlgorithm cp = getAlgorithm(graph);
try {
fCriticalPath = cp.compute(head, null);
return true;
} catch (CriticalPathAlgorithmException e) {
Activator.getInstance().logError(NonNullUtils.nullToEmptyString(e.getMessage()), e);
}
return false;
}
use of org.eclipse.tracecompass.analysis.graph.core.building.TmfGraphBuilderModule in project tracecompass by tracecompass.
the class DistributedCriticalPathTest method internalTestNetworkExchange.
private static void internalTestNetworkExchange(@NonNull ITmfTrace experiment) throws TmfAnalysisException {
TmfGraphBuilderModule module = TmfTraceUtils.getAnalysisModuleOfClass(experiment, TmfGraphBuilderModule.class, TEST_ANALYSIS_ID);
assertNotNull(module);
TmfGraph graph = module.getGraph();
assertNotNull(graph);
Set<IGraphWorker> workers = graph.getWorkers();
assertEquals(7, workers.size());
// Prepare a worker map
final int clientThread = 200;
final int otherClient = 201;
final int depClient = 202;
final int serverThread = 100;
final int otherServer = 101;
OsWorker clientWorker = null;
OsWorker serverWorker = null;
Map<Integer, IGraphWorker> workerMap = new HashMap<>();
for (IGraphWorker worker : workers) {
OsWorker osWorker = (OsWorker) worker;
if (osWorker.getHostThread().getTid() < 0) {
if (osWorker.getHostId().equals("simple_network_server.xml")) {
serverWorker = osWorker;
} else {
clientWorker = osWorker;
}
}
workerMap.put(osWorker.getHostThread().getTid(), worker);
}
// Make the expected graph
TmfGraph expected = new TmfGraph();
// other thread on client side
IGraphWorker worker = workerMap.get(otherClient);
assertNotNull(worker);
expected.add(worker, new TmfVertex(7));
expected.append(worker, new TmfVertex(10), EdgeType.RUNNING);
expected.append(worker, new TmfVertex(15), EdgeType.PREEMPTED);
expected.append(worker, new TmfVertex(75), EdgeType.RUNNING);
// client thread
worker = workerMap.get(clientThread);
assertNotNull(worker);
expected.add(worker, new TmfVertex(10));
TmfVertex packet1Sent = new TmfVertex(13);
expected.append(worker, packet1Sent, EdgeType.RUNNING);
expected.append(worker, new TmfVertex(15), EdgeType.RUNNING);
TmfVertex packet2Received = new TmfVertex(70);
expected.append(worker, packet2Received, EdgeType.NETWORK);
expected.append(worker, new TmfVertex(75), EdgeType.PREEMPTED);
TmfVertex wakeupSource = new TmfVertex(90);
expected.append(worker, wakeupSource, EdgeType.RUNNING);
expected.append(worker, new TmfVertex(95), EdgeType.RUNNING);
// client kernel worker
worker = clientWorker;
assertNotNull(worker);
expected.add(worker, new TmfVertex(60));
expected.append(worker, new TmfVertex(65), EdgeType.RUNNING);
// thread on client waiting for client process
worker = workerMap.get(depClient);
assertNotNull(worker);
expected.add(worker, new TmfVertex(7));
TmfVertex wakeupTarget = new TmfVertex(90);
expected.append(worker, wakeupTarget, EdgeType.BLOCKED);
expected.append(worker, new TmfVertex(95), EdgeType.PREEMPTED);
wakeupSource.linkVertical(wakeupTarget);
// Other thread on server side
worker = workerMap.get(otherServer);
assertNotNull(worker);
expected.add(worker, new TmfVertex(5));
expected.append(worker, new TmfVertex(40), EdgeType.RUNNING);
expected.append(worker, new TmfVertex(55), EdgeType.PREEMPTED);
// Server thread
worker = workerMap.get(serverThread);
assertNotNull(worker);
expected.add(worker, new TmfVertex(5));
TmfVertex packet1Received = new TmfVertex(35);
expected.append(worker, packet1Received, EdgeType.NETWORK);
expected.append(worker, new TmfVertex(40), EdgeType.PREEMPTED);
TmfVertex packet2Sent = new TmfVertex(45);
expected.append(worker, packet2Sent, EdgeType.RUNNING);
expected.append(worker, new TmfVertex(55), EdgeType.RUNNING);
// Create the vertical links
TmfEdge link = packet1Sent.linkVertical(packet1Received);
link.setType(EdgeType.NETWORK);
link = packet2Sent.linkVertical(packet2Received);
link.setType(EdgeType.NETWORK);
// kernel worker on server side
worker = serverWorker;
assertNotNull(worker);
expected.add(worker, new TmfVertex(30));
expected.append(worker, new TmfVertex(33), EdgeType.RUNNING);
GraphOps.checkEquality(expected, graph);
/* Test the critical path */
// Build the expected critical path
expected = new TmfGraph();
// Client worker
worker = workerMap.get(clientThread);
assertNotNull(worker);
expected.add(worker, new TmfVertex(10));
expected.append(worker, new TmfVertex(13), EdgeType.RUNNING);
packet1Sent = new TmfVertex(15);
expected.append(worker, packet1Sent, EdgeType.RUNNING);
packet2Received = new TmfVertex(70);
expected.add(worker, packet2Received);
expected.append(worker, new TmfVertex(75), EdgeType.PREEMPTED);
expected.append(worker, new TmfVertex(90), EdgeType.RUNNING);
expected.append(worker, new TmfVertex(95), EdgeType.RUNNING);
// Server worker
worker = workerMap.get(serverThread);
assertNotNull(worker);
packet1Received = new TmfVertex(35);
expected.add(worker, packet1Received);
expected.append(worker, new TmfVertex(40), EdgeType.PREEMPTED);
packet2Sent = new TmfVertex(45);
expected.append(worker, packet2Sent, EdgeType.RUNNING);
link = packet1Sent.linkVertical(packet1Received);
link.setType(EdgeType.NETWORK);
link = packet2Sent.linkVertical(packet2Received);
link.setType(EdgeType.NETWORK);
// Execute the critical path module and compare equality
CriticalPathModule critPathModule = new CriticalPathModule(module);
try {
critPathModule.setTrace(experiment);
critPathModule.setParameter(CriticalPathModule.PARAM_WORKER, workerMap.get(clientThread));
critPathModule.schedule();
assertTrue(critPathModule.waitForCompletion());
TmfGraph criticalPath = critPathModule.getCriticalPath();
assertNotNull(criticalPath);
GraphOps.checkEquality(expected, criticalPath);
} finally {
critPathModule.dispose();
}
}
use of org.eclipse.tracecompass.analysis.graph.core.building.TmfGraphBuilderModule in project tracecompass by tracecompass.
the class DistributedCriticalPathTest method internalTestNetworkExchangeOneTrace.
private static void internalTestNetworkExchangeOneTrace(@NonNull ITmfTrace experiment) throws TmfAnalysisException {
TmfGraphBuilderModule module = TmfTraceUtils.getAnalysisModuleOfClass(experiment, TmfGraphBuilderModule.class, TEST_ANALYSIS_ID);
assertNotNull(module);
TmfGraph graph = module.getGraph();
assertNotNull(graph);
Set<IGraphWorker> workers = graph.getWorkers();
assertEquals(3, workers.size());
// Prepare a worker map
final int irqThread = 50;
final int clientThread = 200;
final int otherClient = 201;
Map<Integer, IGraphWorker> workerMap = new HashMap<>();
for (IGraphWorker worker : workers) {
workerMap.put(((OsWorker) worker).getHostThread().getTid(), worker);
}
// Make the expected graph
TmfGraph expected = new TmfGraph();
// other thread on client side
IGraphWorker worker = workerMap.get(otherClient);
assertNotNull(worker);
expected.add(worker, new TmfVertex(10));
expected.append(worker, new TmfVertex(15), EdgeType.PREEMPTED);
expected.append(worker, new TmfVertex(60), EdgeType.RUNNING);
// client thread
worker = workerMap.get(clientThread);
assertNotNull(worker);
expected.add(worker, new TmfVertex(10));
TmfVertex packet1Sent = new TmfVertex(13);
expected.append(worker, packet1Sent, EdgeType.RUNNING);
expected.append(worker, new TmfVertex(15), EdgeType.RUNNING);
TmfVertex packet2Received = new TmfVertex(70);
expected.append(worker, packet2Received, EdgeType.NETWORK, "irq/30-handler");
expected.append(worker, new TmfVertex(75), EdgeType.PREEMPTED);
// irq thread
worker = workerMap.get(irqThread);
assertNotNull(worker);
expected.add(worker, new TmfVertex(55));
expected.append(worker, new TmfVertex(60), EdgeType.PREEMPTED);
expected.append(worker, new TmfVertex(65), EdgeType.RUNNING);
expected.append(worker, new TmfVertex(75), EdgeType.RUNNING);
GraphOps.checkEquality(expected, graph);
/* Test the critical path */
// Build the expected graph: it should be the client thread only
expected = new TmfGraph();
worker = workerMap.get(clientThread);
assertNotNull(worker);
for (TmfVertex vertex : graph.getNodesOf(worker)) {
expected.add(worker, vertex);
}
// Execute the critical path module and compare equality
CriticalPathModule critPathModule = new CriticalPathModule(module);
try {
critPathModule.setTrace(experiment);
critPathModule.setParameter(CriticalPathModule.PARAM_WORKER, workerMap.get(clientThread));
critPathModule.schedule();
assertTrue(critPathModule.waitForCompletion());
TmfGraph criticalPath = critPathModule.getCriticalPath();
assertNotNull(criticalPath);
GraphOps.checkEquality(expected, criticalPath);
} finally {
critPathModule.dispose();
}
}
use of org.eclipse.tracecompass.analysis.graph.core.building.TmfGraphBuilderModule in project tracecompass by tracecompass.
the class LttngExecutionGraphTest method testSchedEvents.
/**
* Test the graph building with sched events only
*
* TODO: Add wakeup events to this test case
*/
@Test
public void testSchedEvents() {
ITmfTrace trace = setUpTrace("testfiles/graph/sched_only.xml");
assertNotNull(trace);
TmfGraphBuilderModule module = TmfTraceUtils.getAnalysisModuleOfClass(trace, TmfGraphBuilderModule.class, TEST_ANALYSIS_ID);
assertNotNull(module);
module.schedule();
assertTrue(module.waitForCompletion());
TmfGraph graph = module.getGraph();
assertNotNull(graph);
Set<IGraphWorker> workers = graph.getWorkers();
assertEquals(2, workers.size());
for (IGraphWorker worker : workers) {
assertTrue(worker instanceof OsWorker);
OsWorker lttngWorker = (OsWorker) worker;
switch(lttngWorker.getHostThread().getTid()) {
case 1:
{
List<TmfVertex> nodesOf = graph.getNodesOf(lttngWorker);
assertEquals(4, nodesOf.size());
/* Check first vertice has outgoing edge preempted */
TmfVertex v = nodesOf.get(0);
assertEquals(10, v.getTs());
assertNull(v.getEdge(EdgeDirection.INCOMING_HORIZONTAL_EDGE));
assertNull(v.getEdge(EdgeDirection.INCOMING_VERTICAL_EDGE));
assertNull(v.getEdge(EdgeDirection.OUTGOING_VERTICAL_EDGE));
TmfEdge edge = v.getEdge(EdgeDirection.OUTGOING_HORIZONTAL_EDGE);
assertNotNull(edge);
assertEquals(EdgeType.PREEMPTED, edge.getType());
v = nodesOf.get(1);
assertEquals(v, edge.getVertexTo());
/* Check second vertice has outgoing edge running */
assertEquals(20, v.getTs());
assertNull(v.getEdge(EdgeDirection.INCOMING_VERTICAL_EDGE));
assertNull(v.getEdge(EdgeDirection.OUTGOING_VERTICAL_EDGE));
assertNotNull(v.getEdge(EdgeDirection.INCOMING_HORIZONTAL_EDGE));
edge = v.getEdge(EdgeDirection.OUTGOING_HORIZONTAL_EDGE);
assertNotNull(edge);
assertEquals(EdgeType.RUNNING, edge.getType());
v = nodesOf.get(2);
assertEquals(v, edge.getVertexTo());
/* Check third vertice has outgoing edge preempted */
assertEquals(30, v.getTs());
assertNull(v.getEdge(EdgeDirection.INCOMING_VERTICAL_EDGE));
assertNull(v.getEdge(EdgeDirection.OUTGOING_VERTICAL_EDGE));
assertNotNull(v.getEdge(EdgeDirection.INCOMING_HORIZONTAL_EDGE));
edge = v.getEdge(EdgeDirection.OUTGOING_HORIZONTAL_EDGE);
assertNotNull(edge);
assertEquals(EdgeType.PREEMPTED, edge.getType());
v = nodesOf.get(3);
assertEquals(v, edge.getVertexTo());
/* Check 4th vertice */
assertEquals(40, v.getTs());
assertNull(v.getEdge(EdgeDirection.INCOMING_VERTICAL_EDGE));
assertNull(v.getEdge(EdgeDirection.OUTGOING_VERTICAL_EDGE));
assertNotNull(v.getEdge(EdgeDirection.INCOMING_HORIZONTAL_EDGE));
assertNull(v.getEdge(EdgeDirection.OUTGOING_HORIZONTAL_EDGE));
}
break;
case 2:
{
List<TmfVertex> nodesOf = graph.getNodesOf(lttngWorker);
assertEquals(4, nodesOf.size());
/* Check first vertice has outgoing edge preempted */
TmfVertex v = nodesOf.get(0);
assertEquals(10, v.getTs());
assertNull(v.getEdge(EdgeDirection.INCOMING_HORIZONTAL_EDGE));
assertNull(v.getEdge(EdgeDirection.INCOMING_VERTICAL_EDGE));
assertNull(v.getEdge(EdgeDirection.OUTGOING_VERTICAL_EDGE));
TmfEdge edge = v.getEdge(EdgeDirection.OUTGOING_HORIZONTAL_EDGE);
assertNotNull(edge);
assertEquals(EdgeType.RUNNING, edge.getType());
v = nodesOf.get(1);
assertEquals(v, edge.getVertexTo());
/* Check second vertice has outgoing edge running */
assertEquals(20, v.getTs());
assertNull(v.getEdge(EdgeDirection.INCOMING_VERTICAL_EDGE));
assertNull(v.getEdge(EdgeDirection.OUTGOING_VERTICAL_EDGE));
assertNotNull(v.getEdge(EdgeDirection.INCOMING_HORIZONTAL_EDGE));
edge = v.getEdge(EdgeDirection.OUTGOING_HORIZONTAL_EDGE);
assertNotNull(edge);
assertEquals(EdgeType.BLOCKED, edge.getType());
v = nodesOf.get(2);
assertEquals(v, edge.getVertexTo());
/* Check third vertice has outgoing edge preempted */
assertEquals(30, v.getTs());
assertNull(v.getEdge(EdgeDirection.INCOMING_VERTICAL_EDGE));
assertNull(v.getEdge(EdgeDirection.OUTGOING_VERTICAL_EDGE));
assertNotNull(v.getEdge(EdgeDirection.INCOMING_HORIZONTAL_EDGE));
edge = v.getEdge(EdgeDirection.OUTGOING_HORIZONTAL_EDGE);
assertNotNull(edge);
assertEquals(EdgeType.RUNNING, edge.getType());
v = nodesOf.get(3);
assertEquals(v, edge.getVertexTo());
/* Check 4th vertice */
assertEquals(40, v.getTs());
assertNull(v.getEdge(EdgeDirection.INCOMING_VERTICAL_EDGE));
assertNull(v.getEdge(EdgeDirection.OUTGOING_VERTICAL_EDGE));
assertNotNull(v.getEdge(EdgeDirection.INCOMING_HORIZONTAL_EDGE));
assertNull(v.getEdge(EdgeDirection.OUTGOING_HORIZONTAL_EDGE));
}
break;
default:
fail("Unknown worker");
break;
}
}
trace.dispose();
}
Aggregations