1 /**********************************************************************
2 * Copyright (c) 2012, 2013 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 * Bernd Hufmann - Updated for support of LTTng Tools 2.1
12 * Simon Delisle - Updated for support of LTTng Tools 2.2
13 **********************************************************************/
14 package org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.service
;
16 import java
.util
.ArrayList
;
17 import java
.util
.Iterator
;
18 import java
.util
.List
;
19 import java
.util
.regex
.Matcher
;
21 import org
.eclipse
.core
.commands
.ExecutionException
;
22 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
23 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
24 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.IBaseEventInfo
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.IChannelInfo
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.IDomainInfo
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.IEventInfo
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.IFieldInfo
;
29 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.IProbeEventInfo
;
30 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.ISessionInfo
;
31 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.IUstProviderInfo
;
32 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.LogLevelType
;
33 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.TraceEventType
;
34 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.TraceLogLevel
;
35 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.BaseEventInfo
;
36 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.BufferType
;
37 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.ChannelInfo
;
38 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.DomainInfo
;
39 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.EventInfo
;
40 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.FieldInfo
;
41 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.ProbeEventInfo
;
42 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.SessionInfo
;
43 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.UstProviderInfo
;
44 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.logging
.ControlCommandLogger
;
45 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.messages
.Messages
;
46 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.preferences
.ControlPreferences
;
47 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.remote
.ICommandResult
;
48 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.remote
.ICommandShell
;
52 * Service for sending LTTng trace control commands to remote host.
55 * @author Bernd Hufmann
57 public class LTTngControlService
implements ILttngControlService
{
59 // ------------------------------------------------------------------------
61 // ------------------------------------------------------------------------
63 * The command shell implementation
65 private final ICommandShell fCommandShell
;
70 private LttngVersion fVersion
= null;
72 // ------------------------------------------------------------------------
74 // ------------------------------------------------------------------------
80 * - the command shell implementation to use
82 public LTTngControlService(ICommandShell shell
) {
83 fCommandShell
= shell
;
86 // ------------------------------------------------------------------------
88 // ------------------------------------------------------------------------
91 public String
getVersion() {
92 if (fVersion
== null) {
93 return "Unknown"; //$NON-NLS-1$
95 return fVersion
.toString();
99 * Sets the version of the LTTng 2.0 control service.
100 * @param version - a version to set
102 public void setVersion(String version
) {
103 fVersion
= new LttngVersion(version
);
107 public boolean isVersionSupported(String version
) {
108 LttngVersion tmp
= new LttngVersion(version
);
109 return (fVersion
!= null && fVersion
.compareTo(tmp
) >= 0) ?
true : false;
113 * Returns the command shell implementation.
115 * @return the command shell implementation
117 protected ICommandShell
getCommandShell() {
118 return fCommandShell
;
121 // ------------------------------------------------------------------------
123 // ------------------------------------------------------------------------
126 public String
[] getSessionNames(IProgressMonitor monitor
) throws ExecutionException
{
127 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST
);
129 ICommandResult result
= executeCommand(command
.toString(), monitor
);
132 // Available tracing sessions:
133 // 1) mysession1 (/home/user/lttng-traces/mysession1-20120123-083928) [inactive]
134 // 2) mysession (/home/user/lttng-traces/mysession-20120123-083318) [inactive]
136 // Use lttng list <session_name> for more details
138 ArrayList
<String
> retArray
= new ArrayList
<String
>();
140 while (index
< result
.getOutput().length
) {
141 String line
= result
.getOutput()[index
];
142 Matcher matcher
= LTTngControlServiceConstants
.SESSION_PATTERN
.matcher(line
);
143 if (matcher
.matches()) {
144 retArray
.add(matcher
.group(2).trim());
148 return retArray
.toArray(new String
[retArray
.size()]);
152 public ISessionInfo
getSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
153 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST
, sessionName
);
154 ICommandResult result
= executeCommand(command
.toString(), monitor
);
159 // Tracing session mysession2: [inactive]
160 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
161 ISessionInfo sessionInfo
= new SessionInfo(sessionName
);
163 while (index
< result
.getOutput().length
) {
164 // Tracing session mysession2: [inactive]
165 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
167 // === Domain: Kernel ===
169 String line
= result
.getOutput()[index
];
170 Matcher matcher
= LTTngControlServiceConstants
.TRACE_SESSION_PATTERN
.matcher(line
);
171 if (matcher
.matches()) {
172 sessionInfo
.setSessionState(matcher
.group(2));
177 matcher
= LTTngControlServiceConstants
.TRACE_NETWORK_PATH_PATTERN
.matcher(line
);
178 if (matcher
.matches()) {
179 sessionInfo
.setStreamedTrace(true);
182 matcher
= LTTngControlServiceConstants
.TRACE_SESSION_PATH_PATTERN
.matcher(line
);
183 if (matcher
.matches()) {
184 sessionInfo
.setSessionPath(matcher
.group(1).trim());
189 matcher
= LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(line
);
190 if (matcher
.matches()) {
192 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_KernelDomainDisplayName
);
195 domainInfo
.setIsKernel(true);
198 ArrayList
<IChannelInfo
> channels
= new ArrayList
<IChannelInfo
>();
199 index
= parseDomain(result
.getOutput(), index
, channels
, domainInfo
);
201 if (channels
.size() > 0) {
203 sessionInfo
.addDomain(domainInfo
);
206 domainInfo
.setChannels(channels
);
211 matcher
= LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
);
212 if (matcher
.matches()) {
213 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_UstGlobalDomainDisplayName
);
216 domainInfo
.setIsKernel(false);
219 ArrayList
<IChannelInfo
> channels
= new ArrayList
<IChannelInfo
>();
220 index
= parseDomain(result
.getOutput(), index
, channels
, domainInfo
);
222 if (channels
.size() > 0) {
224 sessionInfo
.addDomain(domainInfo
);
227 domainInfo
.setChannels(channels
);
237 public List
<IBaseEventInfo
> getKernelProvider(IProgressMonitor monitor
) throws ExecutionException
{
238 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST_KERNEL
);
239 ICommandResult result
= executeCommand(command
.toString(), monitor
, false);
241 List
<IBaseEventInfo
> events
= new ArrayList
<IBaseEventInfo
>();
243 if (result
.getOutput() != null) {
244 // Ignore the following 2 cases:
245 // Spawning a session daemon
246 // Error: Unable to list kernel events
248 // Error: Unable to list kernel events
251 while (index
< result
.getOutput().length
) {
252 String line
= result
.getOutput()[index
];
253 Matcher matcher
= LTTngControlServiceConstants
.LIST_KERNEL_NO_KERNEL_PROVIDER_PATTERN
.matcher(line
);
254 if (matcher
.matches()) {
261 if (isError(result
)) {
262 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$
267 // sched_kthread_stop (type: tracepoint)
268 getProviderEventInfo(result
.getOutput(), 0, events
);
273 public List
<IUstProviderInfo
> getUstProvider() throws ExecutionException
{
274 return getUstProvider(new NullProgressMonitor());
278 public List
<IUstProviderInfo
> getUstProvider(IProgressMonitor monitor
) throws ExecutionException
{
279 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST_UST
);
281 if (isVersionSupported("2.1.0")) { //$NON-NLS-1$
282 command
.append(LTTngControlServiceConstants
.OPTION_FIELDS
);
285 ICommandResult result
= executeCommand(command
.toString(), monitor
, false);
286 List
<IUstProviderInfo
> allProviders
= new ArrayList
<IUstProviderInfo
>();
288 // Workaround for versions 2.0.x which causes a segmentation fault for this command
289 // if LTTng Tools is compiled without UST support.
290 if (!isVersionSupported("2.1.0") && (result
.getResult() != 0)) { //$NON-NLS-1$
294 if (result
.getOutput() != null) {
295 // Ignore the following 2 cases:
296 // Spawning a session daemon
297 // Error: Unable to list UST events: Listing UST events failed
299 // Error: Unable to list UST events: Listing UST events failed
302 while (index
< result
.getOutput().length
) {
303 String line
= result
.getOutput()[index
];
304 Matcher matcher
= LTTngControlServiceConstants
.LIST_UST_NO_UST_PROVIDER_PATTERN
.matcher(line
);
305 if (matcher
.matches()) {
312 if (isError(result
)) {
313 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$
316 // Note that field print-outs exists for version >= 2.1.0
322 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
323 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
325 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
326 // field: doublefield (float)
327 // field: floatfield (float)
328 // field: stringfield (string)
331 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
332 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
334 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
335 // field: doublefield (float)
336 // field: floatfield (float)
337 // field: stringfield (string)
339 IUstProviderInfo provider
= null;
342 while (index
< result
.getOutput().length
) {
343 String line
= result
.getOutput()[index
];
344 Matcher matcher
= LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
);
345 if (matcher
.matches()) {
346 provider
= new UstProviderInfo(matcher
.group(2).trim());
347 provider
.setPid(Integer
.valueOf(matcher
.group(1).trim()));
348 List
<IBaseEventInfo
> events
= new ArrayList
<IBaseEventInfo
>();
349 index
= getProviderEventInfo(result
.getOutput(), ++index
, events
);
350 provider
.setEvents(events
);
351 allProviders
.add(provider
);
360 public ISessionInfo
createSession(String sessionName
, String sessionPath
, IProgressMonitor monitor
) throws ExecutionException
{
362 String newName
= formatParameter(sessionName
);
363 String newPath
= formatParameter(sessionPath
);
365 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_CREATE_SESSION
, newName
);
367 if (newPath
!= null && !"".equals(newPath
)) { //$NON-NLS-1$
368 command
.append(LTTngControlServiceConstants
.OPTION_OUTPUT_PATH
);
369 command
.append(newPath
);
372 ICommandResult result
= executeCommand(command
.toString(), monitor
);
374 //Session myssession2 created.
375 //Traces will be written in /home/user/lttng-traces/myssession2-20120209-095418
376 String
[] output
= result
.getOutput();
378 // Get and session name and path
383 while (index
< output
.length
) {
384 String line
= output
[index
];
385 Matcher nameMatcher
= LTTngControlServiceConstants
.CREATE_SESSION_NAME_PATTERN
.matcher(line
);
386 Matcher pathMatcher
= LTTngControlServiceConstants
.CREATE_SESSION_PATH_PATTERN
.matcher(line
);
387 if (nameMatcher
.matches()) {
388 name
= String
.valueOf(nameMatcher
.group(1).trim());
389 } else if (pathMatcher
.matches()) {
390 path
= String
.valueOf(pathMatcher
.group(1).trim());
395 // Verify session name
396 if ((name
== null) || (!"".equals(sessionName
) && !name
.equals(sessionName
))) { //$NON-NLS-1$
397 // Unexpected name returned
398 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
399 Messages
.TraceControl_UnexpectedNameError
+ ": " + name
); //$NON-NLS-1$
402 SessionInfo sessionInfo
= new SessionInfo(name
);
404 // Verify session path
405 if ((path
== null) || ((sessionPath
!= null) && (!path
.contains(sessionPath
)))) {
407 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
408 Messages
.TraceControl_UnexpectedPathError
+ ": " + name
); //$NON-NLS-1$
411 sessionInfo
.setSessionPath(path
);
418 public ISessionInfo
createSession(String sessionName
, String networkUrl
, String controlUrl
, String dataUrl
, IProgressMonitor monitor
) throws ExecutionException
{
420 String newName
= formatParameter(sessionName
);
421 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_CREATE_SESSION
, newName
);
423 if (networkUrl
!= null) {
424 command
.append(LTTngControlServiceConstants
.OPTION_NETWORK_URL
);
425 command
.append(networkUrl
);
427 command
.append(LTTngControlServiceConstants
.OPTION_CONTROL_URL
);
428 command
.append(controlUrl
);
430 command
.append(LTTngControlServiceConstants
.OPTION_DATA_URL
);
431 command
.append(dataUrl
);
434 ICommandResult result
= executeCommand(command
.toString(), monitor
);
437 String
[] output
= result
.getOutput();
439 // Get and session name and path
444 while (index
< output
.length
) {
445 String line
= output
[index
];
446 Matcher nameMatcher
= LTTngControlServiceConstants
.CREATE_SESSION_NAME_PATTERN
.matcher(line
);
447 Matcher pathMatcher
= LTTngControlServiceConstants
.CREATE_SESSION_PATH_PATTERN
.matcher(line
);
449 if (nameMatcher
.matches()) {
450 name
= String
.valueOf(nameMatcher
.group(1).trim());
451 } else if (pathMatcher
.matches() && (networkUrl
!= null)) {
452 path
= String
.valueOf(pathMatcher
.group(1).trim());
457 // Verify session name
458 if ((name
== null) || (!"".equals(sessionName
) && !name
.equals(sessionName
))) { //$NON-NLS-1$
459 // Unexpected name returned
460 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
461 Messages
.TraceControl_UnexpectedNameError
+ ": " + name
); //$NON-NLS-1$
464 SessionInfo sessionInfo
= new SessionInfo(name
);
466 sessionInfo
.setStreamedTrace(true);
468 // Verify session path
469 if (networkUrl
!= null) {
472 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
473 Messages
.TraceControl_UnexpectedPathError
+ ": " + name
); //$NON-NLS-1$
476 sessionInfo
.setSessionPath(path
);
478 // Check file protocol
479 Matcher matcher
= LTTngControlServiceConstants
.TRACE_FILE_PROTOCOL_PATTERN
.matcher(path
);
480 if (matcher
.matches()) {
481 sessionInfo
.setStreamedTrace(false);
484 // When using controlUrl and dataUrl the full session path is not known yet
485 // and will be set later on when listing the session
491 public void destroySession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
492 String newName
= formatParameter(sessionName
);
494 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_DESTROY_SESSION
, newName
);
496 ICommandResult result
= executeCommand(command
.toString(), monitor
, false);
497 String
[] output
= result
.getOutput();
499 boolean isError
= isError(result
);
500 if (isError
&& (output
!= null)) {
502 while (index
< output
.length
) {
503 String line
= output
[index
];
504 Matcher matcher
= LTTngControlServiceConstants
.SESSION_NOT_FOUND_ERROR_PATTERN
.matcher(line
);
505 if (matcher
.matches()) {
506 // Don't treat this as an error
514 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$
517 //Session <sessionName> destroyed
521 public void startSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
523 String newSessionName
= formatParameter(sessionName
);
525 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_START_SESSION
, newSessionName
);
527 executeCommand(command
.toString(), monitor
);
529 //Session <sessionName> started
533 public void stopSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
534 String newSessionName
= formatParameter(sessionName
);
535 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_STOP_SESSION
, newSessionName
);
537 executeCommand(command
.toString(), monitor
);
539 //Session <sessionName> stopped
544 public void enableChannels(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IChannelInfo info
, IProgressMonitor monitor
) throws ExecutionException
{
546 // no channels to enable
547 if (channelNames
.isEmpty()) {
551 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_CHANNEL
);
553 for (Iterator
<String
> iterator
= channelNames
.iterator(); iterator
.hasNext();) {
554 String channel
= iterator
.next();
555 command
.append(channel
);
556 if (iterator
.hasNext()) {
562 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
564 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
567 String newSessionName
= formatParameter(sessionName
);
568 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
569 command
.append(newSessionName
);
572 // --discard Discard event when buffers are full (default)
574 // --overwrite Flight recorder mode
575 if (info
.isOverwriteMode()) {
576 command
.append(LTTngControlServiceConstants
.OPTION_OVERWRITE
);
578 // --subbuf-size SIZE Subbuffer size in bytes
579 // (default: 4096, kernel default: 262144)
580 if (info
.getSubBufferSize() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
581 command
.append(LTTngControlServiceConstants
.OPTION_SUB_BUFFER_SIZE
);
582 command
.append(String
.valueOf(info
.getSubBufferSize()));
585 // --num-subbuf NUM Number of subbufers
586 if (info
.getNumberOfSubBuffers() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
587 command
.append(LTTngControlServiceConstants
.OPTION_NUM_SUB_BUFFERS
);
588 command
.append(String
.valueOf(info
.getNumberOfSubBuffers()));
591 // --switch-timer USEC Switch timer interval in usec
592 if (info
.getSwitchTimer() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
593 command
.append(LTTngControlServiceConstants
.OPTION_SWITCH_TIMER
);
594 command
.append(String
.valueOf(info
.getSwitchTimer()));
597 // --read-timer USEC Read timer interval in usec
598 if (info
.getReadTimer() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
599 command
.append(LTTngControlServiceConstants
.OPTION_READ_TIMER
);
600 command
.append(String
.valueOf(info
.getReadTimer()));
603 if (isVersionSupported("2.2.0")) { //$NON-NLS-1$
604 // --buffers-uid Every application sharing the same UID use the same buffers
605 // --buffers-pid Buffers are allocated per PID
607 if (info
.getBufferType() == BufferType
.BUFFER_PER_PID
) {
608 command
.append(LTTngControlServiceConstants
.OPTION_PER_PID_BUFFERS
);
610 } else if (info
.getBufferType() == BufferType
.BUFFER_PER_UID
) {
611 command
.append(LTTngControlServiceConstants
.OPTION_PER_UID_BUFFERS
);
615 // -C SIZE Maximum size of trace files in bytes
616 if (info
.getMaxSizeTraceFiles() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
617 command
.append(LTTngControlServiceConstants
.OPTION_MAX_SIZE_TRACE_FILES
);
618 command
.append(String
.valueOf(info
.getMaxSizeTraceFiles()));
621 // -W NUM Maximum number of trace files
622 if (info
.getMaxNumberTraceFiles() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
623 command
.append(LTTngControlServiceConstants
.OPTION_MAX_TRACE_FILES
);
624 command
.append(String
.valueOf(info
.getMaxNumberTraceFiles()));
629 executeCommand(command
.toString(), monitor
);
634 public void disableChannels(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
636 // no channels to enable
637 if (channelNames
.isEmpty()) {
641 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_DISABLE_CHANNEL
);
643 for (Iterator
<String
> iterator
= channelNames
.iterator(); iterator
.hasNext();) {
644 String channel
= iterator
.next();
645 command
.append(channel
);
646 if (iterator
.hasNext()) {
652 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
654 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
657 String newSessionName
= formatParameter(sessionName
);
658 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
659 command
.append(newSessionName
);
661 executeCommand(command
.toString(), monitor
);
665 public void enableEvents(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, String filterExpression
, IProgressMonitor monitor
) throws ExecutionException
{
667 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
669 if (eventNames
== null || eventNames
.isEmpty()) {
670 command
.append(LTTngControlServiceConstants
.OPTION_ALL
);
673 StringBuffer eventNameParameter
= new StringBuffer();
674 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
675 String event
= iterator
.next();
676 eventNameParameter
.append(event
);
677 if (iterator
.hasNext()) {
678 eventNameParameter
.append(',');
681 command
.append(formatParameter(eventNameParameter
.toString()));
685 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
687 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
690 String newSessionName
= formatParameter(sessionName
);
692 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
693 command
.append(newSessionName
);
695 if (channelName
!= null) {
696 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
697 command
.append(channelName
);
700 command
.append(LTTngControlServiceConstants
.OPTION_TRACEPOINT
);
702 if (filterExpression
!= null) {
703 command
.append(LTTngControlServiceConstants
.OPTION_FILTER
);
704 command
.append('\'');
705 command
.append(filterExpression
);
706 command
.append('\'');
709 executeCommand(command
.toString(), monitor
);
714 public void enableSyscalls(String sessionName
, String channelName
, IProgressMonitor monitor
) throws ExecutionException
{
716 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
718 command
.append(LTTngControlServiceConstants
.OPTION_ALL
);
719 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
721 String newSessionName
= formatParameter(sessionName
);
723 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
724 command
.append(newSessionName
);
726 if (channelName
!= null) {
727 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
728 command
.append(channelName
);
731 command
.append(LTTngControlServiceConstants
.OPTION_SYSCALL
);
733 executeCommand(command
.toString(), monitor
);
737 public void enableProbe(String sessionName
, String channelName
, String eventName
, boolean isFunction
, String probe
, IProgressMonitor monitor
) throws ExecutionException
{
738 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
740 command
.append(eventName
);
741 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
743 String newSessionName
= formatParameter(sessionName
);
744 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
745 command
.append(newSessionName
);
747 if (channelName
!= null) {
748 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
749 command
.append(channelName
);
752 command
.append(LTTngControlServiceConstants
.OPTION_FUNCTION_PROBE
);
754 command
.append(LTTngControlServiceConstants
.OPTION_PROBE
);
757 command
.append(probe
);
759 executeCommand(command
.toString(), monitor
);
763 public void enableLogLevel(String sessionName
, String channelName
, String eventName
, LogLevelType logLevelType
, TraceLogLevel level
, String filterExpression
, IProgressMonitor monitor
) throws ExecutionException
{
764 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
766 command
.append(eventName
);
767 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
769 String newSessionName
= formatParameter(sessionName
);
770 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
771 command
.append(newSessionName
);
773 if (channelName
!= null) {
774 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
775 command
.append(channelName
);
778 if (logLevelType
== LogLevelType
.LOGLEVEL
) {
779 command
.append(LTTngControlServiceConstants
.OPTION_LOGLEVEL
);
780 } else if (logLevelType
== LogLevelType
.LOGLEVEL_ONLY
) {
781 command
.append(LTTngControlServiceConstants
.OPTION_LOGLEVEL_ONLY
);
786 command
.append(level
.getInName());
788 executeCommand(command
.toString(), monitor
);
792 public void disableEvent(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
793 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_DISABLE_EVENT
);
795 if (eventNames
== null) {
796 command
.append(LTTngControlServiceConstants
.OPTION_ALL
);
798 // no events to disable
799 if (eventNames
.isEmpty()) {
803 StringBuffer eventNameParameter
= new StringBuffer();
804 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
805 String event
= iterator
.next();
806 eventNameParameter
.append(event
);
807 if (iterator
.hasNext()) {
808 eventNameParameter
.append(',');
811 command
.append(formatParameter(eventNameParameter
.toString()));
815 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
817 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
820 String newSessionName
= formatParameter(sessionName
);
821 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
822 command
.append(newSessionName
);
824 if (channelName
!= null) {
825 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
826 command
.append(channelName
);
829 executeCommand(command
.toString(), monitor
);
833 public List
<String
> getContextList(IProgressMonitor monitor
) throws ExecutionException
{
835 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ADD_CONTEXT
, LTTngControlServiceConstants
.OPTION_HELP
);
837 ICommandResult result
= executeCommand(command
.toString(), monitor
);
839 String
[] output
= result
.getOutput();
841 List
<String
> contexts
= new ArrayList
<String
>(0);
844 boolean inList
= false;
845 while (index
< output
.length
) {
846 String line
= result
.getOutput()[index
];
848 Matcher startMatcher
= LTTngControlServiceConstants
.ADD_CONTEXT_HELP_CONTEXTS_INTRO
.matcher(line
);
849 Matcher endMatcher
= LTTngControlServiceConstants
.ADD_CONTEXT_HELP_CONTEXTS_END_LINE
.matcher(line
);
851 if (startMatcher
.matches()) {
853 } else if (endMatcher
.matches()) {
855 } else if (inList
== true) {
856 String
[] tmp
= line
.split(","); //$NON-NLS-1$
857 for (int i
= 0; i
< tmp
.length
; i
++) {
858 contexts
.add(tmp
[i
].trim());
867 public void addContexts(String sessionName
, String channelName
, String eventName
, boolean isKernel
, List
<String
> contextNames
, IProgressMonitor monitor
) throws ExecutionException
{
868 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ADD_CONTEXT
);
870 String newSessionName
= formatParameter(sessionName
);
871 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
872 command
.append(newSessionName
);
874 if (channelName
!= null) {
875 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
876 command
.append(channelName
);
879 if (eventName
!= null) {
880 command
.append(LTTngControlServiceConstants
.OPTION_EVENT
);
881 command
.append(eventName
);
885 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
887 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
890 for (Iterator
<String
> iterator
= contextNames
.iterator(); iterator
.hasNext();) {
891 String context
= iterator
.next();
892 command
.append(LTTngControlServiceConstants
.OPTION_CONTEXT_TYPE
);
893 command
.append(context
);
896 executeCommand(command
.toString(), monitor
);
901 public void calibrate(boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
902 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_CALIBRATE
);
905 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
907 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
910 command
.append(LTTngControlServiceConstants
.OPTION_FUNCTION_PROBE
);
912 executeCommand(command
.toString(), monitor
);
915 // ------------------------------------------------------------------------
917 // ------------------------------------------------------------------------
920 * Checks if command result is an error result.
923 * - the command result to check
924 * @return true if error else false
926 protected boolean isError(ICommandResult result
) {
927 // Check return code and length of returned strings
928 if ((result
.getResult()) != 0 || (result
.getOutput().length
< 1)) {
932 // Look for error pattern
934 while (index
< result
.getOutput().length
) {
935 String line
= result
.getOutput()[index
];
936 Matcher matcher
= LTTngControlServiceConstants
.ERROR_PATTERN
.matcher(line
);
937 if (matcher
.matches()) {
947 * Formats the output string as single string.
951 * @return - the formatted output
953 public static String
formatOutput(ICommandResult result
) {
954 if ((result
== null) || result
.getOutput() == null || result
.getOutput().length
== 0) {
955 return ""; //$NON-NLS-1$
957 String
[] output
= result
.getOutput();
958 StringBuffer ret
= new StringBuffer();
959 ret
.append("Return Value: "); //$NON-NLS-1$
960 ret
.append(result
.getResult());
961 ret
.append("\n"); //$NON-NLS-1$
962 for (int i
= 0; i
< output
.length
; i
++) {
963 ret
.append(output
[i
]).append("\n"); //$NON-NLS-1$
965 return ret
.toString();
969 * Parses the domain information.
972 * - a command output array
973 * @param currentIndex
974 * - current index in command output array
976 * - list for returning channel information
978 * - The domain information
979 * @return the new current index in command output array
981 protected int parseDomain(String
[] output
, int currentIndex
, List
<IChannelInfo
> channels
, IDomainInfo domainInfo
) {
982 int index
= currentIndex
;
984 // if kernel set the buffer type to shared
985 if (domainInfo
.isKernel()) {
986 domainInfo
.setBufferType(BufferType
.BUFFER_SHARED
);
991 // - channnel1: [enabled]
995 // subbufers size: 262144
996 // number of subbufers: 4
997 // switch timer interval: 0
998 // read timer interval: 200
1001 while (index
< output
.length
) {
1002 String line
= output
[index
];
1004 if (isVersionSupported("2.2.0")) { //$NON-NLS-1$
1005 Matcher bufferTypeMatcher
= LTTngControlServiceConstants
.BUFFER_TYPE_PATTERN
.matcher(line
);
1006 if (bufferTypeMatcher
.matches()) {
1007 String bufferTypeString
= getAttributeValue(line
);
1008 if (BufferType
.BUFFER_PER_PID
.getInName().equals(bufferTypeString
)) {
1009 domainInfo
.setBufferType(BufferType
.BUFFER_PER_PID
);
1010 } else if (BufferType
.BUFFER_PER_UID
.getInName().equals(bufferTypeString
)) {
1011 domainInfo
.setBufferType(BufferType
.BUFFER_PER_UID
);
1013 domainInfo
.setBufferType(BufferType
.BUFFER_TYPE_UNKNOWN
);
1017 domainInfo
.setBufferType(BufferType
.BUFFER_TYPE_UNKNOWN
);
1019 Matcher outerMatcher
= LTTngControlServiceConstants
.CHANNELS_SECTION_PATTERN
.matcher(line
);
1020 Matcher noKernelChannelMatcher
= LTTngControlServiceConstants
.DOMAIN_NO_KERNEL_CHANNEL_PATTERN
.matcher(line
);
1021 Matcher noUstChannelMatcher
= LTTngControlServiceConstants
.DOMAIN_NO_UST_CHANNEL_PATTERN
.matcher(line
);
1022 if (outerMatcher
.matches()) {
1023 IChannelInfo channelInfo
= null;
1024 while (index
< output
.length
) {
1025 String subLine
= output
[index
];
1027 Matcher innerMatcher
= LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(subLine
);
1028 if (innerMatcher
.matches()) {
1029 channelInfo
= new ChannelInfo(""); //$NON-NLS-1$
1031 channelInfo
.setName(innerMatcher
.group(1));
1033 // get channel enablement
1034 channelInfo
.setState(innerMatcher
.group(2));
1037 channelInfo
.setBufferType(domainInfo
.getBufferType());
1040 channels
.add(channelInfo
);
1042 } else if (LTTngControlServiceConstants
.OVERWRITE_MODE_ATTRIBUTE
.matcher(subLine
).matches()) {
1043 String value
= getAttributeValue(subLine
);
1044 if (channelInfo
!= null) {
1045 channelInfo
.setOverwriteMode(!LTTngControlServiceConstants
.OVERWRITE_MODE_ATTRIBUTE_FALSE
.equals(value
));
1047 } else if (LTTngControlServiceConstants
.SUBBUFFER_SIZE_ATTRIBUTE
.matcher(subLine
).matches()) {
1048 if (channelInfo
!= null) {
1049 channelInfo
.setSubBufferSize(Long
.valueOf(getAttributeValue(subLine
)));
1052 } else if (LTTngControlServiceConstants
.NUM_SUBBUFFERS_ATTRIBUTE
.matcher(subLine
).matches()) {
1053 if (channelInfo
!= null) {
1054 channelInfo
.setNumberOfSubBuffers(Integer
.valueOf(getAttributeValue(subLine
)));
1057 } else if (LTTngControlServiceConstants
.SWITCH_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
1058 if (channelInfo
!= null) {
1059 channelInfo
.setSwitchTimer(Long
.valueOf(getAttributeValue(subLine
)));
1062 } else if (LTTngControlServiceConstants
.READ_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
1063 if (channelInfo
!= null) {
1064 channelInfo
.setReadTimer(Long
.valueOf(getAttributeValue(subLine
)));
1067 } else if (LTTngControlServiceConstants
.OUTPUT_ATTRIBUTE
.matcher(subLine
).matches()) {
1068 if (channelInfo
!= null) {
1069 channelInfo
.setOutputType(getAttributeValue(subLine
));
1072 } else if (LTTngControlServiceConstants
.EVENT_SECTION_PATTERN
.matcher(subLine
).matches()) {
1073 List
<IEventInfo
> events
= new ArrayList
<IEventInfo
>();
1074 index
= parseEvents(output
, index
, events
);
1075 if (channelInfo
!= null) {
1076 channelInfo
.setEvents(events
);
1078 // we want to stay at the current index to be able to
1081 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(subLine
).matches()) {
1084 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(subLine
).matches()) {
1089 } else if (noKernelChannelMatcher
.matches() || noUstChannelMatcher
.matches()) {
1090 // domain indicates that no channels were found -> return
1100 * Parses the event information within a domain.
1103 * - a command output array
1104 * @param currentIndex
1105 * - current index in command output array
1107 * - list for returning event information
1108 * @return the new current index in command output array
1110 protected int parseEvents(String
[] output
, int currentIndex
, List
<IEventInfo
> events
) {
1111 int index
= currentIndex
;
1113 while (index
< output
.length
) {
1114 String line
= output
[index
];
1115 if (LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(line
).matches()) {
1118 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(line
).matches()) {
1121 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
).matches()) {
1126 Matcher matcher
= LTTngControlServiceConstants
.EVENT_PATTERN
.matcher(line
);
1127 Matcher matcher2
= LTTngControlServiceConstants
.WILDCARD_EVENT_PATTERN
.matcher(line
);
1129 if (matcher
.matches()) {
1130 IEventInfo eventInfo
= new EventInfo(matcher
.group(1).trim());
1131 eventInfo
.setLogLevel(matcher
.group(2).trim());
1132 eventInfo
.setEventType(matcher
.group(3).trim());
1133 eventInfo
.setState(matcher
.group(4));
1134 String filter
= matcher
.group(5);
1135 if (filter
!= null) {
1136 filter
= filter
.substring(1, filter
.length() - 1); // remove '[' and ']'
1137 eventInfo
.setFilterExpression(filter
);
1139 events
.add(eventInfo
);
1141 } else if (matcher2
.matches()) {
1142 IEventInfo eventInfo
= new EventInfo(matcher2
.group(1).trim());
1143 eventInfo
.setLogLevel(TraceLogLevel
.LEVEL_UNKNOWN
);
1144 eventInfo
.setEventType(matcher2
.group(2).trim());
1145 eventInfo
.setState(matcher2
.group(3));
1146 String filter
= matcher2
.group(4);
1147 if (filter
!= null) {
1148 filter
= filter
.substring(1, filter
.length() - 1); // remove '[' and ']'
1149 eventInfo
.setFilterExpression(filter
);
1152 if (eventInfo
.getEventType() == TraceEventType
.PROBE
) {
1153 IProbeEventInfo probeEvent
= new ProbeEventInfo(eventInfo
.getName());
1154 probeEvent
.setLogLevel(eventInfo
.getLogLevel());
1155 probeEvent
.setEventType(eventInfo
.getEventType());
1156 probeEvent
.setState(eventInfo
.getState());
1158 // Overwrite eventinfo
1159 eventInfo
= probeEvent
;
1161 // myevent2 (type: probe) [enabled]
1163 // myevent0 (type: probe) [enabled]
1165 // symbol: init_post
1167 while (index
< output
.length
) {
1168 String probeLine
= output
[index
];
1170 Matcher addrMatcher
= LTTngControlServiceConstants
.PROBE_ADDRESS_PATTERN
.matcher(probeLine
);
1171 Matcher offsetMatcher
= LTTngControlServiceConstants
.PROBE_OFFSET_PATTERN
.matcher(probeLine
);
1172 Matcher symbolMatcher
= LTTngControlServiceConstants
.PROBE_SYMBOL_PATTERN
.matcher(probeLine
);
1173 if (addrMatcher
.matches()) {
1174 String addr
= addrMatcher
.group(2).trim();
1175 probeEvent
.setAddress(addr
);
1176 } else if (offsetMatcher
.matches()) {
1177 String offset
= offsetMatcher
.group(2).trim();
1178 probeEvent
.setOffset(offset
);
1179 } else if (symbolMatcher
.matches()) {
1180 String symbol
= symbolMatcher
.group(2).trim();
1181 probeEvent
.setSymbol(symbol
);
1182 } else if ((LTTngControlServiceConstants
.EVENT_PATTERN
.matcher(probeLine
).matches()) || (LTTngControlServiceConstants
.WILDCARD_EVENT_PATTERN
.matcher(probeLine
).matches())) {
1184 } else if (LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(probeLine
).matches()) {
1186 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(probeLine
).matches()) {
1189 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(probeLine
).matches()) {
1195 events
.add(eventInfo
);
1197 events
.add(eventInfo
);
1210 * Parses a line with attributes: <attribute Name>: <attribute value>
1213 * - attribute line to parse
1214 * @return the attribute value as string
1216 protected String
getAttributeValue(String line
) {
1217 String
[] temp
= line
.split("\\: "); //$NON-NLS-1$
1222 * Parses the event information within a provider.
1225 * - a command output array
1226 * @param currentIndex
1227 * - current index in command output array
1229 * - list for returning event information
1230 * @return the new current index in command output array
1232 protected int getProviderEventInfo(String
[] output
, int currentIndex
, List
<IBaseEventInfo
> events
) {
1233 int index
= currentIndex
;
1234 IBaseEventInfo eventInfo
= null;
1235 while (index
< output
.length
) {
1236 String line
= output
[index
];
1237 Matcher matcher
= LTTngControlServiceConstants
.PROVIDER_EVENT_PATTERN
.matcher(line
);
1238 if (matcher
.matches()) {
1239 // sched_kthread_stop (loglevel: TRACE_EMERG0) (type: tracepoint)
1240 eventInfo
= new BaseEventInfo(matcher
.group(1).trim());
1241 eventInfo
.setLogLevel(matcher
.group(2).trim());
1242 eventInfo
.setEventType(matcher
.group(3).trim());
1243 events
.add(eventInfo
);
1245 } else if (LTTngControlServiceConstants
.EVENT_FIELD_PATTERN
.matcher(line
).matches()) {
1246 if (eventInfo
!= null) {
1247 List
<IFieldInfo
> fields
= new ArrayList
<IFieldInfo
>();
1248 index
= getFieldInfo(output
, index
, fields
);
1249 eventInfo
.setFields(fields
);
1254 else if (LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
).matches()) {
1265 * Parse a field's information.
1268 * A command output array
1269 * @param currentIndex
1270 * The current index in the command output array
1272 * List for returning the field information
1273 * @return The new current index in the command output array
1275 protected int getFieldInfo(String
[] output
, int currentIndex
, List
<IFieldInfo
> fields
) {
1276 int index
= currentIndex
;
1277 IFieldInfo fieldInfo
= null;
1278 while (index
< output
.length
) {
1279 String line
= output
[index
];
1280 Matcher matcher
= LTTngControlServiceConstants
.EVENT_FIELD_PATTERN
.matcher(line
);
1281 if (matcher
.matches()) {
1282 // field: content (string)
1283 fieldInfo
= new FieldInfo(matcher
.group(2).trim());
1284 fieldInfo
.setFieldType(matcher
.group(3).trim());
1285 fields
.add(fieldInfo
);
1286 } else if (LTTngControlServiceConstants
.PROVIDER_EVENT_PATTERN
.matcher(line
).matches()) {
1288 } else if (LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
).matches()) {
1297 * Formats a command parameter for the command execution i.e. adds quotes
1298 * at the beginning and end if necessary.
1299 * @param parameter - parameter to format
1300 * @return formated parameter
1302 protected String
formatParameter(String parameter
) {
1303 if (parameter
!= null) {
1304 StringBuffer newString
= new StringBuffer();
1305 newString
.append(parameter
);
1307 if (parameter
.contains(" ") || parameter
.contains("*")) { //$NON-NLS-1$ //$NON-NLS-2$
1308 newString
.insert(0, "\""); //$NON-NLS-1$
1309 newString
.append("\""); //$NON-NLS-1$
1311 return newString
.toString();
1317 * @param strings array of string that makes up a command line
1318 * @return string buffer with created command line
1320 protected StringBuffer
createCommand(String
... strings
) {
1321 StringBuffer command
= new StringBuffer();
1322 command
.append(LTTngControlServiceConstants
.CONTROL_COMMAND
);
1323 command
.append(getTracingGroupOption());
1324 command
.append(getVerboseOption());
1325 for (String string
: strings
) {
1326 command
.append(string
);
1332 * @return the tracing group option if configured in the preferences
1334 protected String
getTracingGroupOption() {
1335 if (!ControlPreferences
.getInstance().isDefaultTracingGroup() && !ControlPreferences
.getInstance().getTracingGroup().equals("")) { //$NON-NLS-1$
1336 return LTTngControlServiceConstants
.OPTION_TRACING_GROUP
+ ControlPreferences
.getInstance().getTracingGroup();
1338 return ""; //$NON-NLS-1$
1342 * @return the verbose option as configured in the preferences
1344 protected String
getVerboseOption() {
1345 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1346 String level
= ControlPreferences
.getInstance().getVerboseLevel();
1347 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_VERBOSE
.equals(level
)) {
1348 return LTTngControlServiceConstants
.OPTION_VERBOSE
;
1350 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_V_VERBOSE
.equals(level
)) {
1351 return LTTngControlServiceConstants
.OPTION_VERY_VERBOSE
;
1353 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_V_V_VERBOSE
.equals(level
)) {
1354 return LTTngControlServiceConstants
.OPTION_VERY_VERY_VERBOSE
;
1357 return ""; //$NON-NLS-1$
1361 * Method that logs the command and command result if logging is enabled as
1362 * well as forwards the command execution to the shell.
1365 * - the command to execute
1367 * - a progress monitor
1368 * @return the command result
1369 * @throws ExecutionException
1370 * If the command fails
1372 protected ICommandResult
executeCommand(String command
,
1373 IProgressMonitor monitor
) throws ExecutionException
{
1374 return executeCommand(command
, monitor
, true);
1378 * Method that logs the command and command result if logging is enabled as
1379 * well as forwards the command execution to the shell.
1382 * - the command to execute
1384 * - a progress monitor
1385 * @param checkForError
1386 * - true to verify command result, else false
1387 * @return the command result
1388 * @throws ExecutionException
1389 * in case of error result
1391 protected ICommandResult
executeCommand(String command
,
1392 IProgressMonitor monitor
, boolean checkForError
)
1393 throws ExecutionException
{
1394 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1395 ControlCommandLogger
.log(command
);
1398 ICommandResult result
= fCommandShell
.executeCommand(
1399 command
.toString(), monitor
);
1401 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1402 ControlCommandLogger
.log(formatOutput(result
));
1405 if (checkForError
&& isError(result
)) {
1406 throw new ExecutionException(Messages
.TraceControl_CommandError
1407 + " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$