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