Commit | Line | Data |
---|---|---|
eb1bab5b BH |
1 | /********************************************************************** |
2 | * Copyright (c) 2012 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 | **********************************************************************/ | |
12 | package org.eclipse.linuxtools.lttng.ui.views.control.service; | |
13 | ||
14 | import java.util.ArrayList; | |
bbb3538a | 15 | import java.util.Iterator; |
eb1bab5b BH |
16 | import java.util.List; |
17 | import java.util.regex.Matcher; | |
18 | import java.util.regex.Pattern; | |
eb1bab5b BH |
19 | |
20 | import org.eclipse.core.commands.ExecutionException; | |
21 | import org.eclipse.core.runtime.IProgressMonitor; | |
22 | import org.eclipse.core.runtime.NullProgressMonitor; | |
23 | import org.eclipse.linuxtools.lttng.ui.views.control.Messages; | |
24 | import org.eclipse.linuxtools.lttng.ui.views.control.model.IBaseEventInfo; | |
25 | import org.eclipse.linuxtools.lttng.ui.views.control.model.IChannelInfo; | |
26 | import org.eclipse.linuxtools.lttng.ui.views.control.model.IDomainInfo; | |
27 | import org.eclipse.linuxtools.lttng.ui.views.control.model.IEventInfo; | |
d132bcc7 | 28 | import org.eclipse.linuxtools.lttng.ui.views.control.model.IProbeEventInfo; |
eb1bab5b BH |
29 | import org.eclipse.linuxtools.lttng.ui.views.control.model.ISessionInfo; |
30 | import org.eclipse.linuxtools.lttng.ui.views.control.model.IUstProviderInfo; | |
ccc66d01 | 31 | import org.eclipse.linuxtools.lttng.ui.views.control.model.LogLevelType; |
d132bcc7 | 32 | import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceEventType; |
4775bcbf | 33 | import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceLogLevel; |
eb1bab5b BH |
34 | import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.BaseEventInfo; |
35 | import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.ChannelInfo; | |
36 | import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.DomainInfo; | |
37 | import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.EventInfo; | |
d132bcc7 | 38 | import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.ProbeEventInfo; |
eb1bab5b BH |
39 | import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.SessionInfo; |
40 | import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.UstProviderInfo; | |
4775bcbf | 41 | |
eb1bab5b BH |
42 | /** |
43 | * <b><u>LTTngControlService</u></b> | |
44 | * <p> | |
45 | * Service for sending LTTng trace control commands to remote host. | |
46 | * </p> | |
47 | */ | |
48 | public class LTTngControlService implements ILttngControlService { | |
49 | // ------------------------------------------------------------------------ | |
50 | // Constants | |
51 | // ------------------------------------------------------------------------ | |
52 | // Command constants | |
53 | /** | |
54 | * The lttng tools command. | |
55 | */ | |
56 | private final static String CONTROL_COMMAND = "lttng"; //$NON-NLS-1$ | |
57 | /** | |
4775bcbf | 58 | * Command: lttng list. |
eb1bab5b BH |
59 | */ |
60 | private final static String COMMAND_LIST = CONTROL_COMMAND + " list "; //$NON-NLS-1$ | |
61 | /** | |
4775bcbf | 62 | * Command to list kernel tracer information. |
eb1bab5b | 63 | */ |
4775bcbf | 64 | private final static String COMMAND_LIST_KERNEL = COMMAND_LIST + "-k"; //$NON-NLS-1$ |
eb1bab5b | 65 | /** |
4775bcbf | 66 | * Command to list user space trace information. |
eb1bab5b | 67 | */ |
bbb3538a BH |
68 | private final static String COMMAND_LIST_UST = COMMAND_LIST + "-u"; //$NON-NLS-1$ |
69 | /** | |
70 | * Command to create a session. | |
71 | */ | |
72 | private final static String COMMAND_CREATE_SESSION = CONTROL_COMMAND + " create "; //$NON-NLS-1$ | |
73 | /** | |
74 | * Command to destroy a session. | |
75 | */ | |
76 | private final static String COMMAND_DESTROY_SESSION = CONTROL_COMMAND + " destroy "; //$NON-NLS-1$ | |
77 | /** | |
78 | * Command to destroy a session. | |
79 | */ | |
80 | private final static String COMMAND_START_SESSION = CONTROL_COMMAND + " start "; //$NON-NLS-1$ | |
81 | /** | |
82 | * Command to destroy a session. | |
83 | */ | |
84 | private final static String COMMAND_STOP_SESSION = CONTROL_COMMAND + " stop "; //$NON-NLS-1$ | |
85 | /** | |
86 | * Command to enable a channel. | |
87 | */ | |
88 | private final static String COMMAND_ENABLE_CHANNEL = CONTROL_COMMAND + " enable-channel "; //$NON-NLS-1$ | |
89 | /** | |
6503ae0f | 90 | * Command to disable a channel. |
bbb3538a BH |
91 | */ |
92 | private final static String COMMAND_DISABLE_CHANNEL = CONTROL_COMMAND + " disable-channel "; //$NON-NLS-1$ | |
6503ae0f BH |
93 | /** |
94 | * Command to enable a event. | |
95 | */ | |
96 | private final static String COMMAND_ENABLE_EVENT = CONTROL_COMMAND + " enable-event "; //$NON-NLS-1$ | |
97 | /** | |
98 | * Command to disable a event. | |
99 | */ | |
100 | private final static String COMMAND_DISABLE_EVENT = CONTROL_COMMAND + " disable-event "; //$NON-NLS-1$ | |
eb1bab5b | 101 | |
6503ae0f BH |
102 | // Command options constants |
103 | /** | |
104 | * Command line option for kernel tracer. | |
105 | */ | |
106 | private final static String OPTION_KERNEL = " -k "; //$NON-NLS-1$ | |
107 | /** | |
108 | * Command line option for UST tracer. | |
109 | */ | |
110 | private final static String OPTION_UST = " -u "; //$NON-NLS-1$ | |
111 | /** | |
112 | * Command line option for specifying a session. | |
113 | */ | |
114 | private final static String OPTION_SESSION = " -s "; //$NON-NLS-1$ | |
115 | /** | |
116 | * Command line option for specifying a channel. | |
117 | */ | |
118 | private final static String OPTION_CHANNEL = " -c "; //$NON-NLS-1$ | |
3e91c9c0 BH |
119 | /** |
120 | * Command line option for specifying all events. | |
121 | */ | |
122 | private final static String OPTION_ALL = " -a "; //$NON-NLS-1$ | |
498704b3 BH |
123 | /** |
124 | * Command line option for specifying tracepoint events. | |
125 | */ | |
126 | private final static String OPTION_TRACEPOINT = " --tracepoint "; //$NON-NLS-1$ | |
127 | /** | |
128 | * Command line option for specifying syscall events. | |
129 | */ | |
130 | private final static String OPTION_SYSCALL = " --syscall "; //$NON-NLS-1$ | |
131 | /** | |
132 | * Command line option for specifying a dynamic probe. | |
133 | */ | |
134 | private final static String OPTION_PROBE = " --probe "; //$NON-NLS-1$ | |
135 | /** | |
136 | * Command line option for specifying a dynamic function entry/return probe. | |
137 | */ | |
138 | private final static String OPTION_FUNCTION_PROBE = " --function "; //$NON-NLS-1$ | |
ccc66d01 BH |
139 | /** |
140 | * Command line option for specifying a log level range. | |
141 | */ | |
142 | private final static String OPTION_LOGLEVEL = " --loglevel "; //$NON-NLS-1$ | |
143 | /** | |
144 | * Command line option for specifying a specific log level. | |
145 | */ | |
146 | private final static String OPTION_LOGLEVEL_ONLY = " --loglevel-only "; //$NON-NLS-1$ | |
6503ae0f BH |
147 | /** |
148 | * Optional command line option for configuring a channel's overwrite mode. | |
149 | */ | |
150 | private final static String OPTION_OVERWRITE = " --overwrite "; //$NON-NLS-1$ | |
151 | /** | |
152 | * Optional command line option for configuring a channel's number of sub buffers. | |
153 | */ | |
154 | private final static String OPTION_NUM_SUB_BUFFERS = " --num-subbuf "; //$NON-NLS-1$ | |
155 | /** | |
156 | * Optional command line option for configuring a channel's sub buffer size. | |
157 | */ | |
158 | private final static String OPTION_SUB_BUFFER_SIZE = " --subbuf-size "; //$NON-NLS-1$ | |
159 | /** | |
160 | * Optional command line option for configuring a channel's switch timer interval. | |
161 | */ | |
162 | private final static String OPTION_SWITCH_TIMER = " --switch-timer "; //$NON-NLS-1$ | |
163 | /** | |
164 | * Optional command line option for configuring a channel's read timer interval. | |
165 | */ | |
166 | private final static String OPTION_READ_TIMER = " --read-timer "; //$NON-NLS-1$ | |
167 | ||
eb1bab5b BH |
168 | // Parsing constants |
169 | /** | |
170 | * Pattern to match for error output | |
171 | */ | |
4775bcbf | 172 | private final static Pattern ERROR_PATTERN = Pattern.compile("\\s*Error\\:.*"); //$NON-NLS-1$ |
eb1bab5b BH |
173 | /** |
174 | * Pattern to match for session information (lttng list) | |
175 | */ | |
4775bcbf | 176 | private final static Pattern SESSION_PATTERN = Pattern.compile("\\s+(\\d+)\\)\\s+(.*)\\s+\\((.*)\\)\\s+\\[(active|inactive)\\].*"); //$NON-NLS-1$ |
eb1bab5b BH |
177 | /** |
178 | * Pattern to match for session information (lttng list <session>) | |
179 | */ | |
4775bcbf | 180 | private final static Pattern TRACE_SESSION_PATTERN = Pattern.compile("\\s*Tracing\\s+session\\s+(.*)\\:\\s+\\[(active|inactive)\\].*"); //$NON-NLS-1$ |
eb1bab5b BH |
181 | /** |
182 | * Pattern to match for session path information (lttng list <session>) | |
183 | */ | |
4775bcbf | 184 | private final static Pattern TRACE_SESSION_PATH_PATTERN = Pattern.compile("\\s*Trace\\s+path\\:\\s+(.*)"); //$NON-NLS-1$ |
eb1bab5b BH |
185 | /** |
186 | * Pattern to match for kernel domain information (lttng list <session>) | |
187 | */ | |
4775bcbf | 188 | private final static Pattern DOMAIN_KERNEL_PATTERN = Pattern.compile("=== Domain: Kernel ==="); //$NON-NLS-1$ |
eb1bab5b BH |
189 | /** |
190 | * Pattern to match for ust domain information (lttng list <session>) | |
191 | */ | |
4775bcbf | 192 | private final static Pattern DOMAIN_UST_GLOBAL_PATTERN = Pattern.compile("=== Domain: UST global ==="); //$NON-NLS-1$ |
eb1bab5b BH |
193 | /** |
194 | * Pattern to match for channels section (lttng list <session>) | |
195 | */ | |
4775bcbf | 196 | private final static Pattern CHANNELS_SECTION_PATTERN = Pattern.compile("\\s*Channels\\:"); //$NON-NLS-1$ |
eb1bab5b BH |
197 | /** |
198 | * Pattern to match for channel information (lttng list <session>) | |
199 | */ | |
4775bcbf | 200 | private final static Pattern CHANNEL_PATTERN = Pattern.compile("\\s*-\\s+(.*)\\:\\s+\\[(enabled|disabled)\\]"); //$NON-NLS-1$ |
eb1bab5b BH |
201 | /** |
202 | * Pattern to match for events section information (lttng list <session>) | |
203 | */ | |
4775bcbf | 204 | private final static Pattern EVENT_SECTION_PATTERN = Pattern.compile("\\s*Events\\:"); //$NON-NLS-1$ |
eb1bab5b | 205 | /** |
6503ae0f | 206 | * Pattern to match for event information (no enabled events) (lttng list <session>) |
eb1bab5b | 207 | */ |
4775bcbf | 208 | // private final static String EVENT_NONE_PATTERN = "\\s+None"; //$NON-NLS-1$ |
eb1bab5b BH |
209 | /** |
210 | * Pattern to match for event information (lttng list <session>) | |
211 | */ | |
4775bcbf BH |
212 | private final static Pattern EVENT_PATTERN = Pattern.compile("\\s+(.*)\\s+\\(loglevel:\\s+(.*)\\s+\\(\\d*\\)\\)\\s+\\(type:\\s+(.*)\\)\\s+\\[(enabled|disabled)\\].*"); //$NON-NLS-1$ |
213 | /** | |
214 | * Pattern to match a wildcarded event information (lttng list <session>) | |
215 | */ | |
216 | private final static Pattern WILDCARD_EVENT_PATTERN = Pattern.compile("\\s+(.*)\\s+\\(type:\\s+(.*)\\)\\s+\\[(enabled|disabled)\\].*"); //$NON-NLS-1$ | |
d132bcc7 BH |
217 | /** |
218 | * Pattern to match a probe address information (lttng list <session>) | |
219 | */ | |
220 | private final static Pattern PROBE_ADDRESS_PATTERN = Pattern.compile("\\s+(addr)\\:\\s+(0x[0-9a-fA-F]{1,8})"); //$NON-NLS-1$ | |
221 | /** | |
222 | * Pattern to match a probe OFFSET information (lttng list <session>) | |
223 | */ | |
224 | private final static Pattern PROBE_OFFSET_PATTERN = Pattern.compile("\\s+(offset)\\:\\s+(0x[0-9a-fA-F]{1,8})"); //$NON-NLS-1$ | |
225 | /** | |
226 | * Pattern to match a probe SYMBOL information (lttng list <session>) | |
227 | */ | |
228 | private final static Pattern PROBE_SYMBOL_PATTERN = Pattern.compile("\\s+(symbol)\\:\\s+(.+)"); //$NON-NLS-1$ | |
eb1bab5b | 229 | /** |
4775bcbf BH |
230 | * Pattern to match for channel (overwite mode) information (lttng list |
231 | * <session>) | |
eb1bab5b | 232 | */ |
4775bcbf | 233 | private final static Pattern OVERWRITE_MODE_ATTRIBUTE = Pattern.compile("\\s+overwrite\\s+mode\\:.*"); //$NON-NLS-1$ |
eb1bab5b BH |
234 | /** |
235 | * Pattern to match indicating false for overwrite mode | |
236 | */ | |
237 | private final static String OVERWRITE_MODE_ATTRIBUTE_FALSE = "0"; //$NON-NLS-1$ | |
238 | /** | |
4775bcbf BH |
239 | * Pattern to match for channel (sub-buffer size) information (lttng list |
240 | * <session>) | |
eb1bab5b | 241 | */ |
4775bcbf | 242 | private final static Pattern SUBBUFFER_SIZE_ATTRIBUTE = Pattern.compile("\\s+subbufers\\s+size\\:.*"); //$NON-NLS-1$ |
eb1bab5b | 243 | /** |
4775bcbf BH |
244 | * Pattern to match for channel (number of sub-buffers) information (lttng |
245 | * list <session>) | |
eb1bab5b | 246 | */ |
4775bcbf | 247 | private final static Pattern NUM_SUBBUFFERS_ATTRIBUTE = Pattern.compile("\\s+number\\s+of\\s+subbufers\\:.*"); //$NON-NLS-1$ |
eb1bab5b | 248 | /** |
4775bcbf BH |
249 | * Pattern to match for channel (switch timer) information (lttng list |
250 | * <session>) | |
eb1bab5b | 251 | */ |
4775bcbf | 252 | private final static Pattern SWITCH_TIMER_ATTRIBUTE = Pattern.compile("\\s+switch\\s+timer\\s+interval\\:.*"); //$NON-NLS-1$ |
eb1bab5b | 253 | /** |
4775bcbf BH |
254 | * Pattern to match for channel (read timer) information (lttng list |
255 | * <session>) | |
eb1bab5b | 256 | */ |
4775bcbf | 257 | private final static Pattern READ_TIMER_ATTRIBUTE = Pattern.compile("\\s+read\\s+timer\\s+interval\\:.*"); //$NON-NLS-1$ |
eb1bab5b | 258 | /** |
4775bcbf BH |
259 | * Pattern to match for channel (output type) information (lttng list |
260 | * <session>) | |
eb1bab5b | 261 | */ |
4775bcbf | 262 | private final static Pattern OUTPUT_ATTRIBUTE = Pattern.compile("\\s+output\\:.*"); //$NON-NLS-1$ |
eb1bab5b BH |
263 | /** |
264 | * Pattern to match for provider information (lttng list -k/-u) | |
265 | */ | |
4775bcbf | 266 | private final static Pattern PROVIDER_EVENT_PATTERN = Pattern.compile("\\s*(.*)\\s+\\(loglevel:\\s+(.*)\\s+\\(\\d*\\)\\)\\s+\\(type:\\s+(.*)\\)"); //$NON-NLS-1$ |
eb1bab5b BH |
267 | /** |
268 | * Pattern to match for UST provider information (lttng list -u) | |
4775bcbf BH |
269 | */ |
270 | private final static Pattern UST_PROVIDER_PATTERN = Pattern.compile("\\s*PID\\:\\s+(\\d+)\\s+-\\s+Name\\:\\s+(.*)"); //$NON-NLS-1$ | |
bbb3538a BH |
271 | /** |
272 | * Pattern to match for session information (lttng create <session name>) | |
273 | */ | |
274 | private final static Pattern CREATE_SESSION_NAME_PATTERN = Pattern.compile("\\s*Session\\s+(.*)\\s+created\\."); //$NON-NLS-1$ | |
275 | /** | |
276 | * Pattern to match for session path information (lttng create <session name>) | |
277 | */ | |
278 | private final static Pattern CREATE_SESSION_PATH_PATTERN = Pattern.compile("\\s*Traces\\s+will\\s+be\\s+written\\s+in\\s+(.*).*"); //$NON-NLS-1$ | |
279 | /** | |
280 | * Pattern to match for session command output for "session name not found". | |
281 | */ | |
282 | private final static Pattern SESSION_NOT_FOUND_ERROR_PATTERN = Pattern.compile("\\s*Error:\\s+Session\\s+name\\s+not\\s+found"); //$NON-NLS-1$ | |
283 | ||
eb1bab5b BH |
284 | // ------------------------------------------------------------------------ |
285 | // Attributes | |
286 | // ------------------------------------------------------------------------ | |
287 | /** | |
288 | * The command shell implementation | |
289 | */ | |
290 | private ICommandShell fCommandShell = null; | |
291 | ||
292 | // ------------------------------------------------------------------------ | |
293 | // Constructors | |
294 | // ------------------------------------------------------------------------ | |
295 | ||
296 | /** | |
297 | * Constructor | |
4775bcbf BH |
298 | * |
299 | * @param shell | |
300 | * - the command shell implementation to use | |
eb1bab5b BH |
301 | */ |
302 | public LTTngControlService(ICommandShell shell) { | |
303 | fCommandShell = shell; | |
304 | } | |
4775bcbf | 305 | |
eb1bab5b BH |
306 | // ------------------------------------------------------------------------ |
307 | // Operations | |
4775bcbf | 308 | // ------------------------------------------------------------------------ |
eb1bab5b | 309 | |
eb1bab5b BH |
310 | /* |
311 | * (non-Javadoc) | |
4775bcbf BH |
312 | * |
313 | * @see | |
314 | * org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService | |
315 | * #getSessionNames(org.eclipse.core.runtime.IProgressMonitor) | |
eb1bab5b BH |
316 | */ |
317 | @Override | |
318 | public String[] getSessionNames(IProgressMonitor monitor) throws ExecutionException { | |
319 | ||
4775bcbf BH |
320 | String command = COMMAND_LIST; |
321 | ICommandResult result = fCommandShell.executeCommand(command, monitor); | |
322 | ||
323 | if (isError(result)) { | |
4775bcbf BH |
324 | throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$ |
325 | } | |
326 | ||
327 | // Output: | |
328 | // Available tracing sessions: | |
329 | // 1) mysession1 (/home/user/lttng-traces/mysession1-20120123-083928) | |
330 | // [inactive] | |
331 | // 2) mysession (/home/user/lttng-traces/mysession-20120123-083318) | |
332 | // [inactive] | |
333 | // | |
334 | // Use lttng list <session_name> for more details | |
335 | ||
336 | ArrayList<String> retArray = new ArrayList<String>(); | |
337 | int index = 0; | |
338 | while (index < result.getOutput().length) { | |
339 | String line = result.getOutput()[index]; | |
340 | Matcher matcher = SESSION_PATTERN.matcher(line); | |
341 | if (matcher.matches()) { | |
342 | retArray.add(matcher.group(2).trim()); | |
343 | } | |
344 | index++; | |
345 | } | |
346 | return retArray.toArray(new String[retArray.size()]); | |
eb1bab5b BH |
347 | } |
348 | ||
eb1bab5b BH |
349 | /* |
350 | * (non-Javadoc) | |
4775bcbf BH |
351 | * |
352 | * @see | |
353 | * org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService | |
354 | * #getSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor) | |
eb1bab5b BH |
355 | */ |
356 | @Override | |
357 | public ISessionInfo getSession(String sessionName, IProgressMonitor monitor) throws ExecutionException { | |
d132bcc7 | 358 | |
eb1bab5b BH |
359 | String command = COMMAND_LIST + sessionName; |
360 | ICommandResult result = fCommandShell.executeCommand(command, monitor); | |
d132bcc7 BH |
361 | |
362 | ||
eb1bab5b BH |
363 | if (isError(result)) { |
364 | throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$ | |
365 | } | |
366 | ||
367 | int index = 0; | |
368 | ||
369 | // Output: | |
4775bcbf BH |
370 | // Tracing session mysession2: [inactive] |
371 | // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330 | |
eb1bab5b BH |
372 | ISessionInfo sessionInfo = new SessionInfo(sessionName); |
373 | ||
4775bcbf BH |
374 | while (index < result.getOutput().length) { |
375 | // Tracing session mysession2: [inactive] | |
376 | // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330 | |
377 | // | |
378 | // === Domain: Kernel === | |
379 | // | |
380 | String line = result.getOutput()[index]; | |
381 | Matcher matcher = TRACE_SESSION_PATTERN.matcher(line); | |
382 | if (matcher.matches()) { | |
383 | sessionInfo.setSessionState(matcher.group(2)); | |
384 | index++; | |
385 | continue; | |
386 | } | |
387 | ||
388 | matcher = TRACE_SESSION_PATH_PATTERN.matcher(line); | |
389 | if (matcher.matches()) { | |
390 | sessionInfo.setSessionPath(matcher.group(1).trim()); | |
391 | index++; | |
392 | continue; | |
393 | } | |
eb1bab5b | 394 | |
4775bcbf BH |
395 | matcher = DOMAIN_KERNEL_PATTERN.matcher(line); |
396 | if (matcher.matches()) { | |
397 | // Create Domain | |
398 | IDomainInfo domainInfo = new DomainInfo(Messages.TraceControl_KernelDomainDisplayName); | |
399 | sessionInfo.addDomain(domainInfo); | |
eb1bab5b | 400 | |
4775bcbf BH |
401 | // in domain kernel |
402 | ArrayList<IChannelInfo> channels = new ArrayList<IChannelInfo>(); | |
403 | index = parseDomain(result.getOutput(), index, channels); | |
eb1bab5b | 404 | |
4775bcbf BH |
405 | // set channels |
406 | domainInfo.setChannels(channels); | |
bbb3538a BH |
407 | |
408 | // set kernel flag | |
409 | domainInfo.setIsKernel(true); | |
4775bcbf BH |
410 | continue; |
411 | } | |
eb1bab5b | 412 | |
4775bcbf BH |
413 | matcher = DOMAIN_UST_GLOBAL_PATTERN.matcher(line); |
414 | if (matcher.matches()) { | |
415 | IDomainInfo domainInfo = new DomainInfo(Messages.TraceControl_UstGlobalDomainDisplayName); | |
416 | sessionInfo.addDomain(domainInfo); | |
eb1bab5b | 417 | |
bbb3538a | 418 | // in domain UST |
4775bcbf BH |
419 | ArrayList<IChannelInfo> channels = new ArrayList<IChannelInfo>(); |
420 | index = parseDomain(result.getOutput(), index, channels); | |
421 | ||
422 | // set channels | |
423 | domainInfo.setChannels(channels); | |
bbb3538a BH |
424 | |
425 | // set kernel flag | |
426 | domainInfo.setIsKernel(false); | |
4775bcbf | 427 | continue; |
eb1bab5b | 428 | } |
4775bcbf BH |
429 | index++; |
430 | } | |
eb1bab5b BH |
431 | return sessionInfo; |
432 | } | |
4775bcbf | 433 | |
eb1bab5b BH |
434 | /* |
435 | * (non-Javadoc) | |
4775bcbf BH |
436 | * |
437 | * @see | |
438 | * org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService | |
439 | * #getKernelProvider(org.eclipse.core.runtime.IProgressMonitor) | |
eb1bab5b BH |
440 | */ |
441 | @Override | |
442 | public List<IBaseEventInfo> getKernelProvider(IProgressMonitor monitor) throws ExecutionException { | |
443 | String command = COMMAND_LIST_KERNEL; | |
444 | ICommandResult result = fCommandShell.executeCommand(command, monitor); | |
445 | if (isError(result)) { | |
446 | throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$ | |
447 | } | |
4775bcbf BH |
448 | |
449 | // Kernel events: | |
450 | // ------------- | |
451 | // sched_kthread_stop (type: tracepoint) | |
eb1bab5b BH |
452 | List<IBaseEventInfo> events = new ArrayList<IBaseEventInfo>(); |
453 | getProviderEventInfo(result.getOutput(), 0, events); | |
454 | return events; | |
455 | } | |
456 | ||
457 | /* | |
458 | * (non-Javadoc) | |
4775bcbf BH |
459 | * |
460 | * @see | |
461 | * org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService | |
462 | * #getUstProvider() | |
eb1bab5b BH |
463 | */ |
464 | @Override | |
465 | public List<IUstProviderInfo> getUstProvider() throws ExecutionException { | |
466 | return getUstProvider(new NullProgressMonitor()); | |
467 | } | |
4775bcbf | 468 | |
eb1bab5b BH |
469 | /* |
470 | * (non-Javadoc) | |
4775bcbf BH |
471 | * |
472 | * @see | |
473 | * org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService | |
474 | * #getUstProvider(org.eclipse.core.runtime.IProgressMonitor) | |
eb1bab5b BH |
475 | */ |
476 | @Override | |
477 | public List<IUstProviderInfo> getUstProvider(IProgressMonitor monitor) throws ExecutionException { | |
478 | String command = COMMAND_LIST_UST; | |
479 | ICommandResult result = fCommandShell.executeCommand(command, monitor); | |
480 | ||
481 | if (isError(result)) { | |
482 | throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$ | |
483 | } | |
4775bcbf BH |
484 | |
485 | // UST events: | |
486 | // ------------- | |
487 | // | |
488 | // PID: 3635 - Name: | |
489 | // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello | |
490 | // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type: | |
491 | // tracepoint) | |
492 | // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint) | |
493 | // | |
494 | // PID: 6459 - Name: | |
495 | // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello | |
496 | // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type: | |
497 | // tracepoint) | |
498 | // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint) | |
eb1bab5b BH |
499 | |
500 | List<IUstProviderInfo> allProviders = new ArrayList<IUstProviderInfo>(); | |
501 | IUstProviderInfo provider = null; | |
4775bcbf | 502 | |
eb1bab5b BH |
503 | int index = 0; |
504 | while (index < result.getOutput().length) { | |
505 | String line = result.getOutput()[index]; | |
4775bcbf BH |
506 | Matcher matcher = UST_PROVIDER_PATTERN.matcher(line); |
507 | if (matcher.matches()) { | |
eb1bab5b | 508 | |
4775bcbf BH |
509 | provider = new UstProviderInfo(matcher.group(2).trim()); |
510 | provider.setPid(Integer.valueOf(matcher.group(1).trim())); | |
511 | List<IBaseEventInfo> events = new ArrayList<IBaseEventInfo>(); | |
512 | index = getProviderEventInfo(result.getOutput(), ++index, events); | |
513 | provider.setEvents(events); | |
514 | allProviders.add(provider); | |
eb1bab5b BH |
515 | |
516 | } else { | |
517 | index++; | |
518 | } | |
4775bcbf | 519 | |
eb1bab5b BH |
520 | } |
521 | return allProviders; | |
522 | } | |
523 | ||
bbb3538a BH |
524 | /* |
525 | * (non-Javadoc) | |
526 | * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#createSession(java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor) | |
527 | */ | |
528 | @Override | |
529 | public ISessionInfo createSession(String sessionName, String sessionPath, IProgressMonitor monitor) throws ExecutionException { | |
530 | ||
531 | String newName = formatParameter(sessionName); | |
532 | String newPath = formatParameter(sessionPath); | |
533 | ||
534 | String command = COMMAND_CREATE_SESSION + newName; | |
535 | if (newPath != null && !"".equals(newPath)) { //$NON-NLS-1$ | |
536 | command += " -o " + newPath; //$NON-NLS-1$ | |
537 | } | |
538 | ||
539 | ICommandResult result = fCommandShell.executeCommand(command, monitor); | |
540 | ||
541 | if (isError(result)) { | |
542 | throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$ | |
543 | } | |
544 | //Session myssession2 created. | |
545 | //Traces will be written in /home/user/lttng-traces/myssession2-20120209-095418 | |
546 | String[] output = result.getOutput(); | |
547 | ||
548 | // Get and verify session name | |
549 | Matcher matcher = CREATE_SESSION_NAME_PATTERN.matcher(output[0]); | |
550 | String name = null; | |
551 | ||
552 | if (matcher.matches()) { | |
553 | name = String.valueOf(matcher.group(1).trim()); | |
554 | } else { | |
555 | // Output format not expected | |
556 | throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$ | |
557 | Messages.TraceControl_UnexpectedCommnadOutputFormat + ":\n" + //$NON-NLS-1$ | |
558 | formatOutput(result.getOutput())); | |
559 | } | |
560 | ||
561 | if ((name == null) || (!name.equals(sessionName))) { | |
562 | // Unexpected name returned | |
563 | throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$ | |
564 | Messages.TraceControl_UnexpectedNameError + ": " + name); //$NON-NLS-1$ | |
565 | } | |
566 | ||
567 | // Get and verify session path | |
568 | matcher = CREATE_SESSION_PATH_PATTERN.matcher(output[1]); | |
569 | String path = null; | |
570 | ||
571 | if (matcher.matches()) { | |
572 | path = String.valueOf(matcher.group(1).trim()); | |
573 | } else { | |
574 | // Output format not expected | |
575 | throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$ | |
576 | Messages.TraceControl_UnexpectedCommnadOutputFormat + ":\n" + //$NON-NLS-1$ | |
577 | formatOutput(result.getOutput())); | |
578 | } | |
579 | ||
580 | if ((path == null) || ((sessionPath != null) && (!path.contains(sessionPath)))) { | |
581 | // Unexpected path | |
582 | throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$ | |
583 | Messages.TraceControl_UnexpectedPathError + ": " + name); //$NON-NLS-1$ | |
584 | } | |
585 | ||
586 | SessionInfo sessionInfo = new SessionInfo(name); | |
587 | sessionInfo.setSessionPath(path); | |
588 | ||
589 | return sessionInfo; | |
590 | } | |
591 | ||
592 | @Override | |
593 | public void destroySession(String sessionName, IProgressMonitor monitor) throws ExecutionException { | |
594 | String newName = formatParameter(sessionName); | |
595 | String command = COMMAND_DESTROY_SESSION + newName; | |
596 | ||
597 | ICommandResult result = fCommandShell.executeCommand(command, monitor); | |
598 | String[] output = result.getOutput(); | |
599 | ||
600 | if (isError(result)) { | |
601 | // In case "session not found" treat it as success | |
602 | if ((output == null) || (!SESSION_NOT_FOUND_ERROR_PATTERN.matcher(output[0]).matches())) { | |
603 | throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$ | |
604 | } | |
605 | } | |
606 | //Session <sessionName> destroyed | |
607 | } | |
608 | ||
609 | /* | |
610 | * (non-Javadoc) | |
611 | * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#startSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor) | |
612 | */ | |
613 | @Override | |
614 | public void startSession(String sessionName, IProgressMonitor monitor) throws ExecutionException { | |
615 | ||
616 | String newSessionName = formatParameter(sessionName); | |
617 | ||
618 | String command = COMMAND_START_SESSION + newSessionName; | |
619 | ||
620 | ICommandResult result = fCommandShell.executeCommand(command, monitor); | |
621 | ||
622 | if (isError(result)) { | |
623 | throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$ | |
624 | } | |
625 | //Session <sessionName> started | |
626 | } | |
627 | ||
628 | /* | |
629 | * (non-Javadoc) | |
630 | * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#stopSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor) | |
631 | */ | |
632 | @Override | |
633 | public void stopSession(String sessionName, IProgressMonitor monitor) throws ExecutionException { | |
634 | String newSessionName = formatParameter(sessionName); | |
635 | String command = COMMAND_STOP_SESSION + newSessionName; | |
636 | ||
637 | ICommandResult result = fCommandShell.executeCommand(command, monitor); | |
638 | ||
639 | if (isError(result)) { | |
640 | throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$ | |
641 | } | |
642 | //Session <sessionName> stopped | |
643 | ||
644 | } | |
645 | ||
646 | /* | |
647 | * (non-Javadoc) | |
648 | * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#enableChannel(java.lang.String, java.util.List, boolean, org.eclipse.linuxtools.lttng.ui.views.control.model.IChannelInfo, org.eclipse.core.runtime.IProgressMonitor) | |
649 | */ | |
650 | @Override | |
498704b3 | 651 | public void enableChannels(String sessionName, List<String> channelNames, boolean isKernel, IChannelInfo info, IProgressMonitor monitor) throws ExecutionException { |
bbb3538a BH |
652 | |
653 | // no channels to enable | |
654 | if (channelNames.size() == 0) { | |
655 | return; | |
656 | } | |
657 | ||
658 | String newSessionName = formatParameter(sessionName); | |
659 | ||
660 | StringBuffer command = new StringBuffer(COMMAND_ENABLE_CHANNEL); | |
661 | ||
662 | for (Iterator<String> iterator = channelNames.iterator(); iterator.hasNext();) { | |
663 | String channel = (String) iterator.next(); | |
664 | command.append(channel); | |
665 | if (iterator.hasNext()) { | |
666 | command.append(","); //$NON-NLS-1$ | |
667 | } | |
668 | } | |
669 | ||
670 | if (isKernel) { | |
6503ae0f | 671 | command.append(OPTION_KERNEL); |
bbb3538a | 672 | } else { |
6503ae0f | 673 | command.append(OPTION_UST); |
bbb3538a BH |
674 | } |
675 | ||
6503ae0f | 676 | command.append(OPTION_SESSION); |
bbb3538a BH |
677 | command.append(newSessionName); |
678 | ||
679 | if (info != null) { | |
680 | // --discard Discard event when buffers are full (default) | |
bbb3538a BH |
681 | |
682 | // --overwrite Flight recorder mode | |
683 | if (info.isOverwriteMode()) { | |
6503ae0f | 684 | command.append(OPTION_OVERWRITE); |
bbb3538a BH |
685 | } |
686 | // --subbuf-size SIZE Subbuffer size in bytes | |
687 | // (default: 4096, kernel default: 262144) | |
6503ae0f | 688 | command.append(OPTION_SUB_BUFFER_SIZE); |
bbb3538a BH |
689 | command.append(String.valueOf(info.getSubBufferSize())); |
690 | ||
691 | // --num-subbuf NUM Number of subbufers | |
692 | // (default: 8, kernel default: 4) | |
6503ae0f | 693 | command.append(OPTION_NUM_SUB_BUFFERS); |
bbb3538a BH |
694 | command.append(String.valueOf(info.getNumberOfSubBuffers())); |
695 | ||
696 | // --switch-timer USEC Switch timer interval in usec (default: 0) | |
6503ae0f | 697 | command.append(OPTION_SWITCH_TIMER); |
bbb3538a BH |
698 | command.append(String.valueOf(info.getSwitchTimer())); |
699 | ||
700 | // --read-timer USEC Read timer interval in usec (default: 200) | |
6503ae0f | 701 | command.append(OPTION_READ_TIMER); |
bbb3538a BH |
702 | command.append(String.valueOf(info.getReadTimer())); |
703 | } | |
704 | ||
705 | ICommandResult result = fCommandShell.executeCommand(command.toString(), monitor); | |
706 | ||
707 | if (isError(result)) { | |
708 | throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$ | |
709 | } | |
bbb3538a BH |
710 | } |
711 | ||
712 | /* | |
713 | * (non-Javadoc) | |
714 | * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#disableChannel(java.lang.String, java.util.List, org.eclipse.core.runtime.IProgressMonitor) | |
715 | */ | |
716 | @Override | |
498704b3 | 717 | public void disableChannels(String sessionName, List<String> channelNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException { |
bbb3538a BH |
718 | |
719 | // no channels to enable | |
720 | if (channelNames.size() == 0) { | |
721 | return; | |
722 | } | |
723 | ||
724 | String newSessionName = formatParameter(sessionName); | |
725 | ||
726 | StringBuffer command = new StringBuffer(COMMAND_DISABLE_CHANNEL); | |
727 | ||
728 | for (Iterator<String> iterator = channelNames.iterator(); iterator.hasNext();) { | |
729 | String channel = (String) iterator.next(); | |
730 | command.append(channel); | |
731 | if (iterator.hasNext()) { | |
732 | command.append(","); //$NON-NLS-1$ | |
733 | } | |
734 | } | |
735 | ||
736 | if (isKernel) { | |
6503ae0f BH |
737 | command.append(OPTION_KERNEL); |
738 | } else { | |
739 | command.append(OPTION_UST); | |
740 | } | |
741 | ||
742 | command.append(OPTION_SESSION); | |
743 | command.append(newSessionName); | |
744 | ||
745 | ICommandResult result = fCommandShell.executeCommand(command.toString(), monitor); | |
746 | ||
747 | if (isError(result)) { | |
748 | throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$ | |
749 | } | |
750 | } | |
751 | ||
752 | /* | |
753 | * (non-Javadoc) | |
754 | * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#enableEvent(java.lang.String, java.lang.String, java.util.List, boolean, org.eclipse.core.runtime.IProgressMonitor) | |
755 | */ | |
756 | @Override | |
498704b3 | 757 | public void enableEvents(String sessionName, String channelName, List<String> eventNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException { |
6503ae0f BH |
758 | |
759 | String newSessionName = formatParameter(sessionName); | |
760 | ||
761 | StringBuffer command = new StringBuffer(COMMAND_ENABLE_EVENT); | |
762 | ||
d132bcc7 | 763 | if (eventNames == null || eventNames.size() == 0) { |
3e91c9c0 BH |
764 | command.append(OPTION_ALL); |
765 | } else { | |
3e91c9c0 BH |
766 | |
767 | for (Iterator<String> iterator = eventNames.iterator(); iterator.hasNext();) { | |
768 | String event = (String) iterator.next(); | |
769 | command.append(event); | |
770 | if (iterator.hasNext()) { | |
771 | command.append(","); //$NON-NLS-1$ | |
772 | } | |
6503ae0f BH |
773 | } |
774 | } | |
775 | ||
776 | if (isKernel) { | |
777 | command.append(OPTION_KERNEL); | |
bbb3538a | 778 | } else { |
6503ae0f | 779 | command.append(OPTION_UST); |
bbb3538a BH |
780 | } |
781 | ||
6503ae0f | 782 | command.append(OPTION_SESSION); |
bbb3538a BH |
783 | command.append(newSessionName); |
784 | ||
6503ae0f BH |
785 | if (channelName != null) { |
786 | command.append(OPTION_CHANNEL); | |
787 | command.append(channelName); | |
788 | } | |
498704b3 BH |
789 | |
790 | command.append(OPTION_TRACEPOINT); | |
791 | ||
792 | ICommandResult result = fCommandShell.executeCommand(command.toString(), monitor); | |
793 | ||
794 | if (isError(result)) { | |
795 | throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$ | |
796 | } | |
797 | } | |
6503ae0f | 798 | |
498704b3 BH |
799 | /* |
800 | * (non-Javadoc) | |
801 | * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#enableSyscalls(java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor) | |
802 | */ | |
803 | @Override | |
804 | public void enableSyscalls(String sessionName, String channelName, IProgressMonitor monitor) throws ExecutionException { | |
805 | String newSessionName = formatParameter(sessionName); | |
806 | ||
807 | StringBuffer command = new StringBuffer(COMMAND_ENABLE_EVENT); | |
808 | ||
809 | command.append(OPTION_ALL); | |
810 | command.append(OPTION_KERNEL); | |
811 | ||
812 | command.append(OPTION_SESSION); | |
813 | command.append(newSessionName); | |
814 | ||
815 | if (channelName != null) { | |
816 | command.append(OPTION_CHANNEL); | |
817 | command.append(channelName); | |
818 | } | |
819 | ||
820 | command.append(OPTION_SYSCALL); | |
821 | ||
bbb3538a BH |
822 | ICommandResult result = fCommandShell.executeCommand(command.toString(), monitor); |
823 | ||
824 | if (isError(result)) { | |
825 | throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$ | |
498704b3 BH |
826 | } |
827 | } | |
828 | ||
829 | /* | |
830 | * (non-Javadoc) | |
831 | * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#enableProbe(java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor) | |
832 | */ | |
833 | @Override | |
d132bcc7 | 834 | public void enableProbe(String sessionName, String channelName, String eventName, boolean isFunction, String probe, IProgressMonitor monitor) throws ExecutionException { |
498704b3 BH |
835 | String newSessionName = formatParameter(sessionName); |
836 | ||
837 | StringBuffer command = new StringBuffer(COMMAND_ENABLE_EVENT); | |
838 | ||
839 | command.append(eventName); | |
840 | command.append(OPTION_KERNEL); | |
841 | ||
842 | command.append(OPTION_SESSION); | |
843 | command.append(newSessionName); | |
844 | ||
845 | if (channelName != null) { | |
846 | command.append(OPTION_CHANNEL); | |
847 | command.append(channelName); | |
bbb3538a | 848 | } |
d132bcc7 BH |
849 | if (isFunction) { |
850 | command.append(OPTION_FUNCTION_PROBE); | |
851 | } else { | |
852 | command.append(OPTION_PROBE); | |
498704b3 BH |
853 | } |
854 | ||
498704b3 BH |
855 | command.append(probe); |
856 | ||
857 | ICommandResult result = fCommandShell.executeCommand(command.toString(), monitor); | |
858 | ||
859 | if (isError(result)) { | |
860 | throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$ | |
d132bcc7 | 861 | } |
498704b3 | 862 | } |
ccc66d01 BH |
863 | |
864 | /* | |
865 | * (non-Javadoc) | |
866 | * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#enableLogLevel(java.lang.String, java.lang.String, java.lang.String, org.eclipse.linuxtools.lttng.ui.views.control.model.LogLevelType, org.eclipse.linuxtools.lttng.ui.views.control.model.TraceLogLevel, org.eclipse.core.runtime.IProgressMonitor) | |
867 | */ | |
868 | @Override | |
869 | public void enableLogLevel(String sessionName, String channelName, String eventName, LogLevelType logLevelType, TraceLogLevel level, IProgressMonitor monitor) throws ExecutionException { | |
870 | String newSessionName = formatParameter(sessionName); | |
871 | ||
872 | StringBuffer command = new StringBuffer(COMMAND_ENABLE_EVENT); | |
873 | ||
874 | command.append(eventName); | |
875 | command.append(OPTION_UST); | |
876 | ||
877 | command.append(OPTION_SESSION); | |
878 | command.append(newSessionName); | |
879 | ||
880 | if (channelName != null) { | |
881 | command.append(OPTION_CHANNEL); | |
882 | command.append(channelName); | |
883 | } | |
884 | ||
885 | if (logLevelType == LogLevelType.LOGLEVEL) { | |
886 | command.append(OPTION_LOGLEVEL); | |
887 | } else if (logLevelType == LogLevelType.LOGLEVEL_ONLY) { | |
888 | command.append(OPTION_LOGLEVEL_ONLY); | |
889 | ||
890 | } else { | |
891 | return; | |
892 | } | |
893 | command.append(level.getInName()); | |
894 | ||
895 | ICommandResult result = fCommandShell.executeCommand(command.toString(), monitor); | |
896 | ||
897 | if (isError(result)) { | |
898 | throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$ | |
899 | } | |
900 | } | |
901 | ||
6503ae0f BH |
902 | /* |
903 | * (non-Javadoc) | |
904 | * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#disableEvent(java.lang.String, java.lang.String, java.util.List, boolean, org.eclipse.core.runtime.IProgressMonitor) | |
905 | */ | |
906 | @Override | |
907 | public void disableEvent(String sessionName, String channelName, List<String> eventNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException { | |
6503ae0f BH |
908 | String newSessionName = formatParameter(sessionName); |
909 | ||
910 | StringBuffer command = new StringBuffer(COMMAND_DISABLE_EVENT); | |
3e91c9c0 BH |
911 | if (eventNames == null) { |
912 | command.append(OPTION_ALL); | |
913 | } else { | |
914 | // no events to enable | |
915 | if (eventNames.size() == 0) { | |
916 | return; | |
917 | } | |
6503ae0f | 918 | |
3e91c9c0 BH |
919 | for (Iterator<String> iterator = eventNames.iterator(); iterator.hasNext();) { |
920 | String event = (String) iterator.next(); | |
921 | command.append(event); | |
922 | if (iterator.hasNext()) { | |
923 | command.append(","); //$NON-NLS-1$ | |
924 | } | |
6503ae0f BH |
925 | } |
926 | } | |
927 | ||
928 | if (isKernel) { | |
929 | command.append(OPTION_KERNEL); | |
930 | } else { | |
931 | command.append(OPTION_UST); | |
932 | } | |
933 | ||
934 | command.append(OPTION_SESSION); | |
935 | command.append(newSessionName); | |
936 | ||
937 | if (channelName != null) { | |
938 | command.append(OPTION_CHANNEL); | |
939 | command.append(channelName); | |
940 | } | |
941 | ||
942 | ICommandResult result = fCommandShell.executeCommand(command.toString(), monitor); | |
943 | ||
944 | if (isError(result)) { | |
945 | throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$ | |
946 | } | |
947 | } | |
948 | ||
eb1bab5b BH |
949 | // ------------------------------------------------------------------------ |
950 | // Helper methods | |
951 | // ------------------------------------------------------------------------ | |
952 | /** | |
953 | * Checks if command result is an error result. | |
4775bcbf BH |
954 | * |
955 | * @param result | |
956 | * - the command result to check | |
eb1bab5b BH |
957 | * @return true if error else false |
958 | */ | |
959 | private boolean isError(ICommandResult result) { | |
4775bcbf | 960 | if ((result.getResult()) != 0 || (result.getOutput().length < 1 || ERROR_PATTERN.matcher(result.getOutput()[0]).matches())) { |
eb1bab5b BH |
961 | return true; |
962 | } | |
963 | return false; | |
964 | } | |
4775bcbf | 965 | |
eb1bab5b BH |
966 | /** |
967 | * Formats the output string as single string. | |
4775bcbf BH |
968 | * |
969 | * @param output | |
970 | * - output array | |
eb1bab5b BH |
971 | * @return - the formatted output |
972 | */ | |
973 | private String formatOutput(String[] output) { | |
974 | if (output == null || output.length == 0) { | |
975 | return ""; //$NON-NLS-1$ | |
976 | } | |
977 | ||
978 | StringBuffer ret = new StringBuffer(); | |
979 | for (int i = 0; i < output.length; i++) { | |
980 | ret.append(output[i] + "\n"); //$NON-NLS-1$ | |
981 | } | |
982 | return ret.toString(); | |
983 | } | |
4775bcbf | 984 | |
eb1bab5b BH |
985 | /** |
986 | * Parses the domain information. | |
987 | * | |
4775bcbf BH |
988 | * @param output |
989 | * - a command output array | |
990 | * @param currentIndex | |
991 | * - current index in command output array | |
992 | * @param channels | |
993 | * - list for returning channel information | |
994 | * @return the new current index in command output array | |
eb1bab5b | 995 | */ |
887a93a3 | 996 | private int parseDomain(String[] output, int currentIndex, List<IChannelInfo> channels) { |
eb1bab5b BH |
997 | int index = currentIndex; |
998 | ||
4775bcbf BH |
999 | // Channels: |
1000 | // ------------- | |
1001 | // - channnel1: [enabled] | |
1002 | // | |
1003 | // Attributes: | |
1004 | // overwrite mode: 0 | |
1005 | // subbufers size: 262144 | |
1006 | // number of subbufers: 4 | |
1007 | // switch timer interval: 0 | |
1008 | // read timer interval: 200 | |
1009 | // output: splice() | |
1010 | ||
eb1bab5b BH |
1011 | while (index < output.length) { |
1012 | String line = output[index]; | |
4775bcbf BH |
1013 | |
1014 | Matcher outerMatcher = CHANNELS_SECTION_PATTERN.matcher(line); | |
1015 | if (outerMatcher.matches()) { | |
eb1bab5b BH |
1016 | IChannelInfo channelInfo = null; |
1017 | while (index < output.length) { | |
1018 | String subLine = output[index]; | |
4775bcbf BH |
1019 | |
1020 | Matcher innerMatcher = CHANNEL_PATTERN.matcher(subLine); | |
1021 | if (innerMatcher.matches()) { | |
eb1bab5b | 1022 | channelInfo = new ChannelInfo(""); //$NON-NLS-1$ |
4775bcbf BH |
1023 | // get channel name |
1024 | channelInfo.setName(innerMatcher.group(1)); | |
1025 | ||
1026 | // get channel enablement | |
1027 | channelInfo.setState(innerMatcher.group(2)); | |
1028 | ||
1029 | // add channel | |
1030 | channels.add(channelInfo); | |
1031 | ||
1032 | } else if (OVERWRITE_MODE_ATTRIBUTE.matcher(subLine).matches()) { | |
eb1bab5b BH |
1033 | String value = getAttributeValue(subLine); |
1034 | channelInfo.setOverwriteMode(!OVERWRITE_MODE_ATTRIBUTE_FALSE.equals(value)); | |
4775bcbf | 1035 | } else if (SUBBUFFER_SIZE_ATTRIBUTE.matcher(subLine).matches()) { |
eb1bab5b | 1036 | channelInfo.setSubBufferSize(Long.valueOf(getAttributeValue(subLine))); |
4775bcbf BH |
1037 | |
1038 | } else if (NUM_SUBBUFFERS_ATTRIBUTE.matcher(subLine).matches()) { | |
eb1bab5b | 1039 | channelInfo.setNumberOfSubBuffers(Integer.valueOf(getAttributeValue(subLine))); |
4775bcbf BH |
1040 | |
1041 | } else if (SWITCH_TIMER_ATTRIBUTE.matcher(subLine).matches()) { | |
eb1bab5b | 1042 | channelInfo.setSwitchTimer(Long.valueOf(getAttributeValue(subLine))); |
4775bcbf BH |
1043 | |
1044 | } else if (READ_TIMER_ATTRIBUTE.matcher(subLine).matches()) { | |
eb1bab5b | 1045 | channelInfo.setReadTimer(Long.valueOf(getAttributeValue(subLine))); |
4775bcbf BH |
1046 | |
1047 | } else if (OUTPUT_ATTRIBUTE.matcher(subLine).matches()) { | |
eb1bab5b | 1048 | channelInfo.setOutputType(getAttributeValue(subLine)); |
4775bcbf BH |
1049 | |
1050 | } else if (EVENT_SECTION_PATTERN.matcher(subLine).matches()) { | |
1051 | List<IEventInfo> events = new ArrayList<IEventInfo>(); | |
eb1bab5b BH |
1052 | index = parseEvents(output, index, events); |
1053 | channelInfo.setEvents(events); | |
4775bcbf BH |
1054 | // we want to stay at the current index to be able to |
1055 | // exit the domain | |
eb1bab5b | 1056 | continue; |
4775bcbf | 1057 | } else if (DOMAIN_KERNEL_PATTERN.matcher(subLine).matches()) { |
eb1bab5b BH |
1058 | return index; |
1059 | ||
4775bcbf | 1060 | } else if (DOMAIN_UST_GLOBAL_PATTERN.matcher(subLine).matches()) { |
eb1bab5b BH |
1061 | return index; |
1062 | } | |
1063 | index++; | |
1064 | } | |
1065 | } | |
1066 | index++; | |
1067 | } | |
1068 | return index; | |
1069 | } | |
1070 | ||
1071 | /** | |
1072 | * Parses the event information within a domain. | |
1073 | * | |
4775bcbf BH |
1074 | * @param output |
1075 | * - a command output array | |
1076 | * @param currentIndex | |
1077 | * - current index in command output array | |
1078 | * @param events | |
1079 | * - list for returning event information | |
eb1bab5b | 1080 | * @return the new current index in command output array |
eb1bab5b | 1081 | */ |
887a93a3 | 1082 | private int parseEvents(String[] output, int currentIndex, List<IEventInfo> events) { |
eb1bab5b BH |
1083 | int index = currentIndex; |
1084 | ||
1085 | while (index < output.length) { | |
1086 | String line = output[index]; | |
4775bcbf | 1087 | if (CHANNEL_PATTERN.matcher(line).matches()) { |
eb1bab5b BH |
1088 | // end of channel |
1089 | return index; | |
4775bcbf | 1090 | } else if (DOMAIN_KERNEL_PATTERN.matcher(line).matches()) { |
eb1bab5b BH |
1091 | // end of domain |
1092 | return index; | |
4775bcbf | 1093 | } else if (DOMAIN_UST_GLOBAL_PATTERN.matcher(line).matches()) { |
eb1bab5b BH |
1094 | // end of domain |
1095 | return index; | |
4775bcbf BH |
1096 | } |
1097 | ||
1098 | Matcher matcher = EVENT_PATTERN.matcher(line); | |
1099 | Matcher matcher2 = WILDCARD_EVENT_PATTERN.matcher(line); | |
1100 | ||
1101 | if (matcher.matches()) { | |
1102 | IEventInfo eventInfo = new EventInfo(matcher.group(1).trim()); | |
1103 | eventInfo.setLogLevel(matcher.group(2).trim()); | |
1104 | eventInfo.setEventType(matcher.group(3).trim()); | |
1105 | eventInfo.setState(matcher.group(4)); | |
1106 | events.add(eventInfo); | |
d132bcc7 | 1107 | index++; |
4775bcbf BH |
1108 | } else if (matcher2.matches()) { |
1109 | IEventInfo eventInfo = new EventInfo(matcher2.group(1).trim()); | |
1110 | eventInfo.setLogLevel(TraceLogLevel.LEVEL_UNKNOWN); | |
1111 | eventInfo.setEventType(matcher2.group(2).trim()); | |
1112 | eventInfo.setState(matcher2.group(3)); | |
d132bcc7 BH |
1113 | |
1114 | if (eventInfo.getEventType() == TraceEventType.PROBE) { | |
1115 | IProbeEventInfo probeEvent = new ProbeEventInfo(eventInfo.getName()); | |
1116 | probeEvent.setLogLevel(eventInfo.getLogLevel()); | |
1117 | probeEvent.setEventType(eventInfo.getEventType()); | |
1118 | probeEvent.setState(eventInfo.getState()); | |
1119 | ||
1120 | // Overwrite eventinfo | |
1121 | eventInfo = probeEvent; | |
1122 | ||
1123 | // myevent2 (type: probe) [enabled] | |
1124 | // addr: 0xc0101340 | |
1125 | // myevent0 (type: probe) [enabled] | |
1126 | // offset: 0x0 | |
1127 | // symbol: init_post | |
1128 | index++; | |
1129 | while (index < output.length) { | |
1130 | String probeLine = output[index]; | |
1131 | // parse probe | |
1132 | Matcher addrMatcher = PROBE_ADDRESS_PATTERN.matcher(probeLine); | |
1133 | Matcher offsetMatcher = PROBE_OFFSET_PATTERN.matcher(probeLine); | |
1134 | Matcher symbolMatcher = PROBE_SYMBOL_PATTERN.matcher(probeLine); | |
1135 | if (addrMatcher.matches()) { | |
1136 | String addr = addrMatcher.group(2).trim(); | |
1137 | probeEvent.setAddress(addr); | |
1138 | } else if (offsetMatcher.matches()) { | |
1139 | String offset = offsetMatcher.group(2).trim(); | |
1140 | probeEvent.setOffset(offset); | |
1141 | } else if (symbolMatcher.matches()) { | |
1142 | String symbol = symbolMatcher.group(2).trim(); | |
1143 | probeEvent.setSymbol(symbol); | |
1144 | } else if ((EVENT_PATTERN.matcher(probeLine).matches()) || (WILDCARD_EVENT_PATTERN.matcher(probeLine).matches())) { | |
1145 | break; | |
1146 | } else if (CHANNEL_PATTERN.matcher(probeLine).matches()) { | |
1147 | break; | |
1148 | } else if (DOMAIN_KERNEL_PATTERN.matcher(probeLine).matches()) { | |
1149 | // end of domain | |
1150 | break; | |
1151 | } else if (DOMAIN_UST_GLOBAL_PATTERN.matcher(probeLine).matches()) { | |
1152 | // end of domain | |
1153 | break; | |
1154 | } | |
1155 | index++; | |
1156 | } | |
1157 | events.add(eventInfo); | |
1158 | } else { | |
1159 | events.add(eventInfo); | |
1160 | index++; | |
1161 | continue; | |
1162 | } | |
1163 | } else { | |
1164 | index++; | |
eb1bab5b BH |
1165 | } |
1166 | // else if (line.matches(EVENT_NONE_PATTERN)) { | |
1167 | // do nothing | |
1168 | // } else | |
d132bcc7 | 1169 | |
eb1bab5b BH |
1170 | } |
1171 | ||
1172 | return index; | |
1173 | } | |
1174 | ||
1175 | /** | |
1176 | * Parses a line with attributes: <attribute Name>: <attribute value> | |
1177 | * | |
4775bcbf BH |
1178 | * @param line |
1179 | * - attribute line to parse | |
eb1bab5b | 1180 | * @return the attribute value as string |
eb1bab5b BH |
1181 | */ |
1182 | private String getAttributeValue(String line) { | |
1183 | String[] temp = line.split("\\: "); //$NON-NLS-1$ | |
1184 | return temp[1]; | |
1185 | } | |
1186 | ||
1187 | /** | |
4775bcbf | 1188 | * Parses the event information within a provider. |
eb1bab5b | 1189 | * |
4775bcbf BH |
1190 | * @param output |
1191 | * - a command output array | |
1192 | * @param currentIndex | |
1193 | * - current index in command output array | |
1194 | * @param events | |
1195 | * - list for returning event information | |
eb1bab5b BH |
1196 | * @return the new current index in command output array |
1197 | */ | |
1198 | private int getProviderEventInfo(String[] output, int currentIndex, List<IBaseEventInfo> events) { | |
1199 | int index = currentIndex; | |
1200 | while (index < output.length) { | |
1201 | String line = output[index]; | |
4775bcbf BH |
1202 | Matcher matcher = PROVIDER_EVENT_PATTERN.matcher(line); |
1203 | if (matcher.matches()) { | |
1204 | // sched_kthread_stop (loglevel: TRACE_EMERG0) (type: | |
1205 | // tracepoint) | |
1206 | IBaseEventInfo eventInfo = new BaseEventInfo(matcher.group(1).trim()); | |
1207 | eventInfo.setLogLevel(matcher.group(2).trim()); | |
1208 | eventInfo.setEventType(matcher.group(3).trim()); | |
1209 | events.add(eventInfo); | |
1210 | } else if (UST_PROVIDER_PATTERN.matcher(line).matches()) { | |
eb1bab5b BH |
1211 | return index; |
1212 | } | |
1213 | index++; | |
1214 | } | |
1215 | return index; | |
1216 | } | |
1217 | ||
bbb3538a BH |
1218 | /** |
1219 | * Formats a command parameter for the command execution i.e. adds quotes | |
1220 | * at the beginning and end if necessary. | |
1221 | * @param parameter - parameter to format | |
1222 | * @return formated parameter | |
1223 | */ | |
1224 | private String formatParameter(String parameter) { | |
1225 | if (parameter != null) { | |
1226 | String newString = String.valueOf(parameter); | |
1227 | ||
1228 | if (parameter.contains(" ")) { //$NON-NLS-1$ | |
1229 | newString = "\"" + newString + "\""; //$NON-NLS-1$ //$NON-NLS-2$ | |
1230 | } | |
1231 | return newString; | |
1232 | } | |
1233 | return null; | |
1234 | } | |
1235 | ||
eb1bab5b | 1236 | } |