1 /**********************************************************************
2 * Copyright (c) 2012, 2015 Ericsson
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
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12 package org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.handlers
;
14 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
16 import java
.util
.Iterator
;
18 import org
.eclipse
.core
.commands
.ExecutionEvent
;
19 import org
.eclipse
.core
.commands
.ExecutionException
;
20 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
21 import org
.eclipse
.core
.runtime
.IStatus
;
22 import org
.eclipse
.core
.runtime
.Status
;
23 import org
.eclipse
.core
.runtime
.jobs
.Job
;
24 import org
.eclipse
.jface
.viewers
.ISelection
;
25 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
26 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.Activator
;
27 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.ControlView
;
28 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.messages
.Messages
;
29 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceDomainComponent
;
30 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceSessionComponent
;
31 import org
.eclipse
.ui
.IWorkbenchPage
;
32 import org
.eclipse
.ui
.IWorkbenchWindow
;
33 import org
.eclipse
.ui
.PlatformUI
;
37 * Command handler implementation to execute command calibrate to quantify LTTng overhead.
40 * @author Bernd Hufmann
42 public class CalibrateHandler
extends BaseControlViewHandler
{
44 // ------------------------------------------------------------------------
46 // ------------------------------------------------------------------------
48 * The command execution parameter.
50 protected DomainCommandParameter fParam
= null;
52 // ------------------------------------------------------------------------
54 // ------------------------------------------------------------------------
57 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
59 final IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
67 DomainCommandParameter tmpParam
= fParam
;
68 if (tmpParam
== null) {
72 // Make a copy for thread safety
73 final DomainCommandParameter param
= new DomainCommandParameter(tmpParam
);
75 Job addJob
= new Job(Messages
.TraceControl_AddCalibrateJob
) {
77 protected IStatus
run(IProgressMonitor monitor
) {
79 param
.getDomain().calibrate(monitor
);
80 } catch (ExecutionException e
) {
81 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_AddCalibrateFailure
, e
);
84 return Status
.OK_STATUS
;
93 return Status
.OK_STATUS
;
97 public boolean isEnabled() {
99 // Get workbench page for the Control View
100 IWorkbenchPage page
= getWorkbenchPage();
105 TraceDomainComponent domain
= null;
106 TraceSessionComponent session
= null;
108 // Check if one domain is selected
109 ISelection selection
= page
.getSelection(ControlView
.ID
);
110 if (selection
instanceof StructuredSelection
) {
111 StructuredSelection structered
= ((StructuredSelection
) selection
);
112 for (Iterator
<?
> iterator
= structered
.iterator(); iterator
.hasNext();) {
113 Object element
= iterator
.next();
114 if (element
instanceof TraceDomainComponent
) {
115 TraceDomainComponent tmpDomain
= (TraceDomainComponent
) element
;
116 session
= (TraceSessionComponent
) tmpDomain
.getParent();
118 // Add only TraceDomainComponent whose TraceSessionComponent parent is not destroyed
119 if ((!session
.isDestroyed())) {
126 boolean isEnabled
= domain
!= null;
132 fParam
= new DomainCommandParameter(checkNotNull(session
), checkNotNull(domain
));