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 * Command line option for specifying tracepoint events.
122 private final static String OPTION_TRACEPOINT
= " --tracepoint "; //$NON-NLS-1$
124 * Command line option for specifying syscall events.
126 private final static String OPTION_SYSCALL
= " --syscall "; //$NON-NLS-1$
128 * Command line option for specifying a dynamic probe.
130 private final static String OPTION_PROBE
= " --probe "; //$NON-NLS-1$
132 * Command line option for specifying a dynamic function entry/return probe.
134 private final static String OPTION_FUNCTION_PROBE
= " --function "; //$NON-NLS-1$
136 * Optional command line option for configuring a channel's overwrite mode.
138 private final static String OPTION_OVERWRITE
= " --overwrite "; //$NON-NLS-1$
140 * Optional command line option for configuring a channel's number of sub buffers.
142 private final static String OPTION_NUM_SUB_BUFFERS
= " --num-subbuf "; //$NON-NLS-1$
144 * Optional command line option for configuring a channel's sub buffer size.
146 private final static String OPTION_SUB_BUFFER_SIZE
= " --subbuf-size "; //$NON-NLS-1$
148 * Optional command line option for configuring a channel's switch timer interval.
150 private final static String OPTION_SWITCH_TIMER
= " --switch-timer "; //$NON-NLS-1$
152 * Optional command line option for configuring a channel's read timer interval.
154 private final static String OPTION_READ_TIMER
= " --read-timer "; //$NON-NLS-1$
158 * Pattern to match for error output
160 private final static Pattern ERROR_PATTERN
= Pattern
.compile("\\s*Error\\:.*"); //$NON-NLS-1$
162 * Pattern to match for session information (lttng list)
164 private final static Pattern SESSION_PATTERN
= Pattern
.compile("\\s+(\\d+)\\)\\s+(.*)\\s+\\((.*)\\)\\s+\\[(active|inactive)\\].*"); //$NON-NLS-1$
166 * Pattern to match for session information (lttng list <session>)
168 private final static Pattern TRACE_SESSION_PATTERN
= Pattern
.compile("\\s*Tracing\\s+session\\s+(.*)\\:\\s+\\[(active|inactive)\\].*"); //$NON-NLS-1$
170 * Pattern to match for session path information (lttng list <session>)
172 private final static Pattern TRACE_SESSION_PATH_PATTERN
= Pattern
.compile("\\s*Trace\\s+path\\:\\s+(.*)"); //$NON-NLS-1$
174 * Pattern to match for kernel domain information (lttng list <session>)
176 private final static Pattern DOMAIN_KERNEL_PATTERN
= Pattern
.compile("=== Domain: Kernel ==="); //$NON-NLS-1$
178 * Pattern to match for ust domain information (lttng list <session>)
180 private final static Pattern DOMAIN_UST_GLOBAL_PATTERN
= Pattern
.compile("=== Domain: UST global ==="); //$NON-NLS-1$
182 * Pattern to match for channels section (lttng list <session>)
184 private final static Pattern CHANNELS_SECTION_PATTERN
= Pattern
.compile("\\s*Channels\\:"); //$NON-NLS-1$
186 * Pattern to match for channel information (lttng list <session>)
188 private final static Pattern CHANNEL_PATTERN
= Pattern
.compile("\\s*-\\s+(.*)\\:\\s+\\[(enabled|disabled)\\]"); //$NON-NLS-1$
190 * Pattern to match for events section information (lttng list <session>)
192 private final static Pattern EVENT_SECTION_PATTERN
= Pattern
.compile("\\s*Events\\:"); //$NON-NLS-1$
194 * Pattern to match for event information (no enabled events) (lttng list <session>)
196 // private final static String EVENT_NONE_PATTERN = "\\s+None"; //$NON-NLS-1$
198 * Pattern to match for event information (lttng list <session>)
200 private final static Pattern EVENT_PATTERN
= Pattern
.compile("\\s+(.*)\\s+\\(loglevel:\\s+(.*)\\s+\\(\\d*\\)\\)\\s+\\(type:\\s+(.*)\\)\\s+\\[(enabled|disabled)\\].*"); //$NON-NLS-1$
202 * Pattern to match a wildcarded event information (lttng list <session>)
204 private final static Pattern WILDCARD_EVENT_PATTERN
= Pattern
.compile("\\s+(.*)\\s+\\(type:\\s+(.*)\\)\\s+\\[(enabled|disabled)\\].*"); //$NON-NLS-1$
206 * Pattern to match for channel (overwite mode) information (lttng list
209 private final static Pattern OVERWRITE_MODE_ATTRIBUTE
= Pattern
.compile("\\s+overwrite\\s+mode\\:.*"); //$NON-NLS-1$
211 * Pattern to match indicating false for overwrite mode
213 private final static String OVERWRITE_MODE_ATTRIBUTE_FALSE
= "0"; //$NON-NLS-1$
215 * Pattern to match for channel (sub-buffer size) information (lttng list
218 private final static Pattern SUBBUFFER_SIZE_ATTRIBUTE
= Pattern
.compile("\\s+subbufers\\s+size\\:.*"); //$NON-NLS-1$
220 * Pattern to match for channel (number of sub-buffers) information (lttng
223 private final static Pattern NUM_SUBBUFFERS_ATTRIBUTE
= Pattern
.compile("\\s+number\\s+of\\s+subbufers\\:.*"); //$NON-NLS-1$
225 * Pattern to match for channel (switch timer) information (lttng list
228 private final static Pattern SWITCH_TIMER_ATTRIBUTE
= Pattern
.compile("\\s+switch\\s+timer\\s+interval\\:.*"); //$NON-NLS-1$
230 * Pattern to match for channel (read timer) information (lttng list
233 private final static Pattern READ_TIMER_ATTRIBUTE
= Pattern
.compile("\\s+read\\s+timer\\s+interval\\:.*"); //$NON-NLS-1$
235 * Pattern to match for channel (output type) information (lttng list
238 private final static Pattern OUTPUT_ATTRIBUTE
= Pattern
.compile("\\s+output\\:.*"); //$NON-NLS-1$
240 * Pattern to match for provider information (lttng list -k/-u)
242 private final static Pattern PROVIDER_EVENT_PATTERN
= Pattern
.compile("\\s*(.*)\\s+\\(loglevel:\\s+(.*)\\s+\\(\\d*\\)\\)\\s+\\(type:\\s+(.*)\\)"); //$NON-NLS-1$
244 * Pattern to match for UST provider information (lttng list -u)
246 private final static Pattern UST_PROVIDER_PATTERN
= Pattern
.compile("\\s*PID\\:\\s+(\\d+)\\s+-\\s+Name\\:\\s+(.*)"); //$NON-NLS-1$
248 * Pattern to match for session information (lttng create <session name>)
250 private final static Pattern CREATE_SESSION_NAME_PATTERN
= Pattern
.compile("\\s*Session\\s+(.*)\\s+created\\."); //$NON-NLS-1$
252 * Pattern to match for session path information (lttng create <session name>)
254 private final static Pattern CREATE_SESSION_PATH_PATTERN
= Pattern
.compile("\\s*Traces\\s+will\\s+be\\s+written\\s+in\\s+(.*).*"); //$NON-NLS-1$
256 * Pattern to match for session command output for "session name not found".
258 private final static Pattern SESSION_NOT_FOUND_ERROR_PATTERN
= Pattern
.compile("\\s*Error:\\s+Session\\s+name\\s+not\\s+found"); //$NON-NLS-1$
260 // ------------------------------------------------------------------------
262 // ------------------------------------------------------------------------
264 * The command shell implementation
266 private ICommandShell fCommandShell
= null;
268 // ------------------------------------------------------------------------
270 // ------------------------------------------------------------------------
276 * - the command shell implementation to use
278 public LTTngControlService(ICommandShell shell
) {
279 fCommandShell
= shell
;
282 // ------------------------------------------------------------------------
284 // ------------------------------------------------------------------------
290 * org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService
291 * #getSessionNames(org.eclipse.core.runtime.IProgressMonitor)
294 public String
[] getSessionNames(IProgressMonitor monitor
) throws ExecutionException
{
296 String command
= COMMAND_LIST
;
297 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
299 if (isError(result
)) {
300 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
304 // Available tracing sessions:
305 // 1) mysession1 (/home/user/lttng-traces/mysession1-20120123-083928)
307 // 2) mysession (/home/user/lttng-traces/mysession-20120123-083318)
310 // Use lttng list <session_name> for more details
312 ArrayList
<String
> retArray
= new ArrayList
<String
>();
314 while (index
< result
.getOutput().length
) {
315 String line
= result
.getOutput()[index
];
316 Matcher matcher
= SESSION_PATTERN
.matcher(line
);
317 if (matcher
.matches()) {
318 retArray
.add(matcher
.group(2).trim());
322 return retArray
.toArray(new String
[retArray
.size()]);
329 * org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService
330 * #getSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
333 public ISessionInfo
getSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
334 String command
= COMMAND_LIST
+ sessionName
;
335 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
337 if (isError(result
)) {
338 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
344 // Tracing session mysession2: [inactive]
345 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
346 ISessionInfo sessionInfo
= new SessionInfo(sessionName
);
348 while (index
< result
.getOutput().length
) {
349 // Tracing session mysession2: [inactive]
350 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
352 // === Domain: Kernel ===
354 String line
= result
.getOutput()[index
];
355 Matcher matcher
= TRACE_SESSION_PATTERN
.matcher(line
);
356 if (matcher
.matches()) {
357 sessionInfo
.setSessionState(matcher
.group(2));
362 matcher
= TRACE_SESSION_PATH_PATTERN
.matcher(line
);
363 if (matcher
.matches()) {
364 sessionInfo
.setSessionPath(matcher
.group(1).trim());
369 matcher
= DOMAIN_KERNEL_PATTERN
.matcher(line
);
370 if (matcher
.matches()) {
372 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_KernelDomainDisplayName
);
373 sessionInfo
.addDomain(domainInfo
);
376 ArrayList
<IChannelInfo
> channels
= new ArrayList
<IChannelInfo
>();
377 index
= parseDomain(result
.getOutput(), index
, channels
);
380 domainInfo
.setChannels(channels
);
383 domainInfo
.setIsKernel(true);
387 matcher
= DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
);
388 if (matcher
.matches()) {
389 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_UstGlobalDomainDisplayName
);
390 sessionInfo
.addDomain(domainInfo
);
393 ArrayList
<IChannelInfo
> channels
= new ArrayList
<IChannelInfo
>();
394 index
= parseDomain(result
.getOutput(), index
, channels
);
397 domainInfo
.setChannels(channels
);
400 domainInfo
.setIsKernel(false);
412 * org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService
413 * #getKernelProvider(org.eclipse.core.runtime.IProgressMonitor)
416 public List
<IBaseEventInfo
> getKernelProvider(IProgressMonitor monitor
) throws ExecutionException
{
417 String command
= COMMAND_LIST_KERNEL
;
418 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
419 if (isError(result
)) {
420 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
425 // sched_kthread_stop (type: tracepoint)
426 List
<IBaseEventInfo
> events
= new ArrayList
<IBaseEventInfo
>();
427 getProviderEventInfo(result
.getOutput(), 0, events
);
435 * org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService
439 public List
<IUstProviderInfo
> getUstProvider() throws ExecutionException
{
440 return getUstProvider(new NullProgressMonitor());
447 * org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService
448 * #getUstProvider(org.eclipse.core.runtime.IProgressMonitor)
451 public List
<IUstProviderInfo
> getUstProvider(IProgressMonitor monitor
) throws ExecutionException
{
452 String command
= COMMAND_LIST_UST
;
453 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
455 if (isError(result
)) {
456 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
463 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
464 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
466 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
469 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
470 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
472 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
474 List
<IUstProviderInfo
> allProviders
= new ArrayList
<IUstProviderInfo
>();
475 IUstProviderInfo provider
= null;
478 while (index
< result
.getOutput().length
) {
479 String line
= result
.getOutput()[index
];
480 Matcher matcher
= UST_PROVIDER_PATTERN
.matcher(line
);
481 if (matcher
.matches()) {
483 provider
= new UstProviderInfo(matcher
.group(2).trim());
484 provider
.setPid(Integer
.valueOf(matcher
.group(1).trim()));
485 List
<IBaseEventInfo
> events
= new ArrayList
<IBaseEventInfo
>();
486 index
= getProviderEventInfo(result
.getOutput(), ++index
, events
);
487 provider
.setEvents(events
);
488 allProviders
.add(provider
);
500 * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#createSession(java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
503 public ISessionInfo
createSession(String sessionName
, String sessionPath
, IProgressMonitor monitor
) throws ExecutionException
{
505 String newName
= formatParameter(sessionName
);
506 String newPath
= formatParameter(sessionPath
);
508 String command
= COMMAND_CREATE_SESSION
+ newName
;
509 if (newPath
!= null && !"".equals(newPath
)) { //$NON-NLS-1$
510 command
+= " -o " + newPath
; //$NON-NLS-1$
513 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
515 if (isError(result
)) {
516 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
518 //Session myssession2 created.
519 //Traces will be written in /home/user/lttng-traces/myssession2-20120209-095418
520 String
[] output
= result
.getOutput();
522 // Get and verify session name
523 Matcher matcher
= CREATE_SESSION_NAME_PATTERN
.matcher(output
[0]);
526 if (matcher
.matches()) {
527 name
= String
.valueOf(matcher
.group(1).trim());
529 // Output format not expected
530 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
531 Messages
.TraceControl_UnexpectedCommnadOutputFormat
+ ":\n" + //$NON-NLS-1$
532 formatOutput(result
.getOutput()));
535 if ((name
== null) || (!name
.equals(sessionName
))) {
536 // Unexpected name returned
537 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
538 Messages
.TraceControl_UnexpectedNameError
+ ": " + name
); //$NON-NLS-1$
541 // Get and verify session path
542 matcher
= CREATE_SESSION_PATH_PATTERN
.matcher(output
[1]);
545 if (matcher
.matches()) {
546 path
= String
.valueOf(matcher
.group(1).trim());
548 // Output format not expected
549 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
550 Messages
.TraceControl_UnexpectedCommnadOutputFormat
+ ":\n" + //$NON-NLS-1$
551 formatOutput(result
.getOutput()));
554 if ((path
== null) || ((sessionPath
!= null) && (!path
.contains(sessionPath
)))) {
556 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
557 Messages
.TraceControl_UnexpectedPathError
+ ": " + name
); //$NON-NLS-1$
560 SessionInfo sessionInfo
= new SessionInfo(name
);
561 sessionInfo
.setSessionPath(path
);
567 public void destroySession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
568 String newName
= formatParameter(sessionName
);
569 String command
= COMMAND_DESTROY_SESSION
+ newName
;
571 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
572 String
[] output
= result
.getOutput();
574 if (isError(result
)) {
575 // In case "session not found" treat it as success
576 if ((output
== null) || (!SESSION_NOT_FOUND_ERROR_PATTERN
.matcher(output
[0]).matches())) {
577 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
580 //Session <sessionName> destroyed
585 * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#startSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
588 public void startSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
590 String newSessionName
= formatParameter(sessionName
);
592 String command
= COMMAND_START_SESSION
+ newSessionName
;
594 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
596 if (isError(result
)) {
597 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
599 //Session <sessionName> started
604 * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#stopSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
607 public void stopSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
608 String newSessionName
= formatParameter(sessionName
);
609 String command
= COMMAND_STOP_SESSION
+ newSessionName
;
611 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
613 if (isError(result
)) {
614 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
616 //Session <sessionName> stopped
622 * @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)
625 public void enableChannels(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IChannelInfo info
, IProgressMonitor monitor
) throws ExecutionException
{
627 // no channels to enable
628 if (channelNames
.size() == 0) {
632 String newSessionName
= formatParameter(sessionName
);
634 StringBuffer command
= new StringBuffer(COMMAND_ENABLE_CHANNEL
);
636 for (Iterator
<String
> iterator
= channelNames
.iterator(); iterator
.hasNext();) {
637 String channel
= (String
) iterator
.next();
638 command
.append(channel
);
639 if (iterator
.hasNext()) {
640 command
.append(","); //$NON-NLS-1$
645 command
.append(OPTION_KERNEL
);
647 command
.append(OPTION_UST
);
650 command
.append(OPTION_SESSION
);
651 command
.append(newSessionName
);
654 // --discard Discard event when buffers are full (default)
656 // --overwrite Flight recorder mode
657 if (info
.isOverwriteMode()) {
658 command
.append(OPTION_OVERWRITE
);
660 // --subbuf-size SIZE Subbuffer size in bytes
661 // (default: 4096, kernel default: 262144)
662 command
.append(OPTION_SUB_BUFFER_SIZE
);
663 command
.append(String
.valueOf(info
.getSubBufferSize()));
665 // --num-subbuf NUM Number of subbufers
666 // (default: 8, kernel default: 4)
667 command
.append(OPTION_NUM_SUB_BUFFERS
);
668 command
.append(String
.valueOf(info
.getNumberOfSubBuffers()));
670 // --switch-timer USEC Switch timer interval in usec (default: 0)
671 command
.append(OPTION_SWITCH_TIMER
);
672 command
.append(String
.valueOf(info
.getSwitchTimer()));
674 // --read-timer USEC Read timer interval in usec (default: 200)
675 command
.append(OPTION_READ_TIMER
);
676 command
.append(String
.valueOf(info
.getReadTimer()));
679 ICommandResult result
= fCommandShell
.executeCommand(command
.toString(), monitor
);
681 if (isError(result
)) {
682 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
688 * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#disableChannel(java.lang.String, java.util.List, org.eclipse.core.runtime.IProgressMonitor)
691 public void disableChannels(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
693 // no channels to enable
694 if (channelNames
.size() == 0) {
698 String newSessionName
= formatParameter(sessionName
);
700 StringBuffer command
= new StringBuffer(COMMAND_DISABLE_CHANNEL
);
702 for (Iterator
<String
> iterator
= channelNames
.iterator(); iterator
.hasNext();) {
703 String channel
= (String
) iterator
.next();
704 command
.append(channel
);
705 if (iterator
.hasNext()) {
706 command
.append(","); //$NON-NLS-1$
711 command
.append(OPTION_KERNEL
);
713 command
.append(OPTION_UST
);
716 command
.append(OPTION_SESSION
);
717 command
.append(newSessionName
);
719 ICommandResult result
= fCommandShell
.executeCommand(command
.toString(), monitor
);
721 if (isError(result
)) {
722 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
728 * @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)
731 public void enableEvents(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
733 String newSessionName
= formatParameter(sessionName
);
735 StringBuffer command
= new StringBuffer(COMMAND_ENABLE_EVENT
);
737 if (eventNames
== null) {
738 command
.append(OPTION_ALL
);
740 // no events to enable
741 if (eventNames
.size() == 0) {
745 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
746 String event
= (String
) iterator
.next();
747 command
.append(event
);
748 if (iterator
.hasNext()) {
749 command
.append(","); //$NON-NLS-1$
755 command
.append(OPTION_KERNEL
);
757 command
.append(OPTION_UST
);
760 command
.append(OPTION_SESSION
);
761 command
.append(newSessionName
);
763 if (channelName
!= null) {
764 command
.append(OPTION_CHANNEL
);
765 command
.append(channelName
);
768 command
.append(OPTION_TRACEPOINT
);
770 ICommandResult result
= fCommandShell
.executeCommand(command
.toString(), monitor
);
772 if (isError(result
)) {
773 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
779 * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#enableSyscalls(java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
782 public void enableSyscalls(String sessionName
, String channelName
, IProgressMonitor monitor
) throws ExecutionException
{
783 String newSessionName
= formatParameter(sessionName
);
785 StringBuffer command
= new StringBuffer(COMMAND_ENABLE_EVENT
);
787 command
.append(OPTION_ALL
);
788 command
.append(OPTION_KERNEL
);
790 command
.append(OPTION_SESSION
);
791 command
.append(newSessionName
);
793 if (channelName
!= null) {
794 command
.append(OPTION_CHANNEL
);
795 command
.append(channelName
);
798 command
.append(OPTION_SYSCALL
);
800 ICommandResult result
= fCommandShell
.executeCommand(command
.toString(), monitor
);
802 if (isError(result
)) {
803 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
809 * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#enableProbe(java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
812 public void enableProbe(String sessionName
, String channelName
, String eventName
, String probe
, IProgressMonitor monitor
) throws ExecutionException
{
813 String newSessionName
= formatParameter(sessionName
);
815 StringBuffer command
= new StringBuffer(COMMAND_ENABLE_EVENT
);
817 command
.append(eventName
);
818 command
.append(OPTION_KERNEL
);
820 command
.append(OPTION_SESSION
);
821 command
.append(newSessionName
);
823 if (channelName
!= null) {
824 command
.append(OPTION_CHANNEL
);
825 command
.append(channelName
);
828 command
.append(OPTION_PROBE
);
829 command
.append(probe
);
831 ICommandResult result
= fCommandShell
.executeCommand(command
.toString(), monitor
);
833 if (isError(result
)) {
834 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
840 * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#enableFunctionProbe(java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
843 public void enableFunctionProbe(String sessionName
, String channelName
, String eventName
, String probe
, IProgressMonitor monitor
) throws ExecutionException
{
844 String newSessionName
= formatParameter(sessionName
);
846 StringBuffer command
= new StringBuffer(COMMAND_ENABLE_EVENT
);
848 command
.append(eventName
);
849 command
.append(OPTION_KERNEL
);
851 command
.append(OPTION_SESSION
);
852 command
.append(newSessionName
);
854 if (channelName
!= null) {
855 command
.append(OPTION_CHANNEL
);
856 command
.append(channelName
);
859 command
.append(OPTION_FUNCTION_PROBE
);
860 command
.append(probe
);
862 ICommandResult result
= fCommandShell
.executeCommand(command
.toString(), monitor
);
864 if (isError(result
)) {
865 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
871 * @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)
874 public void disableEvent(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
875 String newSessionName
= formatParameter(sessionName
);
877 StringBuffer command
= new StringBuffer(COMMAND_DISABLE_EVENT
);
878 if (eventNames
== null) {
879 command
.append(OPTION_ALL
);
881 // no events to enable
882 if (eventNames
.size() == 0) {
886 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
887 String event
= (String
) iterator
.next();
888 command
.append(event
);
889 if (iterator
.hasNext()) {
890 command
.append(","); //$NON-NLS-1$
896 command
.append(OPTION_KERNEL
);
898 command
.append(OPTION_UST
);
901 command
.append(OPTION_SESSION
);
902 command
.append(newSessionName
);
904 if (channelName
!= null) {
905 command
.append(OPTION_CHANNEL
);
906 command
.append(channelName
);
909 ICommandResult result
= fCommandShell
.executeCommand(command
.toString(), monitor
);
911 if (isError(result
)) {
912 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
916 // ------------------------------------------------------------------------
918 // ------------------------------------------------------------------------
920 * Checks if command result is an error result.
923 * - the command result to check
924 * @return true if error else false
926 private boolean isError(ICommandResult result
) {
927 if ((result
.getResult()) != 0 || (result
.getOutput().length
< 1 || ERROR_PATTERN
.matcher(result
.getOutput()[0]).matches())) {
934 * Formats the output string as single string.
938 * @return - the formatted output
940 private String
formatOutput(String
[] output
) {
941 if (output
== null || output
.length
== 0) {
942 return ""; //$NON-NLS-1$
945 StringBuffer ret
= new StringBuffer();
946 for (int i
= 0; i
< output
.length
; i
++) {
947 ret
.append(output
[i
] + "\n"); //$NON-NLS-1$
949 return ret
.toString();
953 * Parses the domain information.
956 * - a command output array
957 * @param currentIndex
958 * - current index in command output array
960 * - list for returning channel information
961 * @return the new current index in command output array
963 private int parseDomain(String
[] output
, int currentIndex
, List
<IChannelInfo
> channels
) {
964 int index
= currentIndex
;
968 // - channnel1: [enabled]
972 // subbufers size: 262144
973 // number of subbufers: 4
974 // switch timer interval: 0
975 // read timer interval: 200
978 while (index
< output
.length
) {
979 String line
= output
[index
];
981 Matcher outerMatcher
= CHANNELS_SECTION_PATTERN
.matcher(line
);
982 if (outerMatcher
.matches()) {
983 IChannelInfo channelInfo
= null;
984 while (index
< output
.length
) {
985 String subLine
= output
[index
];
987 Matcher innerMatcher
= CHANNEL_PATTERN
.matcher(subLine
);
988 if (innerMatcher
.matches()) {
989 channelInfo
= new ChannelInfo(""); //$NON-NLS-1$
991 channelInfo
.setName(innerMatcher
.group(1));
993 // get channel enablement
994 channelInfo
.setState(innerMatcher
.group(2));
997 channels
.add(channelInfo
);
999 } else if (OVERWRITE_MODE_ATTRIBUTE
.matcher(subLine
).matches()) {
1000 String value
= getAttributeValue(subLine
);
1001 channelInfo
.setOverwriteMode(!OVERWRITE_MODE_ATTRIBUTE_FALSE
.equals(value
));
1002 } else if (SUBBUFFER_SIZE_ATTRIBUTE
.matcher(subLine
).matches()) {
1003 channelInfo
.setSubBufferSize(Long
.valueOf(getAttributeValue(subLine
)));
1005 } else if (NUM_SUBBUFFERS_ATTRIBUTE
.matcher(subLine
).matches()) {
1006 channelInfo
.setNumberOfSubBuffers(Integer
.valueOf(getAttributeValue(subLine
)));
1008 } else if (SWITCH_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
1009 channelInfo
.setSwitchTimer(Long
.valueOf(getAttributeValue(subLine
)));
1011 } else if (READ_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
1012 channelInfo
.setReadTimer(Long
.valueOf(getAttributeValue(subLine
)));
1014 } else if (OUTPUT_ATTRIBUTE
.matcher(subLine
).matches()) {
1015 channelInfo
.setOutputType(getAttributeValue(subLine
));
1017 } else if (EVENT_SECTION_PATTERN
.matcher(subLine
).matches()) {
1018 List
<IEventInfo
> events
= new ArrayList
<IEventInfo
>();
1019 index
= parseEvents(output
, index
, events
);
1020 channelInfo
.setEvents(events
);
1021 // we want to stay at the current index to be able to
1024 } else if (DOMAIN_KERNEL_PATTERN
.matcher(subLine
).matches()) {
1027 } else if (DOMAIN_UST_GLOBAL_PATTERN
.matcher(subLine
).matches()) {
1039 * Parses the event information within a domain.
1042 * - a command output array
1043 * @param currentIndex
1044 * - current index in command output array
1046 * - list for returning event information
1047 * @return the new current index in command output array
1049 private int parseEvents(String
[] output
, int currentIndex
, List
<IEventInfo
> events
) {
1050 int index
= currentIndex
;
1052 while (index
< output
.length
) {
1053 String line
= output
[index
];
1054 if (CHANNEL_PATTERN
.matcher(line
).matches()) {
1057 } else if (DOMAIN_KERNEL_PATTERN
.matcher(line
).matches()) {
1060 } else if (DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
).matches()) {
1065 Matcher matcher
= EVENT_PATTERN
.matcher(line
);
1066 Matcher matcher2
= WILDCARD_EVENT_PATTERN
.matcher(line
);
1068 if (matcher
.matches()) {
1069 IEventInfo eventInfo
= new EventInfo(matcher
.group(1).trim());
1070 eventInfo
.setLogLevel(matcher
.group(2).trim());
1071 eventInfo
.setEventType(matcher
.group(3).trim());
1072 eventInfo
.setState(matcher
.group(4));
1073 events
.add(eventInfo
);
1074 } else if (matcher2
.matches()) {
1075 IEventInfo eventInfo
= new EventInfo(matcher2
.group(1).trim());
1076 eventInfo
.setLogLevel(TraceLogLevel
.LEVEL_UNKNOWN
);
1077 eventInfo
.setEventType(matcher2
.group(2).trim());
1078 eventInfo
.setState(matcher2
.group(3));
1079 events
.add(eventInfo
);
1081 // else if (line.matches(EVENT_NONE_PATTERN)) {
1091 * Parses a line with attributes: <attribute Name>: <attribute value>
1094 * - attribute line to parse
1095 * @return the attribute value as string
1097 private String
getAttributeValue(String line
) {
1098 String
[] temp
= line
.split("\\: "); //$NON-NLS-1$
1103 * Parses the event information within a provider.
1106 * - a command output array
1107 * @param currentIndex
1108 * - current index in command output array
1110 * - list for returning event information
1111 * @return the new current index in command output array
1113 private int getProviderEventInfo(String
[] output
, int currentIndex
, List
<IBaseEventInfo
> events
) {
1114 int index
= currentIndex
;
1115 while (index
< output
.length
) {
1116 String line
= output
[index
];
1117 Matcher matcher
= PROVIDER_EVENT_PATTERN
.matcher(line
);
1118 if (matcher
.matches()) {
1119 // sched_kthread_stop (loglevel: TRACE_EMERG0) (type:
1121 IBaseEventInfo eventInfo
= new BaseEventInfo(matcher
.group(1).trim());
1122 eventInfo
.setLogLevel(matcher
.group(2).trim());
1123 eventInfo
.setEventType(matcher
.group(3).trim());
1124 events
.add(eventInfo
);
1125 } else if (UST_PROVIDER_PATTERN
.matcher(line
).matches()) {
1134 * Formats a command parameter for the command execution i.e. adds quotes
1135 * at the beginning and end if necessary.
1136 * @param parameter - parameter to format
1137 * @return formated parameter
1139 private String
formatParameter(String parameter
) {
1140 if (parameter
!= null) {
1141 String newString
= String
.valueOf(parameter
);
1143 if (parameter
.contains(" ")) { //$NON-NLS-1$
1144 newString
= "\"" + newString
+ "\""; //$NON-NLS-1$ //$NON-NLS-2$