lttng: Javadoc udpate for the lttng2.kernel.ui package
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.kernel.ui / src / org / eclipse / linuxtools / internal / lttng2 / kernel / ui / views / controlflow / ControlFlowView.java
1 /*******************************************************************************
2 * Copyright (c) 2012 Ericsson
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 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.controlflow;
14
15 import java.util.ArrayList;
16 import java.util.Arrays;
17 import java.util.Collections;
18 import java.util.Comparator;
19 import java.util.List;
20
21 import org.eclipse.core.runtime.IProgressMonitor;
22 import org.eclipse.core.runtime.NullProgressMonitor;
23 import org.eclipse.jface.action.Action;
24 import org.eclipse.jface.action.IToolBarManager;
25 import org.eclipse.jface.action.Separator;
26 import org.eclipse.jface.viewers.ILabelProviderListener;
27 import org.eclipse.jface.viewers.ITableLabelProvider;
28 import org.eclipse.jface.viewers.ITreeContentProvider;
29 import org.eclipse.jface.viewers.Viewer;
30 import org.eclipse.linuxtools.internal.lttng2.kernel.core.Attributes;
31 import org.eclipse.linuxtools.internal.lttng2.kernel.ui.Messages;
32 import org.eclipse.linuxtools.lttng2.kernel.core.trace.CtfKernelTrace;
33 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTimestamp;
34 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
35 import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
36 import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
37 import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;
38 import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException;
39 import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException;
40 import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval;
41 import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentSelectedSignal;
42 import org.eclipse.linuxtools.tmf.core.signal.TmfRangeSynchSignal;
43 import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
44 import org.eclipse.linuxtools.tmf.core.signal.TmfStateSystemBuildCompleted;
45 import org.eclipse.linuxtools.tmf.core.signal.TmfTimeSynchSignal;
46 import org.eclipse.linuxtools.tmf.core.statesystem.IStateSystemQuerier;
47 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
48 import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment;
49 import org.eclipse.linuxtools.tmf.ui.views.TmfView;
50 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphRangeListener;
51 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphSelectionListener;
52 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphTimeListener;
53 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphCombo;
54 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphRangeUpdateEvent;
55 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphSelectionEvent;
56 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphTimeEvent;
57 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;
58 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
59 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.TimeEvent;
60 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils;
61 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.Resolution;
62 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.TimeFormat;
63 import org.eclipse.swt.SWT;
64 import org.eclipse.swt.graphics.Image;
65 import org.eclipse.swt.widgets.Composite;
66 import org.eclipse.swt.widgets.Display;
67 import org.eclipse.swt.widgets.TreeColumn;
68 import org.eclipse.ui.IActionBars;
69
70 /**
71 * The Control Flow view main object
72 *
73 */
74 public class ControlFlowView extends TmfView {
75
76 // ------------------------------------------------------------------------
77 // Constants
78 // ------------------------------------------------------------------------
79
80 /**
81 * View ID.
82 */
83 public static final String ID = "org.eclipse.linuxtools.lttng2.kernel.ui.views.controlflow"; //$NON-NLS-1$
84
85 /**
86 * Initial time range
87 */
88 private static final long INITIAL_WINDOW_OFFSET = (1L * 100 * 1000 * 1000); // .1sec
89
90 private static final String PROCESS_COLUMN = Messages.ControlFlowView_processColumn;
91 private static final String TID_COLUMN = Messages.ControlFlowView_tidColumn;
92 private static final String PTID_COLUMN = Messages.ControlFlowView_ptidColumn;
93 private static final String BIRTH_TIME_COLUMN = Messages.ControlFlowView_birthTimeColumn;
94 private static final String TRACE_COLUMN = Messages.ControlFlowView_traceColumn;
95
96 private final String[] COLUMN_NAMES = new String[] {
97 PROCESS_COLUMN,
98 TID_COLUMN,
99 PTID_COLUMN,
100 BIRTH_TIME_COLUMN,
101 TRACE_COLUMN
102 };
103
104 // ------------------------------------------------------------------------
105 // Fields
106 // ------------------------------------------------------------------------
107
108 // The timegraph combo
109 private TimeGraphCombo fTimeGraphCombo;
110
111 // The selected experiment
112 private TmfExperiment<ITmfEvent> fSelectedExperiment;
113
114 // The timegraph entry list
115 private ArrayList<ControlFlowEntry> fEntryList;
116
117 // The time graph entry list synchronization object
118 final private Object fEntryListSyncObj = new Object();
119
120 // The start time
121 private long fStartTime;
122
123 // The end time
124 private long fEndTime;
125
126 // The display width
127 private final int fDisplayWidth;
128
129 // The zoom thread
130 private ZoomThread fZoomThread;
131
132 // The next resource action
133 private Action fNextResourceAction;
134
135 // The previous resource action
136 private Action fPreviousResourceAction;
137
138 // A comparator class
139 private final ControlFlowEntryComparator fControlFlowEntryComparator = new ControlFlowEntryComparator();
140
141 // ------------------------------------------------------------------------
142 // Classes
143 // ------------------------------------------------------------------------
144
145 private class TreeContentProvider implements ITreeContentProvider {
146
147 @Override
148 public void dispose() {
149 }
150
151 @Override
152 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
153 }
154
155 @Override
156 public Object[] getElements(Object inputElement) {
157 return (ITimeGraphEntry[]) inputElement;
158 }
159
160 @Override
161 public Object[] getChildren(Object parentElement) {
162 ITimeGraphEntry entry = (ITimeGraphEntry) parentElement;
163 return entry.getChildren();
164 }
165
166 @Override
167 public Object getParent(Object element) {
168 ITimeGraphEntry entry = (ITimeGraphEntry) element;
169 return entry.getParent();
170 }
171
172 @Override
173 public boolean hasChildren(Object element) {
174 ITimeGraphEntry entry = (ITimeGraphEntry) element;
175 return entry.hasChildren();
176 }
177
178 }
179
180 private class TreeLabelProvider implements ITableLabelProvider {
181
182 @Override
183 public void addListener(ILabelProviderListener listener) {
184 }
185
186 @Override
187 public void dispose() {
188 }
189
190 @Override
191 public boolean isLabelProperty(Object element, String property) {
192 return false;
193 }
194
195 @Override
196 public void removeListener(ILabelProviderListener listener) {
197 }
198
199 @Override
200 public Image getColumnImage(Object element, int columnIndex) {
201 return null;
202 }
203
204 @Override
205 public String getColumnText(Object element, int columnIndex) {
206 ControlFlowEntry entry = (ControlFlowEntry) element;
207 if (columnIndex == 0) {
208 return entry.getName();
209 } else if (columnIndex == 1) {
210 return Integer.toString(entry.getThreadId());
211 } else if (columnIndex == 2) {
212 if (entry.getParentThreadId() > 0) {
213 return Integer.toString(entry.getParentThreadId());
214 }
215 } else if (columnIndex == 3) {
216 return Utils.formatTime(entry.getBirthTime(), TimeFormat.ABSOLUTE, Resolution.NANOSEC);
217 } else if (columnIndex == 4) {
218 return entry.getTrace().getName();
219 }
220 return ""; //$NON-NLS-1$
221 }
222
223 }
224
225 private static class ControlFlowEntryComparator implements Comparator<ITimeGraphEntry> {
226
227 @Override
228 public int compare(ITimeGraphEntry o1, ITimeGraphEntry o2) {
229 int result = 0;
230
231 if ((o1 instanceof ControlFlowEntry) && (o2 instanceof ControlFlowEntry)) {
232 ControlFlowEntry entry1 = (ControlFlowEntry) o1;
233 ControlFlowEntry entry2 = (ControlFlowEntry) o2;
234 result = entry1.getTrace().getStartTime().compareTo(entry2.getTrace().getStartTime());
235 if (result == 0) {
236 result = entry1.getTrace().getName().compareTo(entry2.getTrace().getName());
237 }
238 if (result == 0) {
239 result = entry1.getThreadId() < entry2.getThreadId() ? -1 : entry1.getThreadId() > entry2.getThreadId() ? 1 : 0;
240 }
241 }
242
243 if (result == 0) {
244 result = o1.getStartTime() < o2.getStartTime() ? -1 : o1.getStartTime() > o2.getStartTime() ? 1 : 0;
245 }
246
247 return result;
248 }
249 }
250
251
252 private class ZoomThread extends Thread {
253 private final long fZoomStartTime;
254 private final long fZoomEndTime;
255 private final long fResolution;
256 private final IProgressMonitor fMonitor;
257
258 public ZoomThread(long startTime, long endTime) {
259 super("ControlFlowView zoom"); //$NON-NLS-1$
260 fZoomStartTime = startTime;
261 fZoomEndTime = endTime;
262 fResolution = Math.max(1, (fZoomEndTime - fZoomStartTime) / fDisplayWidth);
263 fMonitor = new NullProgressMonitor();
264 }
265
266 @Override
267 public void run() {
268 ArrayList<ControlFlowEntry> entryList = null;
269 synchronized (fEntryListSyncObj) {
270 entryList = fEntryList;
271 }
272 if (entryList == null) {
273 return;
274 }
275 for (ControlFlowEntry entry : entryList) {
276 if (fMonitor.isCanceled()) {
277 break;
278 }
279 zoom(entry, fMonitor);
280 }
281 redraw();
282 }
283
284 private void zoom(ControlFlowEntry entry, IProgressMonitor monitor) {
285 if (fZoomStartTime <= fStartTime && fZoomEndTime >= fEndTime) {
286 entry.setZoomedEventList(null);
287 } else {
288 List<ITimeEvent> zoomedEventList = getEventList(entry, fZoomStartTime, fZoomEndTime, fResolution, monitor);
289 if (zoomedEventList != null) {
290 entry.setZoomedEventList(zoomedEventList);
291 }
292 }
293 for (ControlFlowEntry child : entry.getChildren()) {
294 if (fMonitor.isCanceled()) {
295 return;
296 }
297 zoom(child, monitor);
298 }
299 }
300
301 public void cancel() {
302 fMonitor.setCanceled(true);
303 }
304 }
305
306 // ------------------------------------------------------------------------
307 // Constructors
308 // ------------------------------------------------------------------------
309
310 /**
311 * Constructor
312 */
313 public ControlFlowView() {
314 super(ID);
315 fDisplayWidth = Display.getDefault().getBounds().width;
316 }
317
318 // ------------------------------------------------------------------------
319 // ViewPart
320 // ------------------------------------------------------------------------
321
322 /* (non-Javadoc)
323 * @see org.eclipse.linuxtools.tmf.ui.views.TmfView#createPartControl(org.eclipse.swt.widgets.Composite)
324 */
325 @Override
326 public void createPartControl(Composite parent) {
327 fTimeGraphCombo = new TimeGraphCombo(parent, SWT.NONE);
328
329 fTimeGraphCombo.setTreeContentProvider(new TreeContentProvider());
330
331 fTimeGraphCombo.setTreeLabelProvider(new TreeLabelProvider());
332
333 fTimeGraphCombo.setTimeGraphProvider(new ControlFlowPresentationProvider());
334
335 fTimeGraphCombo.setTreeColumns(COLUMN_NAMES);
336
337 fTimeGraphCombo.getTimeGraphViewer().addRangeListener(new ITimeGraphRangeListener() {
338 @Override
339 public void timeRangeUpdated(TimeGraphRangeUpdateEvent event) {
340 final long startTime = event.getStartTime();
341 final long endTime = event.getEndTime();
342 TmfTimeRange range = new TmfTimeRange(new CtfTmfTimestamp(startTime), new CtfTmfTimestamp(endTime));
343 TmfTimestamp time = new CtfTmfTimestamp(fTimeGraphCombo.getTimeGraphViewer().getSelectedTime());
344 broadcast(new TmfRangeSynchSignal(ControlFlowView.this, range, time));
345 if (fZoomThread != null) {
346 fZoomThread.cancel();
347 }
348 startZoomThread(startTime, endTime);
349 }
350 });
351
352 fTimeGraphCombo.getTimeGraphViewer().addTimeListener(new ITimeGraphTimeListener() {
353 @Override
354 public void timeSelected(TimeGraphTimeEvent event) {
355 long time = event.getTime();
356 broadcast(new TmfTimeSynchSignal(ControlFlowView.this, new CtfTmfTimestamp(time)));
357 }
358 });
359
360 fTimeGraphCombo.addSelectionListener(new ITimeGraphSelectionListener() {
361 @Override
362 public void selectionChanged(TimeGraphSelectionEvent event) {
363 //ITimeGraphEntry selection = event.getSelection();
364 }
365 });
366
367 fTimeGraphCombo.getTimeGraphViewer().setTimeCalendarFormat(true);
368
369 final Thread thread = new Thread("ControlFlowView build") { //$NON-NLS-1$
370 @Override
371 public void run() {
372 if (TmfExperiment.getCurrentExperiment() != null) {
373 selectExperiment(TmfExperiment.getCurrentExperiment());
374 }
375 }
376 };
377 thread.start();
378
379 // View Action Handling
380 makeActions();
381 contributeToActionBars();
382 }
383
384 /* (non-Javadoc)
385 * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
386 */
387 @Override
388 public void setFocus() {
389 fTimeGraphCombo.setFocus();
390 }
391
392 // ------------------------------------------------------------------------
393 // Signal handlers
394 // ------------------------------------------------------------------------
395
396 /**
397 * Handler for the experiment selected signal
398 *
399 * @param signal
400 * The signal that's received
401 */
402 @TmfSignalHandler
403 public void experimentSelected(final TmfExperimentSelectedSignal<? extends ITmfEvent> signal) {
404 if (signal.getExperiment().equals(fSelectedExperiment)) {
405 return;
406 }
407
408 final Thread thread = new Thread("ControlFlowView build") { //$NON-NLS-1$
409 @Override
410 public void run() {
411 selectExperiment(signal.getExperiment());
412 }
413 };
414 thread.start();
415 }
416
417 /**
418 * Handler for the synch signal
419 *
420 * @param signal
421 * The signal that's received
422 */
423 @TmfSignalHandler
424 public void synchToTime(final TmfTimeSynchSignal signal) {
425 if (signal.getSource() == this || fSelectedExperiment == null) {
426 return;
427 }
428 final long time = signal.getCurrentTime().normalize(0, -9).getValue();
429
430 int thread = -1;
431 for (ITmfTrace<?> trace : fSelectedExperiment.getTraces()) {
432 if (thread > 0) {
433 break;
434 }
435 if (trace instanceof CtfKernelTrace) {
436 CtfKernelTrace ctfKernelTrace = (CtfKernelTrace) trace;
437 IStateSystemQuerier ssq = ctfKernelTrace.getStateSystem();
438 if (time >= ssq.getStartTime() && time <= ssq.getCurrentEndTime()) {
439 List<Integer> currentThreadQuarks = ssq.getQuarks(Attributes.CPUS, "*", Attributes.CURRENT_THREAD); //$NON-NLS-1$
440 for (int currentThreadQuark : currentThreadQuarks) {
441 try {
442 ITmfStateInterval currentThreadInterval = ssq.querySingleState(time, currentThreadQuark);
443 int currentThread = currentThreadInterval.getStateValue().unboxInt();
444 if (currentThread > 0) {
445 int statusQuark = ssq.getQuarkAbsolute(Attributes.THREADS, Integer.toString(currentThread), Attributes.STATUS);
446 ITmfStateInterval statusInterval = ssq.querySingleState(time, statusQuark);
447 if (statusInterval.getStartTime() == time) {
448 thread = currentThread;
449 break;
450 }
451 }
452 } catch (AttributeNotFoundException e) {
453 e.printStackTrace();
454 } catch (TimeRangeException e) {
455 e.printStackTrace();
456 } catch (StateValueTypeException e) {
457 e.printStackTrace();
458 }
459 }
460 }
461 }
462 }
463 final int selectedThread = thread;
464
465 Display.getDefault().asyncExec(new Runnable() {
466 @Override
467 public void run() {
468 if (fTimeGraphCombo.isDisposed()) {
469 return;
470 }
471 fTimeGraphCombo.getTimeGraphViewer().setSelectedTime(time, true);
472 startZoomThread(fTimeGraphCombo.getTimeGraphViewer().getTime0(), fTimeGraphCombo.getTimeGraphViewer().getTime1());
473
474 if (selectedThread > 0) {
475 for (Object element : fTimeGraphCombo.getTimeGraphViewer().getExpandedElements()) {
476 if (element instanceof ControlFlowEntry) {
477 ControlFlowEntry entry = (ControlFlowEntry) element;
478 if (entry.getThreadId() == selectedThread) {
479 fTimeGraphCombo.setSelection(entry);
480 break;
481 }
482 }
483 }
484 }
485 }
486 });
487 }
488
489 /**
490 * Handler for the range sync signal
491 *
492 * @param signal
493 * The signal that's received
494 */
495 @TmfSignalHandler
496 public void synchToRange(final TmfRangeSynchSignal signal) {
497 if (signal.getSource() == this || fSelectedExperiment == null) {
498 return;
499 }
500 final long startTime = signal.getCurrentRange().getStartTime().normalize(0, -9).getValue();
501 final long endTime = signal.getCurrentRange().getEndTime().normalize(0, -9).getValue();
502 final long time = signal.getCurrentTime().normalize(0, -9).getValue();
503 Display.getDefault().asyncExec(new Runnable() {
504 @Override
505 public void run() {
506 if (fTimeGraphCombo.isDisposed()) {
507 return;
508 }
509 fTimeGraphCombo.getTimeGraphViewer().setStartFinishTime(startTime, endTime);
510 fTimeGraphCombo.getTimeGraphViewer().setSelectedTime(time, false);
511 startZoomThread(startTime, endTime);
512 }
513 });
514 }
515
516 /**
517 * Handler for the state system build completed signal
518 *
519 * @param signal
520 * The signal that's received
521 */
522 @TmfSignalHandler
523 public void stateSystemBuildCompleted (final TmfStateSystemBuildCompleted signal) {
524 final TmfExperiment<?> selectedExperiment = fSelectedExperiment;
525 if (selectedExperiment == null) {
526 return;
527 }
528 for (ITmfTrace<?> trace : selectedExperiment.getTraces()) {
529 if (trace == signal.getTrace() && trace instanceof CtfKernelTrace) {
530 final Thread thread = new Thread("ControlFlowView build") { //$NON-NLS-1$
531 @Override
532 public void run() {
533 // rebuild the model
534 selectExperiment(selectedExperiment);
535 }
536 };
537 thread.start();
538 }
539 }
540 }
541
542 // ------------------------------------------------------------------------
543 // Internal
544 // ------------------------------------------------------------------------
545
546 @SuppressWarnings("unchecked")
547 private void selectExperiment(TmfExperiment<?> experiment) {
548 fStartTime = Long.MAX_VALUE;
549 fEndTime = Long.MIN_VALUE;
550 fSelectedExperiment = (TmfExperiment<ITmfEvent>) experiment;
551 ArrayList<ControlFlowEntry> rootList = new ArrayList<ControlFlowEntry>();
552 for (ITmfTrace<?> trace : experiment.getTraces()) {
553 if (trace instanceof CtfKernelTrace) {
554 ArrayList<ControlFlowEntry> entryList = new ArrayList<ControlFlowEntry>();
555 CtfKernelTrace ctfKernelTrace = (CtfKernelTrace) trace;
556 IStateSystemQuerier ssq = ctfKernelTrace.getStateSystem();
557 long start = ssq.getStartTime();
558 long end = ssq.getCurrentEndTime() + 1;
559 fStartTime = Math.min(fStartTime, start);
560 fEndTime = Math.max(fEndTime, end);
561 List<Integer> threadQuarks = ssq.getQuarks(Attributes.THREADS, "*"); //$NON-NLS-1$
562 for (int threadQuark : threadQuarks) {
563 String threadName = ssq.getAttributeName(threadQuark);
564 int threadId = -1;
565 try {
566 threadId = Integer.parseInt(threadName);
567 } catch (NumberFormatException e1) {
568 continue;
569 }
570 if (threadId == 0) { // ignore the swapper thread
571 continue;
572 }
573 int execNameQuark = -1;
574 try {
575 try {
576 execNameQuark = ssq.getQuarkRelative(threadQuark, Attributes.EXEC_NAME);
577 } catch (AttributeNotFoundException e) {
578 continue;
579 }
580 int ppidQuark = ssq.getQuarkRelative(threadQuark, Attributes.PPID);
581 List<ITmfStateInterval> execNameIntervals = ssq.queryHistoryRange(execNameQuark, start, end - 1);
582 long birthTime = -1;
583 for (ITmfStateInterval execNameInterval : execNameIntervals) {
584 if (!execNameInterval.getStateValue().isNull() && execNameInterval.getStateValue().getType() == 1) {
585 String execName = execNameInterval.getStateValue().unboxStr();
586 long startTime = execNameInterval.getStartTime();
587 long endTime = execNameInterval.getEndTime() + 1;
588 if (birthTime == -1) {
589 birthTime = startTime;
590 }
591 int ppid = -1;
592 if (ppidQuark != -1) {
593 ITmfStateInterval ppidInterval = ssq.querySingleState(startTime, ppidQuark);
594 ppid = ppidInterval.getStateValue().unboxInt();
595 }
596 ControlFlowEntry entry = new ControlFlowEntry(threadQuark, ctfKernelTrace, execName, threadId, ppid, birthTime, startTime, endTime);
597 entryList.add(entry);
598 entry.addEvent(new TimeEvent(entry, startTime, endTime - startTime));
599 } else {
600 birthTime = -1;
601 }
602 }
603 } catch (AttributeNotFoundException e) {
604 e.printStackTrace();
605 } catch (TimeRangeException e) {
606 e.printStackTrace();
607 } catch (StateValueTypeException e) {
608 e.printStackTrace();
609 }
610 }
611 buildTree(entryList, rootList);
612 }
613 Collections.sort(rootList, fControlFlowEntryComparator);
614 synchronized (fEntryListSyncObj) {
615 fEntryList = (ArrayList<ControlFlowEntry>) rootList.clone();
616 }
617 refresh(INITIAL_WINDOW_OFFSET);
618 }
619 for (ControlFlowEntry entry : rootList) {
620 buildStatusEvents(entry);
621 }
622 }
623
624 private void buildTree(ArrayList<ControlFlowEntry> entryList, ArrayList<ControlFlowEntry> rootList) {
625 for (ControlFlowEntry entry : entryList) {
626 boolean root = true;
627 if (entry.getParentThreadId() > 0) {
628 for (ControlFlowEntry parent : entryList) {
629 if (parent.getThreadId() == entry.getParentThreadId() &&
630 entry.getStartTime() >= parent.getStartTime() &&
631 entry.getStartTime() <= parent.getEndTime()) {
632 parent.addChild(entry);
633 root = false;
634 break;
635 }
636 }
637 }
638 if (root) {
639 rootList.add(entry);
640 }
641 }
642 }
643
644 private void buildStatusEvents(ControlFlowEntry entry) {
645 IStateSystemQuerier ssq = entry.getTrace().getStateSystem();
646 long start = ssq.getStartTime();
647 long end = ssq.getCurrentEndTime() + 1;
648 long resolution = Math.max(1, (end - start) / fDisplayWidth);
649 List<ITimeEvent> eventList = getEventList(entry, entry.getStartTime(), entry.getEndTime(), resolution, new NullProgressMonitor());
650 entry.setEventList(eventList);
651 redraw();
652 for (ITimeGraphEntry child : entry.getChildren()) {
653 buildStatusEvents((ControlFlowEntry) child);
654 }
655 }
656
657 private List<ITimeEvent> getEventList(ControlFlowEntry entry, long startTime, long endTime, long resolution, IProgressMonitor monitor) {
658 startTime = Math.max(startTime, entry.getStartTime());
659 endTime = Math.min(endTime, entry.getEndTime());
660 if (endTime <= startTime) {
661 return null;
662 }
663 IStateSystemQuerier ssq = entry.getTrace().getStateSystem();
664 List<ITimeEvent> eventList = null;
665 try {
666 int statusQuark = ssq.getQuarkRelative(entry.getThreadQuark(), Attributes.STATUS);
667 List<ITmfStateInterval> statusIntervals = ssq.queryHistoryRange(statusQuark, startTime, endTime - 1, resolution);
668 eventList = new ArrayList<ITimeEvent>(statusIntervals.size());
669 long lastEndTime = -1;
670 for (ITmfStateInterval statusInterval : statusIntervals) {
671 if (monitor.isCanceled()) {
672 return null;
673 }
674 long time = statusInterval.getStartTime();
675 long duration = statusInterval.getEndTime() - time + 1;
676 int status = -1;
677 try {
678 status = statusInterval.getStateValue().unboxInt();
679 } catch (StateValueTypeException e) {
680 e.printStackTrace();
681 }
682 if (lastEndTime != time && lastEndTime != -1) {
683 eventList.add(new ControlFlowEvent(entry, lastEndTime, time - lastEndTime, 0));
684 }
685 eventList.add(new ControlFlowEvent(entry, time, duration, status));
686 lastEndTime = time + duration;
687 }
688 } catch (AttributeNotFoundException e) {
689 e.printStackTrace();
690 } catch (TimeRangeException e) {
691 e.printStackTrace();
692 }
693 return eventList;
694 }
695
696 private void refresh(final long windowRange) {
697 Display.getDefault().asyncExec(new Runnable() {
698 @Override
699 public void run() {
700 if (fTimeGraphCombo.isDisposed()) {
701 return;
702 }
703 ITimeGraphEntry[] entries = null;
704 synchronized (fEntryListSyncObj) {
705 entries = fEntryList.toArray(new ITimeGraphEntry[0]);
706 }
707 Arrays.sort(entries, fControlFlowEntryComparator);
708 fTimeGraphCombo.setInput(entries);
709 fTimeGraphCombo.getTimeGraphViewer().setTimeBounds(fStartTime, fEndTime);
710
711 long endTime = fStartTime + windowRange;
712
713 if (fEndTime < endTime) {
714 endTime = fEndTime;
715 }
716 fTimeGraphCombo.getTimeGraphViewer().setStartFinishTime(fStartTime, endTime);
717 for (TreeColumn column : fTimeGraphCombo.getTreeViewer().getTree().getColumns()) {
718 column.pack();
719 }
720
721 startZoomThread(fStartTime, endTime);
722 }
723 });
724 }
725
726 private void redraw() {
727 Display.getDefault().asyncExec(new Runnable() {
728 @Override
729 public void run() {
730 if (fTimeGraphCombo.isDisposed()) {
731 return;
732 }
733 fTimeGraphCombo.redraw();
734 fTimeGraphCombo.update();
735 }
736 });
737 }
738
739 private void startZoomThread(long startTime, long endTime) {
740 if (fZoomThread != null) {
741 fZoomThread.cancel();
742 }
743 fZoomThread = new ZoomThread(startTime, endTime);
744 fZoomThread.start();
745 }
746
747 private void makeActions() {
748 fPreviousResourceAction = fTimeGraphCombo.getTimeGraphViewer().getPreviousItemAction();
749 fPreviousResourceAction.setText(Messages.ControlFlowView_previousProcessActionNameText);
750 fPreviousResourceAction.setToolTipText(Messages.ControlFlowView_previousProcessActionToolTipText);
751 fNextResourceAction = fTimeGraphCombo.getTimeGraphViewer().getNextItemAction();
752 fNextResourceAction.setText(Messages.ControlFlowView_nextProcessActionNameText);
753 fNextResourceAction.setToolTipText(Messages.ControlFlowView_nextProcessActionToolTipText);
754 }
755
756 private void contributeToActionBars() {
757 IActionBars bars = getViewSite().getActionBars();
758 fillLocalToolBar(bars.getToolBarManager());
759 }
760
761 private void fillLocalToolBar(IToolBarManager manager) {
762 manager.add(fTimeGraphCombo.getTimeGraphViewer().getShowLegendAction());
763 manager.add(new Separator());
764 manager.add(fTimeGraphCombo.getTimeGraphViewer().getResetScaleAction());
765 manager.add(fTimeGraphCombo.getTimeGraphViewer().getPreviousEventAction());
766 manager.add(fTimeGraphCombo.getTimeGraphViewer().getNextEventAction());
767 manager.add(fPreviousResourceAction);
768 manager.add(fNextResourceAction);
769 manager.add(fTimeGraphCombo.getTimeGraphViewer().getZoomInAction());
770 manager.add(fTimeGraphCombo.getTimeGraphViewer().getZoomOutAction());
771 manager.add(new Separator());
772 }
773 }
This page took 0.050114 seconds and 5 git commands to generate.