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