/*******************************************************************************
- * Copyright (c) 2012 Ericsson
+ * 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
* Contributors:
* Mathieu Denis <mathieu.denis@polymtl.ca> - Initial API and implementation
* Alexandre Montplaisir - Port to ITmfStatistics provider
+ * Patrick Tasse - Support selection range
*******************************************************************************/
package org.eclipse.linuxtools.tmf.ui.viewers.statistics;
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.signal.TmfTimeSynchSignal;
+import org.eclipse.linuxtools.tmf.core.signal.TmfTraceRangeUpdatedSignal;
import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics;
-import org.eclipse.linuxtools.tmf.core.statistics.TmfStateStatistics;
+import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment;
+import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager;
import org.eclipse.linuxtools.tmf.ui.viewers.TmfViewer;
import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.ITmfColumnDataProvider;
import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfBaseColumnData;
*/
public class TmfStatisticsViewer extends TmfViewer {
- /**
- * The initial window span (in nanoseconds)
- */
- public static final long INITIAL_WINDOW_SPAN = (1L * 100 * 1000 * 1000); // .1sec
-
/**
* Timestamp scale (nanosecond)
*/
- public static final byte TIME_SCALE = -9;
+ public static final byte TIME_SCALE = ITmfTimestamp.NANOSECOND_SCALE;
/**
* Default PAGE_SIZE for background requests.
private int fInstanceNb;
/**
- * Object to store the cursor while waiting for the experiment to load
+ * Object to store the cursor while waiting for the trace to load
*/
private Cursor fWaitCursor = null;
private int fWaitCursorCount = 0;
/**
- * Tells to send a time range request when the experiment gets updated.
+ * Tells to send a time range request when the trace gets updated.
*/
private boolean fSendRangeRequest = true;
+ /** Reference to the trace manager */
+ private final TmfTraceManager fTraceManager;
+
/**
* Empty constructor. To be used in conjunction with
* {@link TmfStatisticsViewer#init(Composite, String, ITmfTrace)}
*/
public TmfStatisticsViewer() {
super();
+ fTraceManager = TmfTraceManager.getInstance();
}
/**
*/
public TmfStatisticsViewer(Composite parent, String viewerName, ITmfTrace trace) {
init(parent, viewerName, trace);
+ fTraceManager = TmfTraceManager.getInstance();
}
/**
fInstanceNb = fCountInstance;
fTrace = trace;
- // The viewer will process all events if he is assigned to the experiment
+ // The viewer will process all events if he is assigned to an experiment
fProcessAll = (trace instanceof TmfExperiment);
initContent(parent);
initInput();
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.linuxtools.tmf.core.component.TmfComponent#dispose()
- */
@Override
public void dispose() {
super.dispose();
// ------------------------------------------------------------------------
/**
- * Handles the signal about new experiment range.
+ * Handles the signal about new trace range.
*
* @param signal
- * The experiment range updated signal
+ * The trace range updated signal
*/
@TmfSignalHandler
- public void experimentRangeUpdated(TmfExperimentRangeUpdatedSignal signal) {
- TmfExperiment experiment = signal.getExperiment();
+ public void traceRangeUpdated(TmfTraceRangeUpdatedSignal signal) {
+ ITmfTrace trace = signal.getTrace();
// validate
- if (!experiment.equals(TmfExperiment.getCurrentExperiment())) {
+ if (!isListeningTo(trace)) {
return;
}
// Sends the time range request only once from this method.
if (fSendRangeRequest) {
fSendRangeRequest = false;
- // Calculate the selected time range to request
- long startTime = signal.getRange().getStartTime().normalize(0, TIME_SCALE).getValue();
- TmfTimestamp startTS = new TmfTimestamp(startTime, TIME_SCALE);
- TmfTimestamp endTS = new TmfTimestamp(startTime + INITIAL_WINDOW_SPAN, TIME_SCALE);
- TmfTimeRange timeRange = new TmfTimeRange(startTS, endTS);
-
- requestTimeRangeData(experiment, timeRange);
+ ITmfTimestamp begin = fTraceManager.getSelectionBeginTime();
+ ITmfTimestamp end = fTraceManager.getSelectionEndTime();
+ TmfTimeRange timeRange = new TmfTimeRange(begin, end);
+ requestTimeRangeData(trace, timeRange);
}
}
- requestData(experiment, signal.getRange());
+ requestData(trace, signal.getRange());
}
/**
*
* @param signal
* Contains the information about the new selected time range.
+ * @deprecated
+ * As of 2.1, use {@link #timeSynchUpdated(TmfTimeSynchSignal)}
*/
+ @Deprecated
@TmfSignalHandler
public void timeRangeUpdated(TmfRangeSynchSignal signal) {
- requestTimeRangeData(TmfExperiment.getCurrentExperiment(), signal.getCurrentRange());
+ }
+
+ /**
+ * Handles the time synch updated signal. It updates the time range
+ * statistics.
+ *
+ * @param signal
+ * Contains the information about the new selected time range.
+ * @since 3.0
+ */
+ @TmfSignalHandler
+ public void timeSynchUpdated(TmfTimeSynchSignal signal) {
+ if (fTrace == null) {
+ return;
+ }
+ ITmfTimestamp begin = signal.getBeginTime();
+ ITmfTimestamp end = signal.getEndTime();
+ TmfTimeRange timeRange = new TmfTimeRange(begin, end);
+ requestTimeRangeData(fTrace, timeRange);
}
/**
/**
* 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();
- TmfStatisticsTreeNode experimentTreeNode;
+ TmfStatisticsTreeNode statisticsTreeNode;
if (TmfStatisticsTreeManager.containsTreeRoot(treeID)) {
- // The experiment root is already present
- experimentTreeNode = TmfStatisticsTreeManager.getStatTreeRoot(treeID);
+ // The statistics root is already present
+ statisticsTreeNode = TmfStatisticsTreeManager.getStatTreeRoot(treeID);
// Checks if the trace is already in the statistics tree.
- int numNodeTraces = experimentTreeNode.getNbChildren();
-
- int numTraces = 1;
- ITmfTrace[] trace = { fTrace };
- // For experiment, gets all the traces within it
- if (fTrace instanceof TmfExperiment) {
- TmfExperiment experiment = (TmfExperiment) fTrace;
- numTraces = experiment.getTraces().length;
- trace = experiment.getTraces();
- }
+ int numNodeTraces = statisticsTreeNode.getNbChildren();
+
+ ITmfTrace[] traces = TmfTraceManager.getTraceSet(fTrace);
+ int numTraces = traces.length;
if (numTraces == numNodeTraces) {
boolean same = true;
* previously selected.
*/
for (int i = 0; i < numTraces; i++) {
- String traceName = trace[i].getName();
- if (!experimentTreeNode.containsChild(traceName)) {
+ String traceName = traces[i].getName();
+ if (!statisticsTreeNode.containsChild(traceName)) {
same = false;
break;
}
if (same) {
// No need to reload data, all traces are already loaded
- fTreeViewer.setInput(experimentTreeNode);
+ fTreeViewer.setInput(statisticsTreeNode);
return;
}
// Clears the old content to start over
- experimentTreeNode.reset();
+ statisticsTreeNode.reset();
}
} else {
// Creates a new tree
- experimentTreeNode = TmfStatisticsTreeManager.addStatsTreeRoot(treeID, getStatisticData());
+ statisticsTreeNode = TmfStatisticsTreeManager.addStatsTreeRoot(treeID, getStatisticData());
}
// Sets the input to a clean data model
- fTreeViewer.setInput(experimentTreeNode);
+ fTreeViewer.setInput(statisticsTreeNode);
resetUpdateSynchronization();
}
/**
- * Tells if the viewer is listening to a trace from the selected experiment.
+ * Tells if the viewer is listening to a trace.
*
* @param trace
* The trace that the viewer may be listening
}
/**
- * Called when an experiment request has been completed successfully.
+ * Called when an trace request has been completed successfully.
*
* @param global
* Tells if the request is a global or time range (partial)
}
/**
- * Called when an experiment request has failed or has been cancelled.
+ * Called when an trace request has failed or has been cancelled.
*
* @param isGlobalRequest
* Tells if the request is a global or time range (partial)
}
/**
- * Sends the request to the experiment for the whole trace
+ * Sends the request to the trace for the whole trace
*
- * @param experiment
- * The experiment used to send the request
- * @param range
- * The range to request to the experiment
+ * @param trace
+ * The trace used to send the request
+ * @param timeRange
+ * The range to request to the trace
*/
- protected void requestData(final TmfExperiment experiment, final TmfTimeRange timeRange) {
- buildStatisticsTree(experiment, timeRange, true);
+ protected void requestData(final ITmfTrace trace, final TmfTimeRange timeRange) {
+ buildStatisticsTree(trace, timeRange, true);
}
/**
- * Sends the time range request from the experiment
+ * Sends the time range request from the trace
*
- * @param experiment
- * The experiment used to send the request
- * @param range
- * The range to request to the experiment
+ * @param trace
+ * The trace used to send the request
+ * @param timeRange
+ * The range to request to the trace
*/
- protected void requestTimeRangeData(final TmfExperiment experiment, final TmfTimeRange timeRange) {
+ protected void requestTimeRangeData(final ITmfTrace trace, final TmfTimeRange timeRange) {
fRequestedTimerange = timeRange;
- buildStatisticsTree(experiment, timeRange, false);
+ buildStatisticsTree(trace, timeRange, false);
}
/**
- * Requests all the data of the experiment to the state system which
+ * Requests all the data of the trace to the state system which
* contains information about the statistics.
*
- * Since the viewer may be listening to multiple traces, it have to receive
- * the experiment rather than a single trace. The filtering is done with the
+ * Since the viewer may be listening to multiple traces, it may receive
+ * an experiment rather than a single trace. The filtering is done with the
* method {@link #isListeningTo(String trace)}.
*
- * @param experiment
- * The experiment for which a request must be done
+ * @param trace
+ * The trace for which a request must be done
* @param timeRange
* The time range that will be requested to the state system
* @param isGlobal
* Tells if the request is for the global event count or the
* partial one.
*/
- private void buildStatisticsTree(final TmfExperiment experiment, TmfTimeRange timeRange, boolean isGlobal) {
+ private void buildStatisticsTree(final ITmfTrace trace, TmfTimeRange timeRange, boolean isGlobal) {
final TmfStatisticsTreeNode statTree = TmfStatisticsTreeManager.getStatTreeRoot(getTreeID());
final TmfStatisticsTree statsData = TmfStatisticsTreeManager.getStatTree(getTreeID());
if (statsData == null) {
statTree.resetTimeRangeValue();
}
- /*
- * Checks each trace in the experiment, since the viewer may be
- * listening to multiple traces.
- */
- for (final ITmfTrace trace : experiment.getTraces()) {
- if (!isListeningTo(trace)) {
+ for (final ITmfTrace aTrace : TmfTraceManager.getTraceSet(trace)) {
+ if (!isListeningTo(aTrace)) {
continue;
}
/* Retrieves the statistics object */
- final ITmfStatistics stats = trace.getStatistics();
+ final ITmfStatistics stats = aTrace.getStatistics();
if (stats == null) {
/*
* The statistics provider for this trace is not accessible
/* 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
* be sent through a {@link TmfStatsUpdatedSignal}, and will be
* processed by the signal handler.
*/
- trace.getStatistics().updateStats(isGlobal, start, end);
+ aTrace.getStatistics().updateStats(isGlobal, start, end);
}
}
}
}
/**
- * When the experiment is loading the cursor will be different so the user
+ * When the trace is loading the cursor will be different so the user
* knows that the processing is not finished yet.
*
* Calls to this method are stacked.
fStatisticsUpdateBusy = false;
if (fStatisticsUpdatePending) {
fStatisticsUpdatePending = false;
- requestData(TmfExperiment.getCurrentExperiment(), fStatisticsUpdateRange);
+ requestData(fTrace, fStatisticsUpdateRange);
fStatisticsUpdateRange = null;
}
}