org.eclipse.tracecompass.common.core,
org.eclipse.tracecompass.tmf.core
Export-Package: org.eclipse.tracecompass.analysis.graph.core.base,
+ org.eclipse.tracecompass.analysis.graph.core.building,
org.eclipse.tracecompass.internal.analysis.graph.core;x-internal=true;uses:="org.eclipse.tracecompass.common.core",
org.eclipse.tracecompass.internal.analysis.graph.core.base;x-friends:="org.eclipse.tracecompass.analysis.graph.ui,org.eclipse.tracecompass.analysis.graph.core.tests"
Import-Package: com.google.common.collect,
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2015 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.analysis.graph.core.building;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.analysis.graph.core.base.TmfGraph;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
+
+/**
+ * Base class for graph providers. It implements most methods common for all
+ * graph builder.
+ *
+ * @author Geneviève Bastien
+ * @author Francis Giraldeau
+ */
+public abstract class AbstractTmfGraphProvider implements ITmfGraphProvider {
+
+ private final ITmfTrace fTrace;
+
+ private final List<ITraceEventHandler> fHandlers;
+
+ private boolean fGraphAssigned;
+
+ /** Graph in which to insert the state changes */
+ private @Nullable TmfGraph fGraph = null;
+
+ /**
+ * Instantiate a new graph builder plugin.
+ *
+ * @param trace
+ * The trace
+ * @param id
+ * Name given to this state change input. Only used internally.
+ */
+ public AbstractTmfGraphProvider(ITmfTrace trace, String id) {
+ this.fTrace = trace;
+ fGraphAssigned = false;
+ fHandlers = new ArrayList<>();
+ }
+
+ @Override
+ public ITmfTrace getTrace() {
+ return fTrace;
+ }
+
+ @Override
+ public long getStartTime() {
+ return fTrace.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
+ }
+
+ @Override
+ public void assignTargetGraph(TmfGraph graph) {
+ fGraph = graph;
+ fGraphAssigned = true;
+ }
+
+ @Override
+ public @Nullable TmfGraph getAssignedGraph() {
+ return fGraph;
+ }
+
+ @Override
+ public void processEvent(ITmfEvent event) {
+ /* Make sure the target graph has been assigned */
+ if (!fGraphAssigned) {
+ return;
+ }
+ eventHandle(event);
+ }
+
+ @Override
+ public void dispose() {
+ fGraphAssigned = false;
+ fGraph = null;
+ }
+
+ @Override
+ public void done() {
+ }
+
+ /**
+ * Internal event handler, using the phase's handlers
+ *
+ * @param event
+ * The event
+ */
+ protected void eventHandle(ITmfEvent event) {
+ for (ITraceEventHandler handler : fHandlers) {
+ handler.handleEvent(event);
+ }
+ }
+
+ @Override
+ public void handleCancel() {
+ }
+
+ /**
+ * Register a handler to a series of events
+ *
+ * @param handler
+ * The trace event handler
+ */
+ public void registerHandler(ITraceEventHandler handler) {
+ fHandlers.add(handler);
+ }
+
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2015 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.analysis.graph.core.building;
+
+/**
+ * Base class for event handlers, implementing common behavior like cancellation
+ *
+ * @author Geneviève Bastien
+ * @author Francis Giraldeau
+ */
+public abstract class AbstractTraceEventHandler implements ITraceEventHandler {
+
+ private volatile boolean fHandlerCancelled = false;
+
+ @Override
+ public boolean isCancelled() {
+ return fHandlerCancelled;
+ }
+
+ @Override
+ public void cancel() {
+ fHandlerCancelled = true;
+ }
+
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2015 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.analysis.graph.core.building;
+
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.analysis.graph.core.base.TmfGraph;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
+
+/**
+ * This is the interface used to define the execution graph building logic.
+ *
+ * Usually the graph builder is the piece of the pipeline which converts trace
+ * events to an execution graph.
+ *
+ * @author Francis Giraldeau
+ * @author Geneviève Bastien
+ */
+public interface ITmfGraphProvider {
+
+ /**
+ * Get the trace with which this graph builder plugin is associated.
+ *
+ * @return The associated trace
+ */
+ ITmfTrace getTrace();
+
+ /**
+ * Return the start time of this "graph builder", which is normally the
+ * start time of the originating trace (or it can be the time of the first
+ * node in the graph).
+ *
+ * @return The start time
+ */
+ long getStartTime();
+
+ /**
+ * Assign the target graph where this builder will add new nodes and
+ * vertices
+ *
+ * This needs to be called before .run()!
+ *
+ * @param graph
+ * Target graph for the state changes generated by this input
+ * plugin
+ */
+ void assignTargetGraph(TmfGraph graph);
+
+ /**
+ * Return the currently assigned target graph.
+ *
+ * @return Reference to the currently assigned graph, or {@code null} if no
+ * graph is assigned yet
+ */
+ @Nullable
+ TmfGraph getAssignedGraph();
+
+ /**
+ * Send an event to this input plugin for processing. The implementation
+ * should check the contents, and call the state-modifying methods of its
+ * IStateSystemBuilder object accordingly.
+ *
+ * @param event
+ * The event (which should be safe to cast to the
+ * expectedEventType) that has to be processed.
+ */
+ void processEvent(ITmfEvent event);
+
+ /**
+ * Indicate to the graph building process that we are done (for now), and
+ * that it should close the current graph.
+ */
+ void dispose();
+
+ /**
+ * Performs the necessary actions when the build is cancelled
+ */
+ void handleCancel();
+
+ /**
+ * Callback when graph is complete
+ */
+ void done();
+
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2015 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.analysis.graph.core.building;
+
+import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+
+/**
+ * Interface that event handlers must implement. Event handlers are independent
+ * actions that need to be performed for an analysis phase
+ *
+ * @author Francis Giraldeau
+ * @author Geneviève Bastien
+ */
+public interface ITraceEventHandler {
+
+ /**
+ * Handles an event
+ *
+ * @param event
+ * The event to handle
+ */
+ void handleEvent(ITmfEvent event);
+
+ /**
+ * Indicate if this handler is cancelled
+ *
+ * @return true if this handler is cancelled
+ */
+ boolean isCancelled();
+
+ /**
+ * Cancels this event handler
+ */
+ void cancel();
+
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2015 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.analysis.graph.core.building;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.analysis.graph.core.base.TmfGraph;
+import org.eclipse.tracecompass.internal.analysis.graph.core.Activator;
+import org.eclipse.tracecompass.tmf.core.analysis.TmfAbstractAnalysisModule;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+import org.eclipse.tracecompass.tmf.core.event.TmfEvent;
+import org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest;
+import org.eclipse.tracecompass.tmf.core.request.TmfEventRequest;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
+
+/**
+ * Base class for all modules building graphs
+ *
+ * @author Francis Giraldeau
+ * @author Geneviève Bastien
+ */
+public abstract class TmfGraphBuilderModule extends TmfAbstractAnalysisModule {
+
+ private @Nullable TmfGraph fGraph;
+ private @Nullable ITmfEventRequest fRequest;
+
+ /**
+ * Gets the graph provider to build this graph
+ *
+ * @return The graph provider
+ */
+ protected abstract ITmfGraphProvider getGraphProvider();
+
+ /**
+ * Gets the graph generated by the analysis
+ *
+ * @return The generated graph
+ */
+ public @Nullable TmfGraph getGraph() {
+ return fGraph;
+ }
+
+ // ------------------------------------------------------------------------
+ // TmfAbstractAnalysisModule
+ // ------------------------------------------------------------------------
+
+ @Override
+ protected boolean executeAnalysis(final IProgressMonitor monitor) {
+ if (fGraph == null) {
+ final ITmfGraphProvider provider = getGraphProvider();
+
+ /*
+ * TODO: This will eventually support multiple backends so we can
+ * save the graph on disk, like the state system, but for now, it is
+ * just in memory
+ */
+
+ createGraph(provider);
+
+ }
+ return !monitor.isCanceled();
+ }
+
+ @Override
+ protected void canceling() {
+ ITmfEventRequest req = fRequest;
+ if ((req != null) && (!req.isCompleted())) {
+ req.cancel();
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // Graph creation methods
+ // ------------------------------------------------------------------------
+
+ private void createGraph(ITmfGraphProvider provider) {
+
+ fGraph = new TmfGraph();
+ provider.assignTargetGraph(fGraph);
+
+ build(provider);
+
+ }
+
+ private void build(ITmfGraphProvider provider) {
+ /* Cancel any previous request */
+ ITmfEventRequest request = fRequest;
+ if ((request != null) && (!request.isCompleted())) {
+ request.cancel();
+ }
+
+ try {
+ request = new TmfGraphBuildRequest(provider);
+ fRequest = request;
+ provider.getTrace().sendRequest(request);
+
+ request.waitForCompletion();
+ } catch (InterruptedException e) {
+ Activator.getInstance().logError("Request interrupted", e); //$NON-NLS-1$
+ }
+ }
+
+ private static class TmfGraphBuildRequest extends TmfEventRequest {
+
+ private final ITmfGraphProvider fProvider;
+
+ /**
+ * Constructor
+ *
+ * @param provider
+ * The graph provider
+ */
+ public TmfGraphBuildRequest(ITmfGraphProvider provider) {
+ super(TmfEvent.class,
+ TmfTimeRange.ETERNITY,
+ 0,
+ ITmfEventRequest.ALL_DATA,
+ ITmfEventRequest.ExecutionType.BACKGROUND);
+
+ fProvider = provider;
+ }
+
+ @Override
+ public void handleData(final ITmfEvent event) {
+ super.handleData(event);
+ fProvider.processEvent(event);
+ }
+
+ @Override
+ public void done() {
+ super.done();
+ fProvider.done();
+ }
+
+ @Override
+ public void handleCancel() {
+ fProvider.handleCancel();
+ super.handleCancel();
+ }
+
+ }
+
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2015 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+@org.eclipse.jdt.annotation.NonNullByDefault
+package org.eclipse.tracecompass.analysis.graph.core.building;
\ No newline at end of file