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