Analysis: Add the dependency graph builder module
authorFrancis Giraldeau <francis.giraldeau@gmail.com>
Tue, 30 Jun 2015 01:50:53 +0000 (21:50 -0400)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Mon, 14 Sep 2015 19:19:55 +0000 (15:19 -0400)
Change-Id: Icca0b33d07b14eee7009a0abd8fd064da061eed0
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Signed-off-by: Francis Giraldeau <francis.giraldeau@gmail.com>
Reviewed-on: https://git.eclipse.org/r/51079
Reviewed-by: Hudson CI
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
analysis/org.eclipse.tracecompass.analysis.graph.core/META-INF/MANIFEST.MF
analysis/org.eclipse.tracecompass.analysis.graph.core/src/org/eclipse/tracecompass/analysis/graph/core/building/AbstractTmfGraphProvider.java [new file with mode: 0644]
analysis/org.eclipse.tracecompass.analysis.graph.core/src/org/eclipse/tracecompass/analysis/graph/core/building/AbstractTraceEventHandler.java [new file with mode: 0644]
analysis/org.eclipse.tracecompass.analysis.graph.core/src/org/eclipse/tracecompass/analysis/graph/core/building/ITmfGraphProvider.java [new file with mode: 0644]
analysis/org.eclipse.tracecompass.analysis.graph.core/src/org/eclipse/tracecompass/analysis/graph/core/building/ITraceEventHandler.java [new file with mode: 0644]
analysis/org.eclipse.tracecompass.analysis.graph.core/src/org/eclipse/tracecompass/analysis/graph/core/building/TmfGraphBuilderModule.java [new file with mode: 0644]
analysis/org.eclipse.tracecompass.analysis.graph.core/src/org/eclipse/tracecompass/analysis/graph/core/building/package-info.java [new file with mode: 0644]

index 80c9856faa4a9c2df0447b70e2395ad605d7fbab..1a8a243c73e7ae54b8030db8c56c36e741c68b2b 100644 (file)
@@ -14,6 +14,7 @@ Require-Bundle: org.eclipse.ui,
  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,
diff --git a/analysis/org.eclipse.tracecompass.analysis.graph.core/src/org/eclipse/tracecompass/analysis/graph/core/building/AbstractTmfGraphProvider.java b/analysis/org.eclipse.tracecompass.analysis.graph.core/src/org/eclipse/tracecompass/analysis/graph/core/building/AbstractTmfGraphProvider.java
new file mode 100644 (file)
index 0000000..cdedc3b
--- /dev/null
@@ -0,0 +1,119 @@
+/*******************************************************************************
+ * 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);
+    }
+
+}
diff --git a/analysis/org.eclipse.tracecompass.analysis.graph.core/src/org/eclipse/tracecompass/analysis/graph/core/building/AbstractTraceEventHandler.java b/analysis/org.eclipse.tracecompass.analysis.graph.core/src/org/eclipse/tracecompass/analysis/graph/core/building/AbstractTraceEventHandler.java
new file mode 100644 (file)
index 0000000..ac8c0f7
--- /dev/null
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * 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;
+    }
+
+}
diff --git a/analysis/org.eclipse.tracecompass.analysis.graph.core/src/org/eclipse/tracecompass/analysis/graph/core/building/ITmfGraphProvider.java b/analysis/org.eclipse.tracecompass.analysis.graph.core/src/org/eclipse/tracecompass/analysis/graph/core/building/ITmfGraphProvider.java
new file mode 100644 (file)
index 0000000..bd14164
--- /dev/null
@@ -0,0 +1,92 @@
+/*******************************************************************************
+ * 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();
+
+}
diff --git a/analysis/org.eclipse.tracecompass.analysis.graph.core/src/org/eclipse/tracecompass/analysis/graph/core/building/ITraceEventHandler.java b/analysis/org.eclipse.tracecompass.analysis.graph.core/src/org/eclipse/tracecompass/analysis/graph/core/building/ITraceEventHandler.java
new file mode 100644 (file)
index 0000000..da088c9
--- /dev/null
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * 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();
+
+}
diff --git a/analysis/org.eclipse.tracecompass.analysis.graph.core/src/org/eclipse/tracecompass/analysis/graph/core/building/TmfGraphBuilderModule.java b/analysis/org.eclipse.tracecompass.analysis.graph.core/src/org/eclipse/tracecompass/analysis/graph/core/building/TmfGraphBuilderModule.java
new file mode 100644 (file)
index 0000000..f248f3f
--- /dev/null
@@ -0,0 +1,150 @@
+/*******************************************************************************
+ * 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();
+        }
+
+    }
+
+}
diff --git a/analysis/org.eclipse.tracecompass.analysis.graph.core/src/org/eclipse/tracecompass/analysis/graph/core/building/package-info.java b/analysis/org.eclipse.tracecompass.analysis.graph.core/src/org/eclipse/tracecompass/analysis/graph/core/building/package-info.java
new file mode 100644 (file)
index 0000000..2da0141
--- /dev/null
@@ -0,0 +1,11 @@
+/*******************************************************************************
+ * 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
This page took 0.030221 seconds and 5 git commands to generate.