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;
*/
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$
*/
@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);
}
*/
@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);
}
*/
@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);
*/
@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);
* 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
*/
* 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.
* 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
* 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
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;
*/
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. */
}
@Override
- public void updateStats(final boolean isGlobal, ITmfTimestamp start,
- ITmfTimestamp end) {
+ public void updateStats(final boolean isGlobal, long start, long end) {
cancelOngoingRequests();
/*
* 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);
}
@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);
}
@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);
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;
}
@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
}
@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();
}
@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();
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();
}
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;
/**
* 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();
*
* @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) {
*
* @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) {
/* 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