1 /**********************************************************************
2 * Copyright (c) 2012 Ericsson
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
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12 package org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.service
;
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
;
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
;
43 * <b><u>LTTngControlService</u></b>
45 * Service for sending LTTng trace control commands to remote host.
48 public class LTTngControlService
implements ILttngControlService
{
49 // ------------------------------------------------------------------------
51 // ------------------------------------------------------------------------
54 * The lttng tools command.
56 private final static String CONTROL_COMMAND
= "lttng"; //$NON-NLS-1$
58 * Command: lttng list.
60 private final static String COMMAND_LIST
= CONTROL_COMMAND
+ " list "; //$NON-NLS-1$
62 * Command to list kernel tracer information.
64 private final static String COMMAND_LIST_KERNEL
= COMMAND_LIST
+ "-k"; //$NON-NLS-1$
66 * Command to list user space trace information.
68 private final static String COMMAND_LIST_UST
= COMMAND_LIST
+ "-u"; //$NON-NLS-1$
70 * Command to create a session.
72 private final static String COMMAND_CREATE_SESSION
= CONTROL_COMMAND
+ " create "; //$NON-NLS-1$
74 * Command to destroy a session.
76 private final static String COMMAND_DESTROY_SESSION
= CONTROL_COMMAND
+ " destroy "; //$NON-NLS-1$
78 * Command to destroy a session.
80 private final static String COMMAND_START_SESSION
= CONTROL_COMMAND
+ " start "; //$NON-NLS-1$
82 * Command to destroy a session.
84 private final static String COMMAND_STOP_SESSION
= CONTROL_COMMAND
+ " stop "; //$NON-NLS-1$
86 * Command to enable a channel.
88 private final static String COMMAND_ENABLE_CHANNEL
= CONTROL_COMMAND
+ " enable-channel "; //$NON-NLS-1$
90 * Command to disable a channel.
92 private final static String COMMAND_DISABLE_CHANNEL
= CONTROL_COMMAND
+ " disable-channel "; //$NON-NLS-1$
94 * Command to enable a event.
96 private final static String COMMAND_ENABLE_EVENT
= CONTROL_COMMAND
+ " enable-event "; //$NON-NLS-1$
98 * Command to disable a event.
100 private final static String COMMAND_DISABLE_EVENT
= CONTROL_COMMAND
+ " disable-event "; //$NON-NLS-1$
102 // Command options constants
104 * Command line option for output path.
106 private final static String OPTION_OUTPUT_PATH
= " -o "; //$NON-NLS-1$
108 * Command line option for kernel tracer.
110 private final static String OPTION_KERNEL
= " -k "; //$NON-NLS-1$
112 * Command line option for UST tracer.
114 private final static String OPTION_UST
= " -u "; //$NON-NLS-1$
116 * Command line option for specifying a session.
118 private final static String OPTION_SESSION
= " -s "; //$NON-NLS-1$
120 * Command line option for specifying a channel.
122 private final static String OPTION_CHANNEL
= " -c "; //$NON-NLS-1$
124 * Command line option for specifying all events.
126 private final static String OPTION_ALL
= " -a "; //$NON-NLS-1$
128 * Command line option for specifying tracepoint events.
130 private final static String OPTION_TRACEPOINT
= " --tracepoint "; //$NON-NLS-1$
132 * Command line option for specifying syscall events.
134 private final static String OPTION_SYSCALL
= " --syscall "; //$NON-NLS-1$
136 * Command line option for specifying a dynamic probe.
138 private final static String OPTION_PROBE
= " --probe "; //$NON-NLS-1$
140 * Command line option for specifying a dynamic function entry/return probe.
142 private final static String OPTION_FUNCTION_PROBE
= " --function "; //$NON-NLS-1$
144 * Command line option for specifying a log level range.
146 private final static String OPTION_LOGLEVEL
= " --loglevel "; //$NON-NLS-1$
148 * Command line option for specifying a specific log level.
150 private final static String OPTION_LOGLEVEL_ONLY
= " --loglevel-only "; //$NON-NLS-1$
152 * Optional command line option for configuring a channel's overwrite mode.
154 private final static String OPTION_OVERWRITE
= " --overwrite "; //$NON-NLS-1$
156 * Optional command line option for configuring a channel's number of sub buffers.
158 private final static String OPTION_NUM_SUB_BUFFERS
= " --num-subbuf "; //$NON-NLS-1$
160 * Optional command line option for configuring a channel's sub buffer size.
162 private final static String OPTION_SUB_BUFFER_SIZE
= " --subbuf-size "; //$NON-NLS-1$
164 * Optional command line option for configuring a channel's switch timer interval.
166 private final static String OPTION_SWITCH_TIMER
= " --switch-timer "; //$NON-NLS-1$
168 * Optional command line option for configuring a channel's read timer interval.
170 private final static String OPTION_READ_TIMER
= " --read-timer "; //$NON-NLS-1$
174 * Pattern to match for error output
176 private final static Pattern ERROR_PATTERN
= Pattern
.compile("\\s*Error\\:.*"); //$NON-NLS-1$
178 * Pattern to match for session information (lttng list)
180 private final static Pattern SESSION_PATTERN
= Pattern
.compile("\\s+(\\d+)\\)\\s+(.*)\\s+\\((.*)\\)\\s+\\[(active|inactive)\\].*"); //$NON-NLS-1$
182 * Pattern to match for session information (lttng list <session>)
184 private final static Pattern TRACE_SESSION_PATTERN
= Pattern
.compile("\\s*Tracing\\s+session\\s+(.*)\\:\\s+\\[(active|inactive)\\].*"); //$NON-NLS-1$
186 * Pattern to match for session path information (lttng list <session>)
188 private final static Pattern TRACE_SESSION_PATH_PATTERN
= Pattern
.compile("\\s*Trace\\s+path\\:\\s+(.*)"); //$NON-NLS-1$
190 * Pattern to match for kernel domain information (lttng list <session>)
192 private final static Pattern DOMAIN_KERNEL_PATTERN
= Pattern
.compile("=== Domain: Kernel ==="); //$NON-NLS-1$
194 * Pattern to match for ust domain information (lttng list <session>)
196 private final static Pattern DOMAIN_UST_GLOBAL_PATTERN
= Pattern
.compile("=== Domain: UST global ==="); //$NON-NLS-1$
198 * Pattern to match for channels section (lttng list <session>)
200 private final static Pattern CHANNELS_SECTION_PATTERN
= Pattern
.compile("\\s*Channels\\:"); //$NON-NLS-1$
202 * Pattern to match for channel information (lttng list <session>)
204 private final static Pattern CHANNEL_PATTERN
= Pattern
.compile("\\s*-\\s+(.*)\\:\\s+\\[(enabled|disabled)\\]"); //$NON-NLS-1$
206 * Pattern to match for events section information (lttng list <session>)
208 private final static Pattern EVENT_SECTION_PATTERN
= Pattern
.compile("\\s*Events\\:"); //$NON-NLS-1$
210 * Pattern to match for event information (no enabled events) (lttng list <session>)
212 // private final static String EVENT_NONE_PATTERN = "\\s+None"; //$NON-NLS-1$
214 * Pattern to match for event information (lttng list <session>)
216 private final static Pattern EVENT_PATTERN
= Pattern
.compile("\\s+(.*)\\s+\\(loglevel:\\s+(.*)\\s+\\(\\d*\\)\\)\\s+\\(type:\\s+(.*)\\)\\s+\\[(enabled|disabled)\\].*"); //$NON-NLS-1$
218 * Pattern to match a wildcarded event information (lttng list <session>)
220 private final static Pattern WILDCARD_EVENT_PATTERN
= Pattern
.compile("\\s+(.*)\\s+\\(type:\\s+(.*)\\)\\s+\\[(enabled|disabled)\\].*"); //$NON-NLS-1$
222 * Pattern to match a probe address information (lttng list <session>)
224 private final static Pattern PROBE_ADDRESS_PATTERN
= Pattern
.compile("\\s+(addr)\\:\\s+(0x[0-9a-fA-F]{1,8})"); //$NON-NLS-1$
226 * Pattern to match a probe OFFSET information (lttng list <session>)
228 private final static Pattern PROBE_OFFSET_PATTERN
= Pattern
.compile("\\s+(offset)\\:\\s+(0x[0-9a-fA-F]{1,8})"); //$NON-NLS-1$
230 * Pattern to match a probe SYMBOL information (lttng list <session>)
232 private final static Pattern PROBE_SYMBOL_PATTERN
= Pattern
.compile("\\s+(symbol)\\:\\s+(.+)"); //$NON-NLS-1$
234 * Pattern to match for channel (overwite mode) information (lttng list
237 private final static Pattern OVERWRITE_MODE_ATTRIBUTE
= Pattern
.compile("\\s+overwrite\\s+mode\\:.*"); //$NON-NLS-1$
239 * Pattern to match indicating false for overwrite mode
241 private final static String OVERWRITE_MODE_ATTRIBUTE_FALSE
= "0"; //$NON-NLS-1$
243 * Pattern to match for channel (sub-buffer size) information (lttng list
246 private final static Pattern SUBBUFFER_SIZE_ATTRIBUTE
= Pattern
.compile("\\s+subbufers\\s+size\\:.*"); //$NON-NLS-1$
248 * Pattern to match for channel (number of sub-buffers) information (lttng
251 private final static Pattern NUM_SUBBUFFERS_ATTRIBUTE
= Pattern
.compile("\\s+number\\s+of\\s+subbufers\\:.*"); //$NON-NLS-1$
253 * Pattern to match for channel (switch timer) information (lttng list
256 private final static Pattern SWITCH_TIMER_ATTRIBUTE
= Pattern
.compile("\\s+switch\\s+timer\\s+interval\\:.*"); //$NON-NLS-1$
258 * Pattern to match for channel (read timer) information (lttng list
261 private final static Pattern READ_TIMER_ATTRIBUTE
= Pattern
.compile("\\s+read\\s+timer\\s+interval\\:.*"); //$NON-NLS-1$
263 * Pattern to match for channel (output type) information (lttng list
266 private final static Pattern OUTPUT_ATTRIBUTE
= Pattern
.compile("\\s+output\\:.*"); //$NON-NLS-1$
268 * Pattern to match for provider information (lttng list -k/-u)
270 private final static Pattern PROVIDER_EVENT_PATTERN
= Pattern
.compile("\\s*(.*)\\s+\\(loglevel:\\s+(.*)\\s+\\(\\d*\\)\\)\\s+\\(type:\\s+(.*)\\)"); //$NON-NLS-1$
272 * Pattern to match for UST provider information (lttng list -u)
274 private final static Pattern UST_PROVIDER_PATTERN
= Pattern
.compile("\\s*PID\\:\\s+(\\d+)\\s+-\\s+Name\\:\\s+(.*)"); //$NON-NLS-1$
276 * Pattern to match for session information (lttng create <session name>)
278 private final static Pattern CREATE_SESSION_NAME_PATTERN
= Pattern
.compile("\\s*Session\\s+(.*)\\s+created\\."); //$NON-NLS-1$
280 * Pattern to match for session path information (lttng create <session name>)
282 private final static Pattern CREATE_SESSION_PATH_PATTERN
= Pattern
.compile("\\s*Traces\\s+will\\s+be\\s+written\\s+in\\s+(.*).*"); //$NON-NLS-1$
284 * Pattern to match for session command output for "session name not found".
286 private final static Pattern SESSION_NOT_FOUND_ERROR_PATTERN
= Pattern
.compile("\\s*Error:\\s+Session\\s+name\\s+not\\s+found"); //$NON-NLS-1$
288 // ------------------------------------------------------------------------
290 // ------------------------------------------------------------------------
292 * The command shell implementation
294 private ICommandShell fCommandShell
= null;
296 // ------------------------------------------------------------------------
298 // ------------------------------------------------------------------------
304 * - the command shell implementation to use
306 public LTTngControlService(ICommandShell shell
) {
307 fCommandShell
= shell
;
310 // ------------------------------------------------------------------------
312 // ------------------------------------------------------------------------
318 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
319 * #getSessionNames(org.eclipse.core.runtime.IProgressMonitor)
322 public String
[] getSessionNames(IProgressMonitor monitor
) throws ExecutionException
{
324 String command
= COMMAND_LIST
;
325 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
327 if (isError(result
)) {
328 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
332 // Available tracing sessions:
333 // 1) mysession1 (/home/user/lttng-traces/mysession1-20120123-083928)
335 // 2) mysession (/home/user/lttng-traces/mysession-20120123-083318)
338 // Use lttng list <session_name> for more details
340 ArrayList
<String
> retArray
= new ArrayList
<String
>();
342 while (index
< result
.getOutput().length
) {
343 String line
= result
.getOutput()[index
];
344 Matcher matcher
= SESSION_PATTERN
.matcher(line
);
345 if (matcher
.matches()) {
346 retArray
.add(matcher
.group(2).trim());
350 return retArray
.toArray(new String
[retArray
.size()]);
357 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
358 * #getSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
361 public ISessionInfo
getSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
363 String command
= COMMAND_LIST
+ sessionName
;
364 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
366 if (isError(result
)) {
367 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
373 // Tracing session mysession2: [inactive]
374 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
375 ISessionInfo sessionInfo
= new SessionInfo(sessionName
);
377 while (index
< result
.getOutput().length
) {
378 // Tracing session mysession2: [inactive]
379 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
381 // === Domain: Kernel ===
383 String line
= result
.getOutput()[index
];
384 Matcher matcher
= TRACE_SESSION_PATTERN
.matcher(line
);
385 if (matcher
.matches()) {
386 sessionInfo
.setSessionState(matcher
.group(2));
391 matcher
= TRACE_SESSION_PATH_PATTERN
.matcher(line
);
392 if (matcher
.matches()) {
393 sessionInfo
.setSessionPath(matcher
.group(1).trim());
398 matcher
= DOMAIN_KERNEL_PATTERN
.matcher(line
);
399 if (matcher
.matches()) {
401 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_KernelDomainDisplayName
);
402 sessionInfo
.addDomain(domainInfo
);
405 ArrayList
<IChannelInfo
> channels
= new ArrayList
<IChannelInfo
>();
406 index
= parseDomain(result
.getOutput(), index
, channels
);
409 domainInfo
.setChannels(channels
);
412 domainInfo
.setIsKernel(true);
416 matcher
= DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
);
417 if (matcher
.matches()) {
418 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_UstGlobalDomainDisplayName
);
419 sessionInfo
.addDomain(domainInfo
);
422 ArrayList
<IChannelInfo
> channels
= new ArrayList
<IChannelInfo
>();
423 index
= parseDomain(result
.getOutput(), index
, channels
);
426 domainInfo
.setChannels(channels
);
429 domainInfo
.setIsKernel(false);
441 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
442 * #getKernelProvider(org.eclipse.core.runtime.IProgressMonitor)
445 public List
<IBaseEventInfo
> getKernelProvider(IProgressMonitor monitor
) throws ExecutionException
{
446 String command
= COMMAND_LIST_KERNEL
;
447 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
448 if (isError(result
)) {
449 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
454 // sched_kthread_stop (type: tracepoint)
455 List
<IBaseEventInfo
> events
= new ArrayList
<IBaseEventInfo
>();
456 getProviderEventInfo(result
.getOutput(), 0, events
);
464 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
468 public List
<IUstProviderInfo
> getUstProvider() throws ExecutionException
{
469 return getUstProvider(new NullProgressMonitor());
476 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
477 * #getUstProvider(org.eclipse.core.runtime.IProgressMonitor)
480 public List
<IUstProviderInfo
> getUstProvider(IProgressMonitor monitor
) throws ExecutionException
{
481 String command
= COMMAND_LIST_UST
;
482 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
484 if (isError(result
)) {
485 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
492 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
493 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
495 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
498 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
499 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
501 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
503 List
<IUstProviderInfo
> allProviders
= new ArrayList
<IUstProviderInfo
>();
504 IUstProviderInfo provider
= null;
507 while (index
< result
.getOutput().length
) {
508 String line
= result
.getOutput()[index
];
509 Matcher matcher
= UST_PROVIDER_PATTERN
.matcher(line
);
510 if (matcher
.matches()) {
512 provider
= new UstProviderInfo(matcher
.group(2).trim());
513 provider
.setPid(Integer
.valueOf(matcher
.group(1).trim()));
514 List
<IBaseEventInfo
> events
= new ArrayList
<IBaseEventInfo
>();
515 index
= getProviderEventInfo(result
.getOutput(), ++index
, events
);
516 provider
.setEvents(events
);
517 allProviders
.add(provider
);
529 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#createSession(java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
532 public ISessionInfo
createSession(String sessionName
, String sessionPath
, IProgressMonitor monitor
) throws ExecutionException
{
534 String newName
= formatParameter(sessionName
);
535 String newPath
= formatParameter(sessionPath
);
537 StringBuffer command
= new StringBuffer();
538 command
.append(COMMAND_CREATE_SESSION
);
539 command
.append(newName
);
541 if (newPath
!= null && !"".equals(newPath
)) { //$NON-NLS-1$
542 command
.append(OPTION_OUTPUT_PATH
);
543 command
.append(newPath
);
546 ICommandResult result
= fCommandShell
.executeCommand(command
.toString(), monitor
);
548 if (isError(result
)) {
549 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
551 //Session myssession2 created.
552 //Traces will be written in /home/user/lttng-traces/myssession2-20120209-095418
553 String
[] output
= result
.getOutput();
555 // Get and verify session name
556 Matcher matcher
= CREATE_SESSION_NAME_PATTERN
.matcher(output
[0]);
559 if (matcher
.matches()) {
560 name
= String
.valueOf(matcher
.group(1).trim());
562 // Output format not expected
563 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
564 Messages
.TraceControl_UnexpectedCommnadOutputFormat
+ ":\n" + //$NON-NLS-1$
565 formatOutput(result
.getOutput()));
568 if ((name
== null) || (!name
.equals(sessionName
))) {
569 // Unexpected name returned
570 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
571 Messages
.TraceControl_UnexpectedNameError
+ ": " + name
); //$NON-NLS-1$
574 // Get and verify session path
575 matcher
= CREATE_SESSION_PATH_PATTERN
.matcher(output
[1]);
578 if (matcher
.matches()) {
579 path
= String
.valueOf(matcher
.group(1).trim());
581 // Output format not expected
582 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
583 Messages
.TraceControl_UnexpectedCommnadOutputFormat
+ ":\n" + //$NON-NLS-1$
584 formatOutput(result
.getOutput()));
587 if ((path
== null) || ((sessionPath
!= null) && (!path
.contains(sessionPath
)))) {
589 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
590 Messages
.TraceControl_UnexpectedPathError
+ ": " + name
); //$NON-NLS-1$
593 SessionInfo sessionInfo
= new SessionInfo(name
);
594 sessionInfo
.setSessionPath(path
);
600 public void destroySession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
601 String newName
= formatParameter(sessionName
);
602 String command
= COMMAND_DESTROY_SESSION
+ newName
;
604 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
605 String
[] output
= result
.getOutput();
607 if (isError(result
) && ((output
== null) || (!SESSION_NOT_FOUND_ERROR_PATTERN
.matcher(output
[0]).matches()))) {
608 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
610 //Session <sessionName> destroyed
615 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#startSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
618 public void startSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
620 String newSessionName
= formatParameter(sessionName
);
622 String command
= COMMAND_START_SESSION
+ newSessionName
;
624 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
626 if (isError(result
)) {
627 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
629 //Session <sessionName> started
634 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#stopSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
637 public void stopSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
638 String newSessionName
= formatParameter(sessionName
);
639 String command
= COMMAND_STOP_SESSION
+ newSessionName
;
641 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
643 if (isError(result
)) {
644 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
646 //Session <sessionName> stopped
652 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#enableChannel(java.lang.String, java.util.List, boolean, org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo, org.eclipse.core.runtime.IProgressMonitor)
655 public void enableChannels(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IChannelInfo info
, IProgressMonitor monitor
) throws ExecutionException
{
657 // no channels to enable
658 if (channelNames
.isEmpty()) {
662 String newSessionName
= formatParameter(sessionName
);
664 StringBuffer command
= new StringBuffer(COMMAND_ENABLE_CHANNEL
);
666 for (Iterator
<String
> iterator
= channelNames
.iterator(); iterator
.hasNext();) {
667 String channel
= (String
) iterator
.next();
668 command
.append(channel
);
669 if (iterator
.hasNext()) {
675 command
.append(OPTION_KERNEL
);
677 command
.append(OPTION_UST
);
680 command
.append(OPTION_SESSION
);
681 command
.append(newSessionName
);
684 // --discard Discard event when buffers are full (default)
686 // --overwrite Flight recorder mode
687 if (info
.isOverwriteMode()) {
688 command
.append(OPTION_OVERWRITE
);
690 // --subbuf-size SIZE Subbuffer size in bytes
691 // (default: 4096, kernel default: 262144)
692 command
.append(OPTION_SUB_BUFFER_SIZE
);
693 command
.append(String
.valueOf(info
.getSubBufferSize()));
695 // --num-subbuf NUM Number of subbufers
696 // (default: 8, kernel default: 4)
697 command
.append(OPTION_NUM_SUB_BUFFERS
);
698 command
.append(String
.valueOf(info
.getNumberOfSubBuffers()));
700 // --switch-timer USEC Switch timer interval in usec (default: 0)
701 command
.append(OPTION_SWITCH_TIMER
);
702 command
.append(String
.valueOf(info
.getSwitchTimer()));
704 // --read-timer USEC Read timer interval in usec (default: 200)
705 command
.append(OPTION_READ_TIMER
);
706 command
.append(String
.valueOf(info
.getReadTimer()));
709 ICommandResult result
= fCommandShell
.executeCommand(command
.toString(), monitor
);
711 if (isError(result
)) {
712 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
718 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#disableChannel(java.lang.String, java.util.List, org.eclipse.core.runtime.IProgressMonitor)
721 public void disableChannels(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
723 // no channels to enable
724 if (channelNames
.isEmpty()) {
728 String newSessionName
= formatParameter(sessionName
);
730 StringBuffer command
= new StringBuffer(COMMAND_DISABLE_CHANNEL
);
732 for (Iterator
<String
> iterator
= channelNames
.iterator(); iterator
.hasNext();) {
733 String channel
= (String
) iterator
.next();
734 command
.append(channel
);
735 if (iterator
.hasNext()) {
741 command
.append(OPTION_KERNEL
);
743 command
.append(OPTION_UST
);
746 command
.append(OPTION_SESSION
);
747 command
.append(newSessionName
);
749 ICommandResult result
= fCommandShell
.executeCommand(command
.toString(), monitor
);
751 if (isError(result
)) {
752 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
758 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#enableEvent(java.lang.String, java.lang.String, java.util.List, boolean, org.eclipse.core.runtime.IProgressMonitor)
761 public void enableEvents(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
763 String newSessionName
= formatParameter(sessionName
);
765 StringBuffer command
= new StringBuffer(COMMAND_ENABLE_EVENT
);
767 if (eventNames
== null || eventNames
.isEmpty()) {
768 command
.append(OPTION_ALL
);
771 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
772 String event
= (String
) iterator
.next();
773 command
.append(event
);
774 if (iterator
.hasNext()) {
781 command
.append(OPTION_KERNEL
);
783 command
.append(OPTION_UST
);
786 command
.append(OPTION_SESSION
);
787 command
.append(newSessionName
);
789 if (channelName
!= null) {
790 command
.append(OPTION_CHANNEL
);
791 command
.append(channelName
);
794 command
.append(OPTION_TRACEPOINT
);
796 ICommandResult result
= fCommandShell
.executeCommand(command
.toString(), monitor
);
798 if (isError(result
)) {
799 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
805 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#enableSyscalls(java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
808 public void enableSyscalls(String sessionName
, String channelName
, IProgressMonitor monitor
) throws ExecutionException
{
809 String newSessionName
= formatParameter(sessionName
);
811 StringBuffer command
= new StringBuffer(COMMAND_ENABLE_EVENT
);
813 command
.append(OPTION_ALL
);
814 command
.append(OPTION_KERNEL
);
816 command
.append(OPTION_SESSION
);
817 command
.append(newSessionName
);
819 if (channelName
!= null) {
820 command
.append(OPTION_CHANNEL
);
821 command
.append(channelName
);
824 command
.append(OPTION_SYSCALL
);
826 ICommandResult result
= fCommandShell
.executeCommand(command
.toString(), monitor
);
828 if (isError(result
)) {
829 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
835 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#enableProbe(java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
838 public void enableProbe(String sessionName
, String channelName
, String eventName
, boolean isFunction
, String probe
, IProgressMonitor monitor
) throws ExecutionException
{
839 String newSessionName
= formatParameter(sessionName
);
841 StringBuffer command
= new StringBuffer(COMMAND_ENABLE_EVENT
);
843 command
.append(eventName
);
844 command
.append(OPTION_KERNEL
);
846 command
.append(OPTION_SESSION
);
847 command
.append(newSessionName
);
849 if (channelName
!= null) {
850 command
.append(OPTION_CHANNEL
);
851 command
.append(channelName
);
854 command
.append(OPTION_FUNCTION_PROBE
);
856 command
.append(OPTION_PROBE
);
859 command
.append(probe
);
861 ICommandResult result
= fCommandShell
.executeCommand(command
.toString(), monitor
);
863 if (isError(result
)) {
864 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
870 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#enableLogLevel(java.lang.String, java.lang.String, java.lang.String, org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.LogLevelType, org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceLogLevel, org.eclipse.core.runtime.IProgressMonitor)
873 public void enableLogLevel(String sessionName
, String channelName
, String eventName
, LogLevelType logLevelType
, TraceLogLevel level
, IProgressMonitor monitor
) throws ExecutionException
{
874 String newSessionName
= formatParameter(sessionName
);
876 StringBuffer command
= new StringBuffer(COMMAND_ENABLE_EVENT
);
878 command
.append(eventName
);
879 command
.append(OPTION_UST
);
881 command
.append(OPTION_SESSION
);
882 command
.append(newSessionName
);
884 if (channelName
!= null) {
885 command
.append(OPTION_CHANNEL
);
886 command
.append(channelName
);
889 if (logLevelType
== LogLevelType
.LOGLEVEL
) {
890 command
.append(OPTION_LOGLEVEL
);
891 } else if (logLevelType
== LogLevelType
.LOGLEVEL_ONLY
) {
892 command
.append(OPTION_LOGLEVEL_ONLY
);
897 command
.append(level
.getInName());
899 ICommandResult result
= fCommandShell
.executeCommand(command
.toString(), monitor
);
901 if (isError(result
)) {
902 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
908 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#disableEvent(java.lang.String, java.lang.String, java.util.List, boolean, org.eclipse.core.runtime.IProgressMonitor)
911 public void disableEvent(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
912 String newSessionName
= formatParameter(sessionName
);
914 StringBuffer command
= new StringBuffer(COMMAND_DISABLE_EVENT
);
915 if (eventNames
== null) {
916 command
.append(OPTION_ALL
);
918 // no events to enable
919 if (eventNames
.isEmpty()) {
923 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
924 String event
= (String
) iterator
.next();
925 command
.append(event
);
926 if (iterator
.hasNext()) {
933 command
.append(OPTION_KERNEL
);
935 command
.append(OPTION_UST
);
938 command
.append(OPTION_SESSION
);
939 command
.append(newSessionName
);
941 if (channelName
!= null) {
942 command
.append(OPTION_CHANNEL
);
943 command
.append(channelName
);
946 ICommandResult result
= fCommandShell
.executeCommand(command
.toString(), monitor
);
948 if (isError(result
)) {
949 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
953 // ------------------------------------------------------------------------
955 // ------------------------------------------------------------------------
957 * Checks if command result is an error result.
960 * - the command result to check
961 * @return true if error else false
963 private boolean isError(ICommandResult result
) {
964 if ((result
.getResult()) != 0 || (result
.getOutput().length
< 1 || ERROR_PATTERN
.matcher(result
.getOutput()[0]).matches())) {
971 * Formats the output string as single string.
975 * @return - the formatted output
977 private String
formatOutput(String
[] output
) {
978 if (output
== null || output
.length
== 0) {
979 return ""; //$NON-NLS-1$
982 StringBuffer ret
= new StringBuffer();
983 for (int i
= 0; i
< output
.length
; i
++) {
984 ret
.append(output
[i
] + "\n"); //$NON-NLS-1$
986 return ret
.toString();
990 * Parses the domain information.
993 * - a command output array
994 * @param currentIndex
995 * - current index in command output array
997 * - list for returning channel information
998 * @return the new current index in command output array
1000 private int parseDomain(String
[] output
, int currentIndex
, List
<IChannelInfo
> channels
) {
1001 int index
= currentIndex
;
1005 // - channnel1: [enabled]
1008 // overwrite mode: 0
1009 // subbufers size: 262144
1010 // number of subbufers: 4
1011 // switch timer interval: 0
1012 // read timer interval: 200
1015 while (index
< output
.length
) {
1016 String line
= output
[index
];
1018 Matcher outerMatcher
= CHANNELS_SECTION_PATTERN
.matcher(line
);
1019 if (outerMatcher
.matches()) {
1020 IChannelInfo channelInfo
= null;
1021 while (index
< output
.length
) {
1022 String subLine
= output
[index
];
1024 Matcher innerMatcher
= CHANNEL_PATTERN
.matcher(subLine
);
1025 if (innerMatcher
.matches()) {
1026 channelInfo
= new ChannelInfo(""); //$NON-NLS-1$
1028 channelInfo
.setName(innerMatcher
.group(1));
1030 // get channel enablement
1031 channelInfo
.setState(innerMatcher
.group(2));
1034 channels
.add(channelInfo
);
1036 } else if (OVERWRITE_MODE_ATTRIBUTE
.matcher(subLine
).matches()) {
1037 String value
= getAttributeValue(subLine
);
1038 channelInfo
.setOverwriteMode(!OVERWRITE_MODE_ATTRIBUTE_FALSE
.equals(value
));
1039 } else if (SUBBUFFER_SIZE_ATTRIBUTE
.matcher(subLine
).matches()) {
1040 channelInfo
.setSubBufferSize(Long
.valueOf(getAttributeValue(subLine
)));
1042 } else if (NUM_SUBBUFFERS_ATTRIBUTE
.matcher(subLine
).matches()) {
1043 channelInfo
.setNumberOfSubBuffers(Integer
.valueOf(getAttributeValue(subLine
)));
1045 } else if (SWITCH_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
1046 channelInfo
.setSwitchTimer(Long
.valueOf(getAttributeValue(subLine
)));
1048 } else if (READ_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
1049 channelInfo
.setReadTimer(Long
.valueOf(getAttributeValue(subLine
)));
1051 } else if (OUTPUT_ATTRIBUTE
.matcher(subLine
).matches()) {
1052 channelInfo
.setOutputType(getAttributeValue(subLine
));
1054 } else if (EVENT_SECTION_PATTERN
.matcher(subLine
).matches()) {
1055 List
<IEventInfo
> events
= new ArrayList
<IEventInfo
>();
1056 index
= parseEvents(output
, index
, events
);
1057 channelInfo
.setEvents(events
);
1058 // we want to stay at the current index to be able to
1061 } else if (DOMAIN_KERNEL_PATTERN
.matcher(subLine
).matches()) {
1064 } else if (DOMAIN_UST_GLOBAL_PATTERN
.matcher(subLine
).matches()) {
1076 * Parses the event information within a domain.
1079 * - a command output array
1080 * @param currentIndex
1081 * - current index in command output array
1083 * - list for returning event information
1084 * @return the new current index in command output array
1086 private int parseEvents(String
[] output
, int currentIndex
, List
<IEventInfo
> events
) {
1087 int index
= currentIndex
;
1089 while (index
< output
.length
) {
1090 String line
= output
[index
];
1091 if (CHANNEL_PATTERN
.matcher(line
).matches()) {
1094 } else if (DOMAIN_KERNEL_PATTERN
.matcher(line
).matches()) {
1097 } else if (DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
).matches()) {
1102 Matcher matcher
= EVENT_PATTERN
.matcher(line
);
1103 Matcher matcher2
= WILDCARD_EVENT_PATTERN
.matcher(line
);
1105 if (matcher
.matches()) {
1106 IEventInfo eventInfo
= new EventInfo(matcher
.group(1).trim());
1107 eventInfo
.setLogLevel(matcher
.group(2).trim());
1108 eventInfo
.setEventType(matcher
.group(3).trim());
1109 eventInfo
.setState(matcher
.group(4));
1110 events
.add(eventInfo
);
1112 } else if (matcher2
.matches()) {
1113 IEventInfo eventInfo
= new EventInfo(matcher2
.group(1).trim());
1114 eventInfo
.setLogLevel(TraceLogLevel
.LEVEL_UNKNOWN
);
1115 eventInfo
.setEventType(matcher2
.group(2).trim());
1116 eventInfo
.setState(matcher2
.group(3));
1118 if (eventInfo
.getEventType() == TraceEventType
.PROBE
) {
1119 IProbeEventInfo probeEvent
= new ProbeEventInfo(eventInfo
.getName());
1120 probeEvent
.setLogLevel(eventInfo
.getLogLevel());
1121 probeEvent
.setEventType(eventInfo
.getEventType());
1122 probeEvent
.setState(eventInfo
.getState());
1124 // Overwrite eventinfo
1125 eventInfo
= probeEvent
;
1127 // myevent2 (type: probe) [enabled]
1129 // myevent0 (type: probe) [enabled]
1131 // symbol: init_post
1133 while (index
< output
.length
) {
1134 String probeLine
= output
[index
];
1136 Matcher addrMatcher
= PROBE_ADDRESS_PATTERN
.matcher(probeLine
);
1137 Matcher offsetMatcher
= PROBE_OFFSET_PATTERN
.matcher(probeLine
);
1138 Matcher symbolMatcher
= PROBE_SYMBOL_PATTERN
.matcher(probeLine
);
1139 if (addrMatcher
.matches()) {
1140 String addr
= addrMatcher
.group(2).trim();
1141 probeEvent
.setAddress(addr
);
1142 } else if (offsetMatcher
.matches()) {
1143 String offset
= offsetMatcher
.group(2).trim();
1144 probeEvent
.setOffset(offset
);
1145 } else if (symbolMatcher
.matches()) {
1146 String symbol
= symbolMatcher
.group(2).trim();
1147 probeEvent
.setSymbol(symbol
);
1148 } else if ((EVENT_PATTERN
.matcher(probeLine
).matches()) || (WILDCARD_EVENT_PATTERN
.matcher(probeLine
).matches())) {
1150 } else if (CHANNEL_PATTERN
.matcher(probeLine
).matches()) {
1152 } else if (DOMAIN_KERNEL_PATTERN
.matcher(probeLine
).matches()) {
1155 } else if (DOMAIN_UST_GLOBAL_PATTERN
.matcher(probeLine
).matches()) {
1161 events
.add(eventInfo
);
1163 events
.add(eventInfo
);
1170 // else if (line.matches(EVENT_NONE_PATTERN)) {
1180 * Parses a line with attributes: <attribute Name>: <attribute value>
1183 * - attribute line to parse
1184 * @return the attribute value as string
1186 private String
getAttributeValue(String line
) {
1187 String
[] temp
= line
.split("\\: "); //$NON-NLS-1$
1192 * Parses the event information within a provider.
1195 * - a command output array
1196 * @param currentIndex
1197 * - current index in command output array
1199 * - list for returning event information
1200 * @return the new current index in command output array
1202 private int getProviderEventInfo(String
[] output
, int currentIndex
, List
<IBaseEventInfo
> events
) {
1203 int index
= currentIndex
;
1204 while (index
< output
.length
) {
1205 String line
= output
[index
];
1206 Matcher matcher
= PROVIDER_EVENT_PATTERN
.matcher(line
);
1207 if (matcher
.matches()) {
1208 // sched_kthread_stop (loglevel: TRACE_EMERG0) (type:
1210 IBaseEventInfo eventInfo
= new BaseEventInfo(matcher
.group(1).trim());
1211 eventInfo
.setLogLevel(matcher
.group(2).trim());
1212 eventInfo
.setEventType(matcher
.group(3).trim());
1213 events
.add(eventInfo
);
1214 } else if (UST_PROVIDER_PATTERN
.matcher(line
).matches()) {
1223 * Formats a command parameter for the command execution i.e. adds quotes
1224 * at the beginning and end if necessary.
1225 * @param parameter - parameter to format
1226 * @return formated parameter
1228 private String
formatParameter(String parameter
) {
1229 if (parameter
!= null) {
1230 StringBuffer newString
= new StringBuffer();
1231 newString
.append(parameter
);
1233 if (parameter
.contains(" ")) { //$NON-NLS-1$
1234 newString
.insert(0, "\""); //$NON-NLS-1$
1235 newString
.append("\""); //$NON-NLS-1$
1237 return newString
.toString();