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 * Command line option for specifying all events.
118 private final static String OPTION_ALL
= " -a "; //$NON-NLS-1$
120 * Optional command line option for configuring a channel's overwrite mode.
122 private final static String OPTION_OVERWRITE
= " --overwrite "; //$NON-NLS-1$
124 * Optional command line option for configuring a channel's number of sub buffers.
126 private final static String OPTION_NUM_SUB_BUFFERS
= " --num-subbuf "; //$NON-NLS-1$
128 * Optional command line option for configuring a channel's sub buffer size.
130 private final static String OPTION_SUB_BUFFER_SIZE
= " --subbuf-size "; //$NON-NLS-1$
132 * Optional command line option for configuring a channel's switch timer interval.
134 private final static String OPTION_SWITCH_TIMER
= " --switch-timer "; //$NON-NLS-1$
136 * Optional command line option for configuring a channel's read timer interval.
138 private final static String OPTION_READ_TIMER
= " --read-timer "; //$NON-NLS-1$
142 * Pattern to match for error output
144 private final static Pattern ERROR_PATTERN
= Pattern
.compile("\\s*Error\\:.*"); //$NON-NLS-1$
146 * Pattern to match for session information (lttng list)
148 private final static Pattern SESSION_PATTERN
= Pattern
.compile("\\s+(\\d+)\\)\\s+(.*)\\s+\\((.*)\\)\\s+\\[(active|inactive)\\].*"); //$NON-NLS-1$
150 * Pattern to match for session information (lttng list <session>)
152 private final static Pattern TRACE_SESSION_PATTERN
= Pattern
.compile("\\s*Tracing\\s+session\\s+(.*)\\:\\s+\\[(active|inactive)\\].*"); //$NON-NLS-1$
154 * Pattern to match for session path information (lttng list <session>)
156 private final static Pattern TRACE_SESSION_PATH_PATTERN
= Pattern
.compile("\\s*Trace\\s+path\\:\\s+(.*)"); //$NON-NLS-1$
158 * Pattern to match for kernel domain information (lttng list <session>)
160 private final static Pattern DOMAIN_KERNEL_PATTERN
= Pattern
.compile("=== Domain: Kernel ==="); //$NON-NLS-1$
162 * Pattern to match for ust domain information (lttng list <session>)
164 private final static Pattern DOMAIN_UST_GLOBAL_PATTERN
= Pattern
.compile("=== Domain: UST global ==="); //$NON-NLS-1$
166 * Pattern to match for channels section (lttng list <session>)
168 private final static Pattern CHANNELS_SECTION_PATTERN
= Pattern
.compile("\\s*Channels\\:"); //$NON-NLS-1$
170 * Pattern to match for channel information (lttng list <session>)
172 private final static Pattern CHANNEL_PATTERN
= Pattern
.compile("\\s*-\\s+(.*)\\:\\s+\\[(enabled|disabled)\\]"); //$NON-NLS-1$
174 * Pattern to match for events section information (lttng list <session>)
176 private final static Pattern EVENT_SECTION_PATTERN
= Pattern
.compile("\\s*Events\\:"); //$NON-NLS-1$
178 * Pattern to match for event information (no enabled events) (lttng list <session>)
180 // private final static String EVENT_NONE_PATTERN = "\\s+None"; //$NON-NLS-1$
182 * Pattern to match for event information (lttng list <session>)
184 private final static Pattern EVENT_PATTERN
= Pattern
.compile("\\s+(.*)\\s+\\(loglevel:\\s+(.*)\\s+\\(\\d*\\)\\)\\s+\\(type:\\s+(.*)\\)\\s+\\[(enabled|disabled)\\].*"); //$NON-NLS-1$
186 * Pattern to match a wildcarded event information (lttng list <session>)
188 private final static Pattern WILDCARD_EVENT_PATTERN
= Pattern
.compile("\\s+(.*)\\s+\\(type:\\s+(.*)\\)\\s+\\[(enabled|disabled)\\].*"); //$NON-NLS-1$
190 * Pattern to match for channel (overwite mode) information (lttng list
193 private final static Pattern OVERWRITE_MODE_ATTRIBUTE
= Pattern
.compile("\\s+overwrite\\s+mode\\:.*"); //$NON-NLS-1$
195 * Pattern to match indicating false for overwrite mode
197 private final static String OVERWRITE_MODE_ATTRIBUTE_FALSE
= "0"; //$NON-NLS-1$
199 * Pattern to match for channel (sub-buffer size) information (lttng list
202 private final static Pattern SUBBUFFER_SIZE_ATTRIBUTE
= Pattern
.compile("\\s+subbufers\\s+size\\:.*"); //$NON-NLS-1$
204 * Pattern to match for channel (number of sub-buffers) information (lttng
207 private final static Pattern NUM_SUBBUFFERS_ATTRIBUTE
= Pattern
.compile("\\s+number\\s+of\\s+subbufers\\:.*"); //$NON-NLS-1$
209 * Pattern to match for channel (switch timer) information (lttng list
212 private final static Pattern SWITCH_TIMER_ATTRIBUTE
= Pattern
.compile("\\s+switch\\s+timer\\s+interval\\:.*"); //$NON-NLS-1$
214 * Pattern to match for channel (read timer) information (lttng list
217 private final static Pattern READ_TIMER_ATTRIBUTE
= Pattern
.compile("\\s+read\\s+timer\\s+interval\\:.*"); //$NON-NLS-1$
219 * Pattern to match for channel (output type) information (lttng list
222 private final static Pattern OUTPUT_ATTRIBUTE
= Pattern
.compile("\\s+output\\:.*"); //$NON-NLS-1$
224 * Pattern to match for provider information (lttng list -k/-u)
226 private final static Pattern PROVIDER_EVENT_PATTERN
= Pattern
.compile("\\s*(.*)\\s+\\(loglevel:\\s+(.*)\\s+\\(\\d*\\)\\)\\s+\\(type:\\s+(.*)\\)"); //$NON-NLS-1$
228 * Pattern to match for UST provider information (lttng list -u)
230 private final static Pattern UST_PROVIDER_PATTERN
= Pattern
.compile("\\s*PID\\:\\s+(\\d+)\\s+-\\s+Name\\:\\s+(.*)"); //$NON-NLS-1$
232 * Pattern to match for session information (lttng create <session name>)
234 private final static Pattern CREATE_SESSION_NAME_PATTERN
= Pattern
.compile("\\s*Session\\s+(.*)\\s+created\\."); //$NON-NLS-1$
236 * Pattern to match for session path information (lttng create <session name>)
238 private final static Pattern CREATE_SESSION_PATH_PATTERN
= Pattern
.compile("\\s*Traces\\s+will\\s+be\\s+written\\s+in\\s+(.*).*"); //$NON-NLS-1$
240 * Pattern to match for session command output for "session name not found".
242 private final static Pattern SESSION_NOT_FOUND_ERROR_PATTERN
= Pattern
.compile("\\s*Error:\\s+Session\\s+name\\s+not\\s+found"); //$NON-NLS-1$
244 // ------------------------------------------------------------------------
246 // ------------------------------------------------------------------------
248 * The command shell implementation
250 private ICommandShell fCommandShell
= null;
252 // ------------------------------------------------------------------------
254 // ------------------------------------------------------------------------
260 * - the command shell implementation to use
262 public LTTngControlService(ICommandShell shell
) {
263 fCommandShell
= shell
;
266 // ------------------------------------------------------------------------
268 // ------------------------------------------------------------------------
274 * org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService
275 * #getSessionNames(org.eclipse.core.runtime.IProgressMonitor)
278 public String
[] getSessionNames(IProgressMonitor monitor
) throws ExecutionException
{
280 String command
= COMMAND_LIST
;
281 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
283 if (isError(result
)) {
284 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
288 // Available tracing sessions:
289 // 1) mysession1 (/home/user/lttng-traces/mysession1-20120123-083928)
291 // 2) mysession (/home/user/lttng-traces/mysession-20120123-083318)
294 // Use lttng list <session_name> for more details
296 ArrayList
<String
> retArray
= new ArrayList
<String
>();
298 while (index
< result
.getOutput().length
) {
299 String line
= result
.getOutput()[index
];
300 Matcher matcher
= SESSION_PATTERN
.matcher(line
);
301 if (matcher
.matches()) {
302 retArray
.add(matcher
.group(2).trim());
306 return retArray
.toArray(new String
[retArray
.size()]);
313 * org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService
314 * #getSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
317 public ISessionInfo
getSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
318 String command
= COMMAND_LIST
+ sessionName
;
319 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
321 if (isError(result
)) {
322 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
328 // Tracing session mysession2: [inactive]
329 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
330 ISessionInfo sessionInfo
= new SessionInfo(sessionName
);
332 while (index
< result
.getOutput().length
) {
333 // Tracing session mysession2: [inactive]
334 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
336 // === Domain: Kernel ===
338 String line
= result
.getOutput()[index
];
339 Matcher matcher
= TRACE_SESSION_PATTERN
.matcher(line
);
340 if (matcher
.matches()) {
341 sessionInfo
.setSessionState(matcher
.group(2));
346 matcher
= TRACE_SESSION_PATH_PATTERN
.matcher(line
);
347 if (matcher
.matches()) {
348 sessionInfo
.setSessionPath(matcher
.group(1).trim());
353 matcher
= DOMAIN_KERNEL_PATTERN
.matcher(line
);
354 if (matcher
.matches()) {
356 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_KernelDomainDisplayName
);
357 sessionInfo
.addDomain(domainInfo
);
360 ArrayList
<IChannelInfo
> channels
= new ArrayList
<IChannelInfo
>();
361 index
= parseDomain(result
.getOutput(), index
, channels
);
364 domainInfo
.setChannels(channels
);
367 domainInfo
.setIsKernel(true);
371 matcher
= DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
);
372 if (matcher
.matches()) {
373 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_UstGlobalDomainDisplayName
);
374 sessionInfo
.addDomain(domainInfo
);
377 ArrayList
<IChannelInfo
> channels
= new ArrayList
<IChannelInfo
>();
378 index
= parseDomain(result
.getOutput(), index
, channels
);
381 domainInfo
.setChannels(channels
);
384 domainInfo
.setIsKernel(false);
396 * org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService
397 * #getKernelProvider(org.eclipse.core.runtime.IProgressMonitor)
400 public List
<IBaseEventInfo
> getKernelProvider(IProgressMonitor monitor
) throws ExecutionException
{
401 String command
= COMMAND_LIST_KERNEL
;
402 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
403 if (isError(result
)) {
404 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
409 // sched_kthread_stop (type: tracepoint)
410 List
<IBaseEventInfo
> events
= new ArrayList
<IBaseEventInfo
>();
411 getProviderEventInfo(result
.getOutput(), 0, events
);
419 * org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService
423 public List
<IUstProviderInfo
> getUstProvider() throws ExecutionException
{
424 return getUstProvider(new NullProgressMonitor());
431 * org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService
432 * #getUstProvider(org.eclipse.core.runtime.IProgressMonitor)
435 public List
<IUstProviderInfo
> getUstProvider(IProgressMonitor monitor
) throws ExecutionException
{
436 String command
= COMMAND_LIST_UST
;
437 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
439 if (isError(result
)) {
440 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
447 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
448 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
450 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
453 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
454 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
456 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
458 List
<IUstProviderInfo
> allProviders
= new ArrayList
<IUstProviderInfo
>();
459 IUstProviderInfo provider
= null;
462 while (index
< result
.getOutput().length
) {
463 String line
= result
.getOutput()[index
];
464 Matcher matcher
= UST_PROVIDER_PATTERN
.matcher(line
);
465 if (matcher
.matches()) {
467 provider
= new UstProviderInfo(matcher
.group(2).trim());
468 provider
.setPid(Integer
.valueOf(matcher
.group(1).trim()));
469 List
<IBaseEventInfo
> events
= new ArrayList
<IBaseEventInfo
>();
470 index
= getProviderEventInfo(result
.getOutput(), ++index
, events
);
471 provider
.setEvents(events
);
472 allProviders
.add(provider
);
484 * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#createSession(java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
487 public ISessionInfo
createSession(String sessionName
, String sessionPath
, IProgressMonitor monitor
) throws ExecutionException
{
489 String newName
= formatParameter(sessionName
);
490 String newPath
= formatParameter(sessionPath
);
492 String command
= COMMAND_CREATE_SESSION
+ newName
;
493 if (newPath
!= null && !"".equals(newPath
)) { //$NON-NLS-1$
494 command
+= " -o " + newPath
; //$NON-NLS-1$
497 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
499 if (isError(result
)) {
500 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
502 //Session myssession2 created.
503 //Traces will be written in /home/user/lttng-traces/myssession2-20120209-095418
504 String
[] output
= result
.getOutput();
506 // Get and verify session name
507 Matcher matcher
= CREATE_SESSION_NAME_PATTERN
.matcher(output
[0]);
510 if (matcher
.matches()) {
511 name
= String
.valueOf(matcher
.group(1).trim());
513 // Output format not expected
514 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
515 Messages
.TraceControl_UnexpectedCommnadOutputFormat
+ ":\n" + //$NON-NLS-1$
516 formatOutput(result
.getOutput()));
519 if ((name
== null) || (!name
.equals(sessionName
))) {
520 // Unexpected name returned
521 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
522 Messages
.TraceControl_UnexpectedNameError
+ ": " + name
); //$NON-NLS-1$
525 // Get and verify session path
526 matcher
= CREATE_SESSION_PATH_PATTERN
.matcher(output
[1]);
529 if (matcher
.matches()) {
530 path
= String
.valueOf(matcher
.group(1).trim());
532 // Output format not expected
533 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
534 Messages
.TraceControl_UnexpectedCommnadOutputFormat
+ ":\n" + //$NON-NLS-1$
535 formatOutput(result
.getOutput()));
538 if ((path
== null) || ((sessionPath
!= null) && (!path
.contains(sessionPath
)))) {
540 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
541 Messages
.TraceControl_UnexpectedPathError
+ ": " + name
); //$NON-NLS-1$
544 SessionInfo sessionInfo
= new SessionInfo(name
);
545 sessionInfo
.setSessionPath(path
);
551 public void destroySession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
552 String newName
= formatParameter(sessionName
);
553 String command
= COMMAND_DESTROY_SESSION
+ newName
;
555 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
556 String
[] output
= result
.getOutput();
558 if (isError(result
)) {
559 // In case "session not found" treat it as success
560 if ((output
== null) || (!SESSION_NOT_FOUND_ERROR_PATTERN
.matcher(output
[0]).matches())) {
561 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
564 //Session <sessionName> destroyed
569 * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#startSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
572 public void startSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
574 String newSessionName
= formatParameter(sessionName
);
576 String command
= COMMAND_START_SESSION
+ newSessionName
;
578 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
580 if (isError(result
)) {
581 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
583 //Session <sessionName> started
588 * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#stopSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
591 public void stopSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
592 String newSessionName
= formatParameter(sessionName
);
593 String command
= COMMAND_STOP_SESSION
+ newSessionName
;
595 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
597 if (isError(result
)) {
598 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
600 //Session <sessionName> stopped
606 * @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)
609 public void enableChannel(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IChannelInfo info
, IProgressMonitor monitor
) throws ExecutionException
{
611 // no channels to enable
612 if (channelNames
.size() == 0) {
616 String newSessionName
= formatParameter(sessionName
);
618 StringBuffer command
= new StringBuffer(COMMAND_ENABLE_CHANNEL
);
620 for (Iterator
<String
> iterator
= channelNames
.iterator(); iterator
.hasNext();) {
621 String channel
= (String
) iterator
.next();
622 command
.append(channel
);
623 if (iterator
.hasNext()) {
624 command
.append(","); //$NON-NLS-1$
629 command
.append(OPTION_KERNEL
);
631 command
.append(OPTION_UST
);
634 command
.append(OPTION_SESSION
);
635 command
.append(newSessionName
);
638 // --discard Discard event when buffers are full (default)
640 // --overwrite Flight recorder mode
641 if (info
.isOverwriteMode()) {
642 command
.append(OPTION_OVERWRITE
);
644 // --subbuf-size SIZE Subbuffer size in bytes
645 // (default: 4096, kernel default: 262144)
646 command
.append(OPTION_SUB_BUFFER_SIZE
);
647 command
.append(String
.valueOf(info
.getSubBufferSize()));
649 // --num-subbuf NUM Number of subbufers
650 // (default: 8, kernel default: 4)
651 command
.append(OPTION_NUM_SUB_BUFFERS
);
652 command
.append(String
.valueOf(info
.getNumberOfSubBuffers()));
654 // --switch-timer USEC Switch timer interval in usec (default: 0)
655 command
.append(OPTION_SWITCH_TIMER
);
656 command
.append(String
.valueOf(info
.getSwitchTimer()));
658 // --read-timer USEC Read timer interval in usec (default: 200)
659 command
.append(OPTION_READ_TIMER
);
660 command
.append(String
.valueOf(info
.getReadTimer()));
663 ICommandResult result
= fCommandShell
.executeCommand(command
.toString(), monitor
);
665 if (isError(result
)) {
666 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
672 * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#disableChannel(java.lang.String, java.util.List, org.eclipse.core.runtime.IProgressMonitor)
675 public void disableChannel(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
677 // no channels to enable
678 if (channelNames
.size() == 0) {
682 String newSessionName
= formatParameter(sessionName
);
684 StringBuffer command
= new StringBuffer(COMMAND_DISABLE_CHANNEL
);
686 for (Iterator
<String
> iterator
= channelNames
.iterator(); iterator
.hasNext();) {
687 String channel
= (String
) iterator
.next();
688 command
.append(channel
);
689 if (iterator
.hasNext()) {
690 command
.append(","); //$NON-NLS-1$
695 command
.append(OPTION_KERNEL
);
697 command
.append(OPTION_UST
);
700 command
.append(OPTION_SESSION
);
701 command
.append(newSessionName
);
703 ICommandResult result
= fCommandShell
.executeCommand(command
.toString(), monitor
);
705 if (isError(result
)) {
706 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
712 * @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)
715 public void enableEvent(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
717 String newSessionName
= formatParameter(sessionName
);
719 StringBuffer command
= new StringBuffer(COMMAND_ENABLE_EVENT
);
721 if (eventNames
== null) {
722 command
.append(OPTION_ALL
);
724 // no events to enable
725 if (eventNames
.size() == 0) {
729 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
730 String event
= (String
) iterator
.next();
731 command
.append(event
);
732 if (iterator
.hasNext()) {
733 command
.append(","); //$NON-NLS-1$
739 command
.append(OPTION_KERNEL
);
741 command
.append(OPTION_UST
);
744 command
.append(OPTION_SESSION
);
745 command
.append(newSessionName
);
747 if (channelName
!= null) {
748 command
.append(OPTION_CHANNEL
);
749 command
.append(channelName
);
752 ICommandResult result
= fCommandShell
.executeCommand(command
.toString(), monitor
);
754 if (isError(result
)) {
755 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
761 * @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)
764 public void disableEvent(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
765 String newSessionName
= formatParameter(sessionName
);
767 StringBuffer command
= new StringBuffer(COMMAND_DISABLE_EVENT
);
768 if (eventNames
== null) {
769 command
.append(OPTION_ALL
);
771 // no events to enable
772 if (eventNames
.size() == 0) {
776 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
777 String event
= (String
) iterator
.next();
778 command
.append(event
);
779 if (iterator
.hasNext()) {
780 command
.append(","); //$NON-NLS-1$
786 command
.append(OPTION_KERNEL
);
788 command
.append(OPTION_UST
);
791 command
.append(OPTION_SESSION
);
792 command
.append(newSessionName
);
794 if (channelName
!= null) {
795 command
.append(OPTION_CHANNEL
);
796 command
.append(channelName
);
799 ICommandResult result
= fCommandShell
.executeCommand(command
.toString(), monitor
);
801 if (isError(result
)) {
802 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
806 // ------------------------------------------------------------------------
808 // ------------------------------------------------------------------------
810 * Checks if command result is an error result.
813 * - the command result to check
814 * @return true if error else false
816 private boolean isError(ICommandResult result
) {
817 if ((result
.getResult()) != 0 || (result
.getOutput().length
< 1 || ERROR_PATTERN
.matcher(result
.getOutput()[0]).matches())) {
824 * Formats the output string as single string.
828 * @return - the formatted output
830 private String
formatOutput(String
[] output
) {
831 if (output
== null || output
.length
== 0) {
832 return ""; //$NON-NLS-1$
835 StringBuffer ret
= new StringBuffer();
836 for (int i
= 0; i
< output
.length
; i
++) {
837 ret
.append(output
[i
] + "\n"); //$NON-NLS-1$
839 return ret
.toString();
843 * Parses the domain information.
846 * - a command output array
847 * @param currentIndex
848 * - current index in command output array
850 * - list for returning channel information
851 * @return the new current index in command output array
853 private int parseDomain(String
[] output
, int currentIndex
, List
<IChannelInfo
> channels
) {
854 int index
= currentIndex
;
858 // - channnel1: [enabled]
862 // subbufers size: 262144
863 // number of subbufers: 4
864 // switch timer interval: 0
865 // read timer interval: 200
868 while (index
< output
.length
) {
869 String line
= output
[index
];
871 Matcher outerMatcher
= CHANNELS_SECTION_PATTERN
.matcher(line
);
872 if (outerMatcher
.matches()) {
873 IChannelInfo channelInfo
= null;
874 while (index
< output
.length
) {
875 String subLine
= output
[index
];
877 Matcher innerMatcher
= CHANNEL_PATTERN
.matcher(subLine
);
878 if (innerMatcher
.matches()) {
879 channelInfo
= new ChannelInfo(""); //$NON-NLS-1$
881 channelInfo
.setName(innerMatcher
.group(1));
883 // get channel enablement
884 channelInfo
.setState(innerMatcher
.group(2));
887 channels
.add(channelInfo
);
889 } else if (OVERWRITE_MODE_ATTRIBUTE
.matcher(subLine
).matches()) {
890 String value
= getAttributeValue(subLine
);
891 channelInfo
.setOverwriteMode(!OVERWRITE_MODE_ATTRIBUTE_FALSE
.equals(value
));
892 } else if (SUBBUFFER_SIZE_ATTRIBUTE
.matcher(subLine
).matches()) {
893 channelInfo
.setSubBufferSize(Long
.valueOf(getAttributeValue(subLine
)));
895 } else if (NUM_SUBBUFFERS_ATTRIBUTE
.matcher(subLine
).matches()) {
896 channelInfo
.setNumberOfSubBuffers(Integer
.valueOf(getAttributeValue(subLine
)));
898 } else if (SWITCH_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
899 channelInfo
.setSwitchTimer(Long
.valueOf(getAttributeValue(subLine
)));
901 } else if (READ_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
902 channelInfo
.setReadTimer(Long
.valueOf(getAttributeValue(subLine
)));
904 } else if (OUTPUT_ATTRIBUTE
.matcher(subLine
).matches()) {
905 channelInfo
.setOutputType(getAttributeValue(subLine
));
907 } else if (EVENT_SECTION_PATTERN
.matcher(subLine
).matches()) {
908 List
<IEventInfo
> events
= new ArrayList
<IEventInfo
>();
909 index
= parseEvents(output
, index
, events
);
910 channelInfo
.setEvents(events
);
911 // we want to stay at the current index to be able to
914 } else if (DOMAIN_KERNEL_PATTERN
.matcher(subLine
).matches()) {
917 } else if (DOMAIN_UST_GLOBAL_PATTERN
.matcher(subLine
).matches()) {
929 * Parses the event information within a domain.
932 * - a command output array
933 * @param currentIndex
934 * - current index in command output array
936 * - list for returning event information
937 * @return the new current index in command output array
939 private int parseEvents(String
[] output
, int currentIndex
, List
<IEventInfo
> events
) {
940 int index
= currentIndex
;
942 while (index
< output
.length
) {
943 String line
= output
[index
];
944 if (CHANNEL_PATTERN
.matcher(line
).matches()) {
947 } else if (DOMAIN_KERNEL_PATTERN
.matcher(line
).matches()) {
950 } else if (DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
).matches()) {
955 Matcher matcher
= EVENT_PATTERN
.matcher(line
);
956 Matcher matcher2
= WILDCARD_EVENT_PATTERN
.matcher(line
);
958 if (matcher
.matches()) {
959 IEventInfo eventInfo
= new EventInfo(matcher
.group(1).trim());
960 eventInfo
.setLogLevel(matcher
.group(2).trim());
961 eventInfo
.setEventType(matcher
.group(3).trim());
962 eventInfo
.setState(matcher
.group(4));
963 events
.add(eventInfo
);
964 } else if (matcher2
.matches()) {
965 IEventInfo eventInfo
= new EventInfo(matcher2
.group(1).trim());
966 eventInfo
.setLogLevel(TraceLogLevel
.LEVEL_UNKNOWN
);
967 eventInfo
.setEventType(matcher2
.group(2).trim());
968 eventInfo
.setState(matcher2
.group(3));
969 events
.add(eventInfo
);
971 // else if (line.matches(EVENT_NONE_PATTERN)) {
981 * Parses a line with attributes: <attribute Name>: <attribute value>
984 * - attribute line to parse
985 * @return the attribute value as string
987 private String
getAttributeValue(String line
) {
988 String
[] temp
= line
.split("\\: "); //$NON-NLS-1$
993 * Parses the event information within a provider.
996 * - a command output array
997 * @param currentIndex
998 * - current index in command output array
1000 * - list for returning event information
1001 * @return the new current index in command output array
1003 private int getProviderEventInfo(String
[] output
, int currentIndex
, List
<IBaseEventInfo
> events
) {
1004 int index
= currentIndex
;
1005 while (index
< output
.length
) {
1006 String line
= output
[index
];
1007 Matcher matcher
= PROVIDER_EVENT_PATTERN
.matcher(line
);
1008 if (matcher
.matches()) {
1009 // sched_kthread_stop (loglevel: TRACE_EMERG0) (type:
1011 IBaseEventInfo eventInfo
= new BaseEventInfo(matcher
.group(1).trim());
1012 eventInfo
.setLogLevel(matcher
.group(2).trim());
1013 eventInfo
.setEventType(matcher
.group(3).trim());
1014 events
.add(eventInfo
);
1015 } else if (UST_PROVIDER_PATTERN
.matcher(line
).matches()) {
1024 * Formats a command parameter for the command execution i.e. adds quotes
1025 * at the beginning and end if necessary.
1026 * @param parameter - parameter to format
1027 * @return formated parameter
1029 private String
formatParameter(String parameter
) {
1030 if (parameter
!= null) {
1031 String newString
= String
.valueOf(parameter
);
1033 if (parameter
.contains(" ")) { //$NON-NLS-1$
1034 newString
= "\"" + newString
+ "\""; //$NON-NLS-1$ //$NON-NLS-2$