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
1 /*******************************************************************************
2 * Copyright (c) 2009, 2013 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * William Bourque - Initial API and implementation
11 * Yuriy Vashchuk - Heritage correction.
12 * Francois Chouinard - Cleanup and refactoring
13 * Francois Chouinard - Moved from LTTng to TMF
14 * Simon Delisle - Added a new parameter to the constructor
15 *******************************************************************************/
16
17 package org.eclipse.linuxtools.tmf.ui.views.histogram;
18
19 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
20 import org.eclipse.linuxtools.tmf.core.event.ITmfLostEvent;
21 import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
22 import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest;
23 import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
24 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
25 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
26
27 /**
28 * Class to request events for given time range from a trace to fill a
29 * HistogramDataModel and HistogramView.
30 *
31 * @version 1.0
32 * @author Francois Chouinard
33 * <p>
34 */
35 public class HistogramRequest extends TmfEventRequest {
36
37 // ------------------------------------------------------------------------
38 // Attributes
39 // ------------------------------------------------------------------------
40
41 /**
42 * The histogram data model to fill.
43 */
44 protected final HistogramDataModel fHistogram;
45
46 private final boolean fFullRange;
47
48 // ------------------------------------------------------------------------
49 // Constructor
50 // ------------------------------------------------------------------------
51
52 /**
53 * Constructor
54 *
55 * @param histogram
56 * The histogram data model
57 * @param range
58 * The time range to request data
59 * @param rank
60 * The index of the first event to retrieve
61 * @param nbEvents
62 * The number of events requested
63 * @param blockSize
64 * The number of events per block
65 * @param execType
66 * The requested execution priority
67 * @since 2.0
68 *
69 */
70 @Deprecated
71 public HistogramRequest(HistogramDataModel histogram, TmfTimeRange range,
72 int rank, int nbEvents, int blockSize,
73 ITmfDataRequest.ExecutionType execType) {
74 super(ITmfEvent.class, range, rank, nbEvents,
75 (blockSize > 0) ? blockSize : ITmfTrace.DEFAULT_TRACE_CACHE_SIZE,
76 execType);
77 fHistogram = histogram;
78 if (execType == ExecutionType.FOREGROUND) {
79 fFullRange = false;
80 } else {
81 fFullRange = true;
82 }
83 }
84
85 /**
86 * Constructor
87 *
88 * @param histogram
89 * The histogram data model
90 * @param range
91 * The time range to request data
92 * @param rank
93 * The index of the first event to retrieve
94 * @param nbEvents
95 * The number of events requested
96 * @param blockSize
97 * The number of events per block
98 * @param execType
99 * The requested execution priority
100 * @param fullRange
101 * Full range or time range for histogram request
102 * @since 2.1
103 *
104 */
105 public HistogramRequest(HistogramDataModel histogram, TmfTimeRange range,
106 int rank, int nbEvents, int blockSize,
107 ITmfDataRequest.ExecutionType execType, boolean fullRange) {
108 super(ITmfEvent.class, range, rank, nbEvents,
109 (blockSize > 0) ? blockSize : ITmfTrace.DEFAULT_TRACE_CACHE_SIZE,
110 execType);
111 fHistogram = histogram;
112 fFullRange = fullRange;
113 }
114
115 // ------------------------------------------------------------------------
116 // TmfEventRequest
117 // ------------------------------------------------------------------------
118
119 /**
120 * Handle the event from the trace by updating the histogram data model.
121 *
122 * @param event
123 * a event from the trace
124 * @see org.eclipse.linuxtools.tmf.core.request.TmfDataRequest#handleData(org.eclipse.linuxtools.tmf.core.event.ITmfEvent)
125 */
126 @Override
127 public void handleData(ITmfEvent event) {
128 super.handleData(event);
129 if (event != null) {
130 if (event instanceof ITmfLostEvent) {
131 ITmfLostEvent lostEvents = (ITmfLostEvent) event;
132 /* clear the old data when it is a new request */
133 fHistogram.countLostEvent(lostEvents.getTimeRange(), lostEvents.getNbLostEvents(), fFullRange);
134
135 } else { /* handle lost event */
136 long timestamp = event.getTimestamp().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
137 fHistogram.countEvent(getNbRead(), timestamp);
138 }
139 }
140 }
141
142 /**
143 * Complete the request. It also notifies the histogram model about the
144 * completion.
145 *
146 * @see org.eclipse.linuxtools.tmf.core.request.TmfDataRequest#handleCompleted()
147 */
148 @Override
149 public void handleCompleted() {
150 fHistogram.complete();
151 super.handleCompleted();
152 }
153 }
This page took 0.041482 seconds and 5 git commands to generate.