1 /*******************************************************************************
2 * Copyright (c) 2015 É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 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.ui
.criticalpath
;
12 import org
.eclipse
.jface
.viewers
.ISelection
;
13 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
14 import org
.eclipse
.tracecompass
.analysis
.graph
.core
.criticalpath
.CriticalPathModule
;
15 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.model
.HostThread
;
16 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.ui
.views
.controlflow
.ControlFlowEntry
;
17 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.ui
.views
.controlflow
.ControlFlowView
;
18 import org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
;
19 import org
.eclipse
.tracecompass
.internal
.analysis
.graph
.ui
.criticalpath
.view
.CriticalPathView
;
20 import org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.core
.analysis
.graph
.model
.LttngWorker
;
21 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.IAnalysisModule
;
22 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.TmfAbstractAnalysisParamProvider
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
24 import org
.eclipse
.ui
.IPartListener2
;
25 import org
.eclipse
.ui
.ISelectionListener
;
26 import org
.eclipse
.ui
.IViewPart
;
27 import org
.eclipse
.ui
.IWorkbench
;
28 import org
.eclipse
.ui
.IWorkbenchPage
;
29 import org
.eclipse
.ui
.IWorkbenchPart
;
30 import org
.eclipse
.ui
.IWorkbenchPartReference
;
31 import org
.eclipse
.ui
.PlatformUI
;
34 * Class that provides parameters to the critical path analysis for lttng kernel
37 * @author Geneviève Bastien
39 public class CriticalPathParameterProvider
extends TmfAbstractAnalysisParamProvider
{
41 private final class IPartListener2Impl
implements IPartListener2
{
43 private final Class
<?
> fType
;
45 IPartListener2Impl(Class
<?
> type
) {
49 private void toggleState(IWorkbenchPartReference partRef
, boolean state
) {
50 if (fType
.isInstance(partRef
.getPart(false))) {
56 public void partActivated(IWorkbenchPartReference partRef
) {
57 toggleState(partRef
, true);
61 public void partBroughtToTop(IWorkbenchPartReference partRef
) {
66 public void partClosed(IWorkbenchPartReference partRef
) {
67 toggleState(partRef
, false);
71 public void partDeactivated(IWorkbenchPartReference partRef
) {
76 public void partOpened(IWorkbenchPartReference partRef
) {
77 toggleState(partRef
, true);
81 public void partHidden(IWorkbenchPartReference partRef
) {
82 toggleState(partRef
, false);
86 public void partVisible(IWorkbenchPartReference partRef
) {
87 toggleState(partRef
, true);
91 public void partInputChanged(IWorkbenchPartReference partRef
) {
96 private ISelectionListener fSelListener
= new ISelectionListener() {
98 public void selectionChanged(IWorkbenchPart part
, ISelection selection
) {
99 if (selection
instanceof IStructuredSelection
) {
100 Object element
= ((IStructuredSelection
) selection
).getFirstElement();
101 if (element
instanceof ControlFlowEntry
) {
102 ControlFlowEntry entry
= (ControlFlowEntry
) element
;
103 setCurrentThreadId(entry
);
109 private static final String NAME
= "Critical Path Lttng kernel parameter provider"; //$NON-NLS-1$
111 private final IPartListener2 fPartListener
= new IPartListener2Impl(CriticalPathView
.class);
113 private ControlFlowEntry fCurrentEntry
= null;
115 private boolean fActive
= false;
116 private boolean fEntryChanged
= false;
121 public CriticalPathParameterProvider() {
127 public String
getName() {
132 public Object
getParameter(String name
) {
133 if (fCurrentEntry
== null) {
136 if (name
.equals(CriticalPathModule
.PARAM_WORKER
)) {
137 /* Try to find the worker for the critical path */
138 IAnalysisModule mod
= getModule();
139 if ((mod
!= null) && (mod
instanceof CriticalPathModule
)) {
140 Integer threadId
= NonNullUtils
.checkNotNull(fCurrentEntry
.getThreadId());
141 HostThread ht
= new HostThread(fCurrentEntry
.getTrace().getHostId(), threadId
);
142 LttngWorker worker
= new LttngWorker(ht
, "", 0); //$NON-NLS-1$
145 return fCurrentEntry
;
151 public boolean appliesToTrace(ITmfTrace trace
) {
155 private void setCurrentThreadId(ControlFlowEntry entry
) {
156 if (!entry
.equals(fCurrentEntry
)) {
157 fCurrentEntry
= entry
;
159 this.notifyParameterChanged(CriticalPathModule
.PARAM_WORKER
);
161 fEntryChanged
= true;
166 private void toggleActive(boolean active
) {
167 if (active
!= fActive
) {
169 if (fActive
&& fEntryChanged
) {
170 this.notifyParameterChanged(CriticalPathModule
.PARAM_WORKER
);
171 fEntryChanged
= false;
176 private void registerListener() {
177 final IWorkbench wb
= PlatformUI
.getWorkbench();
179 final IWorkbenchPage activePage
= wb
.getActiveWorkbenchWindow().getActivePage();
181 /* Activate the update if critical path view visible */
182 IViewPart view
= activePage
.findView(CriticalPathView
.ID
);
184 if (activePage
.isPartVisible(view
)) {
189 /* Add the listener to the control flow view */
190 view
= activePage
.findView(ControlFlowView
.ID
);
192 view
.getSite().getWorkbenchWindow().getSelectionService().addPostSelectionListener(fSelListener
);
193 view
.getSite().getWorkbenchWindow().getPartService().addPartListener(fPartListener
);