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