tmf: Replace ITmfTimestamp by long in ITmfStatistics API
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Mon, 12 Nov 2012 22:23:31 +0000 (17:23 -0500)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Tue, 13 Nov 2012 20:03:59 +0000 (15:03 -0500)
Some methods in the statistics imlementations can call each
other, and having to create new wrapper objects every event
is not very interesting... The normalization already happens
in the Statistics view anyway.

Change-Id: I9769a867953d8f38dd2816ca7931b35dc22898a3
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/8650
Tested-by: Hudson CI
Reviewed-by: Bernd Hufmann <bhufmann@gmail.com>
IP-Clean: Bernd Hufmann <bhufmann@gmail.com>

org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statistics/TmfStatisticsTest.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/ITmfStatistics.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfEventsStatistics.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfStateStatistics.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/TmfStatisticsViewer.java

index e43e69a2007f5c1b751041dcb32a3a47a5cd25a9..bc571de161651015dd7a154b02a7fae29b552ad8 100644 (file)
@@ -16,8 +16,6 @@ import static org.junit.Assert.assertEquals;
 
 import java.util.Map;
 
-import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
-import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics;
 import org.junit.Test;
 
@@ -29,21 +27,21 @@ import org.junit.Test;
  */
 public abstract class TmfStatisticsTest {
 
+    /** The statistics back-end object */
     protected static ITmfStatistics backend;
 
     /* Known values about the trace */
-    private static final int SCALE = ITmfTimestamp.NANOSECOND_SCALE;
     private static final int totalNbEvents = 695319;
-    private static final ITmfTimestamp tStart = new TmfTimestamp(1332170682440133097L, SCALE); /* Timestamp of first event */
-    private static final ITmfTimestamp tEnd   = new TmfTimestamp(1332170692664579801L, SCALE); /* Timestamp of last event */
+    private static final long tStart = 1332170682440133097L; /* Timestamp of first event */
+    private static final long tEnd   = 1332170692664579801L; /* Timestamp of last event */
 
     /* Timestamps of interest */
-    private static final ITmfTimestamp t1 = new TmfTimestamp(1332170682490946000L, SCALE);
-    private static final ITmfTimestamp t2 = new TmfTimestamp(1332170682490947524L, SCALE); /* event exactly here */
-    private static final ITmfTimestamp t3 = new TmfTimestamp(1332170682490948000L, SCALE);
-    private static final ITmfTimestamp t4 = new TmfTimestamp(1332170682490949000L, SCALE);
-    private static final ITmfTimestamp t5 = new TmfTimestamp(1332170682490949270L, SCALE); /* following event here */
-    private static final ITmfTimestamp t6 = new TmfTimestamp(1332170682490949300L, SCALE);
+    private static final long t1 = 1332170682490946000L;
+    private static final long t2 = 1332170682490947524L; /* event exactly here */
+    private static final long t3 = 1332170682490948000L;
+    private static final long t4 = 1332170682490949000L;
+    private static final long t5 = 1332170682490949270L; /* following event here */
+    private static final long t6 = 1332170682490949300L;
 
     private static final String eventType = "lttng_statedump_process_state"; //$NON-NLS-1$
 
@@ -96,7 +94,7 @@ public abstract class TmfStatisticsTest {
      */
     @Test
     public void testGetEventsInRangeMinusStart() {
-        long count = backend.getEventsInRange(new TmfTimestamp(tStart.getValue() + 1, SCALE), tEnd);
+        long count = backend.getEventsInRange(tStart + 1, tEnd);
         assertEquals(totalNbEvents - 1, count);
     }
 
@@ -106,7 +104,7 @@ public abstract class TmfStatisticsTest {
      */
     @Test
     public void testGetEventsInRangeMinusEnd() {
-        long count = backend.getEventsInRange(tStart, new TmfTimestamp(tEnd.getValue() - 1, SCALE));
+        long count = backend.getEventsInRange(tStart, tEnd - 1);
         assertEquals(totalNbEvents - 1, count);
     }
 
@@ -190,8 +188,7 @@ public abstract class TmfStatisticsTest {
      */
     @Test
     public void testGetEventTypesInRangeMinusStart() {
-        ITmfTimestamp newStart = new TmfTimestamp(tStart.getValue() + 1, SCALE);
-        Map<String, Long> result = backend.getEventTypesInRange(newStart, tEnd);
+        Map<String, Long> result = backend.getEventTypesInRange(tStart + 1, tEnd);
 
         long count = sumOfEvents(result);
         assertEquals(totalNbEvents - 1, count);
@@ -203,8 +200,7 @@ public abstract class TmfStatisticsTest {
      */
     @Test
     public void testGetEventTypesInRangeMinusEnd() {
-        ITmfTimestamp newEnd = new TmfTimestamp(tEnd.getValue() - 1, SCALE);
-        Map<String, Long> result = backend.getEventTypesInRange(tStart, newEnd);
+        Map<String, Long> result = backend.getEventTypesInRange(tStart, tEnd - 1);
 
         long count = sumOfEvents(result);
         assertEquals(totalNbEvents - 1, count);
index f3547ab6ad31b8ef820e70df7187af963bcee0c0..46747496dd6a22390e28ed594376f32081373a77 100644 (file)
@@ -21,6 +21,10 @@ import org.eclipse.linuxtools.tmf.core.signal.TmfStatsUpdatedSignal;
  * Provider for statistics, which is assigned to a trace. This can be used to
  * populate views like the Statistics View or the Histogram.
  *
+ * As a guideline, since any trace type can use this interface, all timestamps
+ * should be normalized to nanoseconds when using these methods
+ * ({@link ITmfTimestamp#NANOSECOND_SCALE}).
+ *
  * @author Alexandre Montplaisir
  * @since 2.0
  */
@@ -46,8 +50,7 @@ public interface ITmfStatistics {
      *            The end time of the query range. Has no effect if isGlobal is
      *            true.
      */
-    public void updateStats(final boolean isGlobal, ITmfTimestamp start,
-            ITmfTimestamp end);
+    public void updateStats(boolean isGlobal, long start, long end);
 
     /**
      * Return the total number of events in the trace.
@@ -73,7 +76,7 @@ public interface ITmfStatistics {
      *            End time of the time range
      * @return The number of events found
      */
-    public long getEventsInRange(ITmfTimestamp start, ITmfTimestamp end);
+    public long getEventsInRange(long start, long end);
 
     /**
      * Retrieve the number of events in the trace, per event type, in a given
@@ -85,8 +88,7 @@ public interface ITmfStatistics {
      *            End time of the time range
      * @return The map of <event_type, count>, for the given time range
      */
-    public Map<String, Long> getEventTypesInRange(ITmfTimestamp start,
-            ITmfTimestamp end);
+    public Map<String, Long> getEventTypesInRange(long start, long end);
 
     /**
      * Notify the statistics back-end that the trace is being closed, so it
index 25253def782a92f936e8b1e5db758fffeef38262..0f8c18c9350c8b0f18984a4b875dcba556aa6807 100644 (file)
@@ -18,6 +18,7 @@ import java.util.Map;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
 import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
+import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
 import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest;
 import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest;
@@ -39,6 +40,9 @@ import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
  */
 public class TmfEventsStatistics implements ITmfStatistics {
 
+    /* All timestamps should be stored in nanoseconds in the statistics backend */
+    private static final int SCALE = ITmfTimestamp.NANOSECOND_SCALE;
+
     private final ITmfTrace trace;
 
     /* Event request objects for the time-range request. */
@@ -61,8 +65,7 @@ public class TmfEventsStatistics implements ITmfStatistics {
     }
 
     @Override
-    public void updateStats(final boolean isGlobal, ITmfTimestamp start,
-            ITmfTimestamp end) {
+    public void updateStats(final boolean isGlobal, long start, long end) {
         cancelOngoingRequests();
 
         /*
@@ -70,7 +73,9 @@ public class TmfEventsStatistics implements ITmfStatistics {
          * same thread, since it will be run by TmfStatisticsViewer's signal
          * handlers, to ensure they get correctly coalesced.
          */
-        TmfTimeRange range = isGlobal ? TmfTimeRange.ETERNITY : new TmfTimeRange(start, end);
+        ITmfTimestamp startTS = new TmfTimestamp(start, SCALE);
+        ITmfTimestamp endTS = new TmfTimestamp(end, SCALE);
+        TmfTimeRange range = isGlobal ? TmfTimeRange.ETERNITY : new TmfTimeRange(startTS, endTS);
         final StatsTotalRequest totalReq = new StatsTotalRequest(trace, range);
         final StatsPerTypeRequest perTypeReq = new StatsPerTypeRequest(trace, range);
 
@@ -151,8 +156,11 @@ public class TmfEventsStatistics implements ITmfStatistics {
     }
 
     @Override
-    public long getEventsInRange(ITmfTimestamp start, ITmfTimestamp end) {
-        TmfTimeRange range = new TmfTimeRange(start, end);
+    public long getEventsInRange(long start, long end) {
+        ITmfTimestamp startTS = new TmfTimestamp(start, SCALE);
+        ITmfTimestamp endTS = new TmfTimestamp(end, SCALE);
+        TmfTimeRange range = new TmfTimeRange(startTS, endTS);
+
         StatsTotalRequest request = new StatsTotalRequest(trace, range);
         sendAndWait(request);
 
@@ -161,9 +169,11 @@ public class TmfEventsStatistics implements ITmfStatistics {
     }
 
     @Override
-    public Map<String, Long> getEventTypesInRange(ITmfTimestamp start,
-            ITmfTimestamp end) {
-        TmfTimeRange range = new TmfTimeRange(start, end);
+    public Map<String, Long> getEventTypesInRange(long start, long end) {
+        ITmfTimestamp startTS = new TmfTimestamp(start, SCALE);
+        ITmfTimestamp endTS = new TmfTimestamp(end, SCALE);
+        TmfTimeRange range = new TmfTimeRange(startTS, endTS);
+
         StatsPerTypeRequest request = new StatsPerTypeRequest(trace, range);
         sendAndWait(request);
 
index 7eeff57631f92862c3b0c2517f1fbf9d1c42076e..024529f22e799b7c5c6a5c7d869d79beaa7e41c8 100644 (file)
@@ -20,7 +20,6 @@ import java.util.Map;
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.linuxtools.tmf.core.TmfCommonConstants;
-import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;
 import org.eclipse.linuxtools.tmf.core.exceptions.StateSystemDisposedException;
 import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException;
@@ -128,8 +127,8 @@ public class TmfStateStatistics implements ITmfStatistics {
     }
 
     @Override
-    public void updateStats(final boolean isGlobal, final ITmfTimestamp start,
-            final ITmfTimestamp end) {
+    public void updateStats(final boolean isGlobal, final long start,
+            final long end) {
         /*
          * Since we are currently in a signal handler (ie, in the UI thread),
          * and since state system queries can be arbitrarily long (O(log n) wrt
@@ -224,7 +223,7 @@ public class TmfStateStatistics implements ITmfStatistics {
     }
 
     @Override
-    public long getEventsInRange(ITmfTimestamp start, ITmfTimestamp end) {
+    public long getEventsInRange(long start, long end) {
         // FIXME Instead of waiting until the end, we could check the current
         // end time, and answer as soon as possible...
         stats.waitUntilBuilt();
@@ -259,7 +258,7 @@ public class TmfStateStatistics implements ITmfStatistics {
     }
 
     @Override
-    public Map<String, Long> getEventTypesInRange(ITmfTimestamp start, ITmfTimestamp end) {
+    public Map<String, Long> getEventTypesInRange(long start, long end) {
         // FIXME Instead of waiting until the end, we could check the current
         // end time, and answer as soon as possible...
         stats.waitUntilBuilt();
@@ -330,16 +329,16 @@ public class TmfStateStatistics implements ITmfStatistics {
         return map;
     }
 
-    private long checkStartTime(ITmfTimestamp startTs) {
-        long start = startTs.normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
+    private long checkStartTime(long initialStart) {
+        long start = initialStart;
         if (start < stats.getStartTime()) {
             return stats.getStartTime();
         }
         return start;
     }
 
-    private long checkEndTime(ITmfTimestamp endTs) {
-        long end = endTs.normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
+    private long checkEndTime(long initialEnd) {
+        long end = initialEnd;
         if (end > stats.getCurrentEndTime()) {
             return stats.getCurrentEndTime();
         }
index c966c00d9d23ee8acd5b8d8986f0d85d6082023e..719d7d11e21dbc2ceaf45aabc42671290d823d19 100644 (file)
@@ -21,17 +21,14 @@ import org.eclipse.jface.viewers.TreeViewerColumn;
 import org.eclipse.jface.viewers.Viewer;
 import org.eclipse.jface.viewers.ViewerComparator;
 import org.eclipse.linuxtools.tmf.core.component.TmfComponent;
-import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
 import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
 import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentRangeUpdatedSignal;
 import org.eclipse.linuxtools.tmf.core.signal.TmfRangeSynchSignal;
 import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
-import org.eclipse.linuxtools.tmf.core.signal.TmfStateSystemBuildCompleted;
 import org.eclipse.linuxtools.tmf.core.signal.TmfStatsUpdatedSignal;
 import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics;
-import org.eclipse.linuxtools.tmf.core.statistics.TmfStateStatistics;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
 import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment;
 import org.eclipse.linuxtools.tmf.ui.viewers.TmfViewer;
@@ -564,9 +561,6 @@ public class TmfStatisticsViewer extends TmfViewer {
 
     /**
      * Initializes the input for the tree viewer.
-     *
-     * @param input
-     *            The input of this viewer, or <code>null</code> if none
      */
     protected void initInput() {
         String treeID = getTreeID();
@@ -675,7 +669,7 @@ public class TmfStatisticsViewer extends TmfViewer {
      *
      * @param experiment
      *            The experiment used to send the request
-     * @param range
+     * @param timeRange
      *            The range to request to the experiment
      */
     protected void requestData(final TmfExperiment experiment, final TmfTimeRange timeRange) {
@@ -687,7 +681,7 @@ public class TmfStatisticsViewer extends TmfViewer {
      *
      * @param experiment
      *            The experiment used to send the request
-     * @param range
+     * @param timeRange
      *            The range to request to the experiment
      */
     protected void requestTimeRangeData(final TmfExperiment experiment, final TmfTimeRange timeRange) {
@@ -746,8 +740,8 @@ public class TmfStatisticsViewer extends TmfViewer {
 
                 /* The generic statistics are stored in nanoseconds, so we must make
                  * sure the time range is scaled correctly. */
-                ITmfTimestamp start = timeRange.getStartTime().normalize(0, TIME_SCALE);
-                ITmfTimestamp end = timeRange.getEndTime().normalize(0, TIME_SCALE);
+                long start = timeRange.getStartTime().normalize(0, TIME_SCALE).getValue();
+                long end = timeRange.getEndTime().normalize(0, TIME_SCALE).getValue();
 
                 /*
                  * Send a request to update the statistics view. The result will
This page took 0.038159 seconds and 5 git commands to generate.