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
.lttng
.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
.lttng
.ui
.views
.control
.Messages
;
24 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.IBaseEventInfo
;
25 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.IChannelInfo
;
26 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.IDomainInfo
;
27 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.IEventInfo
;
28 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.ISessionInfo
;
29 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.IUstProviderInfo
;
30 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.TraceLogLevel
;
31 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.impl
.BaseEventInfo
;
32 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.impl
.ChannelInfo
;
33 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.impl
.DomainInfo
;
34 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.impl
.EventInfo
;
35 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.impl
.SessionInfo
;
36 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.impl
.UstProviderInfo
;
39 * <b><u>LTTngControlService</u></b>
41 * Service for sending LTTng trace control commands to remote host.
44 public class LTTngControlService
implements ILttngControlService
{
45 // ------------------------------------------------------------------------
47 // ------------------------------------------------------------------------
50 * The lttng tools command.
52 private final static String CONTROL_COMMAND
= "lttng"; //$NON-NLS-1$
54 * Command: lttng list.
56 private final static String COMMAND_LIST
= CONTROL_COMMAND
+ " list "; //$NON-NLS-1$
58 * Command to list kernel tracer information.
60 private final static String COMMAND_LIST_KERNEL
= COMMAND_LIST
+ "-k"; //$NON-NLS-1$
62 * Command to list user space trace information.
64 private final static String COMMAND_LIST_UST
= COMMAND_LIST
+ "-u"; //$NON-NLS-1$
66 * Command to create a session.
68 private final static String COMMAND_CREATE_SESSION
= CONTROL_COMMAND
+ " create "; //$NON-NLS-1$
70 * Command to destroy a session.
72 private final static String COMMAND_DESTROY_SESSION
= CONTROL_COMMAND
+ " destroy "; //$NON-NLS-1$
74 * Command to destroy a session.
76 private final static String COMMAND_START_SESSION
= CONTROL_COMMAND
+ " start "; //$NON-NLS-1$
78 * Command to destroy a session.
80 private final static String COMMAND_STOP_SESSION
= CONTROL_COMMAND
+ " stop "; //$NON-NLS-1$
82 * Command to enable a channel.
84 private final static String COMMAND_ENABLE_CHANNEL
= CONTROL_COMMAND
+ " enable-channel "; //$NON-NLS-1$
86 * Command to destroy a session.
88 private final static String COMMAND_DISABLE_CHANNEL
= CONTROL_COMMAND
+ " disable-channel "; //$NON-NLS-1$
92 * Pattern to match for error output
94 private final static Pattern ERROR_PATTERN
= Pattern
.compile("\\s*Error\\:.*"); //$NON-NLS-1$
96 * Pattern to match for session information (lttng list)
98 private final static Pattern SESSION_PATTERN
= Pattern
.compile("\\s+(\\d+)\\)\\s+(.*)\\s+\\((.*)\\)\\s+\\[(active|inactive)\\].*"); //$NON-NLS-1$
100 * Pattern to match for session information (lttng list <session>)
102 private final static Pattern TRACE_SESSION_PATTERN
= Pattern
.compile("\\s*Tracing\\s+session\\s+(.*)\\:\\s+\\[(active|inactive)\\].*"); //$NON-NLS-1$
104 * Pattern to match for session path information (lttng list <session>)
106 private final static Pattern TRACE_SESSION_PATH_PATTERN
= Pattern
.compile("\\s*Trace\\s+path\\:\\s+(.*)"); //$NON-NLS-1$
108 * Pattern to match for kernel domain information (lttng list <session>)
110 private final static Pattern DOMAIN_KERNEL_PATTERN
= Pattern
.compile("=== Domain: Kernel ==="); //$NON-NLS-1$
112 * Pattern to match for ust domain information (lttng list <session>)
114 private final static Pattern DOMAIN_UST_GLOBAL_PATTERN
= Pattern
.compile("=== Domain: UST global ==="); //$NON-NLS-1$
116 * Pattern to match for channels section (lttng list <session>)
118 private final static Pattern CHANNELS_SECTION_PATTERN
= Pattern
.compile("\\s*Channels\\:"); //$NON-NLS-1$
120 * Pattern to match for channel information (lttng list <session>)
122 private final static Pattern CHANNEL_PATTERN
= Pattern
.compile("\\s*-\\s+(.*)\\:\\s+\\[(enabled|disabled)\\]"); //$NON-NLS-1$
124 * Pattern to match for events section information (lttng list <session>)
126 private final static Pattern EVENT_SECTION_PATTERN
= Pattern
.compile("\\s*Events\\:"); //$NON-NLS-1$
128 * Pattern to match for event information (no enabled events) (lttng list
131 // private final static String EVENT_NONE_PATTERN = "\\s+None"; //$NON-NLS-1$
133 * Pattern to match for event information (lttng list <session>)
135 private final static Pattern EVENT_PATTERN
= Pattern
.compile("\\s+(.*)\\s+\\(loglevel:\\s+(.*)\\s+\\(\\d*\\)\\)\\s+\\(type:\\s+(.*)\\)\\s+\\[(enabled|disabled)\\].*"); //$NON-NLS-1$
137 * Pattern to match a wildcarded event information (lttng list <session>)
139 private final static Pattern WILDCARD_EVENT_PATTERN
= Pattern
.compile("\\s+(.*)\\s+\\(type:\\s+(.*)\\)\\s+\\[(enabled|disabled)\\].*"); //$NON-NLS-1$
141 * Pattern to match for channel (overwite mode) information (lttng list
144 private final static Pattern OVERWRITE_MODE_ATTRIBUTE
= Pattern
.compile("\\s+overwrite\\s+mode\\:.*"); //$NON-NLS-1$
146 * Pattern to match indicating false for overwrite mode
148 private final static String OVERWRITE_MODE_ATTRIBUTE_FALSE
= "0"; //$NON-NLS-1$
150 * Pattern to match for channel (sub-buffer size) information (lttng list
153 private final static Pattern SUBBUFFER_SIZE_ATTRIBUTE
= Pattern
.compile("\\s+subbufers\\s+size\\:.*"); //$NON-NLS-1$
155 * Pattern to match for channel (number of sub-buffers) information (lttng
158 private final static Pattern NUM_SUBBUFFERS_ATTRIBUTE
= Pattern
.compile("\\s+number\\s+of\\s+subbufers\\:.*"); //$NON-NLS-1$
160 * Pattern to match for channel (switch timer) information (lttng list
163 private final static Pattern SWITCH_TIMER_ATTRIBUTE
= Pattern
.compile("\\s+switch\\s+timer\\s+interval\\:.*"); //$NON-NLS-1$
165 * Pattern to match for channel (read timer) information (lttng list
168 private final static Pattern READ_TIMER_ATTRIBUTE
= Pattern
.compile("\\s+read\\s+timer\\s+interval\\:.*"); //$NON-NLS-1$
170 * Pattern to match for channel (output type) information (lttng list
173 private final static Pattern OUTPUT_ATTRIBUTE
= Pattern
.compile("\\s+output\\:.*"); //$NON-NLS-1$
175 * Pattern to match for provider information (lttng list -k/-u)
177 private final static Pattern PROVIDER_EVENT_PATTERN
= Pattern
.compile("\\s*(.*)\\s+\\(loglevel:\\s+(.*)\\s+\\(\\d*\\)\\)\\s+\\(type:\\s+(.*)\\)"); //$NON-NLS-1$
179 * Pattern to match for UST provider information (lttng list -u)
181 private final static Pattern UST_PROVIDER_PATTERN
= Pattern
.compile("\\s*PID\\:\\s+(\\d+)\\s+-\\s+Name\\:\\s+(.*)"); //$NON-NLS-1$
183 * Pattern to match for session information (lttng create <session name>)
185 private final static Pattern CREATE_SESSION_NAME_PATTERN
= Pattern
.compile("\\s*Session\\s+(.*)\\s+created\\."); //$NON-NLS-1$
187 * Pattern to match for session path information (lttng create <session name>)
189 private final static Pattern CREATE_SESSION_PATH_PATTERN
= Pattern
.compile("\\s*Traces\\s+will\\s+be\\s+written\\s+in\\s+(.*).*"); //$NON-NLS-1$
191 * Pattern to match for session command output for "session name not found".
193 private final static Pattern SESSION_NOT_FOUND_ERROR_PATTERN
= Pattern
.compile("\\s*Error:\\s+Session\\s+name\\s+not\\s+found"); //$NON-NLS-1$
195 // ------------------------------------------------------------------------
197 // ------------------------------------------------------------------------
199 * The command shell implementation
201 private ICommandShell fCommandShell
= null;
203 // ------------------------------------------------------------------------
205 // ------------------------------------------------------------------------
211 * - the command shell implementation to use
213 public LTTngControlService(ICommandShell shell
) {
214 fCommandShell
= shell
;
217 // ------------------------------------------------------------------------
219 // ------------------------------------------------------------------------
225 * org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService
226 * #getSessionNames(org.eclipse.core.runtime.IProgressMonitor)
229 public String
[] getSessionNames(IProgressMonitor monitor
) throws ExecutionException
{
231 String command
= COMMAND_LIST
;
232 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
234 if (isError(result
)) {
235 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
239 // Available tracing sessions:
240 // 1) mysession1 (/home/user/lttng-traces/mysession1-20120123-083928)
242 // 2) mysession (/home/user/lttng-traces/mysession-20120123-083318)
245 // Use lttng list <session_name> for more details
247 ArrayList
<String
> retArray
= new ArrayList
<String
>();
249 while (index
< result
.getOutput().length
) {
250 String line
= result
.getOutput()[index
];
251 Matcher matcher
= SESSION_PATTERN
.matcher(line
);
252 if (matcher
.matches()) {
253 retArray
.add(matcher
.group(2).trim());
257 return retArray
.toArray(new String
[retArray
.size()]);
264 * org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService
265 * #getSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
268 public ISessionInfo
getSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
269 String command
= COMMAND_LIST
+ sessionName
;
270 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
272 if (isError(result
)) {
273 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
279 // Tracing session mysession2: [inactive]
280 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
281 ISessionInfo sessionInfo
= new SessionInfo(sessionName
);
283 while (index
< result
.getOutput().length
) {
284 // Tracing session mysession2: [inactive]
285 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
287 // === Domain: Kernel ===
289 String line
= result
.getOutput()[index
];
290 Matcher matcher
= TRACE_SESSION_PATTERN
.matcher(line
);
291 if (matcher
.matches()) {
292 sessionInfo
.setSessionState(matcher
.group(2));
297 matcher
= TRACE_SESSION_PATH_PATTERN
.matcher(line
);
298 if (matcher
.matches()) {
299 sessionInfo
.setSessionPath(matcher
.group(1).trim());
304 matcher
= DOMAIN_KERNEL_PATTERN
.matcher(line
);
305 if (matcher
.matches()) {
307 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_KernelDomainDisplayName
);
308 sessionInfo
.addDomain(domainInfo
);
311 ArrayList
<IChannelInfo
> channels
= new ArrayList
<IChannelInfo
>();
312 index
= parseDomain(result
.getOutput(), index
, channels
);
315 domainInfo
.setChannels(channels
);
318 domainInfo
.setIsKernel(true);
322 matcher
= DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
);
323 if (matcher
.matches()) {
324 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_UstGlobalDomainDisplayName
);
325 sessionInfo
.addDomain(domainInfo
);
328 ArrayList
<IChannelInfo
> channels
= new ArrayList
<IChannelInfo
>();
329 index
= parseDomain(result
.getOutput(), index
, channels
);
332 domainInfo
.setChannels(channels
);
335 domainInfo
.setIsKernel(false);
347 * org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService
348 * #getKernelProvider(org.eclipse.core.runtime.IProgressMonitor)
351 public List
<IBaseEventInfo
> getKernelProvider(IProgressMonitor monitor
) throws ExecutionException
{
352 String command
= COMMAND_LIST_KERNEL
;
353 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
354 if (isError(result
)) {
355 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
360 // sched_kthread_stop (type: tracepoint)
361 List
<IBaseEventInfo
> events
= new ArrayList
<IBaseEventInfo
>();
362 getProviderEventInfo(result
.getOutput(), 0, events
);
370 * org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService
374 public List
<IUstProviderInfo
> getUstProvider() throws ExecutionException
{
375 return getUstProvider(new NullProgressMonitor());
382 * org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService
383 * #getUstProvider(org.eclipse.core.runtime.IProgressMonitor)
386 public List
<IUstProviderInfo
> getUstProvider(IProgressMonitor monitor
) throws ExecutionException
{
387 String command
= COMMAND_LIST_UST
;
388 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
390 if (isError(result
)) {
391 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
398 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
399 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
401 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
404 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
405 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
407 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
409 List
<IUstProviderInfo
> allProviders
= new ArrayList
<IUstProviderInfo
>();
410 IUstProviderInfo provider
= null;
413 while (index
< result
.getOutput().length
) {
414 String line
= result
.getOutput()[index
];
415 Matcher matcher
= UST_PROVIDER_PATTERN
.matcher(line
);
416 if (matcher
.matches()) {
418 provider
= new UstProviderInfo(matcher
.group(2).trim());
419 provider
.setPid(Integer
.valueOf(matcher
.group(1).trim()));
420 List
<IBaseEventInfo
> events
= new ArrayList
<IBaseEventInfo
>();
421 index
= getProviderEventInfo(result
.getOutput(), ++index
, events
);
422 provider
.setEvents(events
);
423 allProviders
.add(provider
);
435 * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#createSession(java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
438 public ISessionInfo
createSession(String sessionName
, String sessionPath
, IProgressMonitor monitor
) throws ExecutionException
{
440 String newName
= formatParameter(sessionName
);
441 String newPath
= formatParameter(sessionPath
);
443 String command
= COMMAND_CREATE_SESSION
+ newName
;
444 if (newPath
!= null && !"".equals(newPath
)) { //$NON-NLS-1$
445 command
+= " -o " + newPath
; //$NON-NLS-1$
448 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
450 if (isError(result
)) {
451 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
453 //Session myssession2 created.
454 //Traces will be written in /home/user/lttng-traces/myssession2-20120209-095418
455 String
[] output
= result
.getOutput();
457 // Get and verify session name
458 Matcher matcher
= CREATE_SESSION_NAME_PATTERN
.matcher(output
[0]);
461 if (matcher
.matches()) {
462 name
= String
.valueOf(matcher
.group(1).trim());
464 // Output format not expected
465 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
466 Messages
.TraceControl_UnexpectedCommnadOutputFormat
+ ":\n" + //$NON-NLS-1$
467 formatOutput(result
.getOutput()));
470 if ((name
== null) || (!name
.equals(sessionName
))) {
471 // Unexpected name returned
472 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
473 Messages
.TraceControl_UnexpectedNameError
+ ": " + name
); //$NON-NLS-1$
476 // Get and verify session path
477 matcher
= CREATE_SESSION_PATH_PATTERN
.matcher(output
[1]);
480 if (matcher
.matches()) {
481 path
= String
.valueOf(matcher
.group(1).trim());
483 // Output format not expected
484 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
485 Messages
.TraceControl_UnexpectedCommnadOutputFormat
+ ":\n" + //$NON-NLS-1$
486 formatOutput(result
.getOutput()));
489 if ((path
== null) || ((sessionPath
!= null) && (!path
.contains(sessionPath
)))) {
491 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
492 Messages
.TraceControl_UnexpectedPathError
+ ": " + name
); //$NON-NLS-1$
495 SessionInfo sessionInfo
= new SessionInfo(name
);
496 sessionInfo
.setSessionPath(path
);
502 public void destroySession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
503 String newName
= formatParameter(sessionName
);
504 String command
= COMMAND_DESTROY_SESSION
+ newName
;
506 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
507 String
[] output
= result
.getOutput();
509 if (isError(result
)) {
510 // In case "session not found" treat it as success
511 if ((output
== null) || (!SESSION_NOT_FOUND_ERROR_PATTERN
.matcher(output
[0]).matches())) {
512 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
515 //Session <sessionName> destroyed
520 * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#startSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
523 public void startSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
525 String newSessionName
= formatParameter(sessionName
);
527 String command
= COMMAND_START_SESSION
+ newSessionName
;
529 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
531 if (isError(result
)) {
532 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
534 //Session <sessionName> started
539 * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#stopSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
542 public void stopSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
543 String newSessionName
= formatParameter(sessionName
);
544 String command
= COMMAND_STOP_SESSION
+ newSessionName
;
546 ICommandResult result
= fCommandShell
.executeCommand(command
, 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 <sessionName> stopped
557 * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#enableChannel(java.lang.String, java.util.List, boolean, org.eclipse.linuxtools.lttng.ui.views.control.model.IChannelInfo, org.eclipse.core.runtime.IProgressMonitor)
560 public void enableChannel(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IChannelInfo info
, IProgressMonitor monitor
) throws ExecutionException
{
562 // no channels to enable
563 if (channelNames
.size() == 0) {
567 String newSessionName
= formatParameter(sessionName
);
569 StringBuffer command
= new StringBuffer(COMMAND_ENABLE_CHANNEL
);
571 for (Iterator
<String
> iterator
= channelNames
.iterator(); iterator
.hasNext();) {
572 String channel
= (String
) iterator
.next();
573 command
.append(channel
);
574 if (iterator
.hasNext()) {
575 command
.append(","); //$NON-NLS-1$
580 command
.append(" -k ");
582 command
.append(" -u ");
585 command
.append(" -s "); //$NON-NLS-1$
586 command
.append(newSessionName
);
589 // --discard Discard event when buffers are full (default)
592 // --overwrite Flight recorder mode
593 if (info
.isOverwriteMode()) {
594 command
.append(" --overwrite ");
596 // --subbuf-size SIZE Subbuffer size in bytes
597 // (default: 4096, kernel default: 262144)
598 command
.append(" --subbuf-size ");
599 command
.append(String
.valueOf(info
.getSubBufferSize()));
601 // --num-subbuf NUM Number of subbufers
602 // (default: 8, kernel default: 4)
603 command
.append(" --num-subbuf ");
604 command
.append(String
.valueOf(info
.getNumberOfSubBuffers()));
606 // --switch-timer USEC Switch timer interval in usec (default: 0)
607 command
.append(" --switch-timer ");
608 command
.append(String
.valueOf(info
.getSwitchTimer()));
610 // --read-timer USEC Read timer interval in usec (default: 200)
611 command
.append(" --read-timer ");
612 command
.append(String
.valueOf(info
.getReadTimer()));
615 ICommandResult result
= fCommandShell
.executeCommand(command
.toString(), monitor
);
617 if (isError(result
)) {
618 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
625 * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#disableChannel(java.lang.String, java.util.List, org.eclipse.core.runtime.IProgressMonitor)
628 public void disableChannel(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
630 // no channels to enable
631 if (channelNames
.size() == 0) {
635 String newSessionName
= formatParameter(sessionName
);
637 StringBuffer command
= new StringBuffer(COMMAND_DISABLE_CHANNEL
);
639 for (Iterator
<String
> iterator
= channelNames
.iterator(); iterator
.hasNext();) {
640 String channel
= (String
) iterator
.next();
641 command
.append(channel
);
642 if (iterator
.hasNext()) {
643 command
.append(","); //$NON-NLS-1$
648 command
.append(" -k ");
650 command
.append(" -u ");
653 command
.append(" -s "); //$NON-NLS-1$
654 command
.append(newSessionName
);
656 ICommandResult result
= fCommandShell
.executeCommand(command
.toString(), monitor
);
658 if (isError(result
)) {
659 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
663 // ------------------------------------------------------------------------
665 // ------------------------------------------------------------------------
667 * Checks if command result is an error result.
670 * - the command result to check
671 * @return true if error else false
673 private boolean isError(ICommandResult result
) {
674 if ((result
.getResult()) != 0 || (result
.getOutput().length
< 1 || ERROR_PATTERN
.matcher(result
.getOutput()[0]).matches())) {
681 * Formats the output string as single string.
685 * @return - the formatted output
687 private String
formatOutput(String
[] output
) {
688 if (output
== null || output
.length
== 0) {
689 return ""; //$NON-NLS-1$
692 StringBuffer ret
= new StringBuffer();
693 for (int i
= 0; i
< output
.length
; i
++) {
694 ret
.append(output
[i
] + "\n"); //$NON-NLS-1$
696 return ret
.toString();
700 * Parses the domain information.
703 * - a command output array
704 * @param currentIndex
705 * - current index in command output array
707 * - list for returning channel information
708 * @return the new current index in command output array
710 private int parseDomain(String
[] output
, int currentIndex
, List
<IChannelInfo
> channels
) {
711 int index
= currentIndex
;
715 // - channnel1: [enabled]
719 // subbufers size: 262144
720 // number of subbufers: 4
721 // switch timer interval: 0
722 // read timer interval: 200
725 while (index
< output
.length
) {
726 String line
= output
[index
];
728 Matcher outerMatcher
= CHANNELS_SECTION_PATTERN
.matcher(line
);
729 if (outerMatcher
.matches()) {
730 IChannelInfo channelInfo
= null;
731 while (index
< output
.length
) {
732 String subLine
= output
[index
];
734 Matcher innerMatcher
= CHANNEL_PATTERN
.matcher(subLine
);
735 if (innerMatcher
.matches()) {
736 channelInfo
= new ChannelInfo(""); //$NON-NLS-1$
738 channelInfo
.setName(innerMatcher
.group(1));
740 // get channel enablement
741 channelInfo
.setState(innerMatcher
.group(2));
744 channels
.add(channelInfo
);
746 } else if (OVERWRITE_MODE_ATTRIBUTE
.matcher(subLine
).matches()) {
747 String value
= getAttributeValue(subLine
);
748 channelInfo
.setOverwriteMode(!OVERWRITE_MODE_ATTRIBUTE_FALSE
.equals(value
));
749 } else if (SUBBUFFER_SIZE_ATTRIBUTE
.matcher(subLine
).matches()) {
750 channelInfo
.setSubBufferSize(Long
.valueOf(getAttributeValue(subLine
)));
752 } else if (NUM_SUBBUFFERS_ATTRIBUTE
.matcher(subLine
).matches()) {
753 channelInfo
.setNumberOfSubBuffers(Integer
.valueOf(getAttributeValue(subLine
)));
755 } else if (SWITCH_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
756 channelInfo
.setSwitchTimer(Long
.valueOf(getAttributeValue(subLine
)));
758 } else if (READ_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
759 channelInfo
.setReadTimer(Long
.valueOf(getAttributeValue(subLine
)));
761 } else if (OUTPUT_ATTRIBUTE
.matcher(subLine
).matches()) {
762 channelInfo
.setOutputType(getAttributeValue(subLine
));
764 } else if (EVENT_SECTION_PATTERN
.matcher(subLine
).matches()) {
765 List
<IEventInfo
> events
= new ArrayList
<IEventInfo
>();
766 index
= parseEvents(output
, index
, events
);
767 channelInfo
.setEvents(events
);
768 // we want to stay at the current index to be able to
771 } else if (DOMAIN_KERNEL_PATTERN
.matcher(subLine
).matches()) {
774 } else if (DOMAIN_UST_GLOBAL_PATTERN
.matcher(subLine
).matches()) {
786 * Parses the event information within a domain.
789 * - a command output array
790 * @param currentIndex
791 * - current index in command output array
793 * - list for returning event information
794 * @return the new current index in command output array
796 private int parseEvents(String
[] output
, int currentIndex
, List
<IEventInfo
> events
) {
797 int index
= currentIndex
;
799 while (index
< output
.length
) {
800 String line
= output
[index
];
801 if (CHANNEL_PATTERN
.matcher(line
).matches()) {
804 } else if (DOMAIN_KERNEL_PATTERN
.matcher(line
).matches()) {
807 } else if (DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
).matches()) {
812 Matcher matcher
= EVENT_PATTERN
.matcher(line
);
813 Matcher matcher2
= WILDCARD_EVENT_PATTERN
.matcher(line
);
815 if (matcher
.matches()) {
816 IEventInfo eventInfo
= new EventInfo(matcher
.group(1).trim());
817 eventInfo
.setLogLevel(matcher
.group(2).trim());
818 eventInfo
.setEventType(matcher
.group(3).trim());
819 eventInfo
.setState(matcher
.group(4));
820 events
.add(eventInfo
);
821 } else if (matcher2
.matches()) {
822 IEventInfo eventInfo
= new EventInfo(matcher2
.group(1).trim());
823 eventInfo
.setLogLevel(TraceLogLevel
.LEVEL_UNKNOWN
);
824 eventInfo
.setEventType(matcher2
.group(2).trim());
825 eventInfo
.setState(matcher2
.group(3));
826 events
.add(eventInfo
);
828 // else if (line.matches(EVENT_NONE_PATTERN)) {
838 * Parses a line with attributes: <attribute Name>: <attribute value>
841 * - attribute line to parse
842 * @return the attribute value as string
844 private String
getAttributeValue(String line
) {
845 String
[] temp
= line
.split("\\: "); //$NON-NLS-1$
850 * Parses the event information within a provider.
853 * - a command output array
854 * @param currentIndex
855 * - current index in command output array
857 * - list for returning event information
858 * @return the new current index in command output array
860 private int getProviderEventInfo(String
[] output
, int currentIndex
, List
<IBaseEventInfo
> events
) {
861 int index
= currentIndex
;
862 while (index
< output
.length
) {
863 String line
= output
[index
];
864 Matcher matcher
= PROVIDER_EVENT_PATTERN
.matcher(line
);
865 if (matcher
.matches()) {
866 // sched_kthread_stop (loglevel: TRACE_EMERG0) (type:
868 IBaseEventInfo eventInfo
= new BaseEventInfo(matcher
.group(1).trim());
869 eventInfo
.setLogLevel(matcher
.group(2).trim());
870 eventInfo
.setEventType(matcher
.group(3).trim());
871 events
.add(eventInfo
);
872 } else if (UST_PROVIDER_PATTERN
.matcher(line
).matches()) {
881 * Formats a command parameter for the command execution i.e. adds quotes
882 * at the beginning and end if necessary.
883 * @param parameter - parameter to format
884 * @return formated parameter
886 private String
formatParameter(String parameter
) {
887 if (parameter
!= null) {
888 String newString
= String
.valueOf(parameter
);
890 if (parameter
.contains(" ")) { //$NON-NLS-1$
891 newString
= "\"" + newString
+ "\""; //$NON-NLS-1$ //$NON-NLS-2$