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
.LogLevelType
;
31 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.TraceLogLevel
;
32 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.impl
.BaseEventInfo
;
33 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.impl
.ChannelInfo
;
34 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.impl
.DomainInfo
;
35 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.impl
.EventInfo
;
36 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.impl
.SessionInfo
;
37 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.impl
.UstProviderInfo
;
40 * <b><u>LTTngControlService</u></b>
42 * Service for sending LTTng trace control commands to remote host.
45 public class LTTngControlService
implements ILttngControlService
{
46 // ------------------------------------------------------------------------
48 // ------------------------------------------------------------------------
51 * The lttng tools command.
53 private final static String CONTROL_COMMAND
= "lttng"; //$NON-NLS-1$
55 * Command: lttng list.
57 private final static String COMMAND_LIST
= CONTROL_COMMAND
+ " list "; //$NON-NLS-1$
59 * Command to list kernel tracer information.
61 private final static String COMMAND_LIST_KERNEL
= COMMAND_LIST
+ "-k"; //$NON-NLS-1$
63 * Command to list user space trace information.
65 private final static String COMMAND_LIST_UST
= COMMAND_LIST
+ "-u"; //$NON-NLS-1$
67 * Command to create a session.
69 private final static String COMMAND_CREATE_SESSION
= CONTROL_COMMAND
+ " create "; //$NON-NLS-1$
71 * Command to destroy a session.
73 private final static String COMMAND_DESTROY_SESSION
= CONTROL_COMMAND
+ " destroy "; //$NON-NLS-1$
75 * Command to destroy a session.
77 private final static String COMMAND_START_SESSION
= CONTROL_COMMAND
+ " start "; //$NON-NLS-1$
79 * Command to destroy a session.
81 private final static String COMMAND_STOP_SESSION
= CONTROL_COMMAND
+ " stop "; //$NON-NLS-1$
83 * Command to enable a channel.
85 private final static String COMMAND_ENABLE_CHANNEL
= CONTROL_COMMAND
+ " enable-channel "; //$NON-NLS-1$
87 * Command to disable a channel.
89 private final static String COMMAND_DISABLE_CHANNEL
= CONTROL_COMMAND
+ " disable-channel "; //$NON-NLS-1$
91 * Command to enable a event.
93 private final static String COMMAND_ENABLE_EVENT
= CONTROL_COMMAND
+ " enable-event "; //$NON-NLS-1$
95 * Command to disable a event.
97 private final static String COMMAND_DISABLE_EVENT
= CONTROL_COMMAND
+ " disable-event "; //$NON-NLS-1$
99 // Command options constants
101 * Command line option for kernel tracer.
103 private final static String OPTION_KERNEL
= " -k "; //$NON-NLS-1$
105 * Command line option for UST tracer.
107 private final static String OPTION_UST
= " -u "; //$NON-NLS-1$
109 * Command line option for specifying a session.
111 private final static String OPTION_SESSION
= " -s "; //$NON-NLS-1$
113 * Command line option for specifying a channel.
115 private final static String OPTION_CHANNEL
= " -c "; //$NON-NLS-1$
117 * Command line option for specifying all events.
119 private final static String OPTION_ALL
= " -a "; //$NON-NLS-1$
121 * Command line option for specifying tracepoint events.
123 private final static String OPTION_TRACEPOINT
= " --tracepoint "; //$NON-NLS-1$
125 * Command line option for specifying syscall events.
127 private final static String OPTION_SYSCALL
= " --syscall "; //$NON-NLS-1$
129 * Command line option for specifying a dynamic probe.
131 private final static String OPTION_PROBE
= " --probe "; //$NON-NLS-1$
133 * Command line option for specifying a dynamic function entry/return probe.
135 private final static String OPTION_FUNCTION_PROBE
= " --function "; //$NON-NLS-1$
137 * Command line option for specifying a log level range.
139 private final static String OPTION_LOGLEVEL
= " --loglevel "; //$NON-NLS-1$
141 * Command line option for specifying a specific log level.
143 private final static String OPTION_LOGLEVEL_ONLY
= " --loglevel-only "; //$NON-NLS-1$
145 * Optional command line option for configuring a channel's overwrite mode.
147 private final static String OPTION_OVERWRITE
= " --overwrite "; //$NON-NLS-1$
149 * Optional command line option for configuring a channel's number of sub buffers.
151 private final static String OPTION_NUM_SUB_BUFFERS
= " --num-subbuf "; //$NON-NLS-1$
153 * Optional command line option for configuring a channel's sub buffer size.
155 private final static String OPTION_SUB_BUFFER_SIZE
= " --subbuf-size "; //$NON-NLS-1$
157 * Optional command line option for configuring a channel's switch timer interval.
159 private final static String OPTION_SWITCH_TIMER
= " --switch-timer "; //$NON-NLS-1$
161 * Optional command line option for configuring a channel's read timer interval.
163 private final static String OPTION_READ_TIMER
= " --read-timer "; //$NON-NLS-1$
167 * Pattern to match for error output
169 private final static Pattern ERROR_PATTERN
= Pattern
.compile("\\s*Error\\:.*"); //$NON-NLS-1$
171 * Pattern to match for session information (lttng list)
173 private final static Pattern SESSION_PATTERN
= Pattern
.compile("\\s+(\\d+)\\)\\s+(.*)\\s+\\((.*)\\)\\s+\\[(active|inactive)\\].*"); //$NON-NLS-1$
175 * Pattern to match for session information (lttng list <session>)
177 private final static Pattern TRACE_SESSION_PATTERN
= Pattern
.compile("\\s*Tracing\\s+session\\s+(.*)\\:\\s+\\[(active|inactive)\\].*"); //$NON-NLS-1$
179 * Pattern to match for session path information (lttng list <session>)
181 private final static Pattern TRACE_SESSION_PATH_PATTERN
= Pattern
.compile("\\s*Trace\\s+path\\:\\s+(.*)"); //$NON-NLS-1$
183 * Pattern to match for kernel domain information (lttng list <session>)
185 private final static Pattern DOMAIN_KERNEL_PATTERN
= Pattern
.compile("=== Domain: Kernel ==="); //$NON-NLS-1$
187 * Pattern to match for ust domain information (lttng list <session>)
189 private final static Pattern DOMAIN_UST_GLOBAL_PATTERN
= Pattern
.compile("=== Domain: UST global ==="); //$NON-NLS-1$
191 * Pattern to match for channels section (lttng list <session>)
193 private final static Pattern CHANNELS_SECTION_PATTERN
= Pattern
.compile("\\s*Channels\\:"); //$NON-NLS-1$
195 * Pattern to match for channel information (lttng list <session>)
197 private final static Pattern CHANNEL_PATTERN
= Pattern
.compile("\\s*-\\s+(.*)\\:\\s+\\[(enabled|disabled)\\]"); //$NON-NLS-1$
199 * Pattern to match for events section information (lttng list <session>)
201 private final static Pattern EVENT_SECTION_PATTERN
= Pattern
.compile("\\s*Events\\:"); //$NON-NLS-1$
203 * Pattern to match for event information (no enabled events) (lttng list <session>)
205 // private final static String EVENT_NONE_PATTERN = "\\s+None"; //$NON-NLS-1$
207 * Pattern to match for event information (lttng list <session>)
209 private final static Pattern EVENT_PATTERN
= Pattern
.compile("\\s+(.*)\\s+\\(loglevel:\\s+(.*)\\s+\\(\\d*\\)\\)\\s+\\(type:\\s+(.*)\\)\\s+\\[(enabled|disabled)\\].*"); //$NON-NLS-1$
211 * Pattern to match a wildcarded event information (lttng list <session>)
213 private final static Pattern WILDCARD_EVENT_PATTERN
= Pattern
.compile("\\s+(.*)\\s+\\(type:\\s+(.*)\\)\\s+\\[(enabled|disabled)\\].*"); //$NON-NLS-1$
215 * Pattern to match for channel (overwite mode) information (lttng list
218 private final static Pattern OVERWRITE_MODE_ATTRIBUTE
= Pattern
.compile("\\s+overwrite\\s+mode\\:.*"); //$NON-NLS-1$
220 * Pattern to match indicating false for overwrite mode
222 private final static String OVERWRITE_MODE_ATTRIBUTE_FALSE
= "0"; //$NON-NLS-1$
224 * Pattern to match for channel (sub-buffer size) information (lttng list
227 private final static Pattern SUBBUFFER_SIZE_ATTRIBUTE
= Pattern
.compile("\\s+subbufers\\s+size\\:.*"); //$NON-NLS-1$
229 * Pattern to match for channel (number of sub-buffers) information (lttng
232 private final static Pattern NUM_SUBBUFFERS_ATTRIBUTE
= Pattern
.compile("\\s+number\\s+of\\s+subbufers\\:.*"); //$NON-NLS-1$
234 * Pattern to match for channel (switch timer) information (lttng list
237 private final static Pattern SWITCH_TIMER_ATTRIBUTE
= Pattern
.compile("\\s+switch\\s+timer\\s+interval\\:.*"); //$NON-NLS-1$
239 * Pattern to match for channel (read timer) information (lttng list
242 private final static Pattern READ_TIMER_ATTRIBUTE
= Pattern
.compile("\\s+read\\s+timer\\s+interval\\:.*"); //$NON-NLS-1$
244 * Pattern to match for channel (output type) information (lttng list
247 private final static Pattern OUTPUT_ATTRIBUTE
= Pattern
.compile("\\s+output\\:.*"); //$NON-NLS-1$
249 * Pattern to match for provider information (lttng list -k/-u)
251 private final static Pattern PROVIDER_EVENT_PATTERN
= Pattern
.compile("\\s*(.*)\\s+\\(loglevel:\\s+(.*)\\s+\\(\\d*\\)\\)\\s+\\(type:\\s+(.*)\\)"); //$NON-NLS-1$
253 * Pattern to match for UST provider information (lttng list -u)
255 private final static Pattern UST_PROVIDER_PATTERN
= Pattern
.compile("\\s*PID\\:\\s+(\\d+)\\s+-\\s+Name\\:\\s+(.*)"); //$NON-NLS-1$
257 * Pattern to match for session information (lttng create <session name>)
259 private final static Pattern CREATE_SESSION_NAME_PATTERN
= Pattern
.compile("\\s*Session\\s+(.*)\\s+created\\."); //$NON-NLS-1$
261 * Pattern to match for session path information (lttng create <session name>)
263 private final static Pattern CREATE_SESSION_PATH_PATTERN
= Pattern
.compile("\\s*Traces\\s+will\\s+be\\s+written\\s+in\\s+(.*).*"); //$NON-NLS-1$
265 * Pattern to match for session command output for "session name not found".
267 private final static Pattern SESSION_NOT_FOUND_ERROR_PATTERN
= Pattern
.compile("\\s*Error:\\s+Session\\s+name\\s+not\\s+found"); //$NON-NLS-1$
269 // ------------------------------------------------------------------------
271 // ------------------------------------------------------------------------
273 * The command shell implementation
275 private ICommandShell fCommandShell
= null;
277 // ------------------------------------------------------------------------
279 // ------------------------------------------------------------------------
285 * - the command shell implementation to use
287 public LTTngControlService(ICommandShell shell
) {
288 fCommandShell
= shell
;
291 // ------------------------------------------------------------------------
293 // ------------------------------------------------------------------------
299 * org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService
300 * #getSessionNames(org.eclipse.core.runtime.IProgressMonitor)
303 public String
[] getSessionNames(IProgressMonitor monitor
) throws ExecutionException
{
305 String command
= COMMAND_LIST
;
306 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
308 if (isError(result
)) {
309 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
313 // Available tracing sessions:
314 // 1) mysession1 (/home/user/lttng-traces/mysession1-20120123-083928)
316 // 2) mysession (/home/user/lttng-traces/mysession-20120123-083318)
319 // Use lttng list <session_name> for more details
321 ArrayList
<String
> retArray
= new ArrayList
<String
>();
323 while (index
< result
.getOutput().length
) {
324 String line
= result
.getOutput()[index
];
325 Matcher matcher
= SESSION_PATTERN
.matcher(line
);
326 if (matcher
.matches()) {
327 retArray
.add(matcher
.group(2).trim());
331 return retArray
.toArray(new String
[retArray
.size()]);
338 * org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService
339 * #getSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
342 public ISessionInfo
getSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
343 String command
= COMMAND_LIST
+ sessionName
;
344 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
346 if (isError(result
)) {
347 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
353 // Tracing session mysession2: [inactive]
354 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
355 ISessionInfo sessionInfo
= new SessionInfo(sessionName
);
357 while (index
< result
.getOutput().length
) {
358 // Tracing session mysession2: [inactive]
359 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
361 // === Domain: Kernel ===
363 String line
= result
.getOutput()[index
];
364 Matcher matcher
= TRACE_SESSION_PATTERN
.matcher(line
);
365 if (matcher
.matches()) {
366 sessionInfo
.setSessionState(matcher
.group(2));
371 matcher
= TRACE_SESSION_PATH_PATTERN
.matcher(line
);
372 if (matcher
.matches()) {
373 sessionInfo
.setSessionPath(matcher
.group(1).trim());
378 matcher
= DOMAIN_KERNEL_PATTERN
.matcher(line
);
379 if (matcher
.matches()) {
381 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_KernelDomainDisplayName
);
382 sessionInfo
.addDomain(domainInfo
);
385 ArrayList
<IChannelInfo
> channels
= new ArrayList
<IChannelInfo
>();
386 index
= parseDomain(result
.getOutput(), index
, channels
);
389 domainInfo
.setChannels(channels
);
392 domainInfo
.setIsKernel(true);
396 matcher
= DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
);
397 if (matcher
.matches()) {
398 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_UstGlobalDomainDisplayName
);
399 sessionInfo
.addDomain(domainInfo
);
402 ArrayList
<IChannelInfo
> channels
= new ArrayList
<IChannelInfo
>();
403 index
= parseDomain(result
.getOutput(), index
, channels
);
406 domainInfo
.setChannels(channels
);
409 domainInfo
.setIsKernel(false);
421 * org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService
422 * #getKernelProvider(org.eclipse.core.runtime.IProgressMonitor)
425 public List
<IBaseEventInfo
> getKernelProvider(IProgressMonitor monitor
) throws ExecutionException
{
426 String command
= COMMAND_LIST_KERNEL
;
427 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
428 if (isError(result
)) {
429 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
434 // sched_kthread_stop (type: tracepoint)
435 List
<IBaseEventInfo
> events
= new ArrayList
<IBaseEventInfo
>();
436 getProviderEventInfo(result
.getOutput(), 0, events
);
444 * org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService
448 public List
<IUstProviderInfo
> getUstProvider() throws ExecutionException
{
449 return getUstProvider(new NullProgressMonitor());
456 * org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService
457 * #getUstProvider(org.eclipse.core.runtime.IProgressMonitor)
460 public List
<IUstProviderInfo
> getUstProvider(IProgressMonitor monitor
) throws ExecutionException
{
461 String command
= COMMAND_LIST_UST
;
462 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
464 if (isError(result
)) {
465 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
472 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
473 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
475 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
478 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
479 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
481 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
483 List
<IUstProviderInfo
> allProviders
= new ArrayList
<IUstProviderInfo
>();
484 IUstProviderInfo provider
= null;
487 while (index
< result
.getOutput().length
) {
488 String line
= result
.getOutput()[index
];
489 Matcher matcher
= UST_PROVIDER_PATTERN
.matcher(line
);
490 if (matcher
.matches()) {
492 provider
= new UstProviderInfo(matcher
.group(2).trim());
493 provider
.setPid(Integer
.valueOf(matcher
.group(1).trim()));
494 List
<IBaseEventInfo
> events
= new ArrayList
<IBaseEventInfo
>();
495 index
= getProviderEventInfo(result
.getOutput(), ++index
, events
);
496 provider
.setEvents(events
);
497 allProviders
.add(provider
);
509 * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#createSession(java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
512 public ISessionInfo
createSession(String sessionName
, String sessionPath
, IProgressMonitor monitor
) throws ExecutionException
{
514 String newName
= formatParameter(sessionName
);
515 String newPath
= formatParameter(sessionPath
);
517 String command
= COMMAND_CREATE_SESSION
+ newName
;
518 if (newPath
!= null && !"".equals(newPath
)) { //$NON-NLS-1$
519 command
+= " -o " + newPath
; //$NON-NLS-1$
522 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
524 if (isError(result
)) {
525 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
527 //Session myssession2 created.
528 //Traces will be written in /home/user/lttng-traces/myssession2-20120209-095418
529 String
[] output
= result
.getOutput();
531 // Get and verify session name
532 Matcher matcher
= CREATE_SESSION_NAME_PATTERN
.matcher(output
[0]);
535 if (matcher
.matches()) {
536 name
= String
.valueOf(matcher
.group(1).trim());
538 // Output format not expected
539 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
540 Messages
.TraceControl_UnexpectedCommnadOutputFormat
+ ":\n" + //$NON-NLS-1$
541 formatOutput(result
.getOutput()));
544 if ((name
== null) || (!name
.equals(sessionName
))) {
545 // Unexpected name returned
546 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
547 Messages
.TraceControl_UnexpectedNameError
+ ": " + name
); //$NON-NLS-1$
550 // Get and verify session path
551 matcher
= CREATE_SESSION_PATH_PATTERN
.matcher(output
[1]);
554 if (matcher
.matches()) {
555 path
= String
.valueOf(matcher
.group(1).trim());
557 // Output format not expected
558 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
559 Messages
.TraceControl_UnexpectedCommnadOutputFormat
+ ":\n" + //$NON-NLS-1$
560 formatOutput(result
.getOutput()));
563 if ((path
== null) || ((sessionPath
!= null) && (!path
.contains(sessionPath
)))) {
565 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
566 Messages
.TraceControl_UnexpectedPathError
+ ": " + name
); //$NON-NLS-1$
569 SessionInfo sessionInfo
= new SessionInfo(name
);
570 sessionInfo
.setSessionPath(path
);
576 public void destroySession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
577 String newName
= formatParameter(sessionName
);
578 String command
= COMMAND_DESTROY_SESSION
+ newName
;
580 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
581 String
[] output
= result
.getOutput();
583 if (isError(result
)) {
584 // In case "session not found" treat it as success
585 if ((output
== null) || (!SESSION_NOT_FOUND_ERROR_PATTERN
.matcher(output
[0]).matches())) {
586 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
589 //Session <sessionName> destroyed
594 * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#startSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
597 public void startSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
599 String newSessionName
= formatParameter(sessionName
);
601 String command
= COMMAND_START_SESSION
+ newSessionName
;
603 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
605 if (isError(result
)) {
606 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
608 //Session <sessionName> started
613 * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#stopSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
616 public void stopSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
617 String newSessionName
= formatParameter(sessionName
);
618 String command
= COMMAND_STOP_SESSION
+ newSessionName
;
620 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
622 if (isError(result
)) {
623 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
625 //Session <sessionName> stopped
631 * @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)
634 public void enableChannels(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IChannelInfo info
, IProgressMonitor monitor
) throws ExecutionException
{
636 // no channels to enable
637 if (channelNames
.size() == 0) {
641 String newSessionName
= formatParameter(sessionName
);
643 StringBuffer command
= new StringBuffer(COMMAND_ENABLE_CHANNEL
);
645 for (Iterator
<String
> iterator
= channelNames
.iterator(); iterator
.hasNext();) {
646 String channel
= (String
) iterator
.next();
647 command
.append(channel
);
648 if (iterator
.hasNext()) {
649 command
.append(","); //$NON-NLS-1$
654 command
.append(OPTION_KERNEL
);
656 command
.append(OPTION_UST
);
659 command
.append(OPTION_SESSION
);
660 command
.append(newSessionName
);
663 // --discard Discard event when buffers are full (default)
665 // --overwrite Flight recorder mode
666 if (info
.isOverwriteMode()) {
667 command
.append(OPTION_OVERWRITE
);
669 // --subbuf-size SIZE Subbuffer size in bytes
670 // (default: 4096, kernel default: 262144)
671 command
.append(OPTION_SUB_BUFFER_SIZE
);
672 command
.append(String
.valueOf(info
.getSubBufferSize()));
674 // --num-subbuf NUM Number of subbufers
675 // (default: 8, kernel default: 4)
676 command
.append(OPTION_NUM_SUB_BUFFERS
);
677 command
.append(String
.valueOf(info
.getNumberOfSubBuffers()));
679 // --switch-timer USEC Switch timer interval in usec (default: 0)
680 command
.append(OPTION_SWITCH_TIMER
);
681 command
.append(String
.valueOf(info
.getSwitchTimer()));
683 // --read-timer USEC Read timer interval in usec (default: 200)
684 command
.append(OPTION_READ_TIMER
);
685 command
.append(String
.valueOf(info
.getReadTimer()));
688 ICommandResult result
= fCommandShell
.executeCommand(command
.toString(), monitor
);
690 if (isError(result
)) {
691 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
697 * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#disableChannel(java.lang.String, java.util.List, org.eclipse.core.runtime.IProgressMonitor)
700 public void disableChannels(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
702 // no channels to enable
703 if (channelNames
.size() == 0) {
707 String newSessionName
= formatParameter(sessionName
);
709 StringBuffer command
= new StringBuffer(COMMAND_DISABLE_CHANNEL
);
711 for (Iterator
<String
> iterator
= channelNames
.iterator(); iterator
.hasNext();) {
712 String channel
= (String
) iterator
.next();
713 command
.append(channel
);
714 if (iterator
.hasNext()) {
715 command
.append(","); //$NON-NLS-1$
720 command
.append(OPTION_KERNEL
);
722 command
.append(OPTION_UST
);
725 command
.append(OPTION_SESSION
);
726 command
.append(newSessionName
);
728 ICommandResult result
= fCommandShell
.executeCommand(command
.toString(), monitor
);
730 if (isError(result
)) {
731 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
737 * @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)
740 public void enableEvents(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
742 String newSessionName
= formatParameter(sessionName
);
744 StringBuffer command
= new StringBuffer(COMMAND_ENABLE_EVENT
);
746 if (eventNames
== null) {
747 command
.append(OPTION_ALL
);
749 // no events to enable
750 if (eventNames
.size() == 0) {
754 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
755 String event
= (String
) iterator
.next();
756 command
.append(event
);
757 if (iterator
.hasNext()) {
758 command
.append(","); //$NON-NLS-1$
764 command
.append(OPTION_KERNEL
);
766 command
.append(OPTION_UST
);
769 command
.append(OPTION_SESSION
);
770 command
.append(newSessionName
);
772 if (channelName
!= null) {
773 command
.append(OPTION_CHANNEL
);
774 command
.append(channelName
);
777 command
.append(OPTION_TRACEPOINT
);
779 ICommandResult result
= fCommandShell
.executeCommand(command
.toString(), monitor
);
781 if (isError(result
)) {
782 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
788 * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#enableSyscalls(java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
791 public void enableSyscalls(String sessionName
, String channelName
, IProgressMonitor monitor
) throws ExecutionException
{
792 String newSessionName
= formatParameter(sessionName
);
794 StringBuffer command
= new StringBuffer(COMMAND_ENABLE_EVENT
);
796 command
.append(OPTION_ALL
);
797 command
.append(OPTION_KERNEL
);
799 command
.append(OPTION_SESSION
);
800 command
.append(newSessionName
);
802 if (channelName
!= null) {
803 command
.append(OPTION_CHANNEL
);
804 command
.append(channelName
);
807 command
.append(OPTION_SYSCALL
);
809 ICommandResult result
= fCommandShell
.executeCommand(command
.toString(), monitor
);
811 if (isError(result
)) {
812 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
818 * @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)
821 public void enableProbe(String sessionName
, String channelName
, String eventName
, String probe
, IProgressMonitor monitor
) throws ExecutionException
{
822 String newSessionName
= formatParameter(sessionName
);
824 StringBuffer command
= new StringBuffer(COMMAND_ENABLE_EVENT
);
826 command
.append(eventName
);
827 command
.append(OPTION_KERNEL
);
829 command
.append(OPTION_SESSION
);
830 command
.append(newSessionName
);
832 if (channelName
!= null) {
833 command
.append(OPTION_CHANNEL
);
834 command
.append(channelName
);
837 command
.append(OPTION_PROBE
);
838 command
.append(probe
);
840 ICommandResult result
= fCommandShell
.executeCommand(command
.toString(), monitor
);
842 if (isError(result
)) {
843 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
849 * @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)
852 public void enableFunctionProbe(String sessionName
, String channelName
, String eventName
, String probe
, IProgressMonitor monitor
) throws ExecutionException
{
853 String newSessionName
= formatParameter(sessionName
);
855 StringBuffer command
= new StringBuffer(COMMAND_ENABLE_EVENT
);
857 command
.append(eventName
);
858 command
.append(OPTION_KERNEL
);
860 command
.append(OPTION_SESSION
);
861 command
.append(newSessionName
);
863 if (channelName
!= null) {
864 command
.append(OPTION_CHANNEL
);
865 command
.append(channelName
);
868 command
.append(OPTION_FUNCTION_PROBE
);
869 command
.append(probe
);
871 ICommandResult result
= fCommandShell
.executeCommand(command
.toString(), monitor
);
873 if (isError(result
)) {
874 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
880 * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#enableLogLevel(java.lang.String, java.lang.String, java.lang.String, org.eclipse.linuxtools.lttng.ui.views.control.model.LogLevelType, org.eclipse.linuxtools.lttng.ui.views.control.model.TraceLogLevel, org.eclipse.core.runtime.IProgressMonitor)
883 public void enableLogLevel(String sessionName
, String channelName
, String eventName
, LogLevelType logLevelType
, TraceLogLevel level
, IProgressMonitor monitor
) throws ExecutionException
{
884 String newSessionName
= formatParameter(sessionName
);
886 StringBuffer command
= new StringBuffer(COMMAND_ENABLE_EVENT
);
888 command
.append(eventName
);
889 command
.append(OPTION_UST
);
891 command
.append(OPTION_SESSION
);
892 command
.append(newSessionName
);
894 if (channelName
!= null) {
895 command
.append(OPTION_CHANNEL
);
896 command
.append(channelName
);
899 if (logLevelType
== LogLevelType
.LOGLEVEL
) {
900 command
.append(OPTION_LOGLEVEL
);
901 } else if (logLevelType
== LogLevelType
.LOGLEVEL_ONLY
) {
902 command
.append(OPTION_LOGLEVEL_ONLY
);
907 command
.append(level
.getInName());
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$
918 * @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)
921 public void disableEvent(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
922 String newSessionName
= formatParameter(sessionName
);
924 StringBuffer command
= new StringBuffer(COMMAND_DISABLE_EVENT
);
925 if (eventNames
== null) {
926 command
.append(OPTION_ALL
);
928 // no events to enable
929 if (eventNames
.size() == 0) {
933 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
934 String event
= (String
) iterator
.next();
935 command
.append(event
);
936 if (iterator
.hasNext()) {
937 command
.append(","); //$NON-NLS-1$
943 command
.append(OPTION_KERNEL
);
945 command
.append(OPTION_UST
);
948 command
.append(OPTION_SESSION
);
949 command
.append(newSessionName
);
951 if (channelName
!= null) {
952 command
.append(OPTION_CHANNEL
);
953 command
.append(channelName
);
956 ICommandResult result
= fCommandShell
.executeCommand(command
.toString(), monitor
);
958 if (isError(result
)) {
959 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
963 // ------------------------------------------------------------------------
965 // ------------------------------------------------------------------------
967 * Checks if command result is an error result.
970 * - the command result to check
971 * @return true if error else false
973 private boolean isError(ICommandResult result
) {
974 if ((result
.getResult()) != 0 || (result
.getOutput().length
< 1 || ERROR_PATTERN
.matcher(result
.getOutput()[0]).matches())) {
981 * Formats the output string as single string.
985 * @return - the formatted output
987 private String
formatOutput(String
[] output
) {
988 if (output
== null || output
.length
== 0) {
989 return ""; //$NON-NLS-1$
992 StringBuffer ret
= new StringBuffer();
993 for (int i
= 0; i
< output
.length
; i
++) {
994 ret
.append(output
[i
] + "\n"); //$NON-NLS-1$
996 return ret
.toString();
1000 * Parses the domain information.
1003 * - a command output array
1004 * @param currentIndex
1005 * - current index in command output array
1007 * - list for returning channel information
1008 * @return the new current index in command output array
1010 private int parseDomain(String
[] output
, int currentIndex
, List
<IChannelInfo
> channels
) {
1011 int index
= currentIndex
;
1015 // - channnel1: [enabled]
1018 // overwrite mode: 0
1019 // subbufers size: 262144
1020 // number of subbufers: 4
1021 // switch timer interval: 0
1022 // read timer interval: 200
1025 while (index
< output
.length
) {
1026 String line
= output
[index
];
1028 Matcher outerMatcher
= CHANNELS_SECTION_PATTERN
.matcher(line
);
1029 if (outerMatcher
.matches()) {
1030 IChannelInfo channelInfo
= null;
1031 while (index
< output
.length
) {
1032 String subLine
= output
[index
];
1034 Matcher innerMatcher
= CHANNEL_PATTERN
.matcher(subLine
);
1035 if (innerMatcher
.matches()) {
1036 channelInfo
= new ChannelInfo(""); //$NON-NLS-1$
1038 channelInfo
.setName(innerMatcher
.group(1));
1040 // get channel enablement
1041 channelInfo
.setState(innerMatcher
.group(2));
1044 channels
.add(channelInfo
);
1046 } else if (OVERWRITE_MODE_ATTRIBUTE
.matcher(subLine
).matches()) {
1047 String value
= getAttributeValue(subLine
);
1048 channelInfo
.setOverwriteMode(!OVERWRITE_MODE_ATTRIBUTE_FALSE
.equals(value
));
1049 } else if (SUBBUFFER_SIZE_ATTRIBUTE
.matcher(subLine
).matches()) {
1050 channelInfo
.setSubBufferSize(Long
.valueOf(getAttributeValue(subLine
)));
1052 } else if (NUM_SUBBUFFERS_ATTRIBUTE
.matcher(subLine
).matches()) {
1053 channelInfo
.setNumberOfSubBuffers(Integer
.valueOf(getAttributeValue(subLine
)));
1055 } else if (SWITCH_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
1056 channelInfo
.setSwitchTimer(Long
.valueOf(getAttributeValue(subLine
)));
1058 } else if (READ_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
1059 channelInfo
.setReadTimer(Long
.valueOf(getAttributeValue(subLine
)));
1061 } else if (OUTPUT_ATTRIBUTE
.matcher(subLine
).matches()) {
1062 channelInfo
.setOutputType(getAttributeValue(subLine
));
1064 } else if (EVENT_SECTION_PATTERN
.matcher(subLine
).matches()) {
1065 List
<IEventInfo
> events
= new ArrayList
<IEventInfo
>();
1066 index
= parseEvents(output
, index
, events
);
1067 channelInfo
.setEvents(events
);
1068 // we want to stay at the current index to be able to
1071 } else if (DOMAIN_KERNEL_PATTERN
.matcher(subLine
).matches()) {
1074 } else if (DOMAIN_UST_GLOBAL_PATTERN
.matcher(subLine
).matches()) {
1086 * Parses the event information within a domain.
1089 * - a command output array
1090 * @param currentIndex
1091 * - current index in command output array
1093 * - list for returning event information
1094 * @return the new current index in command output array
1096 private int parseEvents(String
[] output
, int currentIndex
, List
<IEventInfo
> events
) {
1097 int index
= currentIndex
;
1099 while (index
< output
.length
) {
1100 String line
= output
[index
];
1101 if (CHANNEL_PATTERN
.matcher(line
).matches()) {
1104 } else if (DOMAIN_KERNEL_PATTERN
.matcher(line
).matches()) {
1107 } else if (DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
).matches()) {
1112 Matcher matcher
= EVENT_PATTERN
.matcher(line
);
1113 Matcher matcher2
= WILDCARD_EVENT_PATTERN
.matcher(line
);
1115 if (matcher
.matches()) {
1116 IEventInfo eventInfo
= new EventInfo(matcher
.group(1).trim());
1117 eventInfo
.setLogLevel(matcher
.group(2).trim());
1118 eventInfo
.setEventType(matcher
.group(3).trim());
1119 eventInfo
.setState(matcher
.group(4));
1120 events
.add(eventInfo
);
1121 } else if (matcher2
.matches()) {
1122 IEventInfo eventInfo
= new EventInfo(matcher2
.group(1).trim());
1123 eventInfo
.setLogLevel(TraceLogLevel
.LEVEL_UNKNOWN
);
1124 eventInfo
.setEventType(matcher2
.group(2).trim());
1125 eventInfo
.setState(matcher2
.group(3));
1126 events
.add(eventInfo
);
1128 // else if (line.matches(EVENT_NONE_PATTERN)) {
1138 * Parses a line with attributes: <attribute Name>: <attribute value>
1141 * - attribute line to parse
1142 * @return the attribute value as string
1144 private String
getAttributeValue(String line
) {
1145 String
[] temp
= line
.split("\\: "); //$NON-NLS-1$
1150 * Parses the event information within a provider.
1153 * - a command output array
1154 * @param currentIndex
1155 * - current index in command output array
1157 * - list for returning event information
1158 * @return the new current index in command output array
1160 private int getProviderEventInfo(String
[] output
, int currentIndex
, List
<IBaseEventInfo
> events
) {
1161 int index
= currentIndex
;
1162 while (index
< output
.length
) {
1163 String line
= output
[index
];
1164 Matcher matcher
= PROVIDER_EVENT_PATTERN
.matcher(line
);
1165 if (matcher
.matches()) {
1166 // sched_kthread_stop (loglevel: TRACE_EMERG0) (type:
1168 IBaseEventInfo eventInfo
= new BaseEventInfo(matcher
.group(1).trim());
1169 eventInfo
.setLogLevel(matcher
.group(2).trim());
1170 eventInfo
.setEventType(matcher
.group(3).trim());
1171 events
.add(eventInfo
);
1172 } else if (UST_PROVIDER_PATTERN
.matcher(line
).matches()) {
1181 * Formats a command parameter for the command execution i.e. adds quotes
1182 * at the beginning and end if necessary.
1183 * @param parameter - parameter to format
1184 * @return formated parameter
1186 private String
formatParameter(String parameter
) {
1187 if (parameter
!= null) {
1188 String newString
= String
.valueOf(parameter
);
1190 if (parameter
.contains(" ")) { //$NON-NLS-1$
1191 newString
= "\"" + newString
+ "\""; //$NON-NLS-1$ //$NON-NLS-2$