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