Commit | Line | Data |
---|---|---|
dffc234f GB |
1 | /******************************************************************************* |
2 | * Copyright (c) 2014 École Polytechnique de Montréal | |
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 | * Geneviève Bastien - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.cpuusage; | |
14 | ||
e9a0d1cb GB |
15 | import org.eclipse.jface.viewers.ISelection; |
16 | import org.eclipse.jface.viewers.ISelectionChangedListener; | |
17 | import org.eclipse.jface.viewers.IStructuredSelection; | |
18 | import org.eclipse.jface.viewers.SelectionChangedEvent; | |
dffc234f GB |
19 | import org.eclipse.linuxtools.tmf.core.signal.TmfTraceSelectedSignal; |
20 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; | |
dffc234f GB |
21 | import org.eclipse.linuxtools.tmf.ui.views.TmfView; |
22 | import org.eclipse.swt.SWT; | |
23 | import org.eclipse.swt.custom.SashForm; | |
24 | import org.eclipse.swt.layout.FillLayout; | |
25 | import org.eclipse.swt.widgets.Composite; | |
26 | ||
27 | /** | |
28 | * CPU usage view. It contains 2 viewers: one tree viewer showing all the | |
29 | * threads who were on the CPU in the time range, and one XY chart viewer | |
30 | * plotting the total time spent on CPU and the time of the threads selected in | |
31 | * the tree viewer. | |
32 | * | |
33 | * @author Geneviève Bastien | |
34 | */ | |
35 | public class CpuUsageView extends TmfView { | |
36 | ||
37 | /** ID string */ | |
38 | public static final String ID = "org.eclipse.linuxtools.lttng2.kernel.ui.views.cpuusage"; //$NON-NLS-1$ | |
39 | ||
3df2eabe | 40 | private CpuUsageComposite fTreeViewer = null; |
e9a0d1cb | 41 | private CpuUsageXYViewer fXYViewer = null; |
3df2eabe | 42 | |
dffc234f GB |
43 | /** |
44 | * Constructor | |
45 | */ | |
46 | public CpuUsageView() { | |
47 | super(Messages.CpuUsageView_Title); | |
48 | } | |
49 | ||
50 | @Override | |
51 | public void createPartControl(Composite parent) { | |
52 | ||
53 | final SashForm sash = new SashForm(parent, SWT.NONE); | |
54 | ||
3df2eabe | 55 | fTreeViewer = new CpuUsageComposite(sash); |
dffc234f GB |
56 | |
57 | /* Build the XY chart part of the view */ | |
e9a0d1cb GB |
58 | fXYViewer = new CpuUsageXYViewer(sash); |
59 | ||
60 | /* Add selection listener to tree viewer */ | |
61 | fTreeViewer.addSelectionChangeListener(new ISelectionChangedListener() { | |
62 | @Override | |
63 | public void selectionChanged(SelectionChangedEvent event) { | |
64 | ISelection selection = event.getSelection(); | |
65 | if (selection instanceof IStructuredSelection) { | |
66 | Object structSelection = ((IStructuredSelection) selection).getFirstElement(); | |
67 | if (structSelection instanceof CpuUsageEntry) { | |
68 | CpuUsageEntry entry = (CpuUsageEntry) structSelection; | |
69 | fTreeViewer.setSelectedThread(entry.getTid()); | |
70 | fXYViewer.setSelectedThread(Long.valueOf(entry.getTid())); | |
71 | } | |
72 | } | |
73 | } | |
74 | }); | |
dffc234f GB |
75 | |
76 | sash.setLayout(new FillLayout()); | |
77 | ||
78 | /* Initialize the viewers with the currently selected trace */ | |
79 | ITmfTrace trace = getActiveTrace(); | |
80 | if (trace != null) { | |
81 | TmfTraceSelectedSignal signal = new TmfTraceSelectedSignal(this, trace); | |
3df2eabe BH |
82 | fTreeViewer.traceSelected(signal); |
83 | fXYViewer.traceSelected(signal); | |
dffc234f GB |
84 | } |
85 | ||
86 | } | |
87 | ||
88 | @Override | |
89 | public void setFocus() { | |
90 | } | |
91 | ||
3df2eabe BH |
92 | @Override |
93 | public void dispose() { | |
94 | super.dispose(); | |
95 | if (fTreeViewer != null) { | |
96 | fTreeViewer.dispose(); | |
97 | } | |
98 | if (fXYViewer != null) { | |
99 | fXYViewer.dispose(); | |
100 | } | |
101 | } | |
102 | ||
dffc234f | 103 | } |