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