Commit | Line | Data |
---|---|---|
498704b3 | 1 | /********************************************************************** |
68d1057b | 2 | * Copyright (c) 2012, 2015 Ericsson |
cfdb727a | 3 | * |
498704b3 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: | |
498704b3 | 10 | * Bernd Hufmann - Initial API and implementation |
ba3a9bd2 | 11 | * Bernd Hufmann - Updated for support of LTTng Tools 2.1 |
498704b3 | 12 | **********************************************************************/ |
9bc60be7 | 13 | package org.eclipse.tracecompass.internal.lttng2.control.ui.views.handlers; |
498704b3 BH |
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; | |
68d1057b | 23 | import org.eclipse.jdt.annotation.Nullable; |
498704b3 | 24 | import org.eclipse.jface.window.Window; |
a20452b1 | 25 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.ITraceLogLevel; |
9bc60be7 | 26 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.LogLevelType; |
207ff523 | 27 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceDomainType; |
9bc60be7 AM |
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; | |
207ff523 | 36 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.service.ILttngControlService; |
498704b3 BH |
37 | import org.eclipse.ui.IWorkbenchWindow; |
38 | import org.eclipse.ui.PlatformUI; | |
39 | ||
40 | /** | |
498704b3 | 41 | * <p> |
ccc66d01 | 42 | * Base command handler implementation to enable events. |
498704b3 | 43 | * </p> |
cfdb727a | 44 | * |
dbd4432d | 45 | * @author Bernd Hufmann |
498704b3 | 46 | */ |
77735e82 | 47 | public abstract class BaseEnableEventHandler extends BaseControlViewHandler { |
498704b3 BH |
48 | |
49 | // ------------------------------------------------------------------------ | |
50 | // Attributes | |
51 | // ------------------------------------------------------------------------ | |
52 | /** | |
c56972bb | 53 | * The command execution parameter. |
498704b3 | 54 | */ |
9ee91a86 BH |
55 | @Nullable |
56 | protected CommandParameter fParam = null; | |
498704b3 BH |
57 | |
58 | // ------------------------------------------------------------------------ | |
59 | // Operations | |
60 | // ------------------------------------------------------------------------ | |
cfdb727a | 61 | |
ccc66d01 BH |
62 | /** |
63 | * Enables a list of events for given parameters. | |
cfdb727a AM |
64 | * |
65 | * @param param | |
66 | * - a parameter instance with data for the command execution | |
67 | * @param eventNames | |
68 | * - list of event names | |
1bc37054 BR |
69 | * @param domain |
70 | * - the domain type ({@link TraceDomainType}) | |
d4514365 BH |
71 | * @param filterExpression |
72 | * - a filter expression | |
91dc1c3e BR |
73 | * @param excludedEvents |
74 | * - list of events to exclude | |
cfdb727a AM |
75 | * @param monitor |
76 | * - a progress monitor | |
ccc66d01 | 77 | * @throws ExecutionException |
cfdb727a | 78 | * If the command fails for some reason |
ccc66d01 | 79 | */ |
1bc37054 | 80 | public abstract void enableEvents(CommandParameter param, List<String> eventNames, TraceDomainType domain, String filterExpression, List<String> excludedEvents, IProgressMonitor monitor) throws ExecutionException; |
c56972bb | 81 | |
ccc66d01 BH |
82 | /** |
83 | * Enables all syscall events. | |
cfdb727a AM |
84 | * |
85 | * @param param | |
86 | * - a parameter instance with data for the command execution | |
207ff523 BR |
87 | * @param syscallNames |
88 | * - a list of syscall names | |
cfdb727a AM |
89 | * @param monitor |
90 | * - a progress monitor | |
ccc66d01 | 91 | * @throws ExecutionException |
cfdb727a | 92 | * If the command fails for some reason |
ccc66d01 | 93 | */ |
207ff523 | 94 | public abstract void enableSyscalls(CommandParameter param, List<String> syscallNames, IProgressMonitor monitor) throws ExecutionException; |
cfdb727a | 95 | |
ccc66d01 BH |
96 | /** |
97 | * Enables a dynamic probe. | |
cfdb727a AM |
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 | |
ccc66d01 | 109 | * @throws ExecutionException |
cfdb727a | 110 | * If the command fails for some reason |
ccc66d01 | 111 | */ |
77735e82 | 112 | public abstract void enableProbe(CommandParameter param, String eventName, boolean isFunction, String probe, IProgressMonitor monitor) throws ExecutionException; |
cfdb727a | 113 | |
ccc66d01 BH |
114 | /** |
115 | * Enables events using log level | |
cfdb727a AM |
116 | * |
117 | * @param param | |
118 | * - a parameter instance with data for the command execution | |
a20452b1 BR |
119 | * @param eventNames |
120 | * - a list of event names | |
cfdb727a AM |
121 | * @param logLevelType |
122 | * - a log level type | |
123 | * @param level | |
124 | * - a log level | |
d4514365 BH |
125 | * @param filterExpression |
126 | * - a filter expression | |
a20452b1 BR |
127 | * @param domain |
128 | * - the domain type | |
cfdb727a AM |
129 | * @param monitor |
130 | * - a progress monitor | |
ccc66d01 | 131 | * @throws ExecutionException |
cfdb727a AM |
132 | * If the command fails for some reason |
133 | */ | |
a20452b1 | 134 | public abstract void enableLogLevel(CommandParameter param, List<String> eventNames, LogLevelType logLevelType, ITraceLogLevel level, String filterExpression, TraceDomainType domain, IProgressMonitor monitor) throws ExecutionException; |
cfdb727a | 135 | |
ccc66d01 | 136 | /** |
cfdb727a AM |
137 | * @param param |
138 | * - a parameter instance with data for the command execution | |
ccc66d01 BH |
139 | * @return returns the relevant domain (null if domain is not known) |
140 | */ | |
77735e82 | 141 | public abstract TraceDomainComponent getDomain(CommandParameter param); |
ccc66d01 | 142 | |
498704b3 BH |
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 | } | |
68d1057b BH |
151 | |
152 | // Make a copy for thread safety | |
153 | CommandParameter tmpParam = null; | |
c56972bb BH |
154 | fLock.lock(); |
155 | try { | |
68d1057b BH |
156 | tmpParam = fParam; |
157 | if (tmpParam == null) { | |
c56972bb BH |
158 | return null; |
159 | } | |
b8dbc09c | 160 | tmpParam = tmpParam.clone(); |
68d1057b BH |
161 | } finally { |
162 | fLock.unlock(); | |
163 | } | |
164 | final CommandParameter param = tmpParam; | |
498704b3 | 165 | |
68d1057b BH |
166 | TargetNodeComponent node = param.getSession().getTargetNode(); |
167 | List<ITraceControlComponent> providers = node.getChildren(TraceProviderGroup.class); | |
ccc66d01 | 168 | |
68d1057b | 169 | final IEnableEventsDialog dialog = TraceControlDialogFactory.getInstance().getEnableEventsDialog(); |
21c9f630 BR |
170 | // If you don't have the Kernel tracer and no UST application there is not going to be any providers |
171 | if (providers.size() > 0) { | |
172 | dialog.setTraceProviderGroup((TraceProviderGroup) providers.get(0)); | |
173 | } | |
68d1057b | 174 | dialog.setTraceDomainComponent(getDomain(param)); |
ccc66d01 | 175 | |
68d1057b BH |
176 | if (dialog.open() != Window.OK) { |
177 | return null; | |
178 | } | |
ccc66d01 | 179 | |
68d1057b BH |
180 | Job job = new Job(Messages.TraceControl_ChangeEventStateJob) { |
181 | @Override | |
182 | protected IStatus run(IProgressMonitor monitor) { | |
183 | Exception error = null; | |
68d1057b BH |
184 | try { |
185 | String filter = dialog.getFilterExpression(); | |
74fe9bdd | 186 | List<String> eventNames = null; |
a20452b1 BR |
187 | switch (dialog.getDomain()) { |
188 | case KERNEL: | |
189 | case UST: | |
190 | if (dialog.isAllEvents()) { | |
630367a2 | 191 | enableEvents(param, ILttngControlService.ALL_EVENTS, dialog.getDomain(), filter, dialog.getExcludedEvents(), monitor); |
a20452b1 BR |
192 | } else if (dialog.isTracepoints()) { |
193 | // Enable tracepoint events | |
194 | if (dialog.isAllTracePoints()) { | |
195 | enableEvents(param, null, dialog.getDomain(), filter, dialog.getExcludedEvents(), monitor); | |
196 | } else { | |
74fe9bdd | 197 | eventNames = dialog.getEventNames(); |
a20452b1 BR |
198 | if (!eventNames.isEmpty()) { |
199 | enableEvents(param, eventNames, dialog.getDomain(), filter, dialog.getExcludedEvents(), monitor); | |
200 | } | |
c56972bb | 201 | } |
498704b3 | 202 | } |
c56972bb | 203 | |
a20452b1 | 204 | // Enable syscall events |
207ff523 BR |
205 | if (dialog.isSyscalls()) { |
206 | // Enable all syscall events | |
207 | if (dialog.isAllSyscalls()) { | |
208 | enableSyscalls(param, ILttngControlService.ALL_EVENTS, monitor); | |
209 | } else { | |
210 | List<String> syscallNames = dialog.getEventNames(); | |
211 | if (!syscallNames.isEmpty()) { | |
212 | enableSyscalls(param, syscallNames, monitor); | |
213 | } | |
214 | } | |
a20452b1 | 215 | } |
68d1057b | 216 | |
a20452b1 BR |
217 | // Enable dynamic probe |
218 | if (dialog.isDynamicProbe() && (dialog.getProbeEventName() != null) && (dialog.getProbeName() != null)) { | |
219 | enableProbe(param, dialog.getProbeEventName(), false, dialog.getProbeName(), monitor); | |
220 | } | |
c56972bb | 221 | |
a20452b1 BR |
222 | // Enable dynamic function probe |
223 | if (dialog.isDynamicFunctionProbe() && (dialog.getFunctionEventName() != null) && (dialog.getFunction() != null)) { | |
224 | enableProbe(param, dialog.getFunctionEventName(), true, dialog.getFunction(), monitor); | |
225 | } | |
498704b3 | 226 | |
a20452b1 BR |
227 | // Enable event using a wildcard |
228 | if (dialog.isWildcard()) { | |
74fe9bdd | 229 | eventNames = dialog.getEventNames(); |
a20452b1 | 230 | eventNames.add(dialog.getWildcard()); |
498704b3 | 231 | |
a20452b1 BR |
232 | if (!eventNames.isEmpty()) { |
233 | enableEvents(param, eventNames, dialog.getDomain(), filter, dialog.getExcludedEvents(), monitor); | |
234 | } | |
68d1057b | 235 | } |
68d1057b | 236 | |
a20452b1 BR |
237 | // Enable events using log level |
238 | if (dialog.isLogLevel()) { | |
239 | enableLogLevel(param, dialog.getEventNames(), dialog.getLogLevelType(), dialog.getLogLevel(), filter, dialog.getDomain(), monitor); | |
240 | } | |
241 | break; | |
242 | case JUL: | |
74fe9bdd | 243 | case LOG4J: |
3d2d8c9f | 244 | case PYTHON: |
74fe9bdd BR |
245 | eventNames = dialog.getEventNames(); |
246 | if (dialog.isAllEvents()) { | |
a20452b1 BR |
247 | eventNames = null; |
248 | } | |
249 | if (dialog.isLogLevel()) { | |
250 | enableLogLevel(param, eventNames, dialog.getLogLevelType(), dialog.getLogLevel(), filter, dialog.getDomain(), monitor); | |
251 | } else { | |
252 | enableEvents(param, eventNames, dialog.getDomain(), filter, dialog.getExcludedEvents(), monitor); | |
253 | } | |
254 | break; | |
255 | //$CASES-OMITTED$ | |
256 | default: | |
257 | break; | |
498704b3 | 258 | } |
68d1057b BH |
259 | } catch (ExecutionException e) { |
260 | error = e; | |
498704b3 | 261 | } |
68d1057b BH |
262 | |
263 | // refresh in all cases | |
264 | refresh(param); | |
265 | ||
266 | if (error != null) { | |
267 | return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_ChangeEventStateFailure, error); | |
268 | } | |
269 | return Status.OK_STATUS; | |
270 | } | |
271 | }; | |
272 | job.setUser(true); | |
273 | job.schedule(); | |
498704b3 BH |
274 | return null; |
275 | } | |
276 | } |