1 /*******************************************************************************
2 * Copyright (c) 2009 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 * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation
11 *******************************************************************************/
12 package org
.eclipse
.linuxtools
.lttng
.ui
.views
.common
;
14 import org
.eclipse
.linuxtools
.lttng
.event
.LttngTimestamp
;
15 import org
.eclipse
.linuxtools
.lttng
.ui
.TraceDebug
;
16 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimeRange
;
17 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimestamp
;
18 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.timeAnalysis
.TmfTimeScaleSelectionEvent
;
22 * Preserve the time and space width parameters applicable to a particular view
23 * in order to facilitate filtering of events and request handling.
28 public class ParamsUpdater
{
29 // ========================================================================
31 // ========================================================================
33 private long startTime
= 0;
34 private long endTime
= Long
.MAX_VALUE
;
35 private Long selectedTime
= null;
36 private final int DEFAULT_WIDTH
= 2000; // number of estimated pixels
38 // can hold the time range space
39 private int width
= DEFAULT_WIDTH
; // width in pixels used to represent the
41 private double pixelsPerNs
= 0;
42 private int eventsDiscarded
= 0;
43 private int eventsDiscardedOutOfView
= 0;
44 private int eventsDiscardedNotVisible
= 0;
45 private int eventsDiscardedWrongOrder
= 0;
46 private TmfTimeRange trange
= null;
48 public static final int OUT_OF_VIEWRANGE
= 0;
49 public static final int NOT_VISIBLE
= 1;
51 // ========================================================================
53 // ========================================================================
59 public synchronized boolean processTimeScaleEvent(
60 TmfTimeScaleSelectionEvent event
) {
62 boolean updated
= false;
64 long time0
= event
.getTime0();
65 long time1
= event
.getTime1();
66 int dwidth
= event
.getWidth();
68 updated
= update(time0
, time1
, dwidth
);
70 // initialization only, otherwise wait for the actual selection
71 // event to update its value. Note that the time must be different
72 // upon selection of a new time in order to trigger an update to all
73 if (selectedTime
== null) {
74 setSelectedTime(event
.getSelectedTime());
84 * Save the selected time
87 public void setSelectedTime(long selTime
) {
88 TraceDebug
.debug("Selected time changed from: \n\t" + selectedTime
89 + " to: \n\t" + selTime
);
90 selectedTime
= selTime
;
94 * May return null, if the selected time is invalid
98 public Long
getSelectedTime() {
103 * Update time range but keep width as is
109 public boolean update(long time0
, long time1
) {
110 return update(time0
, time1
, width
);
114 * Only positive attributes are expected
121 public boolean update(long time0
, long time1
, int dwidth
) {
122 boolean updated
= false;
124 if (time0
== startTime
&& time1
== endTime
&& dwidth
== width
) {
129 // Negatives are invalid
130 time0
= time0
> 0 ? time0
: 0;
131 time1
= time1
> 0 ? time1
: 0;
132 dwidth
= dwidth
> 0 ? dwidth
: 0;
135 // Store the new values as long as they are within range
140 pixelsPerNs
= (double) width
/ (double) (endTime
- startTime
);
142 TmfTimestamp fTimeStart
= new LttngTimestamp(startTime
);
143 TmfTimestamp fTimeEnd
= new LttngTimestamp(endTime
);
144 trange
= new TmfTimeRange(fTimeStart
, fTimeEnd
);
146 // make sure the selected time is within the new range or else set
147 // mark it as invalid
148 if (selectedTime
!= null) {
149 setSelectedTime(selectedTime
);
155 TraceDebug
.debug("Configuration updated to: StartTime: " /* */
160 + width
+ " k: " + pixelsPerNs
); /* */
163 .debug("End time is not greater than start time, start time: "
164 + time0
+ " end time: " + time1
);
173 public long getStartTime() {
180 public long getEndTime() {
187 public int getWidth() {
190 .debug("Unexpected width value of 0 pixels, returning default");
191 return DEFAULT_WIDTH
;
198 * Return the current constant "K" of pixels per nano second used for the
199 * widest time space widget registered in this instance.
203 public double getPixelsPerNs() {
208 * Set the value of pixels per nano second as long as the value is grater
213 public void setPixelsPerNs(double pixperNsec
) {
214 if (pixperNsec
> 0) {
215 pixelsPerNs
= pixperNsec
;
222 public void setEventsDiscarded(int value
) {
223 eventsDiscarded
= value
;
225 eventsDiscardedWrongOrder
= 0;
226 eventsDiscardedNotVisible
= 0;
227 eventsDiscardedOutOfView
= 0;
234 public void incrementEventsDiscarded(int reason
) {
235 if (reason
== OUT_OF_VIEWRANGE
) {
236 this.eventsDiscardedOutOfView
++;
239 if (reason
== NOT_VISIBLE
) {
240 this.eventsDiscardedNotVisible
++;
243 this.eventsDiscarded
++;
249 public int getEventsDiscarded() {
250 return eventsDiscarded
;
254 * increase the number of events discarder since they were not received in a
255 * later time than previous events
257 public void incrementEventsDiscardedWrongOrder() {
258 this.eventsDiscarded
++;
259 this.eventsDiscardedWrongOrder
++;
265 public int getEventsDiscardedWrongOrder() {
266 return eventsDiscardedWrongOrder
;
273 public int getEventsDiscardedNotVisible() {
274 return eventsDiscardedNotVisible
;
281 public int getEventsDiscardedOutOfViewRange() {
282 return eventsDiscardedOutOfView
;
289 public TmfTimeRange
getTrange() {