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
CommitLineData
378e7718 1/*******************************************************************************
c8422608 2 * Copyright (c) 2009, 2013 Ericsson
20ff3b75 3 *
378e7718
WB
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
20ff3b75 8 *
378e7718
WB
9 * Contributors:
10 * William Bourque - Initial API and implementation
c392540b
FC
11 * Yuriy Vashchuk - Heritage correction.
12 * Francois Chouinard - Cleanup and refactoring
e0752744 13 * Francois Chouinard - Moved from LTTng to TMF
95aa81ef 14 * Simon Delisle - Added a new parameter to the constructor
378e7718 15 *******************************************************************************/
c392540b 16
e0752744 17package org.eclipse.linuxtools.tmf.ui.views.histogram;
6e512b93 18
e0752744 19import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
95aa81ef 20import org.eclipse.linuxtools.tmf.core.event.ITmfLostEvent;
6c13869b
FC
21import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
22import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest;
3bd46eef
AM
23import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
24import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
0316808c 25import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
6e512b93 26
378e7718 27/**
95aa81ef
JCK
28 * Class to request events for given time range from a trace to fill a
29 * HistogramDataModel and HistogramView.
20ff3b75 30 *
b544077e
BH
31 * @version 1.0
32 * @author Francois Chouinard
95aa81ef 33 * <p>
378e7718 34 */
6256d8ad 35public class HistogramRequest extends TmfEventRequest {
c392540b
FC
36
37 // ------------------------------------------------------------------------
38 // Attributes
39 // ------------------------------------------------------------------------
40
b544077e
BH
41 /**
42 * The histogram data model to fill.
43 */
fbd124dd 44 protected final HistogramDataModel fHistogram;
c392540b 45
95aa81ef
JCK
46 private final boolean fFullRange;
47
c392540b
FC
48 // ------------------------------------------------------------------------
49 // Constructor
50 // ------------------------------------------------------------------------
51
b544077e
BH
52 /**
53 * Constructor
20ff3b75
AM
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
3bd46eef 67 * @since 2.0
20ff3b75 68 *
b544077e 69 */
95aa81ef 70 @Deprecated
20ff3b75
AM
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);
c392540b 77 fHistogram = histogram;
95aa81ef
JCK
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;
c392540b
FC
113 }
114
c392540b
FC
115 // ------------------------------------------------------------------------
116 // TmfEventRequest
117 // ------------------------------------------------------------------------
20ff3b75 118
b544077e
BH
119 /**
120 * Handle the event from the trace by updating the histogram data model.
20ff3b75 121 *
95aa81ef
JCK
122 * @param event
123 * a event from the trace
b544077e
BH
124 * @see org.eclipse.linuxtools.tmf.core.request.TmfDataRequest#handleData(org.eclipse.linuxtools.tmf.core.event.ITmfEvent)
125 */
c392540b 126 @Override
e0752744 127 public void handleData(ITmfEvent event) {
c392540b 128 super.handleData(event);
cb866e08 129 if (event != null) {
95aa81ef
JCK
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 }
7ef9ae3f 139 }
6e512b93 140 }
c392540b 141
b544077e 142 /**
95aa81ef
JCK
143 * Complete the request. It also notifies the histogram model about the
144 * completion.
20ff3b75 145 *
b544077e
BH
146 * @see org.eclipse.linuxtools.tmf.core.request.TmfDataRequest#handleCompleted()
147 */
6e512b93 148 @Override
5419a136 149 public void handleCompleted() {
fbd124dd 150 fHistogram.complete();
c392540b 151 super.handleCompleted();
6e512b93 152 }
6e512b93 153}
This page took 0.053777 seconds and 5 git commands to generate.