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
.internal
.lttng
.ui
.views
.common
;
14 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.event
.LttngTimestamp
;
15 import org
.eclipse
.linuxtools
.internal
.lttng
.ui
.TraceDebug
;
16 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimeRange
;
17 import org
.eclipse
.linuxtools
.tmf
.core
.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 static Long selectedTime
= null;
36 private final int DEFAULT_WIDTH
= 2000; // number of estimated pixels that
37 // can hold the time range space
38 private int width
= DEFAULT_WIDTH
; // width in pixels used to represent the
40 private double pixelsPerNs
= 0;
41 private int eventsDiscarded
= 0;
42 private int eventsDiscardedOutOfView
= 0;
43 private int eventsDiscardedNotVisible
= 0;
44 private int eventsDiscardedWrongOrder
= 0;
45 private TmfTimeRange trange
= null;
47 public static final int OUT_OF_VIEWRANGE
= 0;
48 public static final int NOT_VISIBLE
= 1;
50 // ========================================================================
52 // ========================================================================
58 public synchronized boolean processTimeScaleEvent(
59 TmfTimeScaleSelectionEvent event
) {
61 boolean updated
= false;
63 long time0
= event
.getTime0();
64 long time1
= event
.getTime1();
65 int dwidth
= event
.getWidth();
67 updated
= update(time0
, time1
, dwidth
);
69 // initialization only, otherwise wait for the actual selection
70 // event to update its value. Note that the time must be different
71 // upon selection of a new time in order to trigger an update to all
72 if (selectedTime
== null) {
73 setSelectedTime(event
.getSelectedTime());
83 * Save the selected time
86 public void setSelectedTime(long selTime
) {
87 TraceDebug
.debug("Selected time changed from: \n\t" + selectedTime
//$NON-NLS-1$
88 + " to: \n\t" + selTime
); //$NON-NLS-1$
89 selectedTime
= selTime
;
93 * May return null, if the selected time is invalid
97 public Long
getSelectedTime() {
102 * Update time range but keep width as is
108 public boolean update(long time0
, long time1
) {
109 return update(time0
, time1
, width
);
113 * Only positive attributes are expected
120 public boolean update(long time0
, long time1
, int dwidth
) {
121 boolean updated
= false;
123 if (time0
== startTime
&& time1
== endTime
&& dwidth
== width
) {
128 // Negatives are invalid
129 time0
= time0
> 0 ? time0
: 0;
130 time1
= time1
> 0 ? time1
: 0;
131 dwidth
= dwidth
> 0 ? dwidth
: 0;
134 // Store the new values as long as they are within range
139 pixelsPerNs
= (double) width
/ (double) (endTime
- startTime
);
141 TmfTimestamp fTimeStart
= new LttngTimestamp(startTime
);
142 TmfTimestamp fTimeEnd
= new LttngTimestamp(endTime
);
143 trange
= new TmfTimeRange(fTimeStart
, fTimeEnd
);
145 // make sure the selected time is within the new range or else set
146 // mark it as invalid
147 if (selectedTime
!= null) {
148 setSelectedTime(selectedTime
);
154 TraceDebug
.debug("Configuration updated to: StartTime: " /* */ //$NON-NLS-1$
156 + "-" /* */ //$NON-NLS-1$
158 + " width: " /* */ //$NON-NLS-1$
159 + width
+ " k: " + pixelsPerNs
); /* */ //$NON-NLS-1$
162 .debug("End time is not greater than start time, start time: " //$NON-NLS-1$
163 + time0
+ " end time: " + time1
); //$NON-NLS-1$
172 public long getStartTime() {
179 public long getEndTime() {
186 public int getWidth() {
189 .debug("Unexpected width value of 0 pixels, returning default"); //$NON-NLS-1$
190 return DEFAULT_WIDTH
;
197 * Return the current constant "K" of pixels per nano second used for the
198 * widest time space widget registered in this instance.
202 public double getPixelsPerNs() {
207 * Set the value of pixels per nano second as long as the value is grater
212 public void setPixelsPerNs(double pixperNsec
) {
213 if (pixperNsec
> 0) {
214 pixelsPerNs
= pixperNsec
;
221 public void setEventsDiscarded(int value
) {
222 eventsDiscarded
= value
;
224 eventsDiscardedWrongOrder
= 0;
225 eventsDiscardedNotVisible
= 0;
226 eventsDiscardedOutOfView
= 0;
233 public void incrementEventsDiscarded(int reason
) {
234 if (reason
== OUT_OF_VIEWRANGE
) {
235 this.eventsDiscardedOutOfView
++;
238 if (reason
== NOT_VISIBLE
) {
239 this.eventsDiscardedNotVisible
++;
242 this.eventsDiscarded
++;
248 public int getEventsDiscarded() {
249 return eventsDiscarded
;
253 * increase the number of events discarder since they were not received in a
254 * later time than previous events
256 public void incrementEventsDiscardedWrongOrder() {
257 this.eventsDiscarded
++;
258 this.eventsDiscardedWrongOrder
++;
264 public int getEventsDiscardedWrongOrder() {
265 return eventsDiscardedWrongOrder
;
272 public int getEventsDiscardedNotVisible() {
273 return eventsDiscardedNotVisible
;
280 public int getEventsDiscardedOutOfViewRange() {
281 return eventsDiscardedOutOfView
;
288 public TmfTimeRange
getTrange() {