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; |
9bc60be7 AM |
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; | |
9ee91a86 | 35 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.service.ILttngControlService; |
498704b3 BH |
36 | import org.eclipse.ui.IWorkbenchWindow; |
37 | import org.eclipse.ui.PlatformUI; | |
38 | ||
39 | /** | |
498704b3 | 40 | * <p> |
ccc66d01 | 41 | * Base command handler implementation to enable events. |
498704b3 | 42 | * </p> |
cfdb727a | 43 | * |
dbd4432d | 44 | * @author Bernd Hufmann |
498704b3 | 45 | */ |
77735e82 | 46 | public abstract class BaseEnableEventHandler extends BaseControlViewHandler { |
498704b3 BH |
47 | |
48 | // ------------------------------------------------------------------------ | |
49 | // Attributes | |
50 | // ------------------------------------------------------------------------ | |
51 | /** | |
c56972bb | 52 | * The command execution parameter. |
498704b3 | 53 | */ |
9ee91a86 BH |
54 | @Nullable |
55 | protected CommandParameter fParam = null; | |
498704b3 BH |
56 | |
57 | // ------------------------------------------------------------------------ | |
58 | // Operations | |
59 | // ------------------------------------------------------------------------ | |
cfdb727a | 60 | |
ccc66d01 BH |
61 | /** |
62 | * Enables a list of events for given parameters. | |
cfdb727a AM |
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 | |
d4514365 BH |
70 | * @param filterExpression |
71 | * - a filter expression | |
cfdb727a AM |
72 | * @param monitor |
73 | * - a progress monitor | |
ccc66d01 | 74 | * @throws ExecutionException |
cfdb727a | 75 | * If the command fails for some reason |
ccc66d01 | 76 | */ |
77735e82 | 77 | public abstract void enableEvents(CommandParameter param, List<String> eventNames, boolean isKernel, String filterExpression, IProgressMonitor monitor) throws ExecutionException; |
c56972bb | 78 | |
ccc66d01 BH |
79 | /** |
80 | * Enables all syscall events. | |
cfdb727a AM |
81 | * |
82 | * @param param | |
83 | * - a parameter instance with data for the command execution | |
84 | * @param monitor | |
85 | * - a progress monitor | |
ccc66d01 | 86 | * @throws ExecutionException |
cfdb727a | 87 | * If the command fails for some reason |
ccc66d01 | 88 | */ |
77735e82 | 89 | public abstract void enableSyscalls(CommandParameter param, IProgressMonitor monitor) throws ExecutionException; |
cfdb727a | 90 | |
ccc66d01 BH |
91 | /** |
92 | * Enables a dynamic probe. | |
cfdb727a AM |
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 | |
ccc66d01 | 104 | * @throws ExecutionException |
cfdb727a | 105 | * If the command fails for some reason |
ccc66d01 | 106 | */ |
77735e82 | 107 | public abstract void enableProbe(CommandParameter param, String eventName, boolean isFunction, String probe, IProgressMonitor monitor) throws ExecutionException; |
cfdb727a | 108 | |
ccc66d01 BH |
109 | /** |
110 | * Enables events using log level | |
cfdb727a AM |
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 | |
d4514365 BH |
120 | * @param filterExpression |
121 | * - a filter expression | |
cfdb727a AM |
122 | * @param monitor |
123 | * - a progress monitor | |
ccc66d01 | 124 | * @throws ExecutionException |
cfdb727a AM |
125 | * If the command fails for some reason |
126 | */ | |
77735e82 | 127 | public abstract void enableLogLevel(CommandParameter param, String eventName, LogLevelType logLevelType, TraceLogLevel level, String filterExpression, IProgressMonitor monitor) throws ExecutionException; |
cfdb727a | 128 | |
ccc66d01 | 129 | /** |
cfdb727a AM |
130 | * @param param |
131 | * - a parameter instance with data for the command execution | |
ccc66d01 BH |
132 | * @return returns the relevant domain (null if domain is not known) |
133 | */ | |
77735e82 | 134 | public abstract TraceDomainComponent getDomain(CommandParameter param); |
ccc66d01 | 135 | |
498704b3 BH |
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 | } | |
68d1057b BH |
144 | |
145 | // Make a copy for thread safety | |
146 | CommandParameter tmpParam = null; | |
c56972bb BH |
147 | fLock.lock(); |
148 | try { | |
68d1057b BH |
149 | tmpParam = fParam; |
150 | if (tmpParam == null) { | |
c56972bb BH |
151 | return null; |
152 | } | |
b8dbc09c | 153 | tmpParam = tmpParam.clone(); |
68d1057b BH |
154 | } finally { |
155 | fLock.unlock(); | |
156 | } | |
157 | final CommandParameter param = tmpParam; | |
498704b3 | 158 | |
68d1057b BH |
159 | TargetNodeComponent node = param.getSession().getTargetNode(); |
160 | List<ITraceControlComponent> providers = node.getChildren(TraceProviderGroup.class); | |
ccc66d01 | 161 | |
68d1057b | 162 | final IEnableEventsDialog dialog = TraceControlDialogFactory.getInstance().getEnableEventsDialog(); |
9ee91a86 | 163 | dialog.setTraceProviderGroup((TraceProviderGroup) providers.get(0)); |
68d1057b | 164 | dialog.setTraceDomainComponent(getDomain(param)); |
ccc66d01 | 165 | |
68d1057b BH |
166 | if (dialog.open() != Window.OK) { |
167 | return null; | |
168 | } | |
ccc66d01 | 169 | |
68d1057b BH |
170 | Job job = new Job(Messages.TraceControl_ChangeEventStateJob) { |
171 | @Override | |
172 | protected IStatus run(IProgressMonitor monitor) { | |
173 | Exception error = null; | |
ccc66d01 | 174 | |
68d1057b BH |
175 | try { |
176 | String filter = dialog.getFilterExpression(); | |
9ee91a86 BH |
177 | if (dialog.isAllEvents()) { |
178 | enableEvents(param, ILttngControlService.ALL_EVENTS, dialog.isKernel(), filter, monitor); | |
179 | } else if (dialog.isTracepoints()) { | |
180 | // Enable tracepoint events | |
68d1057b BH |
181 | if (dialog.isAllTracePoints()) { |
182 | enableEvents(param, null, dialog.isKernel(), filter, monitor); | |
183 | } else { | |
184 | List<String> eventNames = dialog.getEventNames(); | |
c56972bb | 185 | if (!eventNames.isEmpty()) { |
d4514365 | 186 | enableEvents(param, eventNames, dialog.isKernel(), filter, monitor); |
c56972bb | 187 | } |
498704b3 | 188 | } |
68d1057b | 189 | } |
c56972bb | 190 | |
68d1057b BH |
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 | } | |
c56972bb | 200 | |
68d1057b BH |
201 | // Enable dynamic function probe |
202 | if (dialog.isDynamicFunctionProbe() && (dialog.getFunctionEventName() != null) && (dialog.getFunction() != null)) { | |
203 | enableProbe(param, dialog.getFunctionEventName(), true, dialog.getFunction(), monitor); | |
ccc66d01 | 204 | } |
498704b3 | 205 | |
68d1057b BH |
206 | // Enable event using a wildcard |
207 | if (dialog.isWildcard()) { | |
208 | List<String> eventNames = dialog.getEventNames(); | |
209 | eventNames.add(dialog.getWildcard()); | |
498704b3 | 210 | |
68d1057b BH |
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); | |
498704b3 | 219 | } |
68d1057b BH |
220 | |
221 | } catch (ExecutionException e) { | |
222 | error = e; | |
498704b3 | 223 | } |
68d1057b BH |
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(); | |
498704b3 BH |
236 | return null; |
237 | } | |
238 | } |