Commit | Line | Data |
---|---|---|
6e512b93 ASL |
1 | /******************************************************************************* |
2 | * Copyright (c) 2009 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: | |
dfaf8391 FC |
10 | * Yann N. Dauphin (dhaemon@gmail.com) - Implementation |
11 | * Francois Chouinard (fchouinard@gmail.com) - Initial API | |
6e512b93 ASL |
12 | *******************************************************************************/ |
13 | ||
14 | package org.eclipse.linuxtools.lttng.ui.views.statistics; | |
15 | ||
dfaf8391 FC |
16 | import java.text.DecimalFormat; |
17 | import java.util.Arrays; | |
18 | import java.util.HashSet; | |
19 | import java.util.Set; | |
20 | ||
21 | import org.eclipse.jface.viewers.ColumnLabelProvider; | |
22 | import org.eclipse.jface.viewers.ITreeContentProvider; | |
23 | import org.eclipse.jface.viewers.TreeViewer; | |
24 | import org.eclipse.jface.viewers.TreeViewerColumn; | |
25 | import org.eclipse.jface.viewers.Viewer; | |
26 | import org.eclipse.jface.viewers.ViewerComparator; | |
c1c69938 | 27 | import org.eclipse.linuxtools.lttng.control.LttngCoreProviderFactory; |
8827c197 FC |
28 | import org.eclipse.linuxtools.lttng.request.ILttngSyntEventRequest; |
29 | import org.eclipse.linuxtools.lttng.state.evProcessor.AbsEventToHandlerResolver; | |
30 | import org.eclipse.linuxtools.lttng.ui.TraceDebug; | |
31 | import org.eclipse.linuxtools.lttng.ui.model.trange.ItemContainer; | |
32 | import org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView; | |
33 | import org.eclipse.linuxtools.lttng.ui.views.common.ParamsUpdater; | |
dfaf8391 | 34 | import org.eclipse.linuxtools.lttng.ui.views.statistics.evProcessor.StatsTimeCountHandlerFactory; |
dfaf8391 | 35 | import org.eclipse.linuxtools.lttng.ui.views.statistics.model.StatisticsTreeNode; |
8827c197 FC |
36 | import org.eclipse.linuxtools.lttng.ui.views.statistics.model.StatisticsTreeRootFactory; |
37 | import org.eclipse.linuxtools.tmf.event.TmfEvent; | |
38 | import org.eclipse.linuxtools.tmf.event.TmfTimeRange; | |
39 | import org.eclipse.linuxtools.tmf.experiment.TmfExperiment; | |
9b635e61 | 40 | import org.eclipse.linuxtools.tmf.request.ITmfDataRequest.ExecutionType; |
8827c197 | 41 | import org.eclipse.linuxtools.tmf.signal.TmfExperimentSelectedSignal; |
dfaf8391 | 42 | import org.eclipse.linuxtools.tmf.signal.TmfSignalHandler; |
8827c197 FC |
43 | import org.eclipse.linuxtools.tmf.trace.ITmfTrace; |
44 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.ITmfTimeAnalysisEntry; | |
dfaf8391 FC |
45 | import org.eclipse.swt.SWT; |
46 | import org.eclipse.swt.events.SelectionAdapter; | |
47 | import org.eclipse.swt.events.SelectionEvent; | |
48 | import org.eclipse.swt.graphics.Color; | |
8827c197 | 49 | import org.eclipse.swt.graphics.Cursor; |
dfaf8391 FC |
50 | import org.eclipse.swt.graphics.Image; |
51 | import org.eclipse.swt.layout.FillLayout; | |
6e512b93 | 52 | import org.eclipse.swt.widgets.Composite; |
8827c197 | 53 | import org.eclipse.swt.widgets.Display; |
dfaf8391 FC |
54 | import org.eclipse.swt.widgets.Event; |
55 | import org.eclipse.swt.widgets.Listener; | |
56 | import org.eclipse.ui.ISharedImages; | |
57 | import org.eclipse.ui.PlatformUI; | |
6e512b93 ASL |
58 | |
59 | /** | |
60 | * <b><u>StatisticsView</u></b> | |
61 | * <p> | |
dfaf8391 FC |
62 | * The Statistics View displays statistics for traces. |
63 | * | |
64 | * It is implemented according to the MVC pattern. - The model is a | |
65 | * StatisticsTreeNode built by the State Manager. - The view is built with a | |
66 | * TreeViewer. - The controller that keeps model and view synchronised is an | |
67 | * observer of the model. | |
6e512b93 | 68 | */ |
8827c197 | 69 | public class StatisticsView extends AbsTimeUpdateView { |
3b38ea61 | 70 | public static final String ID = "org.eclipse.linuxtools.lttng.ui.views.statistics"; //$NON-NLS-1$ |
dfaf8391 FC |
71 | private TreeViewer treeViewer; |
72 | ||
73 | // Table column names | |
74 | private final String LEVEL_COLUMN = "Level"; | |
75 | private final String EVENTS_COUNT_COLUMN = "Number of Events"; | |
76 | private final String CPU_TIME_COLUMN = "CPU Time"; | |
77 | private final String CUMULATIVE_CPU_TIME_COLUMN = "Cumulative CPU Time"; | |
78 | private final String ELAPSED_TIME_COLUMN = "Elapsed Time"; | |
79 | ||
80 | // Table column tooltips | |
81 | private final String LEVEL_COLUMN_TIP = "Level at which statistics apply."; | |
82 | private final String EVENTS_COUNT_COLUMN_TIP = "Total amount of events that are tied to given resource."; | |
83 | private final String CPU_TIME_COLUMN_TIP = "Total amount of time the CPU was used excluding wait times(I/O, etc.) at that level."; | |
84 | private final String CUMULATIVE_CPU_TIME_COLUMN_TIP = "Total amount of time between the first and last event excluding wait times in a level."; | |
85 | private final String ELAPSED_TIME_COLUMN_TIP = "Total amount of time the CPU was used including wait times(I/O, etc.) at that level."; | |
6e512b93 | 86 | |
dfaf8391 FC |
87 | // Level for which statistics should not be displayed. |
88 | private Set<String> folderLevels = new HashSet<String>(Arrays | |
89 | .asList(new String[] { "Event Types", "Modes", "Submodes", "CPUs", | |
90 | "Processes", "Functions" })); | |
6e512b93 | 91 | |
dfaf8391 FC |
92 | // Levels for which sub-levels should not contain time-related statistics. |
93 | private Set<String> levelsWithEmptyTime = new HashSet<String>(Arrays | |
94 | .asList(new String[] { "Event Types" })); | |
95 | ||
96 | private DecimalFormat decimalFormat = new DecimalFormat("0.#########"); | |
8827c197 | 97 | private Cursor fwaitCursor = null; |
dfaf8391 | 98 | |
c1c69938 FC |
99 | private static final Long STATS_INPUT_CHANGED_REFRESH = 5000L; |
100 | ||
dfaf8391 FC |
101 | // Used to draw bar charts in columns. |
102 | private interface ColumnPercentageProvider { | |
103 | public double getPercentage(StatisticsTreeNode node); | |
104 | } | |
105 | ||
106 | /** | |
107 | * Contains all the information necessary to build a column of the table. | |
108 | */ | |
109 | private class ColumnData { | |
110 | // Name of the column. | |
111 | public final String header; | |
112 | // Width of the column. | |
113 | public final int width; | |
114 | // Alignment of the column. | |
115 | public final int alignment; | |
116 | // Tooltip of the column. | |
117 | public final String tooltip; | |
118 | // Adapts a StatisticsTreeNode into the content of it's corresponding | |
119 | // cell for that column. | |
120 | public final ColumnLabelProvider labelProvider; | |
121 | // Used to sort elements of this column. Can be null. | |
122 | public final ViewerComparator comparator; | |
123 | // Used to draw bar charts in this column. Can be null. | |
124 | public final ColumnPercentageProvider percentageProvider; | |
125 | ||
126 | public ColumnData(String h, int w, int a, String t, | |
127 | ColumnLabelProvider l, ViewerComparator c, | |
128 | ColumnPercentageProvider p) { | |
129 | header = h; | |
130 | width = w; | |
131 | alignment = a; | |
132 | tooltip = t; | |
133 | labelProvider = l; | |
134 | comparator = c; | |
135 | percentageProvider = p; | |
136 | } | |
137 | }; | |
138 | ||
139 | // List that will be used to create the table. | |
140 | private ColumnData[] columnDataList = new ColumnData[] { | |
141 | new ColumnData(LEVEL_COLUMN, 200, SWT.LEFT, LEVEL_COLUMN_TIP, | |
142 | new ColumnLabelProvider() { | |
143 | @Override | |
144 | public String getText(Object element) { | |
145 | return ((StatisticsTreeNode) element).getKey(); | |
146 | } | |
147 | ||
148 | @Override | |
149 | public Image getImage(Object element) { | |
150 | StatisticsTreeNode node = (StatisticsTreeNode) element; | |
151 | if (folderLevels.contains(node.getKey())) { | |
152 | return PlatformUI.getWorkbench() | |
153 | .getSharedImages().getImage( | |
154 | ISharedImages.IMG_OBJ_FOLDER); | |
155 | } else { | |
156 | return PlatformUI.getWorkbench() | |
157 | .getSharedImages().getImage( | |
158 | ISharedImages.IMG_OBJ_ELEMENT); | |
159 | } | |
160 | } | |
161 | }, new ViewerComparator() { | |
162 | @Override | |
163 | public int compare(Viewer viewer, Object e1, Object e2) { | |
164 | StatisticsTreeNode n1 = (StatisticsTreeNode) e1; | |
165 | StatisticsTreeNode n2 = (StatisticsTreeNode) e2; | |
166 | ||
167 | return n1.getKey().compareTo(n2.getKey()); | |
168 | } | |
169 | }, null), | |
170 | new ColumnData(EVENTS_COUNT_COLUMN, 125, SWT.LEFT, | |
171 | EVENTS_COUNT_COLUMN_TIP, new ColumnLabelProvider() { | |
172 | @Override | |
173 | public String getText(Object element) { | |
174 | StatisticsTreeNode node = (StatisticsTreeNode) element; | |
175 | if (!folderLevels.contains(node.getKey())) { | |
176 | return Long.toString(node.getValue().nbEvents); | |
177 | } else { | |
3b38ea61 | 178 | return ""; //$NON-NLS-1$ |
dfaf8391 FC |
179 | } |
180 | } | |
181 | }, new ViewerComparator() { | |
182 | @Override | |
183 | public int compare(Viewer viewer, Object e1, Object e2) { | |
184 | StatisticsTreeNode n1 = (StatisticsTreeNode) e1; | |
185 | StatisticsTreeNode n2 = (StatisticsTreeNode) e2; | |
186 | ||
187 | return (int) (n1.getValue().nbEvents - n2 | |
188 | .getValue().nbEvents); | |
189 | } | |
190 | }, new ColumnPercentageProvider() { | |
d4011df2 | 191 | @Override |
dfaf8391 FC |
192 | public double getPercentage(StatisticsTreeNode node) { |
193 | StatisticsTreeNode parent = node; | |
194 | do { | |
195 | parent = parent.getParent(); | |
196 | } while (parent != null | |
197 | && parent.getValue().nbEvents == 0); | |
198 | ||
199 | if (parent == null) { | |
200 | return 0; | |
201 | } else { | |
202 | return (double) node.getValue().nbEvents | |
203 | / parent.getValue().nbEvents; | |
204 | } | |
205 | } | |
206 | }), | |
207 | new ColumnData(CPU_TIME_COLUMN, 125, SWT.LEFT, CPU_TIME_COLUMN_TIP, | |
208 | new ColumnLabelProvider() { | |
209 | @Override | |
210 | public String getText(Object element) { | |
211 | StatisticsTreeNode node = (StatisticsTreeNode) element; | |
212 | ||
213 | if (folderLevels.contains(node.getKey())) { | |
3b38ea61 | 214 | return ""; //$NON-NLS-1$ |
dfaf8391 FC |
215 | } else if (node.getParent() != null |
216 | && levelsWithEmptyTime.contains(node | |
217 | .getParent().getKey())) { | |
3b38ea61 | 218 | return ""; //$NON-NLS-1$ |
dfaf8391 FC |
219 | } else { |
220 | return decimalFormat | |
221 | .format(node.getValue().cpuTime | |
222 | / Math.pow(10, 9)); | |
223 | } | |
224 | } | |
225 | }, null, null), | |
226 | new ColumnData(CUMULATIVE_CPU_TIME_COLUMN, 155, SWT.LEFT, | |
227 | CUMULATIVE_CPU_TIME_COLUMN_TIP, new ColumnLabelProvider() { | |
228 | @Override | |
229 | public String getText(Object element) { | |
230 | StatisticsTreeNode node = (StatisticsTreeNode) element; | |
231 | if (folderLevels.contains(node.getKey())) { | |
3b38ea61 | 232 | return ""; //$NON-NLS-1$ |
dfaf8391 FC |
233 | } else if (node.getParent() != null |
234 | && levelsWithEmptyTime.contains(node | |
235 | .getParent().getKey())) { | |
3b38ea61 | 236 | return ""; //$NON-NLS-1$ |
dfaf8391 FC |
237 | } else { |
238 | return decimalFormat | |
239 | .format(node.getValue().cumulativeCpuTime | |
240 | / Math.pow(10, 9)); | |
241 | } | |
242 | } | |
243 | }, null, null), | |
244 | new ColumnData(ELAPSED_TIME_COLUMN, 100, SWT.LEFT, | |
245 | ELAPSED_TIME_COLUMN_TIP, new ColumnLabelProvider() { | |
246 | @Override | |
247 | public String getText(Object element) { | |
248 | StatisticsTreeNode node = (StatisticsTreeNode) element; | |
249 | if (folderLevels.contains(node.getKey())) { | |
3b38ea61 | 250 | return ""; //$NON-NLS-1$ |
dfaf8391 FC |
251 | } else if (node.getParent() != null |
252 | && levelsWithEmptyTime.contains(node | |
253 | .getParent().getKey())) { | |
3b38ea61 | 254 | return ""; //$NON-NLS-1$ |
dfaf8391 FC |
255 | } else { |
256 | return decimalFormat | |
257 | .format(node.getValue().elapsedTime | |
258 | / Math.pow(10, 9)); | |
259 | } | |
260 | } | |
261 | }, null, null) }; | |
262 | ||
263 | /** | |
264 | * Adapter TreeViewers can use to interact with StatisticsTreeNode objects. | |
6e512b93 | 265 | * |
dfaf8391 | 266 | * @see org.eclipse.jface.viewers.ITreeContentProvider |
6e512b93 | 267 | */ |
dfaf8391 FC |
268 | class TreeContentProvider implements ITreeContentProvider { |
269 | /* | |
270 | * (non-Javadoc) | |
271 | * | |
272 | * @see | |
273 | * org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang | |
274 | * .Object) | |
275 | */ | |
d4011df2 | 276 | @Override |
dfaf8391 FC |
277 | public Object[] getChildren(Object parentElement) { |
278 | return ((StatisticsTreeNode) parentElement).getChildren().toArray(); | |
279 | } | |
280 | ||
281 | /* | |
282 | * (non-Javadoc) | |
283 | * | |
284 | * @see | |
285 | * org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang | |
286 | * .Object) | |
287 | */ | |
d4011df2 | 288 | @Override |
dfaf8391 FC |
289 | public Object getParent(Object element) { |
290 | return ((StatisticsTreeNode) element).getParent(); | |
291 | } | |
292 | ||
293 | /* | |
294 | * (non-Javadoc) | |
295 | * | |
296 | * @see | |
297 | * org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang | |
298 | * .Object) | |
299 | */ | |
d4011df2 | 300 | @Override |
dfaf8391 FC |
301 | public boolean hasChildren(Object element) { |
302 | return ((StatisticsTreeNode) element).hasChildren(); | |
303 | } | |
304 | ||
305 | /* | |
306 | * (non-Javadoc) | |
307 | * | |
308 | * @see | |
309 | * org.eclipse.jface.viewers.IStructuredContentProvider#getElements( | |
310 | * java.lang.Object) | |
311 | */ | |
d4011df2 | 312 | @Override |
dfaf8391 FC |
313 | public Object[] getElements(Object inputElement) { |
314 | return getChildren(inputElement); | |
315 | } | |
316 | ||
317 | /* | |
318 | * (non-Javadoc) | |
319 | * | |
320 | * @see org.eclipse.jface.viewers.IContentProvider#dispose() | |
321 | */ | |
d4011df2 | 322 | @Override |
dfaf8391 FC |
323 | public void dispose() { |
324 | } | |
325 | ||
326 | /* | |
327 | * (non-Javadoc) | |
328 | * | |
329 | * @see | |
330 | * org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse | |
331 | * .jface.viewers.Viewer, java.lang.Object, java.lang.Object) | |
332 | */ | |
333 | // @Override | |
d4011df2 | 334 | @Override |
dfaf8391 FC |
335 | public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { |
336 | } | |
6e512b93 ASL |
337 | } |
338 | ||
fc6ccf6f | 339 | public StatisticsView(String viewName) { |
951d134a FC |
340 | super(viewName); |
341 | } | |
342 | ||
3b38ea61 | 343 | private static final String STATISTICS_VIEW = "StatisticsView"; //$NON-NLS-1$ |
951d134a | 344 | public StatisticsView() { |
3b38ea61 | 345 | this(STATISTICS_VIEW); |
fc6ccf6f FC |
346 | } |
347 | ||
dfaf8391 FC |
348 | /* |
349 | * (non-Javadoc) | |
350 | * | |
351 | * @see | |
352 | * org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets | |
353 | * .Composite) | |
6e512b93 ASL |
354 | */ |
355 | @Override | |
356 | public void createPartControl(Composite parent) { | |
dfaf8391 FC |
357 | parent.setLayout(new FillLayout()); |
358 | ||
359 | treeViewer = new TreeViewer(parent, SWT.BORDER | SWT.H_SCROLL | |
360 | | SWT.V_SCROLL); | |
361 | treeViewer.setContentProvider(new TreeContentProvider()); | |
362 | treeViewer.getTree().setHeaderVisible(true); | |
363 | treeViewer.setUseHashlookup(true); | |
364 | ||
365 | for (final ColumnData columnData : columnDataList) { | |
366 | final TreeViewerColumn treeColumn = new TreeViewerColumn( | |
367 | treeViewer, columnData.alignment); | |
368 | treeColumn.getColumn().setText(columnData.header); | |
369 | treeColumn.getColumn().setWidth(columnData.width); | |
370 | treeColumn.getColumn().setToolTipText(columnData.tooltip); | |
371 | if (columnData.comparator != null) { | |
372 | treeColumn.getColumn().addSelectionListener( | |
373 | new SelectionAdapter() { | |
374 | @Override | |
375 | public void widgetSelected(SelectionEvent e) { | |
376 | if (treeViewer.getTree().getSortDirection() == SWT.UP | |
377 | || treeViewer.getTree().getSortColumn() != treeColumn | |
378 | .getColumn()) { | |
379 | treeViewer | |
380 | .setComparator(columnData.comparator); | |
381 | treeViewer.getTree().setSortDirection( | |
382 | SWT.DOWN); | |
383 | } else { | |
384 | treeViewer | |
385 | .setComparator(new ViewerComparator() { | |
386 | @Override | |
387 | public int compare( | |
388 | Viewer viewer, | |
389 | Object e1, Object e2) { | |
390 | return -1 | |
391 | * columnData.comparator | |
392 | .compare( | |
393 | viewer, | |
394 | e1, | |
395 | e2); | |
396 | } | |
397 | }); | |
398 | treeViewer.getTree().setSortDirection( | |
399 | SWT.UP); | |
400 | } | |
401 | treeViewer.getTree().setSortColumn( | |
402 | treeColumn.getColumn()); | |
403 | } | |
404 | }); | |
405 | } | |
406 | treeColumn.setLabelProvider(columnData.labelProvider); | |
407 | } | |
408 | ||
409 | // Handler that will draw the bar charts. | |
410 | treeViewer.getTree().addListener(SWT.EraseItem, new Listener() { | |
411 | // @Override | |
d4011df2 | 412 | @Override |
dfaf8391 FC |
413 | public void handleEvent(Event event) { |
414 | if (columnDataList[event.index].percentageProvider != null) { | |
415 | StatisticsTreeNode node = (StatisticsTreeNode) event.item | |
416 | .getData(); | |
417 | ||
418 | double percentage = columnDataList[event.index].percentageProvider | |
419 | .getPercentage(node); | |
420 | if (percentage == 0) { | |
421 | return; | |
422 | } | |
423 | ||
424 | if ((event.detail & SWT.SELECTED) > 0) { | |
425 | Color oldForeground = event.gc.getForeground(); | |
426 | event.gc.setForeground(event.item.getDisplay() | |
427 | .getSystemColor(SWT.COLOR_LIST_SELECTION)); | |
428 | event.gc.fillRectangle(event.x, event.y, event.width, | |
429 | event.height); | |
430 | event.gc.setForeground(oldForeground); | |
431 | event.detail &= ~SWT.SELECTED; | |
432 | } | |
433 | ||
434 | int barWidth = (int) ((treeViewer.getTree().getColumn(1) | |
435 | .getWidth() - 8) * percentage); | |
436 | int oldAlpha = event.gc.getAlpha(); | |
437 | Color oldForeground = event.gc.getForeground(); | |
438 | Color oldBackground = event.gc.getBackground(); | |
439 | event.gc.setAlpha(64); | |
440 | event.gc.setForeground(event.item.getDisplay() | |
441 | .getSystemColor(SWT.COLOR_BLUE)); | |
442 | event.gc.setBackground(event.item.getDisplay() | |
443 | .getSystemColor(SWT.COLOR_LIST_BACKGROUND)); | |
444 | event.gc.fillGradientRectangle(event.x, event.y, barWidth, | |
445 | event.height, true); | |
446 | event.gc.drawRectangle(event.x, event.y, barWidth, | |
447 | event.height); | |
448 | event.gc.setForeground(oldForeground); | |
449 | event.gc.setBackground(oldBackground); | |
450 | event.gc.setAlpha(oldAlpha); | |
451 | event.detail &= ~SWT.BACKGROUND; | |
452 | } | |
453 | } | |
454 | }); | |
455 | ||
456 | treeViewer.setComparator(columnDataList[0].comparator); | |
457 | treeViewer.getTree().setSortColumn(treeViewer.getTree().getColumn(0)); | |
458 | treeViewer.getTree().setSortDirection(SWT.DOWN); | |
459 | ||
dfaf8391 | 460 | // Read current data if any available |
8827c197 FC |
461 | TmfExperiment<?> experiment = TmfExperiment.getCurrentExperiment(); |
462 | if (experiment != null) { | |
463 | requestData(experiment); | |
464 | } else { | |
3b38ea61 | 465 | TraceDebug.debug("No selected experiment information available"); //$NON-NLS-1$ |
8827c197 | 466 | } |
dfaf8391 | 467 | } |
8827c197 | 468 | |
dfaf8391 FC |
469 | @Override |
470 | public void dispose() { | |
471 | super.dispose(); | |
8827c197 FC |
472 | if (fwaitCursor != null) { |
473 | fwaitCursor.dispose(); | |
474 | } | |
6e512b93 | 475 | |
8827c197 FC |
476 | // clean the model |
477 | StatisticsTreeRootFactory.removeAll(); | |
6e512b93 ASL |
478 | } |
479 | ||
dfaf8391 FC |
480 | /* |
481 | * (non-Javadoc) | |
482 | * | |
6e512b93 ASL |
483 | * @see org.eclipse.ui.part.WorkbenchPart#setFocus() |
484 | */ | |
485 | @Override | |
486 | public void setFocus() { | |
dfaf8391 FC |
487 | treeViewer.getTree().setFocus(); |
488 | } | |
489 | ||
c1c69938 FC |
490 | |
491 | /* | |
492 | * (non-Javadoc) | |
493 | * @see org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView#getInputChangedRefresh() | |
494 | */ | |
495 | @Override | |
496 | protected Long getInputChangedRefresh() { | |
497 | return STATS_INPUT_CHANGED_REFRESH; | |
498 | } | |
6e512b93 | 499 | |
8827c197 FC |
500 | /** |
501 | * @return | |
502 | */ | |
550d787e | 503 | @Override |
8827c197 FC |
504 | public AbsEventToHandlerResolver getEventProcessor() { |
505 | return StatsTimeCountHandlerFactory.getInstance(); | |
6e512b93 ASL |
506 | } |
507 | ||
8827c197 FC |
508 | /* |
509 | * (non-Javadoc) | |
510 | * | |
511 | * @see | |
512 | * org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView#waitCursor | |
513 | * (boolean) | |
514 | */ | |
550d787e | 515 | @Override |
8827c197 | 516 | protected void waitCursor(final boolean waitInd) { |
db1ea19b | 517 | if ((treeViewer == null) || (treeViewer.getTree().isDisposed())) { |
8827c197 FC |
518 | return; |
519 | } | |
520 | ||
521 | Display display = treeViewer.getControl().getDisplay(); | |
522 | if (fwaitCursor == null) { | |
523 | fwaitCursor = new Cursor(display, SWT.CURSOR_WAIT); | |
524 | } | |
525 | ||
526 | // Perform the updates on the UI thread | |
527 | display.asyncExec(new Runnable() { | |
d4011df2 | 528 | @Override |
8827c197 | 529 | public void run() { |
db1ea19b FC |
530 | if ((treeViewer != null) && (!treeViewer.getTree().isDisposed())) { |
531 | Cursor cursor = null; /* indicates default */ | |
532 | if (waitInd) { | |
533 | cursor = fwaitCursor; | |
534 | } | |
535 | treeViewer.getControl().setCursor(cursor); | |
8827c197 | 536 | } |
8827c197 FC |
537 | } |
538 | }); | |
539 | } | |
540 | ||
541 | @Override | |
542 | public void ModelUpdatePrep(TmfTimeRange timeRange, boolean clearAllData) { | |
543 | Object input = treeViewer.getInput(); | |
db1ea19b | 544 | if ((input != null) && (input instanceof StatisticsTreeNode) && (!treeViewer.getTree().isDisposed())) { |
8827c197 FC |
545 | ((StatisticsTreeNode) input).reset(); |
546 | treeViewer.getTree().getDisplay().asyncExec(new Runnable() { | |
547 | // @Override | |
d4011df2 | 548 | @Override |
8827c197 | 549 | public void run() { |
db1ea19b FC |
550 | if (!treeViewer.getTree().isDisposed()) |
551 | treeViewer.refresh(); | |
8827c197 FC |
552 | } |
553 | }); | |
554 | } | |
555 | } | |
556 | ||
557 | @Override | |
558 | public void modelInputChanged(ILttngSyntEventRequest request, boolean complete) { | |
db1ea19b FC |
559 | // Ignore update if disposed |
560 | if (treeViewer.getTree().isDisposed()) return; | |
561 | ||
dfaf8391 FC |
562 | treeViewer.getTree().getDisplay().asyncExec(new Runnable() { |
563 | // @Override | |
d4011df2 | 564 | @Override |
dfaf8391 | 565 | public void run() { |
db1ea19b FC |
566 | if (!treeViewer.getTree().isDisposed()) |
567 | treeViewer.refresh(); | |
dfaf8391 FC |
568 | } |
569 | }); | |
db1ea19b | 570 | } |
8827c197 FC |
571 | |
572 | /* | |
573 | * (non-Javadoc) | |
574 | * | |
575 | * @see org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView# | |
576 | * modelIncomplete | |
577 | * (org.eclipse.linuxtools.lttng.request.ILttngSyntEventRequest) | |
578 | */ | |
579 | @Override | |
580 | public void modelIncomplete(ILttngSyntEventRequest request) { | |
581 | Object input = treeViewer.getInput(); | |
582 | if (input != null && input instanceof StatisticsTreeNode) { | |
583 | // The data from this experiment is invalid and shall be removed to | |
584 | // refresh upon next selection | |
c1c69938 | 585 | String name = request.getExperimentName(); |
8827c197 FC |
586 | StatisticsTreeRootFactory.removeStatTreeRoot(name); |
587 | } | |
588 | } | |
589 | ||
590 | /** | |
591 | * @param signal | |
592 | */ | |
593 | @TmfSignalHandler | |
594 | public void experimentSelected(TmfExperimentSelectedSignal<? extends TmfEvent> signal) { | |
595 | if (signal != null) { | |
596 | TmfExperiment<?> experiment = signal.getExperiment(); | |
597 | String experimentName = experiment.getName(); | |
598 | ||
599 | if (StatisticsTreeRootFactory.containsTreeRoot(experimentName)) { | |
600 | // The experiment root is already present | |
601 | StatisticsTreeNode experimentTreeNode = StatisticsTreeRootFactory.getStatTreeRoot(experimentName); | |
602 | ||
603 | ITmfTrace[] traces = experiment.getTraces(); | |
604 | ||
605 | // check if there is partial data loaded in the experiment | |
606 | int numTraces = experiment.getTraces().length; | |
607 | int numNodeTraces = experimentTreeNode.getNbChildren(); | |
608 | ||
609 | if (numTraces == numNodeTraces) { | |
610 | boolean same = true; | |
611 | // Detect if the experiment contains the same traces as when | |
612 | // previously selected | |
613 | for (int i = 0; i < numTraces; i++) { | |
614 | String traceName = traces[i].getName(); | |
615 | if (!experimentTreeNode.containsChild(traceName)) { | |
9b635e61 FC |
616 | same = false; |
617 | break; | |
8827c197 FC |
618 | } |
619 | } | |
620 | ||
621 | if (same) { | |
622 | // no need to reload data, all traces are already loaded | |
623 | treeViewer.setInput(experimentTreeNode); | |
624 | return; | |
625 | } | |
626 | } | |
627 | } | |
628 | ||
629 | // if the data is not available or has changed, reload it | |
630 | requestData(experiment); | |
631 | } | |
632 | } | |
633 | ||
634 | /** | |
635 | * @param experiment | |
636 | */ | |
637 | private void requestData(TmfExperiment<?> experiment) { | |
638 | if (experiment != null) { | |
639 | StatisticsTreeNode treeModelRoot = StatisticsTreeRootFactory.getStatTreeRoot(experiment.getName()); | |
640 | ||
641 | // if the model has contents, clear to start over | |
642 | if (treeModelRoot.hasChildren()) { | |
643 | treeModelRoot.reset(); | |
644 | } | |
645 | ||
646 | // set input to a clean data model | |
647 | treeViewer.setInput(treeModelRoot); | |
648 | TmfTimeRange experimentTRange = experiment.getTimeRange(); | |
649 | ||
650 | // send the initial request, to start filling up model | |
f6b14ce2 | 651 | dataRequest(experimentTRange, experimentTRange, true, ExecutionType.BACKGROUND); |
8827c197 | 652 | } else { |
3b38ea61 | 653 | TraceDebug.debug("No selected experiment information available"); //$NON-NLS-1$ |
8827c197 FC |
654 | } |
655 | } | |
656 | ||
657 | /* | |
658 | * (non-Javadoc) | |
659 | * | |
660 | * @see | |
661 | * org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView#displayModel | |
662 | * (org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model. | |
663 | * ITmfTimeAnalysisEntry[], long, long, boolean, long, long, | |
664 | * java.lang.Object) | |
665 | */ | |
666 | @Override | |
667 | protected void displayModel(ITmfTimeAnalysisEntry[] items, long startBoundTime, long endBoundTime, | |
668 | boolean updateTimeBounds, long startVisibleWindow, long endVisibleWindow, Object source) { | |
669 | // No applicable to statistics view | |
670 | } | |
671 | ||
672 | /* | |
673 | * (non-Javadoc) | |
674 | * | |
675 | * @see org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView# | |
676 | * getParamsUpdater() | |
677 | */ | |
678 | @Override | |
679 | protected ParamsUpdater getParamsUpdater() { | |
680 | // Not applicable to statistics view | |
681 | return null; | |
682 | } | |
683 | ||
684 | @Override | |
685 | protected ItemContainer<?> getItemContainer() { | |
686 | // Not applicable to statistics view | |
687 | return null; | |
688 | } | |
c1c69938 FC |
689 | |
690 | /* | |
691 | * (non-Javadoc) | |
692 | * @see org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView#getProviderId() | |
693 | */ | |
694 | @Override | |
695 | protected int getProviderId() { | |
696 | return LttngCoreProviderFactory.STATISTICS_LTTNG_SYTH_EVENT_PROVIDER; | |
697 | } | |
6e512b93 | 698 | } |