control: command support for enabling all tracepoints/syscalls
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.control.ui / src / org / eclipse / tracecompass / internal / lttng2 / control / ui / views / handlers / BaseEnableEventHandler.java
1 /**********************************************************************
2 * Copyright (c) 2012, 2015 Ericsson
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 * Bernd Hufmann - Initial API and implementation
11 * Bernd Hufmann - Updated for support of LTTng Tools 2.1
12 **********************************************************************/
13 package org.eclipse.tracecompass.internal.lttng2.control.ui.views.handlers;
14
15 import java.util.List;
16
17 import org.eclipse.core.commands.ExecutionEvent;
18 import org.eclipse.core.commands.ExecutionException;
19 import org.eclipse.core.runtime.IProgressMonitor;
20 import org.eclipse.core.runtime.IStatus;
21 import org.eclipse.core.runtime.Status;
22 import org.eclipse.core.runtime.jobs.Job;
23 import org.eclipse.jdt.annotation.Nullable;
24 import org.eclipse.jface.window.Window;
25 import org.eclipse.tracecompass.internal.lttng2.control.core.model.LogLevelType;
26 import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceLogLevel;
27 import org.eclipse.tracecompass.internal.lttng2.control.ui.Activator;
28 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.dialogs.IEnableEventsDialog;
29 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.dialogs.TraceControlDialogFactory;
30 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.messages.Messages;
31 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.ITraceControlComponent;
32 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TargetNodeComponent;
33 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceDomainComponent;
34 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceProviderGroup;
35 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.service.ILttngControlService;
36 import org.eclipse.ui.IWorkbenchWindow;
37 import org.eclipse.ui.PlatformUI;
38
39 /**
40 * <p>
41 * Base command handler implementation to enable events.
42 * </p>
43 *
44 * @author Bernd Hufmann
45 */
46 public abstract class BaseEnableEventHandler extends BaseControlViewHandler {
47
48 // ------------------------------------------------------------------------
49 // Attributes
50 // ------------------------------------------------------------------------
51 /**
52 * The command execution parameter.
53 */
54 @Nullable
55 protected CommandParameter fParam = null;
56
57 // ------------------------------------------------------------------------
58 // Operations
59 // ------------------------------------------------------------------------
60
61 /**
62 * Enables a list of events for given parameters.
63 *
64 * @param param
65 * - a parameter instance with data for the command execution
66 * @param eventNames
67 * - list of event names
68 * @param isKernel
69 * - true if kernel domain else false
70 * @param filterExpression
71 * - a filter expression
72 * @param monitor
73 * - a progress monitor
74 * @throws ExecutionException
75 * If the command fails for some reason
76 */
77 public abstract void enableEvents(CommandParameter param, List<String> eventNames, boolean isKernel, String filterExpression, IProgressMonitor monitor) throws ExecutionException;
78
79 /**
80 * Enables all syscall events.
81 *
82 * @param param
83 * - a parameter instance with data for the command execution
84 * @param monitor
85 * - a progress monitor
86 * @throws ExecutionException
87 * If the command fails for some reason
88 */
89 public abstract void enableSyscalls(CommandParameter param, IProgressMonitor monitor) throws ExecutionException;
90
91 /**
92 * Enables a dynamic probe.
93 *
94 * @param param
95 * - a parameter instance with data for the command execution
96 * @param eventName
97 * - a event name
98 * @param isFunction
99 * - true for dynamic function entry/return probe else false
100 * @param probe
101 * - a dynamic probe information
102 * @param monitor
103 * - a progress monitor
104 * @throws ExecutionException
105 * If the command fails for some reason
106 */
107 public abstract void enableProbe(CommandParameter param, String eventName, boolean isFunction, String probe, IProgressMonitor monitor) throws ExecutionException;
108
109 /**
110 * Enables events using log level
111 *
112 * @param param
113 * - a parameter instance with data for the command execution
114 * @param eventName
115 * - a event name
116 * @param logLevelType
117 * - a log level type
118 * @param level
119 * - a log level
120 * @param filterExpression
121 * - a filter expression
122 * @param monitor
123 * - a progress monitor
124 * @throws ExecutionException
125 * If the command fails for some reason
126 */
127 public abstract void enableLogLevel(CommandParameter param, String eventName, LogLevelType logLevelType, TraceLogLevel level, String filterExpression, IProgressMonitor monitor) throws ExecutionException;
128
129 /**
130 * @param param
131 * - a parameter instance with data for the command execution
132 * @return returns the relevant domain (null if domain is not known)
133 */
134 public abstract TraceDomainComponent getDomain(CommandParameter param);
135
136 @Override
137 public Object execute(ExecutionEvent event) throws ExecutionException {
138
139 final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
140
141 if (window == null) {
142 return false;
143 }
144
145 // Make a copy for thread safety
146 CommandParameter tmpParam = null;
147 fLock.lock();
148 try {
149 tmpParam = fParam;
150 if (tmpParam == null) {
151 return null;
152 }
153 tmpParam = tmpParam.clone();
154 } finally {
155 fLock.unlock();
156 }
157 final CommandParameter param = tmpParam;
158
159 TargetNodeComponent node = param.getSession().getTargetNode();
160 List<ITraceControlComponent> providers = node.getChildren(TraceProviderGroup.class);
161
162 final IEnableEventsDialog dialog = TraceControlDialogFactory.getInstance().getEnableEventsDialog();
163 dialog.setTraceProviderGroup((TraceProviderGroup) providers.get(0));
164 dialog.setTraceDomainComponent(getDomain(param));
165
166 if (dialog.open() != Window.OK) {
167 return null;
168 }
169
170 Job job = new Job(Messages.TraceControl_ChangeEventStateJob) {
171 @Override
172 protected IStatus run(IProgressMonitor monitor) {
173 Exception error = null;
174
175 try {
176 String filter = dialog.getFilterExpression();
177 if (dialog.isAllEvents()) {
178 enableEvents(param, ILttngControlService.ALL_EVENTS, dialog.isKernel(), filter, monitor);
179 } else if (dialog.isTracepoints()) {
180 // Enable tracepoint events
181 if (dialog.isAllTracePoints()) {
182 enableEvents(param, null, dialog.isKernel(), filter, monitor);
183 } else {
184 List<String> eventNames = dialog.getEventNames();
185 if (!eventNames.isEmpty()) {
186 enableEvents(param, eventNames, dialog.isKernel(), filter, monitor);
187 }
188 }
189 }
190
191 // Enable syscall events
192 if (dialog.isAllSysCalls()) {
193 enableSyscalls(param, monitor);
194 }
195
196 // Enable dynamic probe
197 if (dialog.isDynamicProbe() && (dialog.getProbeEventName() != null) && (dialog.getProbeName() != null)) {
198 enableProbe(param, dialog.getProbeEventName(), false, dialog.getProbeName(), monitor);
199 }
200
201 // Enable dynamic function probe
202 if (dialog.isDynamicFunctionProbe() && (dialog.getFunctionEventName() != null) && (dialog.getFunction() != null)) {
203 enableProbe(param, dialog.getFunctionEventName(), true, dialog.getFunction(), monitor);
204 }
205
206 // Enable event using a wildcard
207 if (dialog.isWildcard()) {
208 List<String> eventNames = dialog.getEventNames();
209 eventNames.add(dialog.getWildcard());
210
211 if (!eventNames.isEmpty()) {
212 enableEvents(param, eventNames, dialog.isKernel(), filter, monitor);
213 }
214 }
215
216 // Enable events using log level
217 if (dialog.isLogLevel()) {
218 enableLogLevel(param, dialog.getLogLevelEventName(), dialog.getLogLevelType(), dialog.getLogLevel(), filter, monitor);
219 }
220
221 } catch (ExecutionException e) {
222 error = e;
223 }
224
225 // refresh in all cases
226 refresh(param);
227
228 if (error != null) {
229 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_ChangeEventStateFailure, error);
230 }
231 return Status.OK_STATUS;
232 }
233 };
234 job.setUser(true);
235 job.schedule();
236 return null;
237 }
238 }
This page took 0.040116 seconds and 5 git commands to generate.