1 /*******************************************************************************
2 * Copyright (c) 2009, 2013 Ericsson
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
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 *******************************************************************************/
17 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.histogram
;
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
;
28 * Class to request events for given time range from a trace to fill a
29 * HistogramDataModel and HistogramView.
32 * @author Francois Chouinard
35 public class HistogramRequest
extends TmfEventRequest
{
37 // ------------------------------------------------------------------------
39 // ------------------------------------------------------------------------
42 * The histogram data model to fill.
44 protected final HistogramDataModel fHistogram
;
46 private final boolean fFullRange
;
48 // ------------------------------------------------------------------------
50 // ------------------------------------------------------------------------
56 * The histogram data model
58 * The time range to request data
60 * The index of the first event to retrieve
62 * The number of events requested
64 * The number of events per block
66 * The requested execution priority
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
,
77 fHistogram
= histogram
;
78 if (execType
== ExecutionType
.FOREGROUND
) {
89 * The histogram data model
91 * The time range to request data
93 * The index of the first event to retrieve
95 * The number of events requested
97 * The number of events per block
99 * The requested execution priority
101 * Full range or time range for histogram request
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
,
111 fHistogram
= histogram
;
112 fFullRange
= fullRange
;
115 // ------------------------------------------------------------------------
117 // ------------------------------------------------------------------------
120 * Handle the event from the trace by updating the histogram data model.
123 * a event from the trace
124 * @see org.eclipse.linuxtools.tmf.core.request.TmfDataRequest#handleData(org.eclipse.linuxtools.tmf.core.event.ITmfEvent)
127 public void handleData(ITmfEvent event
) {
128 super.handleData(event
);
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
);
135 } else { /* handle lost event */
136 long timestamp
= event
.getTimestamp().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
137 fHistogram
.countEvent(getNbRead(), timestamp
);
143 * Complete the request. It also notifies the histogram model about the
146 * @see org.eclipse.linuxtools.tmf.core.request.TmfDataRequest#handleCompleted()
149 public void handleCompleted() {
150 fHistogram
.complete();
151 super.handleCompleted();