tmf : Update the histogram to handle lost events correctly
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / histogram / HistogramRequest.java
index 7df67cb160b1b9c5e77a758b00e67392e65f03aa..3bfe26d37242874135afc6c55d7b4d05ea6662b7 100644 (file)
  *   Yuriy Vashchuk - Heritage correction.
  *   Francois Chouinard - Cleanup and refactoring
  *   Francois Chouinard - Moved from LTTng to TMF
+ *   Simon Delisle - Added a new parameter to the constructor
  *******************************************************************************/
 
 package org.eclipse.linuxtools.tmf.ui.views.histogram;
 
 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.event.ITmfLostEvent;
 import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
 import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest;
 import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
@@ -23,11 +25,12 @@ import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
 
 /**
- * Class to request events for given time range from a trace to fill a HistogramDataModel and HistogramView.
+ * Class to request events for given time range from a trace to fill a
+ * HistogramDataModel and HistogramView.
  *
  * @version 1.0
  * @author Francois Chouinard
- * <p>
+ *         <p>
  */
 public class HistogramRequest extends TmfEventRequest {
 
@@ -40,6 +43,8 @@ public class HistogramRequest extends TmfEventRequest {
      */
     protected final HistogramDataModel fHistogram;
 
+    private final boolean fFullRange;
+
     // ------------------------------------------------------------------------
     // Constructor
     // ------------------------------------------------------------------------
@@ -62,6 +67,7 @@ public class HistogramRequest extends TmfEventRequest {
      * @since 2.0
      *
      */
+    @Deprecated
     public HistogramRequest(HistogramDataModel histogram, TmfTimeRange range,
             int rank, int nbEvents, int blockSize,
             ITmfDataRequest.ExecutionType execType) {
@@ -69,6 +75,41 @@ public class HistogramRequest extends TmfEventRequest {
                 (blockSize > 0) ? blockSize : ITmfTrace.DEFAULT_TRACE_CACHE_SIZE,
                 execType);
         fHistogram = histogram;
+        if (execType == ExecutionType.FOREGROUND) {
+            fFullRange = false;
+        } else {
+            fFullRange = true;
+        }
+    }
+
+    /**
+     * Constructor
+     *
+     * @param histogram
+     *            The histogram data model
+     * @param range
+     *            The time range to request data
+     * @param rank
+     *            The index of the first event to retrieve
+     * @param nbEvents
+     *            The number of events requested
+     * @param blockSize
+     *            The number of events per block
+     * @param execType
+     *            The requested execution priority
+     * @param fullRange
+     *            Full range or time range for histogram request
+     * @since 2.1
+     *
+     */
+    public HistogramRequest(HistogramDataModel histogram, TmfTimeRange range,
+            int rank, int nbEvents, int blockSize,
+            ITmfDataRequest.ExecutionType execType, boolean fullRange) {
+        super(ITmfEvent.class, range, rank, nbEvents,
+                (blockSize > 0) ? blockSize : ITmfTrace.DEFAULT_TRACE_CACHE_SIZE,
+                execType);
+        fHistogram = histogram;
+        fFullRange = fullRange;
     }
 
     // ------------------------------------------------------------------------
@@ -78,20 +119,29 @@ public class HistogramRequest extends TmfEventRequest {
     /**
      * Handle the event from the trace by updating the histogram data model.
      *
-     * @param event a event from the trace
+     * @param event
+     *            a event from the trace
      * @see org.eclipse.linuxtools.tmf.core.request.TmfDataRequest#handleData(org.eclipse.linuxtools.tmf.core.event.ITmfEvent)
      */
     @Override
     public void handleData(ITmfEvent event) {
         super.handleData(event);
         if (event != null) {
-            long timestamp = event.getTimestamp().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
-            fHistogram.countEvent(getNbRead(), timestamp);
+            if (event instanceof ITmfLostEvent) {
+                ITmfLostEvent lostEvents = (ITmfLostEvent) event;
+                /* clear the old data when it is a new request */
+                fHistogram.countLostEvent(lostEvents.getTimeRange(), lostEvents.getNbLostEvents(), fFullRange);
+
+            } else { /* handle lost event */
+                long timestamp = event.getTimestamp().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
+                fHistogram.countEvent(getNbRead(), timestamp);
+            }
         }
     }
 
     /**
-     * Complete the request. It also notifies the histogram model about the completion.
+     * Complete the request. It also notifies the histogram model about the
+     * completion.
      *
      * @see org.eclipse.linuxtools.tmf.core.request.TmfDataRequest#handleCompleted()
      */
This page took 0.038169 seconds and 5 git commands to generate.