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