Search in sources :

Example 1 with IGraphWorker

use of org.eclipse.tracecompass.analysis.graph.core.base.IGraphWorker in project tracecompass by tracecompass.

the class GraphOps method checkEquality.

/**
 * Check whether 2 graphs are identical
 *
 * @param g1
 *            The first graph to compare
 * @param g2
 *            The second graph
 */
public static void checkEquality(TmfGraph g1, TmfGraph g2) {
    Set<IGraphWorker> obj1 = g1.getWorkers();
    Set<IGraphWorker> obj2 = g2.getWorkers();
    assertEquals("Graph objects", obj1, obj2);
    for (IGraphWorker graphObject : obj1) {
        assertNotNull(graphObject);
        List<TmfVertex> nodesOf1 = g1.getNodesOf(graphObject);
        List<TmfVertex> nodesOf2 = g2.getNodesOf(graphObject);
        for (int i = 0; i < nodesOf1.size(); i++) {
            TmfVertex v1 = nodesOf1.get(i);
            TmfVertex v2 = nodesOf2.get(i);
            assertEquals("Node timestamps for " + graphObject + ", node " + i, v1.getTs(), v2.getTs());
            /* Check each edge */
            for (EdgeDirection dir : EdgeDirection.values()) {
                TmfEdge edge1 = v1.getEdge(dir);
                TmfEdge edge2 = v2.getEdge(dir);
                if (edge1 == null) {
                    assertNull("Expected null edge for " + graphObject + ", node " + i + " and dir " + dir, edge2);
                    continue;
                }
                assertNotNull("Expected non null edge for " + graphObject + ", node " + i + " and dir " + dir, edge2);
                assertEquals("Edge type for " + graphObject + ", node " + i + " and dir " + dir, edge1.getType(), edge2.getType());
                assertEquals("Edge duration for " + graphObject + ", node " + i + " edge direction " + dir, edge1.getDuration(), edge2.getDuration());
                assertEquals("From objects for " + graphObject + ", node " + i + " and dir " + dir, g1.getParentOf(edge1.getVertexFrom()), g2.getParentOf(edge2.getVertexFrom()));
                assertEquals("To objects for " + graphObject + ", node " + i + " and dir " + dir, g1.getParentOf(edge1.getVertexTo()), g2.getParentOf(edge2.getVertexTo()));
                assertEquals("Edge qualifier for " + graphObject + ", node " + i + " and dir " + dir, edge1.getLinkQualifier(), edge2.getLinkQualifier());
            }
        }
    }
}
Also used : TmfEdge(org.eclipse.tracecompass.analysis.graph.core.base.TmfEdge) TmfVertex(org.eclipse.tracecompass.analysis.graph.core.base.TmfVertex) EdgeDirection(org.eclipse.tracecompass.analysis.graph.core.base.TmfVertex.EdgeDirection) IGraphWorker(org.eclipse.tracecompass.analysis.graph.core.base.IGraphWorker)

Example 2 with IGraphWorker

use of org.eclipse.tracecompass.analysis.graph.core.base.IGraphWorker 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;
}
Also used : TmfVertex(org.eclipse.tracecompass.analysis.graph.core.base.TmfVertex) TmfGraph(org.eclipse.tracecompass.analysis.graph.core.base.TmfGraph) TmfAnalysisException(org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException) IGraphWorker(org.eclipse.tracecompass.analysis.graph.core.base.IGraphWorker) TmfGraphBuilderModule(org.eclipse.tracecompass.analysis.graph.core.building.TmfGraphBuilderModule)

Example 3 with IGraphWorker

use of org.eclipse.tracecompass.analysis.graph.core.base.IGraphWorker in project tracecompass by tracecompass.

the class TmfGraphStatistics method visit.

@Override
public void visit(TmfEdge edge, boolean horizontal) {
    // Add the duration of the link only if it is horizontal
    TmfGraph graph = fGraph;
    synchronized (fWorkerStats) {
        if (horizontal && graph != null) {
            IGraphWorker worker = graph.getParentOf(edge.getVertexFrom());
            if (worker == null) {
                return;
            }
            Long duration = edge.getDuration();
            Long currentTotal = fWorkerStats.get(worker);
            if (currentTotal != null) {
                duration += currentTotal;
            }
            fWorkerStats.put(worker, duration);
            fTotal += edge.getDuration();
        }
    }
}
Also used : TmfGraph(org.eclipse.tracecompass.analysis.graph.core.base.TmfGraph) IGraphWorker(org.eclipse.tracecompass.analysis.graph.core.base.IGraphWorker)

Example 4 with IGraphWorker

use of org.eclipse.tracecompass.analysis.graph.core.base.IGraphWorker in project tracecompass by tracecompass.

the class CriticalPathAlgorithmBounded method compute.

@Override
public TmfGraph compute(TmfVertex start, @Nullable TmfVertex end) throws CriticalPathAlgorithmException {
    /* Create new graph for the critical path result */
    TmfGraph criticalPath = new TmfGraph();
    /* Get the main graph from which to get critical path */
    TmfGraph graph = getGraph();
    /*
         * Calculate path starting from the object the start vertex belongs to
         */
    IGraphWorker parent = checkNotNull(graph.getParentOf(start));
    criticalPath.add(parent, new TmfVertex(start));
    TmfVertex currentVertex = start;
    TmfEdge nextEdge = currentVertex.getEdge(EdgeDirection.OUTGOING_HORIZONTAL_EDGE);
    long endTime = Long.MAX_VALUE;
    if (end != null) {
        endTime = end.getTs();
    }
    /*
         * Run through all horizontal edges from this object and resolve each
         * blocking as they come
         */
    while (nextEdge != null) {
        TmfVertex nextVertex = nextEdge.getVertexTo();
        if (nextVertex.getTs() >= endTime) {
            break;
        }
        switch(nextEdge.getType()) {
            case IPI:
            case USER_INPUT:
            case BLOCK_DEVICE:
            case TIMER:
            case INTERRUPTED:
            case PREEMPTED:
            case RUNNING:
            case UNKNOWN:
                /**
                 * This edge is not blocked, so nothing to resolve, just add the
                 * edge to the critical path
                 */
                /**
                 * TODO: Normally, the parent of the link's vertex to should be
                 * the object itself, verify if that is true
                 */
                IGraphWorker parentTo = checkNotNull(graph.getParentOf(nextEdge.getVertexTo()));
                if (parentTo != parent) {
                    // $NON-NLS-1$
                    throw new CriticalPathAlgorithmException("no, the parents of horizontal edges are not always identical... shouldn't they be?");
                }
                criticalPath.append(parentTo, new TmfVertex(nextEdge.getVertexTo()), nextEdge.getType(), nextEdge.getLinkQualifier());
                break;
            case NETWORK:
            case BLOCKED:
                List<TmfEdge> links = resolveBlockingBounded(nextEdge, nextEdge.getVertexFrom());
                Collections.reverse(links);
                appendPathComponent(criticalPath, graph, currentVertex, links);
                break;
            case EPS:
                if (nextEdge.getDuration() != 0) {
                    // $NON-NLS-1$
                    throw new CriticalPathAlgorithmException("epsilon duration is not zero " + nextEdge);
                }
                break;
            case DEFAULT:
                // $NON-NLS-1$
                throw new CriticalPathAlgorithmException("Illegal link type " + nextEdge.getType());
            default:
                break;
        }
        currentVertex = nextVertex;
        nextEdge = currentVertex.getEdge(EdgeDirection.OUTGOING_HORIZONTAL_EDGE);
    }
    return criticalPath;
}
Also used : CriticalPathAlgorithmException(org.eclipse.tracecompass.analysis.graph.core.criticalpath.CriticalPathAlgorithmException) TmfEdge(org.eclipse.tracecompass.analysis.graph.core.base.TmfEdge) TmfVertex(org.eclipse.tracecompass.analysis.graph.core.base.TmfVertex) TmfGraph(org.eclipse.tracecompass.analysis.graph.core.base.TmfGraph) IGraphWorker(org.eclipse.tracecompass.analysis.graph.core.base.IGraphWorker)

Example 5 with IGraphWorker

use of org.eclipse.tracecompass.analysis.graph.core.base.IGraphWorker in project tracecompass by tracecompass.

the class CriticalPathDataProvider method fetchTooltip.

@Override
@NonNull
public TmfModelResponse<@NonNull Map<@NonNull String, @NonNull String>> fetchTooltip(@NonNull Map<@NonNull String, @NonNull Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    SelectionTimeQueryFilter filter = FetchParametersUtils.createSelectionTimeQuery(fetchParameters);
    if (filter == null) {
        return new TmfModelResponse<>(null, Status.FAILED, CommonStatusMessage.INCORRECT_QUERY_PARAMETERS);
    }
    IGraphWorker worker = fWorkerToEntryId.inverse().get(filter.getSelectedItems().iterator().next());
    if (worker == null) {
        return new TmfModelResponse<>(null, Status.COMPLETED, CommonStatusMessage.COMPLETED);
    }
    Map<@NonNull String, @NonNull String> info = worker.getWorkerInformation(filter.getStart());
    return new TmfModelResponse<>(info, Status.COMPLETED, CommonStatusMessage.COMPLETED);
}
Also used : SelectionTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter) IGraphWorker(org.eclipse.tracecompass.analysis.graph.core.base.IGraphWorker) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) NonNull(org.eclipse.jdt.annotation.NonNull)

Aggregations

IGraphWorker (org.eclipse.tracecompass.analysis.graph.core.base.IGraphWorker)17 TmfGraph (org.eclipse.tracecompass.analysis.graph.core.base.TmfGraph)11 TmfVertex (org.eclipse.tracecompass.analysis.graph.core.base.TmfVertex)11 TmfEdge (org.eclipse.tracecompass.analysis.graph.core.base.TmfEdge)7 TmfGraphBuilderModule (org.eclipse.tracecompass.analysis.graph.core.building.TmfGraphBuilderModule)6 OsWorker (org.eclipse.tracecompass.analysis.os.linux.core.execution.graph.OsWorker)6 HashMap (java.util.HashMap)5 CriticalPathModule (org.eclipse.tracecompass.analysis.graph.core.criticalpath.CriticalPathModule)5 NonNull (org.eclipse.jdt.annotation.NonNull)3 TmfModelResponse (org.eclipse.tracecompass.tmf.core.response.TmfModelResponse)3 ArrayList (java.util.ArrayList)2 TmfAnalysisException (org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException)2 SelectionTimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter)2 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Predicate (java.util.function.Predicate)1 Nullable (org.eclipse.jdt.annotation.Nullable)1 EdgeDirection (org.eclipse.tracecompass.analysis.graph.core.base.TmfVertex.EdgeDirection)1 CriticalPathAlgorithmException (org.eclipse.tracecompass.analysis.graph.core.criticalpath.CriticalPathAlgorithmException)1