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