From 8b260d9fa6955c93c9a0552e97d0823814771ae9 Mon Sep 17 00:00:00 2001 From: Alexandre Montplaisir Date: Mon, 12 Nov 2012 17:23:31 -0500 Subject: [PATCH] tmf: Replace ITmfTimestamp by long in ITmfStatistics API 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 Reviewed-on: https://git.eclipse.org/r/8650 Tested-by: Hudson CI Reviewed-by: Bernd Hufmann IP-Clean: Bernd Hufmann --- .../tests/statistics/TmfStatisticsTest.java | 30 ++++++++----------- .../tmf/core/statistics/ITmfStatistics.java | 12 ++++---- .../core/statistics/TmfEventsStatistics.java | 26 +++++++++++----- .../core/statistics/TmfStateStatistics.java | 17 +++++------ .../statistics/TmfStatisticsViewer.java | 14 +++------ 5 files changed, 50 insertions(+), 49 deletions(-) diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statistics/TmfStatisticsTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statistics/TmfStatisticsTest.java index e43e69a200..bc571de161 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statistics/TmfStatisticsTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statistics/TmfStatisticsTest.java @@ -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 result = backend.getEventTypesInRange(newStart, tEnd); + Map 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 result = backend.getEventTypesInRange(tStart, newEnd); + Map result = backend.getEventTypesInRange(tStart, tEnd - 1); long count = sumOfEvents(result); assertEquals(totalNbEvents - 1, count); diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/ITmfStatistics.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/ITmfStatistics.java index f3547ab6ad..46747496dd 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/ITmfStatistics.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/ITmfStatistics.java @@ -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 , for the given time range */ - public Map getEventTypesInRange(ITmfTimestamp start, - ITmfTimestamp end); + public Map getEventTypesInRange(long start, long end); /** * Notify the statistics back-end that the trace is being closed, so it diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfEventsStatistics.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfEventsStatistics.java index 25253def78..0f8c18c935 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfEventsStatistics.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfEventsStatistics.java @@ -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 getEventTypesInRange(ITmfTimestamp start, - ITmfTimestamp end) { - TmfTimeRange range = new TmfTimeRange(start, end); + public Map 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); diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfStateStatistics.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfStateStatistics.java index 7eeff57631..024529f22e 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfStateStatistics.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfStateStatistics.java @@ -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 getEventTypesInRange(ITmfTimestamp start, ITmfTimestamp end) { + public Map 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(); } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/TmfStatisticsViewer.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/TmfStatisticsViewer.java index c966c00d9d..719d7d11e2 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/TmfStatisticsViewer.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/TmfStatisticsViewer.java @@ -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 null 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 -- 2.34.1