Skip to content

Commit

Permalink
Fix compilation error after Trace Compass API clean-up
Browse files Browse the repository at this point in the history
See
eclipse-tracecompass/org.eclipse.tracecompass#87

Note: XAF was broken before due incompatible changes in mainline TC.
This commit, just makes it compile again, but it's still broken.

Signed-off-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
  • Loading branch information
bhufmann authored and vladarama committed Jul 16, 2024
1 parent 63ace45 commit 211a84d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected boolean executeAnalysis(@NonNull IProgressMonitor monitor) throws TmfA
}

@Override
protected @Nullable ISegmentStoreProvider getSegmentProviderAnalysis(@NonNull ITmfTrace trace) {
protected @Nullable ISegmentStoreProvider getSegmentStoreProvider(@NonNull ITmfTrace trace) {
return fSegmentStoreProvider;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@
import java.util.regex.Pattern;

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.tracecompass.analysis.graph.core.base.TmfEdge.EdgeType;
import org.eclipse.tracecompass.analysis.graph.core.base.TmfGraph;
import org.eclipse.tracecompass.analysis.graph.core.base.TmfVertex;
import org.eclipse.tracecompass.analysis.graph.core.building.AbstractTraceEventHandler;
import org.eclipse.tracecompass.analysis.graph.core.building.ITraceEventHandler;
import org.eclipse.tracecompass.analysis.graph.core.graph.ITmfGraph;
import org.eclipse.tracecompass.analysis.graph.core.graph.ITmfVertex;
import org.eclipse.tracecompass.analysis.os.linux.core.event.aspect.LinuxTidAspect;
import org.eclipse.tracecompass.analysis.os.linux.core.execution.graph.IOsExecutionGraphHandlerBuilder;
import org.eclipse.tracecompass.analysis.os.linux.core.execution.graph.OsExecutionGraphProvider;
import org.eclipse.tracecompass.analysis.os.linux.core.execution.graph.OsWorker;
import org.eclipse.tracecompass.analysis.os.linux.core.model.HostThread;
import org.eclipse.tracecompass.analysis.os.linux.core.model.ProcessStatus;
import org.eclipse.tracecompass.internal.analysis.graph.core.graph.legacy.OSEdgeContextState;
import org.eclipse.tracecompass.internal.analysis.graph.core.graph.legacy.OSEdgeContextState.OSEdgeContextEnum;
import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;

Expand All @@ -49,23 +50,23 @@ public class PThreadLockGraphHandler extends AbstractTraceEventHandler {

private static class LastLockOwner {
public final Integer fTid;
public final TmfVertex fVertex;
public final ITmfVertex fVertex;

/**
* @param tid
* The ID of the thread who last released the lock
* @param vertex
* The vertex at which the lock was removed by the worker
*/
public LastLockOwner(Integer tid, TmfVertex vertex) {
public LastLockOwner(Integer tid, ITmfVertex vertex) {
fTid = tid;
fVertex = vertex;
}
}

private final OsExecutionGraphProvider fProvider;
/** tid, mutex ID, vertex of the last lock request */
private final Table<Integer, Long, TmfVertex> fLastRequest;
private final Table<Integer, Long, ITmfVertex> fLastRequest;
/** mutex ID, last lock owner */
private final Map<Long, LastLockOwner> fLastLockOwner = new HashMap<>();

Expand Down Expand Up @@ -97,13 +98,13 @@ public ITraceEventHandler createHandler(@NonNull OsExecutionGraphProvider provid

private OsWorker getOrCreateKernelWorker(ITmfEvent event, Integer tid) {
HostThread ht = new HostThread(event.getTrace().getHostId(), tid);
OsWorker worker = fProvider.getSystem().findWorker(ht);
OsWorker worker = fProvider.getSystem().findWorker(ht, null);
if (worker != null) {
return worker;
}
worker = new OsWorker(ht, "kernel/" + tid, event.getTimestamp().getValue()); //$NON-NLS-1$
worker.setStatus(ProcessStatus.RUN);
fProvider.getSystem().addWorker(worker);
fProvider.getSystem().addWorker(worker, null);
return worker;
}

Expand Down Expand Up @@ -131,23 +132,26 @@ private void handleAcquireLockEvent(ITmfEvent event) {
OsWorker worker = getOrCreateKernelWorker(event, tid);

// Get the vertex for the last request
TmfVertex lastReqVertex = fLastRequest.get(tid, fieldValue);
ITmfVertex lastReqVertex = fLastRequest.get(tid, fieldValue);
if (lastReqVertex == null) {
return;
}

// Get the last lock owner
LastLockOwner lastOwner = fLastLockOwner.get(fieldValue);
if (lastOwner != null && lastOwner.fTid != tid && lastOwner.fVertex.getTs() > lastReqVertex.getTs()) {
if (lastOwner != null && lastOwner.fTid != tid && lastOwner.fVertex.getTimestamp() > lastReqVertex.getTimestamp()) {
// This thread has been blocked, add the proper vertices and links
TmfGraph graph = Objects.requireNonNull(fProvider.getAssignedGraph());
ITmfGraph graph = Objects.requireNonNull(fProvider.getGraph());

// First add a vertex at the time of lock request
graph.append(worker, lastReqVertex, EdgeType.RUNNING);
graph.append(lastReqVertex, new OSEdgeContextState(OSEdgeContextEnum.RUNNING));
// Then add the blocked transition for the current worker
TmfVertex unblockVertex = new TmfVertex(event.getTimestamp().toNanos());
graph.append(worker, unblockVertex, EdgeType.BLOCKED);
ITmfVertex unblockVertex = graph.createVertex(worker, event.getTimestamp().toNanos());
graph.append(unblockVertex, new OSEdgeContextState(OSEdgeContextEnum.BLOCKED));
// And add the vertical link between the unlock and the acquisition
lastOwner.fVertex.linkVertical(unblockVertex);
// TODO: check if it's the correct replacement
// lastOwner.fVertex.linkVertical(unblockVertex);
graph.edgeVertical(lastOwner.fVertex, unblockVertex, new OSEdgeContextState(OSEdgeContextEnum.DEFAULT), MUTEX_FIELD);
}
}

Expand All @@ -161,8 +165,11 @@ private void handleRequestLockEvent(ITmfEvent event) {
return;
}

ITmfGraph graph = Objects.requireNonNull(fProvider.getGraph());
OsWorker worker = getOrCreateKernelWorker(event, tid);

// Don't add a state change to the worker just yet, let's keep the previous state until we know it's being blocked
TmfVertex vertex = new TmfVertex(event.getTimestamp().toNanos());
ITmfVertex vertex = graph.createVertex(worker, event.getTimestamp().toNanos());
//TmfVertex stateChange = stateChange(worker, event.getTimestamp().toNanos(), EdgeType.RUNNING);
fLastRequest.put(tid, fieldValue, vertex);
}
Expand All @@ -179,9 +186,9 @@ private void handleUnlockEvent(ITmfEvent event) {
OsWorker worker = getOrCreateKernelWorker(event, tid);
// Set the previous state to running for the worker and add a vertex at this
// event, so it can be used by any thread that was blocked
TmfGraph graph = Objects.requireNonNull(fProvider.getAssignedGraph());
TmfVertex vertex = new TmfVertex(event.getTimestamp().toNanos());
graph.append(worker, vertex, EdgeType.RUNNING);
ITmfGraph graph = Objects.requireNonNull(fProvider.getGraph());
ITmfVertex vertex = graph.createVertex(worker, event.getTimestamp().toNanos());
graph.append(vertex, new OSEdgeContextState(OSEdgeContextEnum.RUNNING));
fLastLockOwner.put(fieldValue, new LastLockOwner(tid, vertex));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.tracecompass.analysis.graph.core.base.IGraphWorker;
import org.eclipse.tracecompass.analysis.graph.core.base.TmfEdge;
import org.eclipse.tracecompass.analysis.graph.core.base.TmfGraph;
import org.eclipse.tracecompass.analysis.graph.core.base.TmfVertex;
import org.eclipse.tracecompass.analysis.graph.core.criticalpath.CriticalPathAlgorithmException;
import org.eclipse.tracecompass.analysis.graph.core.graph.ITmfGraph;
import org.eclipse.tracecompass.analysis.graph.core.graph.ITmfGraphVisitor;
import org.eclipse.tracecompass.analysis.graph.core.graph.ITmfVertex;
import org.eclipse.tracecompass.analysis.os.linux.core.execution.graph.OsExecutionGraph;
import org.eclipse.tracecompass.analysis.os.linux.core.execution.graph.OsWorker;
import org.eclipse.tracecompass.analysis.os.linux.core.kernel.KernelAnalysisModule;
Expand Down Expand Up @@ -69,8 +69,9 @@
import org.eclipse.tracecompass.incubator.internal.xaf.ui.statemachine.StateMachineReport;
import org.eclipse.tracecompass.incubator.internal.xaf.ui.statemachine.StateMachineSegment;
import org.eclipse.tracecompass.incubator.internal.xaf.ui.statemachine.StateMachineUtils.TimestampInterval;
import org.eclipse.tracecompass.internal.analysis.graph.core.base.TmfEdge;
import org.eclipse.tracecompass.internal.analysis.graph.core.base.TmfGraphVisitor;
import org.eclipse.tracecompass.internal.analysis.graph.core.criticalpath.CriticalPathAlgorithmBounded;
import org.eclipse.tracecompass.internal.analysis.graph.core.criticalpath.OSCriticalPathAlgorithm;
import org.eclipse.tracecompass.internal.segmentstore.core.treemap.TreeMapStore;
import org.eclipse.tracecompass.segmentstore.core.ISegment;
import org.eclipse.tracecompass.segmentstore.core.ISegmentStore;
Expand Down Expand Up @@ -1284,7 +1285,7 @@ private List<InterruptionDuration> getCriticalPathSteps(InstanceStepInformation
g.waitForCompletion();

// Get the general graph for the trace
TmfGraph graph = g.getGraph();
ITmfGraph graph = g.getCriticalPathGraph();
if (graph == null) {
Activator.getInstance().logWarning("graph == null"); //$NON-NLS-1$
continue;
Expand All @@ -1310,12 +1311,18 @@ private List<InterruptionDuration> getCriticalPathSteps(InstanceStepInformation
workerFound = true;

// Compute the path for the period we're interested into
TmfVertex vstart = graph.getVertexAt(Objects.requireNonNull(ti.getStartTime()), lw);
TmfVertex vend = graph.getVertexAt(Objects.requireNonNull(ti.getEndTime()), lw);
TmfGraph path = new CriticalPathAlgorithmBounded(graph).compute(Objects.requireNonNull(vstart), Objects.requireNonNull(vend));
ITmfVertex vstart = graph.getVertexAt(Objects.requireNonNull(ti.getStartTime()), lw);
ITmfVertex vend = graph.getVertexAt(Objects.requireNonNull(ti.getEndTime()), lw);

// Note: compute() method was removed because it was deprecated. More over when it was deprecated the method implementation
// was changed to throw an UnsupportedOperationException().
// See https://git.eclipse.org/r/c/tracecompass/org.eclipse.tracecompass/+/182723
// So, the implementation was broken and this change just makes it compile

ITmfGraph path = new OSCriticalPathAlgorithm(graph).computeCriticalPath(graph, Objects.requireNonNull(vstart), Objects.requireNonNull(vend));

// Then traverse that path to get the data for what happened in there
path.scanLineTraverse(path.getHead(lw), new TmfGraphVisitor() {
path.scanLineTraverse(path.getHead(lw), (ITmfGraphVisitor) new TmfGraphVisitor() {
@Override
public void visit(TmfEdge link, boolean horizontal) {
if (!horizontal) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

import java.util.Objects;

import org.eclipse.tracecompass.analysis.graph.core.base.TmfEdge;
import org.eclipse.tracecompass.analysis.os.linux.core.execution.graph.OsWorker;
import org.eclipse.tracecompass.internal.analysis.graph.core.base.TmfEdge;

/**
* Element representing a Critical Path state
Expand Down

0 comments on commit 211a84d

Please sign in to comment.