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 defaultWidth
= 2000; // number of estimated pixels that
37 // can hold the time range space
38 private int width
= defaultWidth
; // width in pixels used to represent the
40 private double pixelsPerNs
= 0;
41 private int eventsDiscarded
= 0;
42 private int eventsDiscardedWrongOrder
= 0;
43 private TmfTimeRange trange
= null;
45 // ========================================================================
47 // ========================================================================
53 public synchronized boolean processTimeScaleEvent(
54 TmfTimeScaleSelectionEvent event
) {
56 boolean updated
= false;
58 long time0
= event
.getTime0();
59 long time1
= event
.getTime1();
60 int dwidth
= event
.getWidth();
62 updated
= update(time0
, time1
, dwidth
);
63 setSelectedTime(event
.getSelectedTime());
71 * Save the selected time
74 public void setSelectedTime(long selTime
) {
75 if (selTime
> startTime
&& selTime
< endTime
) {
76 selectedTime
= selTime
;
83 * May return null, if the selected time is invalid
87 public Long
getSelectedTime() {
92 * Update time range but keep width as is
98 public boolean update(long time0
, long time1
) {
99 return update(time0
, time1
, width
);
103 * Only positive attributes are expected
110 public boolean update(long time0
, long time1
, int dwidth
) {
111 boolean updated
= false;
113 if (time0
== startTime
&& time1
== endTime
&& dwidth
== width
) {
118 // Negatives are invalid
119 time0
= time0
> 0 ? time0
: 0;
120 time1
= time1
> 0 ? time1
: 0;
121 dwidth
= dwidth
> 0 ? dwidth
: 0;
124 // Store the new values as long as they are within range
129 pixelsPerNs
= (double) width
/ (double) (endTime
- startTime
);
131 TmfTimestamp fTimeStart
= new LttngTimestamp(startTime
);
132 TmfTimestamp fTimeEnd
= new LttngTimestamp(endTime
);
133 trange
= new TmfTimeRange(fTimeStart
, fTimeEnd
);
135 // make sure the selected time is within the new range or else set
136 // mark it as invalid
137 if (selectedTime
!= null) {
138 setSelectedTime(selectedTime
);
144 TraceDebug
.debug("Configuration updated to: StartTime: " /* */
149 + width
+ " k: " + pixelsPerNs
); /* */
152 .debug("End time is not greater than start time, start time: "
153 + time0
+ " end time: " + time1
);
162 public long getStartTime() {
169 public long getEndTime() {
176 public int getWidth() {
180 TraceDebug
.debug("Unexpected width value of 0 pixels");
187 * Return the current constant "K" of pixels per nano second used for the
188 * widest time space widget registered in this instance.
192 public double getPixelsPerNs() {
197 * Set the value of pixels per nano second as long as the value is grater
202 public void setPixelsPerNs(double pixperNsec
) {
203 if (pixperNsec
> 0) {
204 pixelsPerNs
= pixperNsec
;
211 public void setEventsDiscarded(int value
) {
212 eventsDiscarded
= value
;
214 eventsDiscardedWrongOrder
= 0;
221 public void incrementEventsDiscarded() {
222 this.eventsDiscarded
++;
228 public int getEventsDiscarded() {
229 return eventsDiscarded
;
233 * increase the number of events discarder since they were not received in a
234 * later time than previous events
236 public void incrementEventsDiscardedWrongOrder() {
237 this.eventsDiscarded
++;
238 this.eventsDiscardedWrongOrder
++;
244 public int getEventsDiscardedWrongOrder() {
245 return eventsDiscardedWrongOrder
;
252 public TmfTimeRange
getTrange() {