tmf: Move the trace statistics to the analysis framework
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Tue, 12 Nov 2013 00:47:03 +0000 (19:47 -0500)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Mon, 3 Feb 2014 20:17:01 +0000 (15:17 -0500)
By itself, this patch causes a bug where the Statistics view will not be
populated unless it is re-opened *after* the trace has been loaded.

The patch following this one fixes this (and unfortunately, that one
depends on changes from this one, so it wasn't trivial to re-order them).

Change-Id: I8b6c59d70e84fdc5971665e1e78d096e3abe30db
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/19412
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
IP-Clean: Matthew Khouzam <matthew.khouzam@ericsson.com>
Tested-by: Hudson CI
13 files changed:
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfExperimentTest.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfTraceTest.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/StatsProviderEventTypes.java [deleted file]
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/StatsProviderTotals.java [deleted file]
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfStateStatistics.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfStatisticsEventTypesModule.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfStatisticsTotalsModule.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfTrace.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTrace.java
org.eclipse.linuxtools.tmf.ui/plugin.xml
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/TmfStatisticsViewer.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/statistics/TmfStatisticsModule.java [new file with mode: 0644]
org.eclipse.linuxtools.tracing.examples/src/org/eclipse/linuxtools/tracing/examples/ui/viewers/histogram/NewHistogramViewer.java

index 8b853ac6453dbe024fa568560ab41d76f5b4d830..385217cb23ed0ebedcbc866929b53469a32cd222 100644 (file)
@@ -37,7 +37,6 @@ import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
 import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest;
 import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest.ExecutionType;
 import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest;
-import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics;
 import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin;
 import org.eclipse.linuxtools.tmf.core.tests.shared.TmfTestTrace;
 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
@@ -173,13 +172,6 @@ public class TmfExperimentTest {
     // State system, statistics and modules methods
     // ------------------------------------------------------------------------
 
-    @Test
-    public void testGetStatistics() {
-        /* There should not be any experiment-specific statistics */
-        ITmfStatistics stats = fExperiment.getStatistics();
-        assertNull(stats);
-    }
-
     @Test
     public void testGetAnalysisModules() {
         /* There should not be any modules at this point */
index c7f059efba3fec308bf495214b8dbe0fa651ee07..e81b2396e25aea5f312a1e57212fb5b0a6f43bad 100644 (file)
@@ -38,7 +38,6 @@ import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest.ExecutionType;
 import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest;
 import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager;
 import org.eclipse.linuxtools.tmf.core.signal.TmfTraceOpenedSignal;
-import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics;
 import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin;
 import org.eclipse.linuxtools.tmf.core.tests.shared.TmfTestTrace;
 import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
@@ -439,13 +438,6 @@ public class TmfTraceTest {
     // State system, statistics and modules methods
     // ------------------------------------------------------------------------
 
-    @Test
-    public void testGetStatistics() {
-        /* Should be null in unit tests */
-        ITmfStatistics stats = fTrace.getStatistics();
-        assertNull(stats);
-    }
-
     @Test
     public void testGetModulesByClass() {
         /* There should not be any modules at this point */
diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/StatsProviderEventTypes.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/StatsProviderEventTypes.java
deleted file mode 100644 (file)
index 9c5afc1..0000000
+++ /dev/null
@@ -1,123 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012, 2013 Ericsson
- *
- * 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
- *
- * Contributors:
- *   Alexandre Montplaisir - Initial API and implementation
- *   Patrick Tasse - Fix javadoc
- ******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.core.statistics;
-
-import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
-import org.eclipse.linuxtools.tmf.core.event.ITmfLostEvent;
-import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;
-import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException;
-import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException;
-import org.eclipse.linuxtools.tmf.core.statesystem.AbstractTmfStateProvider;
-import org.eclipse.linuxtools.tmf.core.statevalue.TmfStateValue;
-import org.eclipse.linuxtools.tmf.core.statistics.TmfStateStatistics.Attributes;
-import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
-import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
-
-/**
- * The state provider for traces statistics that use TmfStateStatistics. It
- * should work with any trace type for which we can use the state system.
- *
- * It will store number of events seen, per event types. The resulting attribute
- * tree will look like this:
- *
- * <pre>
- * (root)
- *   \-- event_types
- *        |-- (event name 1)
- *        |-- (event name 2)
- *        |-- (event name 3)
- *       ...
- * </pre>
- *
- * And each (event name)'s value will be an integer, representing how many times
- * this particular event type has been seen in the trace so far.
- *
- * @author Alexandre Montplaisir
- * @version 1.0
- */
-class StatsProviderEventTypes extends AbstractTmfStateProvider {
-
-    /**
-     * Version number of this input handler. Please bump this if you modify the
-     * contents of the generated state history in some way.
-     */
-    private static final int VERSION = 2;
-
-    /**
-     * Constructor
-     *
-     * @param trace
-     *            The trace for which we build this state system
-     */
-    public StatsProviderEventTypes(ITmfTrace trace) {
-        super(trace, ITmfEvent.class ,"TMF Statistics, events per type"); //$NON-NLS-1$
-    }
-
-    @Override
-    public int getVersion() {
-        return VERSION;
-    }
-
-    @Override
-    public StatsProviderEventTypes getNewInstance() {
-        return new StatsProviderEventTypes(this.getTrace());
-    }
-
-    @Override
-    protected void eventHandle(ITmfEvent event) {
-        int quark;
-
-        /* Since this can be used for any trace types, normalize all the
-         * timestamp values to nanoseconds. */
-        final long ts = event.getTimestamp().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
-
-        final String eventName = event.getType().getName();
-
-        try {
-            /* Special handling for lost events */
-            if (event instanceof ITmfLostEvent) {
-                ITmfLostEvent le = (ITmfLostEvent) event;
-                quark = ss.getQuarkAbsoluteAndAdd(Attributes.EVENT_TYPES, eventName);
-
-                int curVal = ss.queryOngoingState(quark).unboxInt();
-                if (curVal == -1) {
-                    curVal = 0;
-                }
-
-                TmfStateValue value = TmfStateValue.newValueInt((int) (curVal + le.getNbLostEvents()));
-                ss.modifyAttribute(ts, value, quark);
-                return;
-            }
-
-            /* Number of events of each type, globally */
-            quark = ss.getQuarkAbsoluteAndAdd(Attributes.EVENT_TYPES, eventName);
-            ss.incrementAttribute(ts, quark);
-
-//            /* Number of events per CPU */
-//            quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.STATISTICS, Attributes.EVENT_TYPES, eventName);
-//            ss.incrementAttribute(ts, quark);
-//
-//            /* Number of events per process */
-//            quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.STATISTICS, Attributes.EVENT_TYPES, eventName);
-//            ss.incrementAttribute(ts, quark);
-
-        } catch (StateValueTypeException e) {
-            e.printStackTrace();
-        } catch (TimeRangeException e) {
-            e.printStackTrace();
-        } catch (AttributeNotFoundException e) {
-            e.printStackTrace();
-        }
-    }
-}
diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/StatsProviderTotals.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/StatsProviderTotals.java
deleted file mode 100644 (file)
index 894e9f5..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012, 2013 Ericsson
- *
- * 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
- *
- * Contributors:
- *   Alexandre Montplaisir - Initial API and implementation
- *   Patrick Tasse - Fix javadoc
- ******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.core.statistics;
-
-import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
-import org.eclipse.linuxtools.tmf.core.event.ITmfLostEvent;
-import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;
-import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException;
-import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException;
-import org.eclipse.linuxtools.tmf.core.statesystem.AbstractTmfStateProvider;
-import org.eclipse.linuxtools.tmf.core.statistics.TmfStateStatistics.Attributes;
-import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
-import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
-
-/**
- * The state provider for traces statistics that use TmfStateStatistics. It
- * should work with any trace type for which we can use the state system.
- *
- * Only one attribute will be stored, containing the total of events seen so
- * far. The resulting attribute tree will look like this:
- *
- * <pre>
- * (root)
- *   \-- total
- * </pre>
- *
- * @author Alexandre Montplaisir
- * @version 1.0
- */
-class StatsProviderTotals extends AbstractTmfStateProvider {
-
-    /**
-     * Version number of this input handler. Please bump this if you modify the
-     * contents of the generated state history in some way.
-     */
-    private static final int VERSION = 2;
-
-    /**
-     * Constructor
-    *
-     * @param trace
-     *            The trace for which we build this state system
-     */
-    public StatsProviderTotals(ITmfTrace trace) {
-        super(trace, ITmfEvent.class ,"TMF Statistics, event totals"); //$NON-NLS-1$
-    }
-
-    @Override
-    public int getVersion() {
-        return VERSION;
-    }
-
-    @Override
-    public StatsProviderTotals getNewInstance() {
-        return new StatsProviderTotals(this.getTrace());
-    }
-
-    @Override
-    protected void eventHandle(ITmfEvent event) {
-        /* Do not count lost events in the total */
-        if (event instanceof ITmfLostEvent) {
-            return;
-        }
-
-        /* Since this can be used for any trace types, normalize all the
-         * timestamp values to nanoseconds. */
-        final long ts = event.getTimestamp().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
-
-        try {
-            /* Total number of events */
-            int quark = ss.getQuarkAbsoluteAndAdd(Attributes.TOTAL);
-            ss.incrementAttribute(ts, quark);
-
-        } catch (StateValueTypeException e) {
-            e.printStackTrace();
-        } catch (TimeRangeException e) {
-            e.printStackTrace();
-        } catch (AttributeNotFoundException e) {
-            e.printStackTrace();
-        }
-    }
-}
index 1a2ddedfc1d66484d9dd64f25bf9859f36c7193f..b43a622f5ad162a59a3fc21a29d42c853a228014 100644 (file)
@@ -18,6 +18,7 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 
+import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;
 import org.eclipse.linuxtools.tmf.core.exceptions.StateSystemDisposedException;
 import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException;
@@ -31,7 +32,6 @@ import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateProvider;
 import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem;
 import org.eclipse.linuxtools.tmf.core.statesystem.TmfStateSystemFactory;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
-import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager;
 
 /**
  * Implementation of ITmfStatistics which uses a state history for storing its
@@ -49,31 +49,6 @@ import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager;
  */
 public class TmfStateStatistics implements ITmfStatistics {
 
-    // ------------------------------------------------------------------------
-    // Constants
-    // ------------------------------------------------------------------------
-
-    /**
-     * @deprecated Do not use, it's been replaced by {@link #TOTALS_STATE_ID}
-     *              and {@link #TYPES_STATE_ID}
-     */
-    @Deprecated
-    public static final String STATE_ID = "org.eclipse.linuxtools.tmf.statistics"; //$NON-NLS-1$
-
-    /** ID for the "event totals" statistics state system
-     * @since 2.2 */
-    public static final String TOTALS_STATE_ID = "org.eclipse.linuxtools.tmf.statistics.totals"; //$NON-NLS-1$
-
-    /** ID for the "event types" statistics state system
-     * @since 2.2 */
-    public static final String TYPES_STATE_ID = "org.eclipse.linuxtools.tmf.statistics.types"; //$NON-NLS-1$
-
-    /** Filename for the "event totals" state history file */
-    private static final String TOTALS_STATE_FILENAME = "statistics-totals.ht"; //$NON-NLS-1$
-
-    /** Filename for the "event types" state history file */
-    private static final String TYPES_STATE_FILENAME = "statistics-types.ht"; //$NON-NLS-1$
-
     // ------------------------------------------------------------------------
     // Fields
     // ------------------------------------------------------------------------
@@ -90,50 +65,23 @@ public class TmfStateStatistics implements ITmfStatistics {
     // Constructors
     // ------------------------------------------------------------------------
 
-    /**
-     * Empty constructor. The resulting TmfStatistics object will not be usable,
-     * but it might be needed for sub-classes.
-     */
-    public TmfStateStatistics() {
-        totalsStats = null;
-        typesStats = null;
-        trace = null;
-    }
-
     /**
      * Constructor
      *
      * @param trace
      *            The trace for which we build these statistics
-     * @throws TmfTraceException
-     *             If something went wrong trying to initialize the statistics
+     * @param totals
+     *            The state system containing the "totals" information
+     * @param eventTypes
+     *            The state system containing the "event types" information
+     * @since 3.0
      */
-    public TmfStateStatistics(ITmfTrace trace) throws TmfTraceException {
+    public TmfStateStatistics(@NonNull ITmfTrace trace,
+            @NonNull ITmfStateSystem totals,
+            @NonNull ITmfStateSystem eventTypes) {
         this.trace = trace;
-        String directory = TmfTraceManager.getSupplementaryFileDir(trace);
-
-        final File totalsFile = new File(directory + TOTALS_STATE_FILENAME);
-        final ITmfStateProvider totalsInput = new StatsProviderTotals(trace);
-        this.totalsStats = TmfStateSystemFactory.newFullHistory(totalsFile, totalsInput, false);
-
-        final File typesFile = new File(directory + TYPES_STATE_FILENAME);
-        final ITmfStateProvider typesInput = new StatsProviderEventTypes(trace);
-        this.typesStats = TmfStateSystemFactory.newFullHistory(typesFile, typesInput, false);
-
-        registerStateSystems();
-    }
-
-    /**
-     * Old manual constructor.
-     *
-     * @param trace Trace
-     * @param historyFile Full history file
-     * @deprecated Need to use {@link #TmfStateStatistics(ITmfTrace trace,
-     * File fullHistoryFile, File partialHistoryFile)} now.
-     */
-    @Deprecated
-    public TmfStateStatistics(ITmfTrace trace, File historyFile) {
-        this();
+        this.totalsStats = totals;
+        this.typesStats = eventTypes;
     }
 
     /**
@@ -151,22 +99,34 @@ public class TmfStateStatistics implements ITmfStatistics {
      *             If the file could not be written to
      * @since 2.2
      */
+    @Deprecated
     public TmfStateStatistics(ITmfTrace trace, File totalsHistoryFile,
             File typesHistoryFile) throws TmfTraceException {
         this.trace = trace;
-        final ITmfStateProvider totalsInput = new StatsProviderTotals(trace);
-        final ITmfStateProvider typesInput = new StatsProviderEventTypes(trace);
+        final ITmfStateProvider totalsInput = new TmfStatisticsTotalsModule().new StatsProviderTotals(trace);
+        final ITmfStateProvider typesInput = new TmfStatisticsEventTypesModule().new StatsProviderEventTypes(trace);
         this.totalsStats = TmfStateSystemFactory.newFullHistory(totalsHistoryFile, totalsInput, true);
         this.typesStats = TmfStateSystemFactory.newFullHistory(typesHistoryFile, typesInput, true);
-        registerStateSystems();
     }
 
     /**
-     * Register the state systems used here into the trace's state system map.
+     * Return the state system containing the "totals" values
+     *
+     * @return The "totals" state system
+     * @since 3.0
+     */
+    public ITmfStateSystem getTotalsSS() {
+        return totalsStats;
+    }
+
+    /**
+     * Return the state system containing the "event types" values
+     *
+     * @return The "event types" state system
+     * @since 3.0
      */
-    private void registerStateSystems() {
-        trace.registerStateSystem(TOTALS_STATE_ID, totalsStats);
-        trace.registerStateSystem(TYPES_STATE_ID, typesStats);
+    public ITmfStateSystem getEventTypesSS() {
+        return typesStats;
     }
 
     // ------------------------------------------------------------------------
@@ -299,11 +259,7 @@ public class TmfStateStatistics implements ITmfStatistics {
 
         } catch (TimeRangeException e) {
             /* Assume there is no events, nothing will be put in the map. */
-        } catch (AttributeNotFoundException e) {
-            e.printStackTrace();
-        } catch (StateValueTypeException e) {
-            e.printStackTrace();
-        } catch (StateSystemDisposedException e) {
+        } catch (AttributeNotFoundException | StateValueTypeException | StateSystemDisposedException e) {
             e.printStackTrace();
         }
         return map;
@@ -388,16 +344,12 @@ public class TmfStateStatistics implements ITmfStatistics {
 
         } catch (TimeRangeException e) {
             /* Assume there is no events, nothing will be put in the map. */
-        } catch (AttributeNotFoundException e) {
+        } catch (AttributeNotFoundException | StateValueTypeException | StateSystemDisposedException e) {
             /*
              * These other exception types would show a logic problem however,
              * so they should not happen.
              */
             e.printStackTrace();
-        } catch (StateValueTypeException e) {
-            e.printStackTrace();
-        } catch (StateSystemDisposedException e) {
-            e.printStackTrace();
         }
         return map;
     }
@@ -418,11 +370,7 @@ public class TmfStateStatistics implements ITmfStatistics {
 
         } catch (TimeRangeException e) {
             /* Assume there is no events for that range */
-        } catch (AttributeNotFoundException e) {
-            e.printStackTrace();
-        } catch (StateValueTypeException e) {
-            e.printStackTrace();
-        } catch (StateSystemDisposedException e) {
+        } catch (AttributeNotFoundException | StateValueTypeException | StateSystemDisposedException e) {
             e.printStackTrace();
         }
 
diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfStatisticsEventTypesModule.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfStatisticsEventTypesModule.java
new file mode 100644 (file)
index 0000000..6260eeb
--- /dev/null
@@ -0,0 +1,163 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Ericsson
+ *
+ * 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
+ *
+ * Contributors:
+ *   Alexandre Montplaisir - Initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.statistics;
+
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.event.ITmfLostEvent;
+import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;
+import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException;
+import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException;
+import org.eclipse.linuxtools.tmf.core.statesystem.AbstractTmfStateProvider;
+import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateProvider;
+import org.eclipse.linuxtools.tmf.core.statesystem.TmfStateSystemAnalysisModule;
+import org.eclipse.linuxtools.tmf.core.statevalue.TmfStateValue;
+import org.eclipse.linuxtools.tmf.core.statistics.TmfStateStatistics.Attributes;
+import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+
+/**
+ * The analysis module building the "event types" statistics state system.
+ *
+ * It is not in the extension point (and as such, not registered in the
+ * TmfAnalysisManager), as it is being handled by the TmfStatisticsModule.
+ *
+ * @author Alexandre Montplaisir
+ * @since 3.0
+ */
+public class TmfStatisticsEventTypesModule extends TmfStateSystemAnalysisModule {
+
+    /**
+     * The ID of this analysis module (which is also the ID of the state system)
+     */
+    public static final String ID = "org.eclipse.linuxtools.tmf.statistics.types"; //$NON-NLS-1$
+
+    private static final String NAME = "TMF Statistics, events per type"; //$NON-NLS-1$
+
+    /**
+     * Constructor
+     */
+    public TmfStatisticsEventTypesModule() {
+        setId(ID);
+        setName(NAME);
+    }
+
+    @Override
+    protected ITmfStateProvider createStateProvider() {
+        return new StatsProviderEventTypes(getTrace());
+    }
+
+    @Override
+    protected StateSystemBackendType getBackendType() {
+        return StateSystemBackendType.FULL;
+    }
+
+    @Override
+    protected String getSsFileName() {
+        return "statistics-types.ht"; //$NON-NLS-1$
+    }
+
+
+    /**
+     * The state provider for traces statistics that use TmfStateStatistics. It
+     * should work with any trace type for which we can use the state system.
+     *
+     * It will store number of events seen, per event types. The resulting attribute
+     * tree will look like this:
+     *
+     * <pre>
+     * (root)
+     *   \-- event_types
+     *        |-- (event name 1)
+     *        |-- (event name 2)
+     *        |-- (event name 3)
+     *       ...
+     * </pre>
+     *
+     * And each (event name)'s value will be an integer, representing how many times
+     * this particular event type has been seen in the trace so far.
+     *
+     * @author Alexandre Montplaisir
+     * @version 1.0
+     */
+    class StatsProviderEventTypes extends AbstractTmfStateProvider {
+
+        /**
+         * Version number of this input handler. Please bump this if you modify the
+         * contents of the generated state history in some way.
+         */
+        private static final int VERSION = 2;
+
+        /**
+         * Constructor
+         *
+         * @param trace
+         *            The trace for which we build this state system
+         */
+        public StatsProviderEventTypes(ITmfTrace trace) {
+            super(trace, ITmfEvent.class ,"TMF Statistics, events per type"); //$NON-NLS-1$
+        }
+
+        @Override
+        public int getVersion() {
+            return VERSION;
+        }
+
+        @Override
+        public StatsProviderEventTypes getNewInstance() {
+            return new StatsProviderEventTypes(this.getTrace());
+        }
+
+        @Override
+        protected void eventHandle(ITmfEvent event) {
+            int quark;
+
+            /* Since this can be used for any trace types, normalize all the
+             * timestamp values to nanoseconds. */
+            final long ts = event.getTimestamp().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
+
+            final String eventName = event.getType().getName();
+
+            try {
+                /* Special handling for lost events */
+                if (event instanceof ITmfLostEvent) {
+                    ITmfLostEvent le = (ITmfLostEvent) event;
+                    quark = ss.getQuarkAbsoluteAndAdd(Attributes.EVENT_TYPES, eventName);
+
+                    int curVal = ss.queryOngoingState(quark).unboxInt();
+                    if (curVal == -1) {
+                        curVal = 0;
+                    }
+
+                    TmfStateValue value = TmfStateValue.newValueInt((int) (curVal + le.getNbLostEvents()));
+                    ss.modifyAttribute(ts, value, quark);
+                    return;
+                }
+
+                /* Number of events of each type, globally */
+                quark = ss.getQuarkAbsoluteAndAdd(Attributes.EVENT_TYPES, eventName);
+                ss.incrementAttribute(ts, quark);
+
+//                /* Number of events per CPU */
+//                quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.STATISTICS, Attributes.EVENT_TYPES, eventName);
+//                ss.incrementAttribute(ts, quark);
+    //
+//                /* Number of events per process */
+//                quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.STATISTICS, Attributes.EVENT_TYPES, eventName);
+//                ss.incrementAttribute(ts, quark);
+
+            } catch (StateValueTypeException | TimeRangeException | AttributeNotFoundException e) {
+                e.printStackTrace();
+            }
+        }
+    }
+}
diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfStatisticsTotalsModule.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfStatisticsTotalsModule.java
new file mode 100644 (file)
index 0000000..cd4b394
--- /dev/null
@@ -0,0 +1,134 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Ericsson
+ *
+ * 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
+ *
+ * Contributors:
+ *   Alexandre Montplaisir - Initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.statistics;
+
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.event.ITmfLostEvent;
+import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;
+import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException;
+import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException;
+import org.eclipse.linuxtools.tmf.core.statesystem.AbstractTmfStateProvider;
+import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateProvider;
+import org.eclipse.linuxtools.tmf.core.statesystem.TmfStateSystemAnalysisModule;
+import org.eclipse.linuxtools.tmf.core.statistics.TmfStateStatistics.Attributes;
+import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+
+/**
+ * The analysis module building the "totals" statistics state system.
+ *
+ * It is not in the extension point (and as such, not registered in the
+ * TmfAnalysisManager), as it is being handled by the TmfStatisticsModule.
+ *
+ * @author Alexandre Montplaisir
+ * @since 3.0
+ */
+public class TmfStatisticsTotalsModule extends TmfStateSystemAnalysisModule {
+
+    /**
+     * The ID of this analysis module (which is also the ID of the state system)
+     */
+    public static final String ID = "org.eclipse.linuxtools.tmf.statistics.totals"; //$NON-NLS-1$
+
+    private static final String NAME = "TMF Statistics, event totals"; //$NON-NLS-1$
+
+    /**
+     * Constructor
+     */
+    public TmfStatisticsTotalsModule() {
+        setId(ID);
+        setName(NAME);
+    }
+
+    @Override
+    protected ITmfStateProvider createStateProvider() {
+        return new StatsProviderTotals(getTrace());
+    }
+
+    @Override
+    protected StateSystemBackendType getBackendType() {
+        return StateSystemBackendType.FULL;
+    }
+
+    @Override
+    protected String getSsFileName() {
+        return "statistics-totals.ht"; //$NON-NLS-1$
+    }
+
+
+    /**
+     * The state provider for traces statistics that use TmfStateStatistics. It
+     * should work with any trace type for which we can use the state system.
+     *
+     * Only one attribute will be stored, containing the total of events seen so
+     * far. The resulting attribute tree will look like this:
+     *
+     * <pre>
+     * (root)
+     *   \-- total
+     * </pre>
+     *
+     * @author Alexandre Montplaisir
+     * @version 1.0
+     */
+    class StatsProviderTotals extends AbstractTmfStateProvider {
+
+        /**
+         * Version number of this input handler. Please bump this if you modify the
+         * contents of the generated state history in some way.
+         */
+        private static final int VERSION = 2;
+
+        /**
+         * Constructor
+        *
+         * @param trace
+         *            The trace for which we build this state system
+         */
+        public StatsProviderTotals(ITmfTrace trace) {
+            super(trace, ITmfEvent.class , NAME);
+        }
+
+        @Override
+        public int getVersion() {
+            return VERSION;
+        }
+
+        @Override
+        public StatsProviderTotals getNewInstance() {
+            return new StatsProviderTotals(this.getTrace());
+        }
+
+        @Override
+        protected void eventHandle(ITmfEvent event) {
+            /* Do not count lost events in the total */
+            if (event instanceof ITmfLostEvent) {
+                return;
+            }
+
+            /* Since this can be used for any trace types, normalize all the
+             * timestamp values to nanoseconds. */
+            final long ts = event.getTimestamp().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
+
+            try {
+                /* Total number of events */
+                int quark = ss.getQuarkAbsoluteAndAdd(Attributes.TOTAL);
+                ss.incrementAttribute(ts, quark);
+
+            } catch (StateValueTypeException | TimeRangeException | AttributeNotFoundException e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
+}
index a012d64ce7eaf9e2e9c54f8f91a259edbf77fe89..9fcfc7d6499a17cad10cf0e9bb8e01168db09f51 100644 (file)
@@ -27,9 +27,8 @@ import org.eclipse.linuxtools.tmf.core.analysis.IAnalysisModule;
 import org.eclipse.linuxtools.tmf.core.component.ITmfEventProvider;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
-import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem;
 import org.eclipse.linuxtools.tmf.core.statesystem.ITmfAnalysisModuleWithStateSystems;
-import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics;
+import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem;
 import org.eclipse.linuxtools.tmf.core.synchronization.ITmfTimestampTransform;
 import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
@@ -196,12 +195,6 @@ public interface ITmfTrace extends ITmfEventProvider {
      */
     int getCacheSize();
 
-    /**
-     * @return The statistics provider for this trace
-     * @since 2.0
-     */
-    ITmfStatistics getStatistics();
-
     /**
      * Return the map of state systems associated with this trace.
      *
index 2872025facf6eb3d28bce22e50802a385d9dbf76..9f8a18d8a281372b46664f44e16a09fc0ab0f557 100644 (file)
@@ -53,8 +53,6 @@ import org.eclipse.linuxtools.tmf.core.signal.TmfTraceOpenedSignal;
 import org.eclipse.linuxtools.tmf.core.signal.TmfTraceRangeUpdatedSignal;
 import org.eclipse.linuxtools.tmf.core.signal.TmfTraceUpdatedSignal;
 import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem;
-import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics;
-import org.eclipse.linuxtools.tmf.core.statistics.TmfStateStatistics;
 import org.eclipse.linuxtools.tmf.core.synchronization.ITmfTimestampTransform;
 import org.eclipse.linuxtools.tmf.core.synchronization.TmfTimestampTransform;
 import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
@@ -122,8 +120,6 @@ public abstract class TmfTrace extends TmfEventProvider implements ITmfTrace {
     // The trace parser
     private ITmfEventParser fParser;
 
-    // The trace's statistics
-    private ITmfStatistics fStatistics;
 
     /**
      * The collection of state systems that are registered with this trace. Each
@@ -283,27 +279,6 @@ public abstract class TmfTrace extends TmfEventProvider implements ITmfTrace {
         getIndexer().buildIndex(0, TmfTimeRange.ETERNITY, waitForCompletion);
     }
 
-    /**
-     * The default implementation of TmfTrace uses a TmfStatistics back-end.
-     * Override this if you want to specify another type (or none at all).
-     *
-     * @return An IStatus indicating if the statistics could be built
-     *         successfully or not.
-     * @since 3.0
-     */
-    protected IStatus buildStatistics() {
-        /*
-         * Initialize the statistics provider, but only if a Resource has been
-         * set (so we don't build it for experiments, for unit tests, etc.)
-         */
-        try {
-            fStatistics = (fResource == null ? null : new TmfStateStatistics(this) );
-        } catch (TmfTraceException e) {
-            return new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e);
-        }
-        return Status.OK_STATUS;
-    }
-
     /**
      * Build the state system(s) associated with this trace type.
      *
@@ -405,11 +380,6 @@ public abstract class TmfTrace extends TmfEventProvider implements ITmfTrace {
             getIndexer().dispose();
         }
 
-        /* Clean up the statistics */
-        if (fStatistics != null) {
-            fStatistics.dispose();
-        }
-
         /* Clean up the state systems */
         for (ITmfStateSystem ss : fStateSystems.values()) {
             ss.dispose();
@@ -469,14 +439,6 @@ public abstract class TmfTrace extends TmfEventProvider implements ITmfTrace {
         return fParser;
     }
 
-    /**
-     * @since 2.0
-     */
-    @Override
-    public ITmfStatistics getStatistics() {
-        return fStatistics;
-    }
-
     /**
      * @since 2.0
      * @deprecated See {@link ITmfTrace}
@@ -787,7 +749,6 @@ public abstract class TmfTrace extends TmfEventProvider implements ITmfTrace {
          * this trace.
          */
         MultiStatus status = new MultiStatus(Activator.PLUGIN_ID, IStatus.OK, null, null);
-        status.add(buildStatistics());
         status.add(buildStateSystem());
         status.add(executeAnalysis());
         if (!status.isOK()) {
index 3c2fe469dabaae5d463976f91d9a84902aab96c9..6af00f9226c80a4ef8a28376184c5f63fe0145c7 100644 (file)
             name="%project.new.category.name">
       </category>
    </extension>
+   <extension
+         point="org.eclipse.linuxtools.tmf.core.analysis">
+      <module
+            analysis_module="org.eclipse.linuxtools.tmf.ui.views.statistics.TmfStatisticsModule"
+            automatic="true"
+            id="org.eclipse.linuxtools.tmf.ui.views.statistics.analysis"
+            name="Tmf Statistics Analysis">
+         <tracetype
+               applies="true"
+               class="org.eclipse.linuxtools.tmf.core.trace.TmfTrace">
+         </tracetype>
+      </module>
+   </extension>
+
 </plugin>
index 16ac50dd9d4e1c29e7af4da504b6ac521989255b..5613964dc26dc3b048f0b59efe4008db17d56e11 100644 (file)
@@ -42,6 +42,7 @@ import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfStatisticsTree;
 import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfStatisticsTreeManager;
 import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfStatisticsTreeNode;
 import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfTreeContentProvider;
+import org.eclipse.linuxtools.tmf.ui.views.statistics.TmfStatisticsModule;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
@@ -735,8 +736,13 @@ public class TmfStatisticsViewer extends TmfViewer {
                     continue;
                 }
 
-                /* Retrieves the statistics object */
-                final ITmfStatistics stats = aTrace.getStatistics();
+                /* Retrieve the statistics object */
+                final TmfStatisticsModule statsMod = aTrace.getAnalysisModuleOfClass(TmfStatisticsModule.class, TmfStatisticsModule.ID);
+                if (statsMod == null) {
+                    /* No statistics module available for this trace */
+                    continue;
+                }
+                final ITmfStatistics stats = statsMod.getStatistics();
                 if (stats == null) {
                     /*
                      * The statistics provider for this trace is not accessible
@@ -755,7 +761,7 @@ public class TmfStatisticsViewer extends TmfViewer {
                  * be sent through a {@link TmfStatsUpdatedSignal}, and will be
                  * processed by the signal handler.
                  */
-                aTrace.getStatistics().updateStats(isGlobal, start, end);
+                stats.updateStats(isGlobal, start, end);
             }
         }
     }
diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/statistics/TmfStatisticsModule.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/statistics/TmfStatisticsModule.java
new file mode 100644 (file)
index 0000000..6197c52
--- /dev/null
@@ -0,0 +1,162 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Ericsson
+ *
+ * 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
+ *
+ * Contributors:
+ *   Alexandre Montplaisir - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.ui.views.statistics;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.linuxtools.tmf.core.analysis.TmfAbstractAnalysisModule;
+import org.eclipse.linuxtools.tmf.core.exceptions.TmfAnalysisException;
+import org.eclipse.linuxtools.tmf.core.statesystem.ITmfAnalysisModuleWithStateSystems;
+import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem;
+import org.eclipse.linuxtools.tmf.core.statesystem.TmfStateSystemAnalysisModule;
+import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics;
+import org.eclipse.linuxtools.tmf.core.statistics.TmfStateStatistics;
+import org.eclipse.linuxtools.tmf.core.statistics.TmfStatisticsEventTypesModule;
+import org.eclipse.linuxtools.tmf.core.statistics.TmfStatisticsTotalsModule;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+import org.eclipse.linuxtools.tmf.ui.analysis.TmfAnalysisViewOutput;
+
+/**
+ * Analysis module to compute the statistics of a trace.
+ *
+ * @author Alexandre Montplaisir
+ * @since 3.0
+ */
+public class TmfStatisticsModule extends TmfAbstractAnalysisModule
+        implements ITmfAnalysisModuleWithStateSystems {
+
+    /** ID of this analysis module */
+    public static final String ID = "org.eclipse.linuxtools.tmf.ui.views.statistics.analysis"; //$NON-NLS-1$
+
+    /** The trace's statistics */
+    private ITmfStatistics fStatistics = null;
+
+    private final TmfStateSystemAnalysisModule totalsModule = new TmfStatisticsTotalsModule();
+    private final TmfStateSystemAnalysisModule eventTypesModule = new TmfStatisticsEventTypesModule();
+
+    /**
+     * Constructor
+     */
+    public TmfStatisticsModule() {
+        super();
+        this.registerOutput(new TmfAnalysisViewOutput(TmfStatisticsView.ID));
+    }
+
+    /**
+     * Get the statistics object built by this analysis
+     *
+     * @return The ITmfStatistics object
+     */
+    public ITmfStatistics getStatistics() {
+        return fStatistics;
+    }
+
+    // ------------------------------------------------------------------------
+    // TmfAbstractAnalysisModule
+    // ------------------------------------------------------------------------
+
+    @Override
+    protected boolean executeAnalysis(IProgressMonitor monitor) throws TmfAnalysisException {
+        ITmfTrace trace = getTrace();
+        if (trace == null) {
+            /* This analysis's trace should not be null when this is called */
+            throw new IllegalStateException();
+        }
+
+        /*
+         * Since these sub-analyzes are not built from an extension point, we
+         * have to assign the trace ourselves. Very important to do so before
+         * calling schedule()!
+         */
+        totalsModule.setTrace(trace);
+        eventTypesModule.setTrace(trace);
+
+        IStatus status1 = totalsModule.schedule();
+        IStatus status2 = eventTypesModule.schedule();
+        if (!status1.isOK() || !status2.isOK()) {
+            return false;
+        }
+
+        /*
+         * The "execute" of this trace will encompass the "execute" of the two
+         * sub-analyzes.
+         */
+        if (!totalsModule.waitForCompletion(monitor) ||
+                !eventTypesModule.waitForCompletion(monitor)) {
+            return false;
+        }
+
+        ITmfStateSystem totalsSS = totalsModule.getStateSystem();
+        ITmfStateSystem eventTypesSS = eventTypesModule.getStateSystem();
+
+        if (totalsSS == null || eventTypesSS == null) {
+            /* Better safe than sorry... */
+            throw new IllegalStateException();
+        }
+
+        fStatistics = new TmfStateStatistics(trace, totalsSS, eventTypesSS);
+        return true;
+    }
+
+    @Override
+    protected void canceling() {
+        /*
+         * FIXME The "right" way to cancel state system construction is not
+         * available yet...
+         */
+        totalsModule.cancel();
+        eventTypesModule.cancel();
+
+        ITmfStatistics stats = fStatistics;
+        if (stats != null) {
+            stats.dispose();
+        }
+    }
+
+    // ------------------------------------------------------------------------
+    // ITmfStateSystemAnalysisModule
+    // ------------------------------------------------------------------------
+
+    @Override
+    public ITmfStateSystem getStateSystem(String id) {
+        switch (id) {
+        case TmfStatisticsTotalsModule.ID:
+            return totalsModule.getStateSystem();
+        case TmfStatisticsEventTypesModule.ID:
+            return eventTypesModule.getStateSystem();
+        default:
+            return null;
+        }
+    }
+
+    @Override
+    public String getStateSystemId(ITmfStateSystem ss) {
+        if (ss.equals(totalsModule.getStateSystem())) {
+            return TmfStatisticsTotalsModule.ID;
+        } else if (ss.equals(eventTypesModule.getStateSystem())){
+            return TmfStatisticsEventTypesModule.ID;
+        }
+        return null;
+    }
+
+    @Override
+    public Iterable<ITmfStateSystem> getStateSystems() {
+        List<ITmfStateSystem> list = new LinkedList<>();
+        list.add(totalsModule.getStateSystem());
+        list.add(eventTypesModule.getStateSystem());
+        return list;
+    }
+}
index e0a722fe246de2df78eb14fcf596af1522c70c78..aa033c263c1cc56d6fcd6ac81816b20340f11dc6 100644 (file)
@@ -19,6 +19,7 @@ import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
 import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager;
 import org.eclipse.linuxtools.tmf.ui.viewers.xycharts.barcharts.TmfBarChartViewer;
+import org.eclipse.linuxtools.tmf.ui.views.statistics.TmfStatisticsModule;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Display;
@@ -73,7 +74,14 @@ public class NewHistogramViewer extends TmfBarChartViewer {
 
                     /* Add the values for each trace */
                     for (ITmfTrace trace : TmfTraceManager.getTraceSet(getTrace())) {
-                        ITmfStatistics stats = trace.getStatistics();
+                        /* Retrieve the statistics object */
+                        final TmfStatisticsModule statsMod =
+                               trace.getAnalysisModuleOfClass(TmfStatisticsModule.class, TmfStatisticsModule.ID);
+                        if (statsMod == null) {
+                            /* No statistics module available for this trace */
+                            continue;
+                        }
+                        final ITmfStatistics stats = statsMod.getStatistics();
                         List<Long> values = stats.histogramQuery(start, end, nb);
 
                         for (int i = 0; i < nb; i++) {
This page took 0.052658 seconds and 5 git commands to generate.