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 disable a channel.
88 private final static String COMMAND_DISABLE_CHANNEL
= CONTROL_COMMAND
+ " disable-channel "; //$NON-NLS-1$
90 * Command to enable a event.
92 private final static String COMMAND_ENABLE_EVENT
= CONTROL_COMMAND
+ " enable-event "; //$NON-NLS-1$
94 * Command to disable a event.
96 private final static String COMMAND_DISABLE_EVENT
= CONTROL_COMMAND
+ " disable-event "; //$NON-NLS-1$
98 // Command options constants
100 * Command line option for kernel tracer.
102 private final static String OPTION_KERNEL
= " -k "; //$NON-NLS-1$
104 * Command line option for UST tracer.
106 private final static String OPTION_UST
= " -u "; //$NON-NLS-1$
108 * Command line option for specifying a session.
110 private final static String OPTION_SESSION
= " -s "; //$NON-NLS-1$
112 * Command line option for specifying a channel.
114 private final static String OPTION_CHANNEL
= " -c "; //$NON-NLS-1$
116 * Optional command line option for configuring a channel's overwrite mode.
118 private final static String OPTION_OVERWRITE
= " --overwrite "; //$NON-NLS-1$
120 * Optional command line option for configuring a channel's number of sub buffers.
122 private final static String OPTION_NUM_SUB_BUFFERS
= " --num-subbuf "; //$NON-NLS-1$
124 * Optional command line option for configuring a channel's sub buffer size.
126 private final static String OPTION_SUB_BUFFER_SIZE
= " --subbuf-size "; //$NON-NLS-1$
128 * Optional command line option for configuring a channel's switch timer interval.
130 private final static String OPTION_SWITCH_TIMER
= " --switch-timer "; //$NON-NLS-1$
132 * Optional command line option for configuring a channel's read timer interval.
134 private final static String OPTION_READ_TIMER
= " --read-timer "; //$NON-NLS-1$
138 * Pattern to match for error output
140 private final static Pattern ERROR_PATTERN
= Pattern
.compile("\\s*Error\\:.*"); //$NON-NLS-1$
142 * Pattern to match for session information (lttng list)
144 private final static Pattern SESSION_PATTERN
= Pattern
.compile("\\s+(\\d+)\\)\\s+(.*)\\s+\\((.*)\\)\\s+\\[(active|inactive)\\].*"); //$NON-NLS-1$
146 * Pattern to match for session information (lttng list <session>)
148 private final static Pattern TRACE_SESSION_PATTERN
= Pattern
.compile("\\s*Tracing\\s+session\\s+(.*)\\:\\s+\\[(active|inactive)\\].*"); //$NON-NLS-1$
150 * Pattern to match for session path information (lttng list <session>)
152 private final static Pattern TRACE_SESSION_PATH_PATTERN
= Pattern
.compile("\\s*Trace\\s+path\\:\\s+(.*)"); //$NON-NLS-1$
154 * Pattern to match for kernel domain information (lttng list <session>)
156 private final static Pattern DOMAIN_KERNEL_PATTERN
= Pattern
.compile("=== Domain: Kernel ==="); //$NON-NLS-1$
158 * Pattern to match for ust domain information (lttng list <session>)
160 private final static Pattern DOMAIN_UST_GLOBAL_PATTERN
= Pattern
.compile("=== Domain: UST global ==="); //$NON-NLS-1$
162 * Pattern to match for channels section (lttng list <session>)
164 private final static Pattern CHANNELS_SECTION_PATTERN
= Pattern
.compile("\\s*Channels\\:"); //$NON-NLS-1$
166 * Pattern to match for channel information (lttng list <session>)
168 private final static Pattern CHANNEL_PATTERN
= Pattern
.compile("\\s*-\\s+(.*)\\:\\s+\\[(enabled|disabled)\\]"); //$NON-NLS-1$
170 * Pattern to match for events section information (lttng list <session>)
172 private final static Pattern EVENT_SECTION_PATTERN
= Pattern
.compile("\\s*Events\\:"); //$NON-NLS-1$
174 * Pattern to match for event information (no enabled events) (lttng list <session>)
176 // private final static String EVENT_NONE_PATTERN = "\\s+None"; //$NON-NLS-1$
178 * Pattern to match for event information (lttng list <session>)
180 private final static Pattern EVENT_PATTERN
= Pattern
.compile("\\s+(.*)\\s+\\(loglevel:\\s+(.*)\\s+\\(\\d*\\)\\)\\s+\\(type:\\s+(.*)\\)\\s+\\[(enabled|disabled)\\].*"); //$NON-NLS-1$
182 * Pattern to match a wildcarded event information (lttng list <session>)
184 private final static Pattern WILDCARD_EVENT_PATTERN
= Pattern
.compile("\\s+(.*)\\s+\\(type:\\s+(.*)\\)\\s+\\[(enabled|disabled)\\].*"); //$NON-NLS-1$
186 * Pattern to match for channel (overwite mode) information (lttng list
189 private final static Pattern OVERWRITE_MODE_ATTRIBUTE
= Pattern
.compile("\\s+overwrite\\s+mode\\:.*"); //$NON-NLS-1$
191 * Pattern to match indicating false for overwrite mode
193 private final static String OVERWRITE_MODE_ATTRIBUTE_FALSE
= "0"; //$NON-NLS-1$
195 * Pattern to match for channel (sub-buffer size) information (lttng list
198 private final static Pattern SUBBUFFER_SIZE_ATTRIBUTE
= Pattern
.compile("\\s+subbufers\\s+size\\:.*"); //$NON-NLS-1$
200 * Pattern to match for channel (number of sub-buffers) information (lttng
203 private final static Pattern NUM_SUBBUFFERS_ATTRIBUTE
= Pattern
.compile("\\s+number\\s+of\\s+subbufers\\:.*"); //$NON-NLS-1$
205 * Pattern to match for channel (switch timer) information (lttng list
208 private final static Pattern SWITCH_TIMER_ATTRIBUTE
= Pattern
.compile("\\s+switch\\s+timer\\s+interval\\:.*"); //$NON-NLS-1$
210 * Pattern to match for channel (read timer) information (lttng list
213 private final static Pattern READ_TIMER_ATTRIBUTE
= Pattern
.compile("\\s+read\\s+timer\\s+interval\\:.*"); //$NON-NLS-1$
215 * Pattern to match for channel (output type) information (lttng list
218 private final static Pattern OUTPUT_ATTRIBUTE
= Pattern
.compile("\\s+output\\:.*"); //$NON-NLS-1$
220 * Pattern to match for provider information (lttng list -k/-u)
222 private final static Pattern PROVIDER_EVENT_PATTERN
= Pattern
.compile("\\s*(.*)\\s+\\(loglevel:\\s+(.*)\\s+\\(\\d*\\)\\)\\s+\\(type:\\s+(.*)\\)"); //$NON-NLS-1$
224 * Pattern to match for UST provider information (lttng list -u)
226 private final static Pattern UST_PROVIDER_PATTERN
= Pattern
.compile("\\s*PID\\:\\s+(\\d+)\\s+-\\s+Name\\:\\s+(.*)"); //$NON-NLS-1$
228 * Pattern to match for session information (lttng create <session name>)
230 private final static Pattern CREATE_SESSION_NAME_PATTERN
= Pattern
.compile("\\s*Session\\s+(.*)\\s+created\\."); //$NON-NLS-1$
232 * Pattern to match for session path information (lttng create <session name>)
234 private final static Pattern CREATE_SESSION_PATH_PATTERN
= Pattern
.compile("\\s*Traces\\s+will\\s+be\\s+written\\s+in\\s+(.*).*"); //$NON-NLS-1$
236 * Pattern to match for session command output for "session name not found".
238 private final static Pattern SESSION_NOT_FOUND_ERROR_PATTERN
= Pattern
.compile("\\s*Error:\\s+Session\\s+name\\s+not\\s+found"); //$NON-NLS-1$
240 // ------------------------------------------------------------------------
242 // ------------------------------------------------------------------------
244 * The command shell implementation
246 private ICommandShell fCommandShell
= null;
248 // ------------------------------------------------------------------------
250 // ------------------------------------------------------------------------
256 * - the command shell implementation to use
258 public LTTngControlService(ICommandShell shell
) {
259 fCommandShell
= shell
;
262 // ------------------------------------------------------------------------
264 // ------------------------------------------------------------------------
270 * org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService
271 * #getSessionNames(org.eclipse.core.runtime.IProgressMonitor)
274 public String
[] getSessionNames(IProgressMonitor monitor
) throws ExecutionException
{
276 String command
= COMMAND_LIST
;
277 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
279 if (isError(result
)) {
280 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
284 // Available tracing sessions:
285 // 1) mysession1 (/home/user/lttng-traces/mysession1-20120123-083928)
287 // 2) mysession (/home/user/lttng-traces/mysession-20120123-083318)
290 // Use lttng list <session_name> for more details
292 ArrayList
<String
> retArray
= new ArrayList
<String
>();
294 while (index
< result
.getOutput().length
) {
295 String line
= result
.getOutput()[index
];
296 Matcher matcher
= SESSION_PATTERN
.matcher(line
);
297 if (matcher
.matches()) {
298 retArray
.add(matcher
.group(2).trim());
302 return retArray
.toArray(new String
[retArray
.size()]);
309 * org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService
310 * #getSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
313 public ISessionInfo
getSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
314 String command
= COMMAND_LIST
+ sessionName
;
315 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
317 if (isError(result
)) {
318 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
324 // Tracing session mysession2: [inactive]
325 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
326 ISessionInfo sessionInfo
= new SessionInfo(sessionName
);
328 while (index
< result
.getOutput().length
) {
329 // Tracing session mysession2: [inactive]
330 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
332 // === Domain: Kernel ===
334 String line
= result
.getOutput()[index
];
335 Matcher matcher
= TRACE_SESSION_PATTERN
.matcher(line
);
336 if (matcher
.matches()) {
337 sessionInfo
.setSessionState(matcher
.group(2));
342 matcher
= TRACE_SESSION_PATH_PATTERN
.matcher(line
);
343 if (matcher
.matches()) {
344 sessionInfo
.setSessionPath(matcher
.group(1).trim());
349 matcher
= DOMAIN_KERNEL_PATTERN
.matcher(line
);
350 if (matcher
.matches()) {
352 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_KernelDomainDisplayName
);
353 sessionInfo
.addDomain(domainInfo
);
356 ArrayList
<IChannelInfo
> channels
= new ArrayList
<IChannelInfo
>();
357 index
= parseDomain(result
.getOutput(), index
, channels
);
360 domainInfo
.setChannels(channels
);
363 domainInfo
.setIsKernel(true);
367 matcher
= DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
);
368 if (matcher
.matches()) {
369 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_UstGlobalDomainDisplayName
);
370 sessionInfo
.addDomain(domainInfo
);
373 ArrayList
<IChannelInfo
> channels
= new ArrayList
<IChannelInfo
>();
374 index
= parseDomain(result
.getOutput(), index
, channels
);
377 domainInfo
.setChannels(channels
);
380 domainInfo
.setIsKernel(false);
392 * org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService
393 * #getKernelProvider(org.eclipse.core.runtime.IProgressMonitor)
396 public List
<IBaseEventInfo
> getKernelProvider(IProgressMonitor monitor
) throws ExecutionException
{
397 String command
= COMMAND_LIST_KERNEL
;
398 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
399 if (isError(result
)) {
400 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
405 // sched_kthread_stop (type: tracepoint)
406 List
<IBaseEventInfo
> events
= new ArrayList
<IBaseEventInfo
>();
407 getProviderEventInfo(result
.getOutput(), 0, events
);
415 * org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService
419 public List
<IUstProviderInfo
> getUstProvider() throws ExecutionException
{
420 return getUstProvider(new NullProgressMonitor());
427 * org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService
428 * #getUstProvider(org.eclipse.core.runtime.IProgressMonitor)
431 public List
<IUstProviderInfo
> getUstProvider(IProgressMonitor monitor
) throws ExecutionException
{
432 String command
= COMMAND_LIST_UST
;
433 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
435 if (isError(result
)) {
436 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
443 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
444 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
446 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
449 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
450 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
452 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
454 List
<IUstProviderInfo
> allProviders
= new ArrayList
<IUstProviderInfo
>();
455 IUstProviderInfo provider
= null;
458 while (index
< result
.getOutput().length
) {
459 String line
= result
.getOutput()[index
];
460 Matcher matcher
= UST_PROVIDER_PATTERN
.matcher(line
);
461 if (matcher
.matches()) {
463 provider
= new UstProviderInfo(matcher
.group(2).trim());
464 provider
.setPid(Integer
.valueOf(matcher
.group(1).trim()));
465 List
<IBaseEventInfo
> events
= new ArrayList
<IBaseEventInfo
>();
466 index
= getProviderEventInfo(result
.getOutput(), ++index
, events
);
467 provider
.setEvents(events
);
468 allProviders
.add(provider
);
480 * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#createSession(java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
483 public ISessionInfo
createSession(String sessionName
, String sessionPath
, IProgressMonitor monitor
) throws ExecutionException
{
485 String newName
= formatParameter(sessionName
);
486 String newPath
= formatParameter(sessionPath
);
488 String command
= COMMAND_CREATE_SESSION
+ newName
;
489 if (newPath
!= null && !"".equals(newPath
)) { //$NON-NLS-1$
490 command
+= " -o " + newPath
; //$NON-NLS-1$
493 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
495 if (isError(result
)) {
496 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
498 //Session myssession2 created.
499 //Traces will be written in /home/user/lttng-traces/myssession2-20120209-095418
500 String
[] output
= result
.getOutput();
502 // Get and verify session name
503 Matcher matcher
= CREATE_SESSION_NAME_PATTERN
.matcher(output
[0]);
506 if (matcher
.matches()) {
507 name
= String
.valueOf(matcher
.group(1).trim());
509 // Output format not expected
510 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
511 Messages
.TraceControl_UnexpectedCommnadOutputFormat
+ ":\n" + //$NON-NLS-1$
512 formatOutput(result
.getOutput()));
515 if ((name
== null) || (!name
.equals(sessionName
))) {
516 // Unexpected name returned
517 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
518 Messages
.TraceControl_UnexpectedNameError
+ ": " + name
); //$NON-NLS-1$
521 // Get and verify session path
522 matcher
= CREATE_SESSION_PATH_PATTERN
.matcher(output
[1]);
525 if (matcher
.matches()) {
526 path
= String
.valueOf(matcher
.group(1).trim());
528 // Output format not expected
529 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
530 Messages
.TraceControl_UnexpectedCommnadOutputFormat
+ ":\n" + //$NON-NLS-1$
531 formatOutput(result
.getOutput()));
534 if ((path
== null) || ((sessionPath
!= null) && (!path
.contains(sessionPath
)))) {
536 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
537 Messages
.TraceControl_UnexpectedPathError
+ ": " + name
); //$NON-NLS-1$
540 SessionInfo sessionInfo
= new SessionInfo(name
);
541 sessionInfo
.setSessionPath(path
);
547 public void destroySession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
548 String newName
= formatParameter(sessionName
);
549 String command
= COMMAND_DESTROY_SESSION
+ newName
;
551 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
552 String
[] output
= result
.getOutput();
554 if (isError(result
)) {
555 // In case "session not found" treat it as success
556 if ((output
== null) || (!SESSION_NOT_FOUND_ERROR_PATTERN
.matcher(output
[0]).matches())) {
557 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
560 //Session <sessionName> destroyed
565 * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#startSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
568 public void startSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
570 String newSessionName
= formatParameter(sessionName
);
572 String command
= COMMAND_START_SESSION
+ newSessionName
;
574 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
576 if (isError(result
)) {
577 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
579 //Session <sessionName> started
584 * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#stopSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
587 public void stopSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
588 String newSessionName
= formatParameter(sessionName
);
589 String command
= COMMAND_STOP_SESSION
+ newSessionName
;
591 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
593 if (isError(result
)) {
594 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
596 //Session <sessionName> stopped
602 * @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)
605 public void enableChannel(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IChannelInfo info
, IProgressMonitor monitor
) throws ExecutionException
{
607 // no channels to enable
608 if (channelNames
.size() == 0) {
612 String newSessionName
= formatParameter(sessionName
);
614 StringBuffer command
= new StringBuffer(COMMAND_ENABLE_CHANNEL
);
616 for (Iterator
<String
> iterator
= channelNames
.iterator(); iterator
.hasNext();) {
617 String channel
= (String
) iterator
.next();
618 command
.append(channel
);
619 if (iterator
.hasNext()) {
620 command
.append(","); //$NON-NLS-1$
625 command
.append(OPTION_KERNEL
);
627 command
.append(OPTION_UST
);
630 command
.append(OPTION_SESSION
);
631 command
.append(newSessionName
);
634 // --discard Discard event when buffers are full (default)
636 // --overwrite Flight recorder mode
637 if (info
.isOverwriteMode()) {
638 command
.append(OPTION_OVERWRITE
);
640 // --subbuf-size SIZE Subbuffer size in bytes
641 // (default: 4096, kernel default: 262144)
642 command
.append(OPTION_SUB_BUFFER_SIZE
);
643 command
.append(String
.valueOf(info
.getSubBufferSize()));
645 // --num-subbuf NUM Number of subbufers
646 // (default: 8, kernel default: 4)
647 command
.append(OPTION_NUM_SUB_BUFFERS
);
648 command
.append(String
.valueOf(info
.getNumberOfSubBuffers()));
650 // --switch-timer USEC Switch timer interval in usec (default: 0)
651 command
.append(OPTION_SWITCH_TIMER
);
652 command
.append(String
.valueOf(info
.getSwitchTimer()));
654 // --read-timer USEC Read timer interval in usec (default: 200)
655 command
.append(OPTION_READ_TIMER
);
656 command
.append(String
.valueOf(info
.getReadTimer()));
659 ICommandResult result
= fCommandShell
.executeCommand(command
.toString(), monitor
);
661 if (isError(result
)) {
662 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
668 * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#disableChannel(java.lang.String, java.util.List, org.eclipse.core.runtime.IProgressMonitor)
671 public void disableChannel(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
673 // no channels to enable
674 if (channelNames
.size() == 0) {
678 String newSessionName
= formatParameter(sessionName
);
680 StringBuffer command
= new StringBuffer(COMMAND_DISABLE_CHANNEL
);
682 for (Iterator
<String
> iterator
= channelNames
.iterator(); iterator
.hasNext();) {
683 String channel
= (String
) iterator
.next();
684 command
.append(channel
);
685 if (iterator
.hasNext()) {
686 command
.append(","); //$NON-NLS-1$
691 command
.append(OPTION_KERNEL
);
693 command
.append(OPTION_UST
);
696 command
.append(OPTION_SESSION
);
697 command
.append(newSessionName
);
699 ICommandResult result
= fCommandShell
.executeCommand(command
.toString(), monitor
);
701 if (isError(result
)) {
702 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
708 * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#enableEvent(java.lang.String, java.lang.String, java.util.List, boolean, org.eclipse.core.runtime.IProgressMonitor)
711 public void enableEvent(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
712 // no channels to enable
713 if (eventNames
.size() == 0) {
717 String newSessionName
= formatParameter(sessionName
);
719 StringBuffer command
= new StringBuffer(COMMAND_ENABLE_EVENT
);
721 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
722 String event
= (String
) iterator
.next();
723 command
.append(event
);
724 if (iterator
.hasNext()) {
725 command
.append(","); //$NON-NLS-1$
730 command
.append(OPTION_KERNEL
);
732 command
.append(OPTION_UST
);
735 command
.append(OPTION_SESSION
);
736 command
.append(newSessionName
);
738 if (channelName
!= null) {
739 command
.append(OPTION_CHANNEL
);
740 command
.append(channelName
);
743 ICommandResult result
= fCommandShell
.executeCommand(command
.toString(), monitor
);
745 if (isError(result
)) {
746 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
752 * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#disableEvent(java.lang.String, java.lang.String, java.util.List, boolean, org.eclipse.core.runtime.IProgressMonitor)
755 public void disableEvent(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
756 // no channels to enable
757 if (eventNames
.size() == 0) {
761 String newSessionName
= formatParameter(sessionName
);
763 StringBuffer command
= new StringBuffer(COMMAND_DISABLE_EVENT
);
765 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
766 String event
= (String
) iterator
.next();
767 command
.append(event
);
768 if (iterator
.hasNext()) {
769 command
.append(","); //$NON-NLS-1$
774 command
.append(OPTION_KERNEL
);
776 command
.append(OPTION_UST
);
779 command
.append(OPTION_SESSION
);
780 command
.append(newSessionName
);
782 if (channelName
!= null) {
783 command
.append(OPTION_CHANNEL
);
784 command
.append(channelName
);
787 ICommandResult result
= fCommandShell
.executeCommand(command
.toString(), monitor
);
789 if (isError(result
)) {
790 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
794 // ------------------------------------------------------------------------
796 // ------------------------------------------------------------------------
798 * Checks if command result is an error result.
801 * - the command result to check
802 * @return true if error else false
804 private boolean isError(ICommandResult result
) {
805 if ((result
.getResult()) != 0 || (result
.getOutput().length
< 1 || ERROR_PATTERN
.matcher(result
.getOutput()[0]).matches())) {
812 * Formats the output string as single string.
816 * @return - the formatted output
818 private String
formatOutput(String
[] output
) {
819 if (output
== null || output
.length
== 0) {
820 return ""; //$NON-NLS-1$
823 StringBuffer ret
= new StringBuffer();
824 for (int i
= 0; i
< output
.length
; i
++) {
825 ret
.append(output
[i
] + "\n"); //$NON-NLS-1$
827 return ret
.toString();
831 * Parses the domain information.
834 * - a command output array
835 * @param currentIndex
836 * - current index in command output array
838 * - list for returning channel information
839 * @return the new current index in command output array
841 private int parseDomain(String
[] output
, int currentIndex
, List
<IChannelInfo
> channels
) {
842 int index
= currentIndex
;
846 // - channnel1: [enabled]
850 // subbufers size: 262144
851 // number of subbufers: 4
852 // switch timer interval: 0
853 // read timer interval: 200
856 while (index
< output
.length
) {
857 String line
= output
[index
];
859 Matcher outerMatcher
= CHANNELS_SECTION_PATTERN
.matcher(line
);
860 if (outerMatcher
.matches()) {
861 IChannelInfo channelInfo
= null;
862 while (index
< output
.length
) {
863 String subLine
= output
[index
];
865 Matcher innerMatcher
= CHANNEL_PATTERN
.matcher(subLine
);
866 if (innerMatcher
.matches()) {
867 channelInfo
= new ChannelInfo(""); //$NON-NLS-1$
869 channelInfo
.setName(innerMatcher
.group(1));
871 // get channel enablement
872 channelInfo
.setState(innerMatcher
.group(2));
875 channels
.add(channelInfo
);
877 } else if (OVERWRITE_MODE_ATTRIBUTE
.matcher(subLine
).matches()) {
878 String value
= getAttributeValue(subLine
);
879 channelInfo
.setOverwriteMode(!OVERWRITE_MODE_ATTRIBUTE_FALSE
.equals(value
));
880 } else if (SUBBUFFER_SIZE_ATTRIBUTE
.matcher(subLine
).matches()) {
881 channelInfo
.setSubBufferSize(Long
.valueOf(getAttributeValue(subLine
)));
883 } else if (NUM_SUBBUFFERS_ATTRIBUTE
.matcher(subLine
).matches()) {
884 channelInfo
.setNumberOfSubBuffers(Integer
.valueOf(getAttributeValue(subLine
)));
886 } else if (SWITCH_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
887 channelInfo
.setSwitchTimer(Long
.valueOf(getAttributeValue(subLine
)));
889 } else if (READ_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
890 channelInfo
.setReadTimer(Long
.valueOf(getAttributeValue(subLine
)));
892 } else if (OUTPUT_ATTRIBUTE
.matcher(subLine
).matches()) {
893 channelInfo
.setOutputType(getAttributeValue(subLine
));
895 } else if (EVENT_SECTION_PATTERN
.matcher(subLine
).matches()) {
896 List
<IEventInfo
> events
= new ArrayList
<IEventInfo
>();
897 index
= parseEvents(output
, index
, events
);
898 channelInfo
.setEvents(events
);
899 // we want to stay at the current index to be able to
902 } else if (DOMAIN_KERNEL_PATTERN
.matcher(subLine
).matches()) {
905 } else if (DOMAIN_UST_GLOBAL_PATTERN
.matcher(subLine
).matches()) {
917 * Parses the event information within a domain.
920 * - a command output array
921 * @param currentIndex
922 * - current index in command output array
924 * - list for returning event information
925 * @return the new current index in command output array
927 private int parseEvents(String
[] output
, int currentIndex
, List
<IEventInfo
> events
) {
928 int index
= currentIndex
;
930 while (index
< output
.length
) {
931 String line
= output
[index
];
932 if (CHANNEL_PATTERN
.matcher(line
).matches()) {
935 } else if (DOMAIN_KERNEL_PATTERN
.matcher(line
).matches()) {
938 } else if (DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
).matches()) {
943 Matcher matcher
= EVENT_PATTERN
.matcher(line
);
944 Matcher matcher2
= WILDCARD_EVENT_PATTERN
.matcher(line
);
946 if (matcher
.matches()) {
947 IEventInfo eventInfo
= new EventInfo(matcher
.group(1).trim());
948 eventInfo
.setLogLevel(matcher
.group(2).trim());
949 eventInfo
.setEventType(matcher
.group(3).trim());
950 eventInfo
.setState(matcher
.group(4));
951 events
.add(eventInfo
);
952 } else if (matcher2
.matches()) {
953 IEventInfo eventInfo
= new EventInfo(matcher2
.group(1).trim());
954 eventInfo
.setLogLevel(TraceLogLevel
.LEVEL_UNKNOWN
);
955 eventInfo
.setEventType(matcher2
.group(2).trim());
956 eventInfo
.setState(matcher2
.group(3));
957 events
.add(eventInfo
);
959 // else if (line.matches(EVENT_NONE_PATTERN)) {
969 * Parses a line with attributes: <attribute Name>: <attribute value>
972 * - attribute line to parse
973 * @return the attribute value as string
975 private String
getAttributeValue(String line
) {
976 String
[] temp
= line
.split("\\: "); //$NON-NLS-1$
981 * Parses the event information within a provider.
984 * - a command output array
985 * @param currentIndex
986 * - current index in command output array
988 * - list for returning event information
989 * @return the new current index in command output array
991 private int getProviderEventInfo(String
[] output
, int currentIndex
, List
<IBaseEventInfo
> events
) {
992 int index
= currentIndex
;
993 while (index
< output
.length
) {
994 String line
= output
[index
];
995 Matcher matcher
= PROVIDER_EVENT_PATTERN
.matcher(line
);
996 if (matcher
.matches()) {
997 // sched_kthread_stop (loglevel: TRACE_EMERG0) (type:
999 IBaseEventInfo eventInfo
= new BaseEventInfo(matcher
.group(1).trim());
1000 eventInfo
.setLogLevel(matcher
.group(2).trim());
1001 eventInfo
.setEventType(matcher
.group(3).trim());
1002 events
.add(eventInfo
);
1003 } else if (UST_PROVIDER_PATTERN
.matcher(line
).matches()) {
1012 * Formats a command parameter for the command execution i.e. adds quotes
1013 * at the beginning and end if necessary.
1014 * @param parameter - parameter to format
1015 * @return formated parameter
1017 private String
formatParameter(String parameter
) {
1018 if (parameter
!= null) {
1019 String newString
= String
.valueOf(parameter
);
1021 if (parameter
.contains(" ")) { //$NON-NLS-1$
1022 newString
= "\"" + newString
+ "\""; //$NON-NLS-1$ //$NON-NLS-2$