Commit | Line | Data |
---|---|---|
6e512b93 | 1 | /******************************************************************************* |
8827c197 | 2 | * Copyright (c) 2009, 2010 Ericsson |
6e512b93 ASL |
3 | * |
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 | |
8 | * | |
9 | * Contributors: | |
10 | * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation | |
de7ddc02 | 11 | * Bernd Hufmann - Bug fixes |
6e512b93 ASL |
12 | *******************************************************************************/ |
13 | package org.eclipse.linuxtools.lttng.ui.views.common; | |
14 | ||
8827c197 FC |
15 | import java.util.Arrays; |
16 | ||
6c13869b FC |
17 | import org.eclipse.linuxtools.lttng.core.LttngConstants; |
18 | import org.eclipse.linuxtools.lttng.core.control.LttngCoreProviderFactory; | |
19 | import org.eclipse.linuxtools.lttng.core.control.LttngSyntheticEventProvider; | |
20 | import org.eclipse.linuxtools.lttng.core.event.LttngSyntheticEvent; | |
21 | import org.eclipse.linuxtools.lttng.core.event.LttngTimestamp; | |
22 | import org.eclipse.linuxtools.lttng.core.request.ILttngSyntEventRequest; | |
23 | import org.eclipse.linuxtools.lttng.core.request.IRequestStatusListener; | |
24 | import org.eclipse.linuxtools.lttng.core.request.LttngSyntEventRequest; | |
25 | import org.eclipse.linuxtools.lttng.core.request.RequestCompletedSignal; | |
26 | import org.eclipse.linuxtools.lttng.core.request.RequestStartedSignal; | |
27 | import org.eclipse.linuxtools.lttng.core.state.evProcessor.ITransEventProcessor; | |
6e512b93 | 28 | import org.eclipse.linuxtools.lttng.ui.TraceDebug; |
8827c197 | 29 | import org.eclipse.linuxtools.lttng.ui.model.trange.ItemContainer; |
4df4581d | 30 | import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; |
6c13869b FC |
31 | import org.eclipse.linuxtools.tmf.core.event.TmfEvent; |
32 | import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange; | |
33 | import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; | |
34 | import org.eclipse.linuxtools.tmf.core.experiment.TmfExperiment; | |
6c13869b | 35 | import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest.ExecutionType; |
4df4581d | 36 | import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest; |
6c13869b FC |
37 | import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentDisposedSignal; |
38 | import org.eclipse.linuxtools.tmf.core.signal.TmfRangeSynchSignal; | |
39 | import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler; | |
40 | import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager; | |
41 | import org.eclipse.linuxtools.tmf.core.signal.TmfTimeSynchSignal; | |
8827c197 FC |
42 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.ITimeAnalysisViewer; |
43 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.TmfTimeScaleSelectionEvent; | |
44 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.TmfTimeSelectionEvent; | |
45 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.ITmfTimeAnalysisEntry; | |
6e512b93 | 46 | import org.eclipse.linuxtools.tmf.ui.views.TmfView; |
8827c197 | 47 | import org.eclipse.swt.widgets.Display; |
6e512b93 ASL |
48 | |
49 | /** | |
50 | * <p> | |
51 | * Abstract class used as a base for views handling specific time range data | |
52 | * requests | |
53 | * </p> | |
54 | * <p> | |
8827c197 FC |
55 | * The class handles a single element queue of data requests, i.e. request can |
56 | * be triggered from different sources e.g. opening a file as well as a new | |
57 | * selected time window | |
6e512b93 ASL |
58 | * </p> |
59 | * | |
60 | * @author alvaro | |
61 | * | |
62 | */ | |
c1c69938 | 63 | public abstract class AbsTimeUpdateView extends TmfView implements IRequestStatusListener { |
6e512b93 ASL |
64 | |
65 | // ======================================================================== | |
66 | // Data | |
67 | // ======================================================================== | |
777ead16 | 68 | |
0c2a2e08 FC |
69 | // private static final long INITIAL_WINDOW_OFFSET = (1L * 1 * 1000 * 1000); // .001sec |
70 | // private static final long INITIAL_WINDOW_OFFSET = (1L * 10 * 1000 * 1000); // .01sec | |
71 | private static final long INITIAL_WINDOW_OFFSET = (1L * 100 * 1000 * 1000); // .1sec | |
72 | // private static final long INITIAL_WINDOW_OFFSET = (1L * 1000 * 1000 * 1000); // 1sec | |
777ead16 | 73 | |
8827c197 FC |
74 | /** |
75 | * Number of events before a GUI refresh | |
76 | */ | |
b12f4544 | 77 | protected static final Long INPUT_CHANGED_REFRESH = 75000L; |
a79913eb | 78 | private static final long DEFAULT_OFFSET = 0; |
8827c197 | 79 | |
0c2a2e08 | 80 | protected boolean synch = true; // time synchronization, used to be an option |
8827c197 | 81 | protected ITimeAnalysisViewer tsfviewer = null; |
6e512b93 | 82 | |
cb866e08 FC |
83 | private LttngSyntEventRequest fCurrentRequest = null; |
84 | ||
c1c69938 FC |
85 | protected LttngSyntheticEventProvider fProvider = LttngCoreProviderFactory.getEventProvider(getProviderId()); |
86 | ||
87 | // ======================================================================== | |
6e512b93 ASL |
88 | // Constructor |
89 | // ======================================================================== | |
90 | public AbsTimeUpdateView(String viewID) { | |
8827c197 FC |
91 | super(viewID); |
92 | // freqState = UiCommonFactory.getQueue(this); | |
6e512b93 ASL |
93 | } |
94 | ||
95 | // ======================================================================== | |
96 | // Methods | |
97 | // ======================================================================== | |
c1c69938 FC |
98 | |
99 | /** | |
100 | * Returns the number of events after which the relevant display will | |
101 | * be refreshed | |
102 | * | |
103 | * @return | |
104 | */ | |
105 | protected Long getInputChangedRefresh() { | |
106 | return INPUT_CHANGED_REFRESH; | |
107 | } | |
108 | ||
90de83da BH |
109 | /** |
110 | * Cancel the ongoing request if another experiment is being selected | |
111 | * @param experimentDisposedSignal | |
112 | */ | |
113 | @TmfSignalHandler | |
114 | public void experimentDisposed(TmfExperimentDisposedSignal<? extends TmfEvent> experimentDisposedSignal) { | |
828e5592 PT |
115 | if (experimentDisposedSignal.getExperiment() != TmfExperiment.getCurrentExperiment()) { |
116 | return; | |
117 | } | |
90de83da BH |
118 | fProvider.conditionallyCancelRequests(); |
119 | } | |
120 | ||
6e512b93 ASL |
121 | /* |
122 | * (non-Javadoc) | |
123 | * | |
124 | * @seeorg.eclipse.linuxtools.lttng.state.IStateDataRequestListener# | |
125 | * processingStarted(org.eclipse.linuxtools.lttng.state.StateDataRequest) | |
126 | */ | |
d4011df2 | 127 | @Override |
6e512b93 ASL |
128 | @TmfSignalHandler |
129 | public synchronized void processingStarted(RequestStartedSignal signal) { | |
8827c197 | 130 | LttngSyntEventRequest request = signal.getRequest(); |
6e512b93 | 131 | if (request != null) { |
8827c197 FC |
132 | // update queue with the id of the current request. |
133 | // freqState.requestStarted(request); | |
134 | ||
135 | // if there was no new request then this one is still on | |
136 | // prepare for the reception of new data | |
137 | waitCursor(true); | |
138 | ||
139 | // no new time range for zoom orders | |
140 | TmfTimeRange trange = null; | |
141 | // Time Range will be used to filter out events which are | |
142 | // not visible in one pixel | |
143 | trange = request.getRange(); | |
144 | ||
145 | // indicate if the data model needs to be cleared e.g. a new | |
146 | // experiment is being selected | |
147 | boolean clearData = request.isclearDataInd(); | |
148 | // Indicate if current data needs to be cleared and if so | |
149 | // specify the new experiment time range that applies | |
150 | ModelUpdatePrep(trange, clearData); | |
6e512b93 ASL |
151 | } |
152 | } | |
153 | ||
154 | /* | |
155 | * (non-Javadoc) | |
156 | * | |
157 | * @seeorg.eclipse.linuxtools.lttng.state.IStateDataRequestListener# | |
158 | * processingCompleted(org.eclipse.linuxtools.lttng.state.StateDataRequest) | |
159 | */ | |
d4011df2 | 160 | @Override |
6e512b93 | 161 | @TmfSignalHandler |
8827c197 FC |
162 | public void processingCompleted(RequestCompletedSignal signal) { |
163 | ILttngSyntEventRequest request = signal.getRequest(); | |
6e512b93 ASL |
164 | |
165 | if (request == null) { | |
166 | return; | |
8035003b | 167 | } |
6e512b93 | 168 | |
8827c197 FC |
169 | // Update wait cursor |
170 | waitCursor(false); | |
171 | ||
6e512b93 ASL |
172 | // No data refresh actions for cancelled requests. |
173 | if (request.isCancelled() || request.isFailed()) { | |
174 | if (TraceDebug.isDEBUG()) { | |
175 | TmfTimeRange trange = request.getRange(); | |
176 | if (request.isCancelled()) { | |
3b38ea61 FC |
177 | TraceDebug.debug("Request cancelled " //$NON-NLS-1$ |
178 | + trange.getStartTime() + "-" + trange.getEndTime() //$NON-NLS-1$ | |
179 | + " Handled Events: " + request.getSynEventCount() //$NON-NLS-1$ | |
180 | + " " + request.toString(), 15); //$NON-NLS-1$ | |
6e512b93 | 181 | } else if (request.isFailed()) { |
3b38ea61 FC |
182 | TraceDebug.debug("Request Failed " + trange.getStartTime() //$NON-NLS-1$ |
183 | + "-" + trange.getEndTime() + " Handled Events: " //$NON-NLS-1$ //$NON-NLS-2$ | |
184 | + request.getSynEventCount() + " " //$NON-NLS-1$ | |
8827c197 | 185 | + request.toString()); |
6e512b93 ASL |
186 | } |
187 | } | |
188 | ||
189 | return; | |
190 | } else { | |
8827c197 | 191 | modelInputChanged(request, true); |
6e512b93 ASL |
192 | } |
193 | } | |
194 | ||
195 | /** | |
8827c197 | 196 | * Registers as listener of time selection from other views |
6e512b93 | 197 | * |
8827c197 | 198 | * @param signal |
6e512b93 | 199 | */ |
8827c197 FC |
200 | public void synchToTime(TmfTimeSynchSignal signal) { |
201 | if (synch) { | |
202 | Object source = signal.getSource(); | |
203 | if (signal != null && source != null && source != this) { | |
de7ddc02 BH |
204 | |
205 | if ((tsfviewer != null) && (!tsfviewer.getControl().isDisposed())) { | |
206 | ||
207 | // Check for GUI thread | |
208 | if (Display.getCurrent() != null) { | |
209 | // GUI thread - execute update right away. | |
210 | ||
211 | // Internal value is expected in nano seconds. | |
212 | long selectedTime = signal.getCurrentTime().getValue(); | |
213 | if (tsfviewer != null) { | |
214 | tsfviewer.setSelectedTime(selectedTime, true, source); | |
215 | ||
216 | ParamsUpdater paramUpdater = getParamsUpdater(); | |
217 | Long savedSelTime = paramUpdater.getSelectedTime(); | |
218 | if ((savedSelTime == null) || (savedSelTime != selectedTime)) { | |
219 | // Update the parameter updater to save the selected time | |
220 | paramUpdater.setSelectedTime(selectedTime); | |
221 | } | |
222 | } | |
223 | } else { | |
224 | // Perform the updates on the UI thread | |
225 | ||
226 | // We need to clone the timestamp in the signal so that it won't be overwritten duo to multipe thread access | |
227 | final TmfTimeSynchSignal savedSignal = new TmfTimeSynchSignal(signal.getSource(), signal.getCurrentTime().clone()); | |
228 | tsfviewer.getControl().getDisplay().asyncExec(new Runnable() { | |
229 | @Override | |
230 | public void run() { | |
231 | if ((tsfviewer != null) && (!tsfviewer.getControl().isDisposed())) { | |
232 | synchToTime(savedSignal); | |
233 | } | |
234 | } | |
235 | }); | |
236 | } | |
41dc35d0 | 237 | } |
8827c197 FC |
238 | } |
239 | } | |
240 | } | |
241 | ||
242 | /** | |
243 | * Process the reception of time window adjustment in this view if the | |
244 | * source of the update is not this view. | |
245 | * | |
246 | * @param signal | |
247 | * @param clearingData | |
248 | */ | |
249 | public void synchToTimeRange(TmfRangeSynchSignal signal, boolean clearingData) { | |
250 | if (synch) { | |
251 | Object source = signal.getSource(); | |
252 | if (signal != null && source != null && source != this) { | |
253 | // Internal value is expected in nano seconds. | |
254 | TmfTimeRange trange = signal.getCurrentRange(); | |
255 | TmfExperiment<?> experiment = TmfExperiment.getCurrentExperiment(); | |
256 | if (experiment == null) { | |
3b38ea61 | 257 | TraceDebug.debug("Current selected experiment is null"); //$NON-NLS-1$ |
8827c197 | 258 | return; |
63eecb47 | 259 | } |
6e512b93 | 260 | |
8827c197 | 261 | // Clearing of process data is configurable |
a79913eb | 262 | eventRequest(trange, experiment.getTimeRange(), clearingData, ExecutionType.FOREGROUND); |
41dc35d0 | 263 | } |
6e512b93 ASL |
264 | } |
265 | } | |
266 | ||
267 | /** | |
8827c197 FC |
268 | * Trigger time synchronisation to other views this method shall be called |
269 | * when a check has been performed to note that an actual change of time has | |
270 | * been performed vs a pure re-selection of the same time | |
271 | * | |
272 | * @param time | |
273 | * @param source | |
6e512b93 | 274 | */ |
8827c197 FC |
275 | protected void synchTimeNotification(long time, Object source) { |
276 | // if synchronisation selected | |
277 | if (synch) { | |
278 | // Notify other views | |
279 | TmfSignalManager.dispatchSignal(new TmfTimeSynchSignal(source, new LttngTimestamp(time))); | |
280 | } | |
281 | } | |
282 | ||
283 | /** | |
284 | * Common implementation of ITmfTimeSelectionListener, not used by all the | |
285 | * views extending this abstract class | |
286 | * | |
287 | * @param event | |
288 | */ | |
289 | protected void tsfTmProcessSelEvent(TmfTimeSelectionEvent event) { | |
290 | Object source = event.getSource(); | |
291 | if (source == null) { | |
292 | return; | |
293 | } | |
294 | ||
295 | ParamsUpdater paramUpdater = getParamsUpdater(); | |
296 | Long savedSelTime = paramUpdater.getSelectedTime(); | |
297 | ||
298 | long selTimens = event.getSelectedTime(); | |
299 | ||
300 | // make sure the new selected time is different than saved before | |
301 | // executing update | |
302 | if (savedSelTime == null || savedSelTime != selTimens) { | |
303 | // Notify listener views. | |
304 | synchTimeNotification(selTimens, source); | |
305 | ||
306 | // Update the parameter updater to save the selected time | |
307 | paramUpdater.setSelectedTime(selTimens); | |
308 | ||
63eecb47 | 309 | if (TraceDebug.isDEBUG()) { |
3b38ea61 | 310 | TraceDebug.debug("Selected Time: " + new LttngTimestamp(selTimens) + "\n\t\t" + getName()); //$NON-NLS-1$ //$NON-NLS-2$ |
63eecb47 | 311 | } |
8827c197 FC |
312 | } |
313 | } | |
63eecb47 | 314 | |
8827c197 FC |
315 | /** |
316 | * Common implementation of ITmfTimeScaleSelectionListener, not used by all | |
317 | * the views extending this abstract class | |
318 | * | |
319 | * @param event | |
320 | */ | |
c1c69938 FC |
321 | protected void tsfTmProcessTimeScaleEvent(TmfTimeScaleSelectionEvent event) { |
322 | // source needed to keep track of source values | |
323 | Object source = event.getSource(); | |
324 | ||
325 | boolean newParams = false; | |
326 | TmfTimeRange trange = null; | |
327 | Long selectedTime = null; | |
328 | ||
329 | // update all information and get relevant data | |
330 | synchronized (this) { | |
331 | if (source != null) { | |
332 | // Update the parameter updater before carrying out a read request | |
333 | ParamsUpdater paramUpdater = getParamsUpdater(); | |
334 | newParams = paramUpdater.processTimeScaleEvent(event); | |
335 | ||
336 | if (newParams) { | |
337 | // Read the updated time window | |
338 | trange = paramUpdater.getTrange(); | |
339 | if (trange != null) { | |
340 | selectedTime = paramUpdater.getSelectedTime(); | |
341 | } | |
342 | } | |
343 | } | |
344 | } | |
345 | ||
346 | // Check for selectedTime is sufficient since it is only set if | |
347 | // newParams is true and trange is not null | |
348 | if (selectedTime != null) { | |
349 | // Notify listener views. to perform data requests | |
350 | // upon this notification | |
351 | ||
352 | // Note that this has to be done outside the synchronized statement | |
353 | // because otherwise we could end-up in a deadlock if a ongoing | |
354 | // request needs to be canceled. | |
355 | synchTimeRangeNotification(trange, selectedTime, source); | |
8827c197 FC |
356 | } |
357 | } | |
358 | ||
359 | /** | |
360 | * Inform registered listeners about the new time range | |
361 | * | |
362 | * @param trange | |
363 | * @param selectedTime | |
364 | * @param source | |
365 | */ | |
366 | protected void synchTimeRangeNotification(TmfTimeRange trange, Long selectedTime, Object source) { | |
367 | // if synchronisation selected | |
368 | if (synch) { | |
369 | // Notify other views | |
370 | TmfSignalManager.dispatchSignal(new TmfRangeSynchSignal(source, trange, new LttngTimestamp(selectedTime))); | |
371 | } | |
372 | } | |
373 | ||
374 | /** | |
375 | * @param zoomedTRange | |
376 | * @param experimentTRange | |
a79913eb FC |
377 | * @param clearingData |
378 | * @param execType | |
379 | */ | |
380 | public void eventRequest(TmfTimeRange zoomedTRange, TmfTimeRange experimentTRange, boolean clearingData, ExecutionType execType) { | |
381 | ||
382 | // timeRange is the Experiment time range | |
383 | boolean sent = processDataRequest(zoomedTRange, experimentTRange, DEFAULT_OFFSET, TmfDataRequest.ALL_DATA, clearingData, execType); | |
384 | ||
385 | if (sent) { | |
386 | waitCursor(true); | |
387 | } | |
388 | } | |
389 | ||
390 | /** | |
391 | * @param offset | |
392 | * @param nbRequested | |
393 | * @param startTime | |
394 | * @param clearingData | |
9b635e61 | 395 | * @param execType |
8827c197 | 396 | */ |
a79913eb | 397 | public void eventRequest(long offset, TmfTimeRange range, boolean clearingData, ExecutionType execType) { |
8827c197 FC |
398 | |
399 | // timeRange is the Experiment time range | |
a79913eb | 400 | boolean sent = processDataRequest(range, null, offset, TmfDataRequest.ALL_DATA, clearingData, execType); |
8827c197 FC |
401 | |
402 | if (sent) { | |
403 | waitCursor(true); | |
404 | } | |
405 | } | |
406 | ||
9b635e61 FC |
407 | // /** |
408 | // * @param zoomedTRange | |
409 | // * @param experimentTRange | |
410 | // * @param execType | |
411 | // */ | |
412 | // public void dataRequest(TmfTimeRange zoomedTRange, | |
413 | // TmfTimeRange experimentTRange, boolean clearingData) { | |
414 | // | |
415 | // // timeRange is the Experiment time range | |
416 | // boolean sent = processDataRequest(zoomedTRange, experimentTRange, clearingData); | |
417 | // | |
418 | // if (sent) { | |
419 | // waitCursor(true); | |
420 | // } | |
421 | // } | |
422 | ||
8827c197 FC |
423 | /** |
424 | * send data request directly e.g. doesn't use a queue | |
425 | * | |
426 | * @param requestTrange | |
427 | * @param listener | |
428 | * @param experimentTRange | |
9b635e61 | 429 | * @param execType |
8827c197 FC |
430 | * @param processor |
431 | * @return | |
432 | */ | |
433 | private boolean processDataRequest(TmfTimeRange requestTrange, | |
a79913eb | 434 | TmfTimeRange experimentTRange, long offset, int nbRequested, boolean clearingData, ExecutionType execType) { |
8827c197 | 435 | // Validate input |
a79913eb | 436 | if (requestTrange == null) { |
3b38ea61 | 437 | TraceDebug.debug("Invalid input"); //$NON-NLS-1$ |
8827c197 FC |
438 | return false; |
439 | } | |
440 | ||
cb866e08 | 441 | // Cancel the currently executing request before starting a new one |
c1c69938 | 442 | fProvider.conditionallyCancelRequests(); |
cb866e08 | 443 | fCurrentRequest = new LttngSyntEventRequest( |
a79913eb | 444 | requestTrange, offset, nbRequested, |
8016d660 | 445 | LttngConstants.DEFAULT_BLOCK_SIZE, this, experimentTRange, getEventProcessor(), |
c1c69938 | 446 | TmfExperiment.getCurrentExperiment().getName(), execType) { |
8827c197 FC |
447 | |
448 | Long fCount = getSynEventCount(); | |
449 | ITransEventProcessor processor = getProcessor(); | |
4df4581d | 450 | ITmfTimestamp frunningTimeStamp; |
8827c197 FC |
451 | |
452 | /* | |
453 | * (non-Javadoc) | |
454 | * | |
455 | * @see | |
456 | * org.eclipse.linuxtools.lttng.request.LttngSyntEventRequest#handleData | |
457 | * () | |
458 | */ | |
f9673903 FC |
459 | //// int handleDataCount = 0; |
460 | //// int handleDataValidCount = 0; | |
461 | // @Override | |
462 | // public void handleData() { | |
463 | // LttngSyntheticEvent[] result = getData(); | |
464 | // | |
465 | // TmfEvent evt = (result.length > 0) ? result[0] : null; | |
466 | //// handleDataCount++; | |
467 | ||
550d787e | 468 | @Override |
f9673903 FC |
469 | public void handleData(LttngSyntheticEvent event) { |
470 | super.handleData(event); | |
471 | if (event != null) { | |
cb866e08 | 472 | // handleDataValidCount++; |
f9673903 | 473 | LttngSyntheticEvent synEvent = (LttngSyntheticEvent) event; |
8827c197 | 474 | // process event |
c1c69938 FC |
475 | switch (synEvent.getSynType()) { |
476 | ||
477 | case STARTREQ: { | |
478 | handleRequestStarted(); | |
479 | break; | |
480 | } | |
481 | ||
482 | case BEFORE: { | |
483 | processor.process(event, synEvent.getTraceModel()); | |
484 | fCount++; | |
485 | if ((fCount != 0) && (fCount % getInputChangedRefresh() == 0)) { | |
486 | // send partial update | |
487 | modelInputChanged(this, false); | |
488 | ||
489 | if (TraceDebug.isDEBUG()) { | |
490 | frunningTimeStamp = event.getTimestamp(); | |
3b38ea61 | 491 | TraceDebug.debug("handled: " + fCount + " sequence: " + synEvent.getSynType()); //$NON-NLS-1$ //$NON-NLS-2$ |
c1c69938 FC |
492 | } |
493 | } | |
494 | break; | |
495 | } | |
496 | ||
497 | case AFTER: | |
498 | // fall-through | |
499 | case ENDREQ:{ | |
500 | processor.process(event, synEvent.getTraceModel()); | |
501 | break; | |
502 | } | |
503 | ||
504 | default: | |
505 | // nothing to do | |
506 | break; | |
507 | } | |
8827c197 FC |
508 | } |
509 | } | |
510 | ||
511 | public void handleRequestStarted() { | |
512 | notifyStarting(); | |
513 | } | |
550d787e FC |
514 | |
515 | @Override | |
516 | public void done() { | |
cb866e08 FC |
517 | // if (TraceDebug.isDEBUG()) { |
518 | // TraceDebug.debug("AbsTimeUpdateView: Received=" + handleDataCount + ", Valid=" + handleDataCount + ", fCount=" + fCount); | |
519 | // } | |
550d787e FC |
520 | super.done(); |
521 | } | |
8827c197 | 522 | |
550d787e | 523 | @Override |
8827c197 FC |
524 | public void handleCompleted() { |
525 | super.handleCompleted(); | |
526 | ||
527 | // Data is not complete and should be handled as such | |
528 | if (isFailed() || isCancelled()) { | |
529 | modelIncomplete(this); | |
530 | } | |
531 | ||
532 | if (TraceDebug.isDEBUG()) { | |
533 | if (frunningTimeStamp != null) { | |
3b38ea61 | 534 | TraceDebug.debug("Last event time stamp: " + frunningTimeStamp.getValue()); //$NON-NLS-1$ |
8827c197 FC |
535 | } |
536 | } | |
537 | } | |
538 | }; | |
539 | ||
8827c197 | 540 | // send the request to TMF |
c1c69938 | 541 | fCurrentRequest.startRequestInd(fProvider); |
cb866e08 | 542 | fCurrentRequest.setclearDataInd(clearingData); |
8827c197 FC |
543 | return true; |
544 | } | |
545 | ||
546 | /** | |
547 | * Returns an initial smaller window to allow the user to select the area of | |
548 | * interest | |
549 | * | |
550 | * @param experimentTRange | |
551 | * @return | |
552 | */ | |
553 | protected TmfTimeRange getInitTRange(TmfTimeRange experimentTRange) { | |
4df4581d | 554 | ITmfTimestamp expStartTime = experimentTRange.getStartTime(); |
555 | ITmfTimestamp expEndTime = experimentTRange.getEndTime(); | |
d7dbf09a | 556 | ITmfTimestamp initialEndOfWindow = new LttngTimestamp(expStartTime |
8827c197 FC |
557 | .getValue() |
558 | + INITIAL_WINDOW_OFFSET); | |
559 | if (initialEndOfWindow.compareTo(expEndTime, false) < 0) { | |
560 | return new TmfTimeRange(expStartTime, initialEndOfWindow); | |
6e512b93 | 561 | } |
8827c197 FC |
562 | |
563 | // The original size of the experiment is smaller than proposed adjusted | |
564 | // time | |
565 | return experimentTRange; | |
6e512b93 ASL |
566 | } |
567 | ||
568 | /** | |
569 | * Request the Time Analysis widget to enable or disable the wait cursor | |
570 | * e.g. data request in progress or data request completed | |
571 | * | |
572 | * @param waitInd | |
573 | */ | |
8827c197 | 574 | protected void waitCursor(final boolean waitInd) { |
db1ea19b | 575 | if ((tsfviewer != null) && (!tsfviewer.getControl().isDisposed())) { |
8827c197 FC |
576 | Display display = tsfviewer.getControl().getDisplay(); |
577 | ||
578 | // Perform the updates on the UI thread | |
579 | display.asyncExec(new Runnable() { | |
d4011df2 | 580 | @Override |
8827c197 | 581 | public void run() { |
db1ea19b FC |
582 | if ((tsfviewer != null) && (!tsfviewer.getControl().isDisposed())) { |
583 | tsfviewer.waitCursor(waitInd); | |
584 | } | |
8827c197 FC |
585 | } |
586 | }); | |
587 | } | |
588 | } | |
6e512b93 ASL |
589 | |
590 | /** | |
8827c197 | 591 | * View preparation to override the current local information |
6e512b93 | 592 | * |
d712a5f3 FC |
593 | * @param timeRange |
594 | * - new total time range e.g. Experiment level | |
8827c197 FC |
595 | * @param clearAllData |
596 | */ | |
597 | protected void ModelUpdatePrep(TmfTimeRange timeRange, boolean clearAllData) { | |
598 | ItemContainer<?> itemContainer = getItemContainer(); | |
599 | if (clearAllData) { | |
600 | // start fresh e.g. new experiment selected | |
601 | itemContainer.clearItems(); | |
602 | } else { | |
603 | // clear children but keep processes | |
604 | itemContainer.clearChildren(); | |
605 | } | |
606 | ||
607 | // Obtain the current resource array | |
608 | ITmfTimeAnalysisEntry[] itemArr = itemContainer.readItems(); | |
609 | ||
610 | // clean up data and boundaries | |
611 | displayModel(itemArr, -1, -1, false, -1, -1, null); | |
612 | ||
613 | ParamsUpdater updater = getParamsUpdater(); | |
614 | if (updater != null) { | |
615 | // Start over | |
616 | updater.setEventsDiscarded(0); | |
617 | ||
618 | // Update new visible time range if available | |
619 | if (timeRange != null) { | |
620 | updater.update(timeRange.getStartTime().getValue(), timeRange.getEndTime().getValue()); | |
621 | } | |
622 | } | |
623 | } | |
624 | ||
625 | /** | |
626 | * Initialize the model and view before reloading items | |
627 | * | |
628 | * @param boundaryRange | |
629 | * @param visibleRange | |
630 | * @param source | |
6e512b93 | 631 | */ |
8827c197 FC |
632 | protected void ModelUpdateInit(TmfTimeRange boundaryRange, TmfTimeRange visibleRange, Object source) { |
633 | // Update the view boundaries | |
634 | if (boundaryRange != null) { | |
635 | ItemContainer<?> itemContainer = getItemContainer(); | |
636 | if (itemContainer != null) { | |
637 | itemContainer.clearItems(); | |
638 | // Obtain the current process array | |
639 | ITmfTimeAnalysisEntry[] itemArr = itemContainer.readItems(); | |
640 | ||
641 | long startTime = boundaryRange.getStartTime().getValue(); | |
642 | long endTime = boundaryRange.getEndTime().getValue(); | |
643 | ||
644 | // Update the view part | |
645 | displayModel(itemArr, startTime, endTime, true, visibleRange.getStartTime().getValue(), visibleRange | |
646 | .getEndTime().getValue(), source); | |
647 | } | |
648 | } | |
649 | ||
650 | // update the view filtering parameters | |
651 | if (visibleRange != null) { | |
652 | ParamsUpdater updater = getParamsUpdater(); | |
653 | if (updater != null) { | |
654 | // Start over | |
655 | updater.setEventsDiscarded(0); | |
656 | // Update new visible time range if available | |
657 | updater.update(visibleRange.getStartTime().getValue(), visibleRange.getEndTime().getValue()); | |
658 | } | |
659 | } | |
660 | } | |
6e512b93 ASL |
661 | |
662 | /** | |
663 | * Actions taken by the view to refresh its widget(s) with the updated data | |
664 | * model | |
665 | * | |
666 | * @param request | |
8827c197 FC |
667 | * @param complete |
668 | * true: yes, false: partial update | |
669 | */ | |
a79913eb | 670 | @SuppressWarnings("deprecation") |
8827c197 FC |
671 | protected void modelInputChanged(ILttngSyntEventRequest request, boolean complete) { |
672 | long experimentStartTime = -1; | |
673 | long experimentEndTime = -1; | |
674 | TmfTimeRange experimentTimeRange = request.getExperimentTimeRange(); | |
675 | if (experimentTimeRange != null) { | |
676 | experimentStartTime = experimentTimeRange.getStartTime().getValue(); | |
677 | experimentEndTime = experimentTimeRange.getEndTime().getValue(); | |
678 | } | |
679 | ||
680 | // Obtain the current resource list | |
681 | ITmfTimeAnalysisEntry[] itemArr = getItemContainer().readItems(); | |
682 | ||
683 | if (itemArr != null) { | |
684 | // Sort the array by pid | |
685 | Arrays.sort(itemArr); | |
686 | ||
687 | // Update the view part | |
688 | displayModel(itemArr, experimentStartTime, experimentEndTime, false, request.getRange().getStartTime() | |
689 | .getValue(), request.getRange().getEndTime().getValue(), request.getSource()); | |
690 | } | |
691 | ||
692 | if (complete) { | |
693 | // reselect to original time | |
5dbe4d3b | 694 | ParamsUpdater paramUpdater = getParamsUpdater(); |
db1ea19b | 695 | if ((paramUpdater != null) && (tsfviewer != null) && (!tsfviewer.getControl().isDisposed())) { |
8827c197 FC |
696 | final Long selTime = paramUpdater.getSelectedTime(); |
697 | if (selTime != null) { | |
3b38ea61 | 698 | TraceDebug.debug("View: " + getName() + "\n\t\tRestoring the selected time to: " + selTime); //$NON-NLS-1$ //$NON-NLS-2$ |
8827c197 FC |
699 | Display display = tsfviewer.getControl().getDisplay(); |
700 | display.asyncExec(new Runnable() { | |
d4011df2 | 701 | @Override |
8827c197 | 702 | public void run() { |
db1ea19b FC |
703 | if ((tsfviewer != null) && (!tsfviewer.getControl().isDisposed())) { |
704 | tsfviewer.setSelectedTime(selTime, false, this); | |
705 | } | |
8827c197 FC |
706 | } |
707 | }); | |
708 | } | |
709 | ||
9b635e61 FC |
710 | // System.out.println(System.currentTimeMillis() + ": AbsTimeUpdate (" + getName() + ") completed"); |
711 | ||
8827c197 FC |
712 | if (TraceDebug.isDEBUG()) { |
713 | int eventCount = 0; | |
714 | Long count = request.getSynEventCount(); | |
715 | for (int pos = 0; pos < itemArr.length; pos++) { | |
716 | eventCount += itemArr[pos].getTraceEvents().size(); | |
717 | } | |
718 | ||
5dbe4d3b | 719 | int discarded = paramUpdater.getEventsDiscarded(); |
8827c197 | 720 | int discardedOutofOrder = paramUpdater.getEventsDiscardedWrongOrder(); |
5dbe4d3b ASL |
721 | int discardedOutofViewRange = paramUpdater.getEventsDiscardedOutOfViewRange(); |
722 | int dicardedNotVisible = paramUpdater.getEventsDiscardedNotVisible(); | |
723 | ||
8827c197 | 724 | TmfTimeRange range = request.getRange(); |
3b38ea61 FC |
725 | StringBuilder sb = new StringBuilder("View: " + getName() + ", Events handled: " + count //$NON-NLS-1$ //$NON-NLS-2$ |
726 | + ", Events loaded in view: " + eventCount + ", Number of events discarded: " + discarded //$NON-NLS-1$ //$NON-NLS-2$ | |
727 | + "\n\tNumber of events discarded with start time earlier than next good time: " //$NON-NLS-1$ | |
728 | + discardedOutofOrder + "\n\tDiscarded Not visible: " + dicardedNotVisible //$NON-NLS-1$ | |
729 | + "\n\tDiscarded out of view Range: " + discardedOutofViewRange); //$NON-NLS-1$ | |
730 | ||
731 | sb.append("\n\t\tRequested Time Range: " + range.getStartTime() + "-" + range.getEndTime()); //$NON-NLS-1$ //$NON-NLS-2$ | |
732 | sb.append("\n\t\tExperiment Time Range: " + experimentStartTime + "-" + experimentEndTime); //$NON-NLS-1$ //$NON-NLS-2$ | |
8827c197 FC |
733 | TraceDebug.debug(sb.toString()); |
734 | } | |
735 | } | |
736 | ||
737 | } | |
738 | } | |
739 | ||
740 | // /** | |
741 | // * Obtains the remainder fraction on unit Seconds of the entered value in | |
742 | // * nanoseconds. e.g. input: 1241207054171080214 ns The number of seconds | |
743 | // can | |
744 | // * be obtain by removing the last 9 digits: 1241207054 the fractional | |
745 | // * portion of seconds, expressed in ns is: 171080214 | |
746 | // * | |
747 | // * @param v | |
748 | // * @return | |
749 | // */ | |
750 | // protected String formatNs(long v) { | |
751 | // StringBuffer str = new StringBuffer(); | |
752 | // boolean neg = v < 0; | |
753 | // if (neg) { | |
754 | // v = -v; | |
755 | // str.append('-'); | |
756 | // } | |
757 | // | |
758 | // String strVal = String.valueOf(v); | |
759 | // if (v < 1000000000) { | |
760 | // return strVal; | |
761 | // } | |
762 | // | |
763 | // // Extract the last nine digits (e.g. fraction of a S expressed in ns | |
764 | // return strVal.substring(strVal.length() - 9); | |
765 | // } | |
766 | ||
767 | /** | |
768 | * The request was stopped, the data is incomplete | |
769 | * | |
770 | * @param request | |
771 | */ | |
772 | protected abstract void modelIncomplete(ILttngSyntEventRequest request); | |
773 | ||
774 | /** | |
775 | * Returns the Event processor instance related to a specific view | |
776 | * | |
777 | * @return | |
778 | */ | |
779 | protected abstract ITransEventProcessor getEventProcessor(); | |
780 | ||
781 | /** | |
782 | * To be overridden by some sub-classes although may not be needed in some | |
783 | * e.g. statistics view | |
784 | * | |
785 | * @param items | |
786 | * @param startBoundTime | |
787 | * @param endBoundTime | |
788 | * @param updateTimeBounds | |
789 | * - Time bounds updated needed e.g. if a new Experiment or trace | |
790 | * is selected | |
791 | * @param startVisibleWindow | |
792 | * @param endVisibleWindow | |
793 | * @param source | |
794 | */ | |
795 | protected abstract void displayModel(final ITmfTimeAnalysisEntry[] items, final long startBoundTime, | |
796 | final long endBoundTime, final boolean updateTimeBounds, final long startVisibleWindow, | |
797 | final long endVisibleWindow, final Object source); | |
798 | ||
799 | /** | |
800 | * To be overridden by some sub-classes although may not be needed in some | |
801 | * e.g. statistics view | |
802 | * | |
803 | * @return | |
804 | */ | |
805 | protected abstract ParamsUpdater getParamsUpdater(); | |
806 | ||
807 | /** | |
808 | * Returns the model's item container | |
809 | * | |
810 | * @return | |
6e512b93 | 811 | */ |
8827c197 | 812 | protected abstract ItemContainer<?> getItemContainer(); |
c1c69938 FC |
813 | |
814 | /** | |
815 | * Returns LTTng Synthetic Provider ID used for current view | |
816 | * | |
817 | * @return | |
818 | */ | |
819 | protected abstract int getProviderId(); | |
6e512b93 | 820 | } |