Commit | Line | Data |
---|---|---|
b720ac44 | 1 | /********************************************************************** |
11252342 | 2 | * Copyright (c) 2012, 2013 Ericsson |
cfdb727a | 3 | * |
b720ac44 BH |
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 | |
cfdb727a AM |
8 | * |
9 | * Contributors: | |
b720ac44 BH |
10 | * Bernd Hufmann - Initial API and implementation |
11 | **********************************************************************/ | |
8e8c0226 | 12 | package org.eclipse.linuxtools.internal.lttng2.control.ui.views.handlers; |
b720ac44 BH |
13 | |
14 | import java.util.Iterator; | |
15 | ||
16 | import org.eclipse.core.commands.ExecutionEvent; | |
17 | import org.eclipse.core.commands.ExecutionException; | |
18 | import org.eclipse.core.runtime.IProgressMonitor; | |
19 | import org.eclipse.core.runtime.IStatus; | |
20 | import org.eclipse.core.runtime.Status; | |
21 | import org.eclipse.core.runtime.jobs.Job; | |
22 | import org.eclipse.jface.viewers.ISelection; | |
23 | import org.eclipse.jface.viewers.StructuredSelection; | |
8e8c0226 AM |
24 | import org.eclipse.linuxtools.internal.lttng2.control.ui.Activator; |
25 | import org.eclipse.linuxtools.internal.lttng2.control.ui.views.ControlView; | |
26 | import org.eclipse.linuxtools.internal.lttng2.control.ui.views.messages.Messages; | |
27 | import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TraceDomainComponent; | |
28 | import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TraceSessionComponent; | |
b720ac44 BH |
29 | import org.eclipse.ui.IWorkbenchPage; |
30 | import org.eclipse.ui.IWorkbenchWindow; | |
31 | import org.eclipse.ui.PlatformUI; | |
32 | ||
33 | /** | |
b720ac44 BH |
34 | * <p> |
35 | * Command handler implementation to execute command calibrate to quantify LTTng overhead. | |
36 | * </p> | |
cfdb727a | 37 | * |
dbd4432d | 38 | * @author Bernd Hufmann |
b720ac44 BH |
39 | */ |
40 | public class CalibrateHandler extends BaseControlViewHandler { | |
41 | ||
42 | // ------------------------------------------------------------------------ | |
43 | // Attributes | |
44 | // ------------------------------------------------------------------------ | |
45 | /** | |
46 | * The command execution parameter. | |
47 | */ | |
48 | protected DomainCommandParameter fParam = null; | |
49 | ||
50 | // ------------------------------------------------------------------------ | |
51 | // Operations | |
52 | // ------------------------------------------------------------------------ | |
cfdb727a | 53 | |
b720ac44 BH |
54 | @Override |
55 | public Object execute(ExecutionEvent event) throws ExecutionException { | |
56 | ||
57 | final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); | |
58 | ||
59 | if (window == null) { | |
60 | return false; | |
61 | } | |
62 | fLock.lock(); | |
63 | try { | |
64 | // Make a copy for thread safety | |
65 | final DomainCommandParameter param = fParam.clone(); | |
66 | ||
67 | Job addJob = new Job(Messages.TraceControl_AddCalibrateJob) { | |
68 | @Override | |
69 | protected IStatus run(IProgressMonitor monitor) { | |
70 | try { | |
71 | param.getDomain().calibrate(monitor); | |
72 | } catch (ExecutionException e) { | |
cfdb727a | 73 | return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_AddCalibrateFailure, e); |
b720ac44 BH |
74 | } |
75 | ||
76 | return Status.OK_STATUS; | |
77 | } | |
78 | }; | |
79 | addJob.setUser(true); | |
80 | addJob.schedule(); | |
81 | ||
82 | } finally { | |
83 | fLock.unlock(); | |
84 | } | |
85 | return Status.OK_STATUS; | |
86 | } | |
87 | ||
b720ac44 BH |
88 | @Override |
89 | public boolean isEnabled() { | |
cfdb727a | 90 | |
b720ac44 BH |
91 | // Get workbench page for the Control View |
92 | IWorkbenchPage page = getWorkbenchPage(); | |
93 | if (page == null) { | |
94 | return false; | |
95 | } | |
96 | ||
97 | TraceDomainComponent domain = null; | |
98 | TraceSessionComponent session = null; | |
99 | ||
100 | // Check if one domain is selected | |
101 | ISelection selection = page.getSelection(ControlView.ID); | |
102 | if (selection instanceof StructuredSelection) { | |
103 | StructuredSelection structered = ((StructuredSelection) selection); | |
104 | for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) { | |
cfdb727a | 105 | Object element = iterator.next(); |
b720ac44 BH |
106 | if (element instanceof TraceDomainComponent) { |
107 | TraceDomainComponent tmpDomain = (TraceDomainComponent) element; | |
108 | session = (TraceSessionComponent) tmpDomain.getParent(); | |
cfdb727a | 109 | |
b720ac44 BH |
110 | // Add only TraceDomainComponent whose TraceSessionComponent parent is not destroyed |
111 | if ((!session.isDestroyed())) { | |
112 | domain = tmpDomain; | |
113 | } | |
114 | } | |
115 | } | |
116 | } | |
117 | ||
118 | boolean isEnabled = domain != null; | |
119 | ||
120 | fLock.lock(); | |
121 | try { | |
122 | fParam = null; | |
123 | if (isEnabled) { | |
124 | fParam = new DomainCommandParameter(session, domain); | |
125 | } | |
126 | } finally { | |
127 | fLock.unlock(); | |
128 | } | |
129 | ||
130 | return isEnabled; | |
131 | } | |
132 | } |