1 /**********************************************************************
2 * Copyright (c) 2016 École Polytechnique de Montréal
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 package org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.ui
.views
.kernelmemoryusage
;
11 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
13 import org
.eclipse
.jdt
.annotation
.NonNull
;
14 import org
.eclipse
.jface
.viewers
.ISelection
;
15 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
16 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
17 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
18 import org
.eclipse
.swt
.events
.ControlAdapter
;
19 import org
.eclipse
.swt
.events
.ControlEvent
;
20 import org
.eclipse
.swt
.widgets
.Composite
;
21 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceSelectedSignal
;
22 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceContext
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceManager
;
25 import org
.eclipse
.tracecompass
.tmf
.ui
.viewers
.TmfViewer
;
26 import org
.eclipse
.tracecompass
.tmf
.ui
.viewers
.xycharts
.TmfXYChartViewer
;
27 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.TmfChartView
;
32 * @author Samuel Gagnon
33 * @author Mahdi Zolnouri
34 * @author Wassim Nasrallah
36 public class KernelMemoryUsageView
extends TmfChartView
{
39 public static final @NonNull String ID
= "org.eclipse.tracecompass.analysis.os.linux.ui.kernelmemoryusageview"; //$NON-NLS-1$
40 /** ID of the Kernel Memory Usage view data in the data map of {@link TmfTraceContext} */
41 public static final @NonNull String KERNEL_MEMORY
= ID
+ ".KERNEL_MEMORY"; //$NON-NLS-1$
44 * We need this reference to update the viewer when there is a new selection
46 private KernelMemoryUsageTreeViewer fTreeViewerReference
= null;
51 public KernelMemoryUsageView() {
52 super(Messages
.MemoryUsageView_title
);
56 protected TmfXYChartViewer
createChartViewer(Composite parent
) {
57 return new KernelMemoryUsageViewer(parent
);
60 private final class SelectionChangeListener
implements ISelectionChangedListener
{
62 public void selectionChanged(SelectionChangedEvent event
) {
63 ISelection selection
= event
.getSelection();
64 if (selection
instanceof IStructuredSelection
) {
65 Object structSelection
= ((IStructuredSelection
) selection
).getFirstElement();
66 if (structSelection
instanceof KernelMemoryUsageEntry
) {
67 KernelMemoryUsageEntry entry
= (KernelMemoryUsageEntry
) structSelection
;
68 fTreeViewerReference
.setSelectedThread(entry
.getTid());
69 ((KernelMemoryUsageViewer
) getChartViewer()).setSelectedThread(entry
.getTid());
70 TmfTraceContext ctx
= TmfTraceManager
.getInstance().getCurrentTraceContext();
71 ctx
.setData(KERNEL_MEMORY
, checkNotNull(entry
.getTid()));
78 protected @NonNull TmfViewer
createLeftChildViewer(Composite parent
) {
80 KernelMemoryUsageTreeViewer fTreeViewer
= new KernelMemoryUsageTreeViewer(parent
);
81 fTreeViewerReference
= fTreeViewer
;
83 fTreeViewer
.addSelectionChangeListener(new SelectionChangeListener());
85 /* Initialize the viewers with the currently selected trace */
86 ITmfTrace trace
= TmfTraceManager
.getInstance().getActiveTrace();
88 TmfTraceSelectedSignal signal
= new TmfTraceSelectedSignal(this, trace
);
89 fTreeViewer
.traceSelected(signal
);
90 fTreeViewerReference
.traceSelected(signal
);
93 fTreeViewer
.getControl().addControlListener(new ControlAdapter() {
95 public void controlResized(ControlEvent e
) {
96 super.controlResized(e
);