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