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 **********************************************************************/
13 package org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.service
;
15 import java
.util
.ArrayList
;
16 import java
.util
.Iterator
;
17 import java
.util
.List
;
18 import java
.util
.regex
.Matcher
;
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
.internal
.lttng2
.core
.control
.model
.IBaseEventInfo
;
24 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.IChannelInfo
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.IDomainInfo
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.IEventInfo
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.IFieldInfo
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.IProbeEventInfo
;
29 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.ISessionInfo
;
30 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.IUstProviderInfo
;
31 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.LogLevelType
;
32 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.TraceEventType
;
33 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.TraceLogLevel
;
34 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.BaseEventInfo
;
35 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.ChannelInfo
;
36 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.DomainInfo
;
37 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.EventInfo
;
38 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.FieldInfo
;
39 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.ProbeEventInfo
;
40 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.SessionInfo
;
41 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.UstProviderInfo
;
42 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.logging
.ControlCommandLogger
;
43 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.messages
.Messages
;
44 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.preferences
.ControlPreferences
;
45 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.remote
.ICommandResult
;
46 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.remote
.ICommandShell
;
47 import org
.osgi
.framework
.Version
;
51 * Service for sending LTTng trace control commands to remote host.
54 * @author Bernd Hufmann
56 public class LTTngControlService
implements ILttngControlService
{
58 // ------------------------------------------------------------------------
60 // ------------------------------------------------------------------------
62 * The command shell implementation
64 protected ICommandShell fCommandShell
= null;
69 protected Version fVersion
= null;
71 // ------------------------------------------------------------------------
73 // ------------------------------------------------------------------------
79 * - the command shell implementation to use
81 public LTTngControlService(ICommandShell shell
) {
82 fCommandShell
= shell
;
85 // ------------------------------------------------------------------------
87 // ------------------------------------------------------------------------
90 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#getVersion()
93 public String
getVersion() {
94 if (fVersion
== null) {
95 return "Unknown"; //$NON-NLS-1$
97 return fVersion
.toString();
101 * Sets the version of the LTTng 2.0 control service.
102 * @param version - a version to set
104 public void setVersion(String version
) {
105 fVersion
= new Version(version
);
110 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#isVersionSupported(java.lang.String)
113 public boolean isVersionSupported(String version
) {
114 Version tmp
= new Version(version
);
115 return (fVersion
!= null && fVersion
.compareTo(tmp
) >= 0) ?
true : false;
118 // ------------------------------------------------------------------------
120 // ------------------------------------------------------------------------
126 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
127 * #getSessionNames(org.eclipse.core.runtime.IProgressMonitor)
130 public String
[] getSessionNames(IProgressMonitor monitor
) throws ExecutionException
{
131 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST
);
133 ICommandResult result
= executeCommand(command
.toString(), monitor
);
136 // Available tracing sessions:
137 // 1) mysession1 (/home/user/lttng-traces/mysession1-20120123-083928) [inactive]
138 // 2) mysession (/home/user/lttng-traces/mysession-20120123-083318) [inactive]
140 // Use lttng list <session_name> for more details
142 ArrayList
<String
> retArray
= new ArrayList
<String
>();
144 while (index
< result
.getOutput().length
) {
145 String line
= result
.getOutput()[index
];
146 Matcher matcher
= LTTngControlServiceConstants
.SESSION_PATTERN
.matcher(line
);
147 if (matcher
.matches()) {
148 retArray
.add(matcher
.group(2).trim());
152 return retArray
.toArray(new String
[retArray
.size()]);
159 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
160 * #getSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
163 public ISessionInfo
getSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
164 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST
, sessionName
);
165 ICommandResult result
= executeCommand(command
.toString(), monitor
);
170 // Tracing session mysession2: [inactive]
171 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
172 ISessionInfo sessionInfo
= new SessionInfo(sessionName
);
174 while (index
< result
.getOutput().length
) {
175 // Tracing session mysession2: [inactive]
176 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
178 // === Domain: Kernel ===
180 String line
= result
.getOutput()[index
];
181 Matcher matcher
= LTTngControlServiceConstants
.TRACE_SESSION_PATTERN
.matcher(line
);
182 if (matcher
.matches()) {
183 sessionInfo
.setSessionState(matcher
.group(2));
188 matcher
= LTTngControlServiceConstants
.TRACE_NETWORK_PATH_PATTERN
.matcher(line
);
189 if (matcher
.matches()) {
190 sessionInfo
.setStreamedTrace(true);
193 matcher
= LTTngControlServiceConstants
.TRACE_SESSION_PATH_PATTERN
.matcher(line
);
194 if (matcher
.matches()) {
195 sessionInfo
.setSessionPath(matcher
.group(1).trim());
200 matcher
= LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(line
);
201 if (matcher
.matches()) {
203 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_KernelDomainDisplayName
);
206 ArrayList
<IChannelInfo
> channels
= new ArrayList
<IChannelInfo
>();
207 index
= parseDomain(result
.getOutput(), index
, channels
);
209 if (channels
.size() > 0) {
211 sessionInfo
.addDomain(domainInfo
);
214 domainInfo
.setChannels(channels
);
217 domainInfo
.setIsKernel(true);
222 matcher
= LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
);
223 if (matcher
.matches()) {
224 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_UstGlobalDomainDisplayName
);
227 ArrayList
<IChannelInfo
> channels
= new ArrayList
<IChannelInfo
>();
228 index
= parseDomain(result
.getOutput(), index
, channels
);
230 if (channels
.size() > 0) {
232 sessionInfo
.addDomain(domainInfo
);
235 domainInfo
.setChannels(channels
);
238 domainInfo
.setIsKernel(false);
251 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
252 * #getKernelProvider(org.eclipse.core.runtime.IProgressMonitor)
255 public List
<IBaseEventInfo
> getKernelProvider(IProgressMonitor monitor
) throws ExecutionException
{
256 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST_KERNEL
);
257 ICommandResult result
= executeCommand(command
.toString(), monitor
, false);
259 List
<IBaseEventInfo
> events
= new ArrayList
<IBaseEventInfo
>();
261 if (result
.getOutput() != null) {
262 // Ignore the following 2 cases:
263 // Spawning a session daemon
264 // Error: Unable to list kernel events
266 // Error: Unable to list kernel events
269 while (index
< result
.getOutput().length
) {
270 String line
= result
.getOutput()[index
];
271 Matcher matcher
= LTTngControlServiceConstants
.LIST_KERNEL_NO_KERNEL_PROVIDER_PATTERN
.matcher(line
);
272 if (matcher
.matches()) {
279 if (isError(result
)) {
280 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$
285 // sched_kthread_stop (type: tracepoint)
286 getProviderEventInfo(result
.getOutput(), 0, events
);
294 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
298 public List
<IUstProviderInfo
> getUstProvider() throws ExecutionException
{
299 return getUstProvider(new NullProgressMonitor());
306 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
307 * #getUstProvider(org.eclipse.core.runtime.IProgressMonitor)
310 public List
<IUstProviderInfo
> getUstProvider(IProgressMonitor monitor
) throws ExecutionException
{
311 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST_UST
);
313 if (isVersionSupported("2.1.0")) { //$NON-NLS-1$
314 command
.append(LTTngControlServiceConstants
.OPTION_FIELDS
);
317 ICommandResult result
= executeCommand(command
.toString(), monitor
);
319 // Note that field print-outs exists for version >= 2.1.0
325 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
326 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
328 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
329 // field: doublefield (float)
330 // field: floatfield (float)
331 // field: stringfield (string)
334 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
335 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
337 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
338 // field: doublefield (float)
339 // field: floatfield (float)
340 // field: stringfield (string)
342 List
<IUstProviderInfo
> allProviders
= new ArrayList
<IUstProviderInfo
>();
343 IUstProviderInfo provider
= null;
346 while (index
< result
.getOutput().length
) {
347 String line
= result
.getOutput()[index
];
348 Matcher matcher
= LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
);
349 if (matcher
.matches()) {
350 provider
= new UstProviderInfo(matcher
.group(2).trim());
351 provider
.setPid(Integer
.valueOf(matcher
.group(1).trim()));
352 List
<IBaseEventInfo
> events
= new ArrayList
<IBaseEventInfo
>();
353 index
= getProviderEventInfo(result
.getOutput(), ++index
, events
);
354 provider
.setEvents(events
);
355 allProviders
.add(provider
);
366 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#createSession(java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
369 public ISessionInfo
createSession(String sessionName
, String sessionPath
, IProgressMonitor monitor
) throws ExecutionException
{
371 String newName
= formatParameter(sessionName
);
372 String newPath
= formatParameter(sessionPath
);
374 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_CREATE_SESSION
, newName
);
376 if (newPath
!= null && !"".equals(newPath
)) { //$NON-NLS-1$
377 command
.append(LTTngControlServiceConstants
.OPTION_OUTPUT_PATH
);
378 command
.append(newPath
);
381 ICommandResult result
= executeCommand(command
.toString(), monitor
);
383 //Session myssession2 created.
384 //Traces will be written in /home/user/lttng-traces/myssession2-20120209-095418
385 String
[] output
= result
.getOutput();
387 // Get and session name and path
392 while (index
< output
.length
) {
393 String line
= output
[index
];
394 Matcher nameMatcher
= LTTngControlServiceConstants
.CREATE_SESSION_NAME_PATTERN
.matcher(line
);
395 Matcher pathMatcher
= LTTngControlServiceConstants
.CREATE_SESSION_PATH_PATTERN
.matcher(line
);
396 if (nameMatcher
.matches()) {
397 name
= String
.valueOf(nameMatcher
.group(1).trim());
398 } else if (pathMatcher
.matches()) {
399 path
= String
.valueOf(pathMatcher
.group(1).trim());
404 // Verify session name
405 if ((name
== null) || (!"".equals(sessionName
) && !name
.equals(sessionName
))) { //$NON-NLS-1$
406 // Unexpected name returned
407 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
408 Messages
.TraceControl_UnexpectedNameError
+ ": " + name
); //$NON-NLS-1$
411 SessionInfo sessionInfo
= new SessionInfo(name
);
413 // Verify session path
414 if ((path
== null) || ((sessionPath
!= null) && (!path
.contains(sessionPath
)))) {
416 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
417 Messages
.TraceControl_UnexpectedPathError
+ ": " + name
); //$NON-NLS-1$
420 sessionInfo
.setSessionPath(path
);
428 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#createSession(java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
431 public ISessionInfo
createSession(String sessionName
, String networkUrl
, String controlUrl
, String dataUrl
, IProgressMonitor monitor
) throws ExecutionException
{
433 String newName
= formatParameter(sessionName
);
434 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_CREATE_SESSION
, newName
);
436 if (networkUrl
!= null) {
437 command
.append(LTTngControlServiceConstants
.OPTION_NETWORK_URL
);
438 command
.append(networkUrl
);
440 command
.append(LTTngControlServiceConstants
.OPTION_CONTROL_URL
);
441 command
.append(controlUrl
);
443 command
.append(LTTngControlServiceConstants
.OPTION_DATA_URL
);
444 command
.append(dataUrl
);
447 ICommandResult result
= executeCommand(command
.toString(), monitor
);
450 String
[] output
= result
.getOutput();
452 // Get and session name and path
457 while (index
< output
.length
) {
458 String line
= output
[index
];
459 Matcher nameMatcher
= LTTngControlServiceConstants
.CREATE_SESSION_NAME_PATTERN
.matcher(line
);
460 Matcher pathMatcher
= LTTngControlServiceConstants
.CREATE_SESSION_PATH_PATTERN
.matcher(line
);
462 if (nameMatcher
.matches()) {
463 name
= String
.valueOf(nameMatcher
.group(1).trim());
464 } else if (pathMatcher
.matches() && (networkUrl
!= null)) {
465 path
= String
.valueOf(pathMatcher
.group(1).trim());
470 // Verify session name
471 if ((name
== null) || (!"".equals(sessionName
) && !name
.equals(sessionName
))) { //$NON-NLS-1$
472 // Unexpected name returned
473 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
474 Messages
.TraceControl_UnexpectedNameError
+ ": " + name
); //$NON-NLS-1$
477 SessionInfo sessionInfo
= new SessionInfo(name
);
479 sessionInfo
.setStreamedTrace(true);
481 // Verify session path
482 if (networkUrl
!= null) {
485 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
486 Messages
.TraceControl_UnexpectedPathError
+ ": " + name
); //$NON-NLS-1$
489 sessionInfo
.setSessionPath(path
);
491 // Check file protocol
492 Matcher matcher
= LTTngControlServiceConstants
.TRACE_FILE_PROTOCOL_PATTERN
.matcher(path
);
493 if (matcher
.matches()) {
494 sessionInfo
.setStreamedTrace(false);
497 // When using controlUrl and dataUrl the full session path is not known yet
498 // and will be set later on when listing the session
504 public void destroySession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
505 String newName
= formatParameter(sessionName
);
507 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_DESTROY_SESSION
, newName
);
509 ICommandResult result
= executeCommand(command
.toString(), monitor
, false);
510 String
[] output
= result
.getOutput();
512 boolean isError
= isError(result
);
513 if (isError
&& (output
!= null)) {
515 while (index
< output
.length
) {
516 String line
= output
[index
];
517 Matcher matcher
= LTTngControlServiceConstants
.SESSION_NOT_FOUND_ERROR_PATTERN
.matcher(line
);
518 if (matcher
.matches()) {
519 // Don't treat this as an error
527 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$
530 //Session <sessionName> destroyed
535 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#startSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
538 public void startSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
540 String newSessionName
= formatParameter(sessionName
);
542 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_START_SESSION
, newSessionName
);
544 executeCommand(command
.toString(), monitor
);
546 //Session <sessionName> started
551 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#stopSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
554 public void stopSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
555 String newSessionName
= formatParameter(sessionName
);
556 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_STOP_SESSION
, newSessionName
);
558 executeCommand(command
.toString(), monitor
);
560 //Session <sessionName> stopped
566 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#enableChannel(java.lang.String, java.util.List, boolean, org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo, org.eclipse.core.runtime.IProgressMonitor)
569 public void enableChannels(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IChannelInfo info
, IProgressMonitor monitor
) throws ExecutionException
{
571 // no channels to enable
572 if (channelNames
.isEmpty()) {
576 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_CHANNEL
);
578 for (Iterator
<String
> iterator
= channelNames
.iterator(); iterator
.hasNext();) {
579 String channel
= iterator
.next();
580 command
.append(channel
);
581 if (iterator
.hasNext()) {
587 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
589 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
592 String newSessionName
= formatParameter(sessionName
);
593 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
594 command
.append(newSessionName
);
597 // --discard Discard event when buffers are full (default)
599 // --overwrite Flight recorder mode
600 if (info
.isOverwriteMode()) {
601 command
.append(LTTngControlServiceConstants
.OPTION_OVERWRITE
);
603 // --subbuf-size SIZE Subbuffer size in bytes
604 // (default: 4096, kernel default: 262144)
605 command
.append(LTTngControlServiceConstants
.OPTION_SUB_BUFFER_SIZE
);
606 command
.append(String
.valueOf(info
.getSubBufferSize()));
608 // --num-subbuf NUM Number of subbufers
609 // (default: 8, kernel default: 4)
610 command
.append(LTTngControlServiceConstants
.OPTION_NUM_SUB_BUFFERS
);
611 command
.append(String
.valueOf(info
.getNumberOfSubBuffers()));
613 // --switch-timer USEC Switch timer interval in usec (default: 0)
614 command
.append(LTTngControlServiceConstants
.OPTION_SWITCH_TIMER
);
615 command
.append(String
.valueOf(info
.getSwitchTimer()));
617 // --read-timer USEC Read timer interval in usec (default: 200)
618 command
.append(LTTngControlServiceConstants
.OPTION_READ_TIMER
);
619 command
.append(String
.valueOf(info
.getReadTimer()));
622 executeCommand(command
.toString(), monitor
);
628 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#disableChannel(java.lang.String, java.util.List, org.eclipse.core.runtime.IProgressMonitor)
631 public void disableChannels(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
633 // no channels to enable
634 if (channelNames
.isEmpty()) {
638 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_DISABLE_CHANNEL
);
640 for (Iterator
<String
> iterator
= channelNames
.iterator(); iterator
.hasNext();) {
641 String channel
= iterator
.next();
642 command
.append(channel
);
643 if (iterator
.hasNext()) {
649 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
651 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
654 String newSessionName
= formatParameter(sessionName
);
655 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
656 command
.append(newSessionName
);
658 executeCommand(command
.toString(), monitor
);
663 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#enableEvents(java.lang.String, java.lang.String, java.util.List, boolean, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
666 public void enableEvents(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, String filterExpression
, IProgressMonitor monitor
) throws ExecutionException
{
668 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
670 if (eventNames
== null || eventNames
.isEmpty()) {
671 command
.append(LTTngControlServiceConstants
.OPTION_ALL
);
674 StringBuffer eventNameParameter
= new StringBuffer();
675 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
676 String event
= iterator
.next();
677 eventNameParameter
.append(event
);
678 if (iterator
.hasNext()) {
679 eventNameParameter
.append(',');
682 command
.append(formatParameter(eventNameParameter
.toString()));
686 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
688 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
691 String newSessionName
= formatParameter(sessionName
);
693 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
694 command
.append(newSessionName
);
696 if (channelName
!= null) {
697 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
698 command
.append(channelName
);
701 command
.append(LTTngControlServiceConstants
.OPTION_TRACEPOINT
);
703 if (filterExpression
!= null) {
704 command
.append(LTTngControlServiceConstants
.OPTION_FILTER
);
705 command
.append('\'');
706 command
.append(filterExpression
);
707 command
.append('\'');
710 executeCommand(command
.toString(), monitor
);
716 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#enableSyscalls(java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
719 public void enableSyscalls(String sessionName
, String channelName
, IProgressMonitor monitor
) throws ExecutionException
{
721 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
723 command
.append(LTTngControlServiceConstants
.OPTION_ALL
);
724 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
726 String newSessionName
= formatParameter(sessionName
);
728 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
729 command
.append(newSessionName
);
731 if (channelName
!= null) {
732 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
733 command
.append(channelName
);
736 command
.append(LTTngControlServiceConstants
.OPTION_SYSCALL
);
738 executeCommand(command
.toString(), monitor
);
743 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#enableProbe(java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
746 public void enableProbe(String sessionName
, String channelName
, String eventName
, boolean isFunction
, String probe
, IProgressMonitor monitor
) throws ExecutionException
{
747 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
749 command
.append(eventName
);
750 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
752 String newSessionName
= formatParameter(sessionName
);
753 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
754 command
.append(newSessionName
);
756 if (channelName
!= null) {
757 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
758 command
.append(channelName
);
761 command
.append(LTTngControlServiceConstants
.OPTION_FUNCTION_PROBE
);
763 command
.append(LTTngControlServiceConstants
.OPTION_PROBE
);
766 command
.append(probe
);
768 executeCommand(command
.toString(), monitor
);
773 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#enableLogLevel(java.lang.String, java.lang.String, java.lang.String, org.eclipse.linuxtools.internal.lttng2.core.control.model.LogLevelType, org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceLogLevel, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
776 public void enableLogLevel(String sessionName
, String channelName
, String eventName
, LogLevelType logLevelType
, TraceLogLevel level
, String filterExpression
, IProgressMonitor monitor
) throws ExecutionException
{
777 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
779 command
.append(eventName
);
780 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
782 String newSessionName
= formatParameter(sessionName
);
783 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
784 command
.append(newSessionName
);
786 if (channelName
!= null) {
787 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
788 command
.append(channelName
);
791 if (logLevelType
== LogLevelType
.LOGLEVEL
) {
792 command
.append(LTTngControlServiceConstants
.OPTION_LOGLEVEL
);
793 } else if (logLevelType
== LogLevelType
.LOGLEVEL_ONLY
) {
794 command
.append(LTTngControlServiceConstants
.OPTION_LOGLEVEL_ONLY
);
799 command
.append(level
.getInName());
801 executeCommand(command
.toString(), monitor
);
808 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#disableEvent(java.lang.String, java.lang.String, java.util.List, boolean, org.eclipse.core.runtime.IProgressMonitor)
811 public void disableEvent(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
812 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_DISABLE_EVENT
);
814 if (eventNames
== null) {
815 command
.append(LTTngControlServiceConstants
.OPTION_ALL
);
817 // no events to disable
818 if (eventNames
.isEmpty()) {
822 StringBuffer eventNameParameter
= new StringBuffer();
823 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
824 String event
= iterator
.next();
825 eventNameParameter
.append(event
);
826 if (iterator
.hasNext()) {
827 eventNameParameter
.append(',');
830 command
.append(formatParameter(eventNameParameter
.toString()));
834 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
836 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
839 String newSessionName
= formatParameter(sessionName
);
840 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
841 command
.append(newSessionName
);
843 if (channelName
!= null) {
844 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
845 command
.append(channelName
);
848 executeCommand(command
.toString(), monitor
);
853 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#getContexts(org.eclipse.core.runtime.IProgressMonitor)
856 public List
<String
> getContextList(IProgressMonitor monitor
) throws ExecutionException
{
858 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ADD_CONTEXT
, LTTngControlServiceConstants
.OPTION_HELP
);
860 ICommandResult result
= executeCommand(command
.toString(), monitor
);
862 String
[] output
= result
.getOutput();
864 List
<String
> contexts
= new ArrayList
<String
>(0);
867 boolean inList
= false;
868 while (index
< output
.length
) {
869 String line
= result
.getOutput()[index
];
871 Matcher startMatcher
= LTTngControlServiceConstants
.ADD_CONTEXT_HELP_CONTEXTS_INTRO
.matcher(line
);
872 Matcher endMatcher
= LTTngControlServiceConstants
.ADD_CONTEXT_HELP_CONTEXTS_END_LINE
.matcher(line
);
874 if (startMatcher
.matches()) {
876 } else if (endMatcher
.matches()) {
878 } else if (inList
== true) {
879 String
[] tmp
= line
.split(","); //$NON-NLS-1$
880 for (int i
= 0; i
< tmp
.length
; i
++) {
881 contexts
.add(tmp
[i
].trim());
891 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#addContexts(java.lang.String, java.lang.String, java.lang.String, boolean, java.util.List, org.eclipse.core.runtime.IProgressMonitor)
894 public void addContexts(String sessionName
, String channelName
, String eventName
, boolean isKernel
, List
<String
> contextNames
, IProgressMonitor monitor
) throws ExecutionException
{
895 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ADD_CONTEXT
);
897 String newSessionName
= formatParameter(sessionName
);
898 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
899 command
.append(newSessionName
);
901 if (channelName
!= null) {
902 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
903 command
.append(channelName
);
906 if (eventName
!= null) {
907 command
.append(LTTngControlServiceConstants
.OPTION_EVENT
);
908 command
.append(eventName
);
912 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
914 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
917 for (Iterator
<String
> iterator
= contextNames
.iterator(); iterator
.hasNext();) {
918 String context
= iterator
.next();
919 command
.append(LTTngControlServiceConstants
.OPTION_CONTEXT_TYPE
);
920 command
.append(context
);
923 executeCommand(command
.toString(), monitor
);
929 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#calibrate(boolean, org.eclipse.core.runtime.IProgressMonitor)
932 public void calibrate(boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
933 // String newSessionName = formatParameter(sessionName);
934 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_CALIBRATE
);
936 // command.append(OPTION_SESSION);
937 // command.append(newSessionName);
940 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
942 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
945 command
.append(LTTngControlServiceConstants
.OPTION_FUNCTION_PROBE
);
947 executeCommand(command
.toString(), monitor
);
950 // ------------------------------------------------------------------------
952 // ------------------------------------------------------------------------
954 * Checks if command result is an error result.
957 * - the command result to check
958 * @return true if error else false
960 protected boolean isError(ICommandResult result
) {
961 // Check return code and length of returned strings
962 if ((result
.getResult()) != 0 || (result
.getOutput().length
< 1)) {
966 // Look for error pattern
968 while (index
< result
.getOutput().length
) {
969 String line
= result
.getOutput()[index
];
970 Matcher matcher
= LTTngControlServiceConstants
.ERROR_PATTERN
.matcher(line
);
971 if (matcher
.matches()) {
981 * Formats the output string as single string.
985 * @return - the formatted output
987 public static String
formatOutput(ICommandResult result
) {
988 if ((result
== null) || result
.getOutput() == null || result
.getOutput().length
== 0) {
989 return ""; //$NON-NLS-1$
991 String
[] output
= result
.getOutput();
992 StringBuffer ret
= new StringBuffer();
993 ret
.append("Return Value: "); //$NON-NLS-1$
994 ret
.append(result
.getResult());
995 ret
.append("\n"); //$NON-NLS-1$
996 for (int i
= 0; i
< output
.length
; i
++) {
997 ret
.append(output
[i
] + "\n"); //$NON-NLS-1$
999 return ret
.toString();
1003 * Parses the domain information.
1006 * - a command output array
1007 * @param currentIndex
1008 * - current index in command output array
1010 * - list for returning channel information
1011 * @return the new current index in command output array
1013 protected int parseDomain(String
[] output
, int currentIndex
, List
<IChannelInfo
> channels
) {
1014 int index
= currentIndex
;
1018 // - channnel1: [enabled]
1021 // overwrite mode: 0
1022 // subbufers size: 262144
1023 // number of subbufers: 4
1024 // switch timer interval: 0
1025 // read timer interval: 200
1028 while (index
< output
.length
) {
1029 String line
= output
[index
];
1031 Matcher outerMatcher
= LTTngControlServiceConstants
.CHANNELS_SECTION_PATTERN
.matcher(line
);
1032 Matcher noKernelChannelMatcher
= LTTngControlServiceConstants
.DOMAIN_NO_KERNEL_CHANNEL_PATTERN
.matcher(line
);
1033 Matcher noUstChannelMatcher
= LTTngControlServiceConstants
.DOMAIN_NO_UST_CHANNEL_PATTERN
.matcher(line
);
1034 if (outerMatcher
.matches()) {
1035 IChannelInfo channelInfo
= null;
1036 while (index
< output
.length
) {
1037 String subLine
= output
[index
];
1039 Matcher innerMatcher
= LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(subLine
);
1040 if (innerMatcher
.matches()) {
1041 channelInfo
= new ChannelInfo(""); //$NON-NLS-1$
1043 channelInfo
.setName(innerMatcher
.group(1));
1045 // get channel enablement
1046 channelInfo
.setState(innerMatcher
.group(2));
1049 channels
.add(channelInfo
);
1051 } else if (LTTngControlServiceConstants
.OVERWRITE_MODE_ATTRIBUTE
.matcher(subLine
).matches()) {
1052 String value
= getAttributeValue(subLine
);
1053 if (channelInfo
!= null) {
1054 channelInfo
.setOverwriteMode(!LTTngControlServiceConstants
.OVERWRITE_MODE_ATTRIBUTE_FALSE
.equals(value
));
1056 } else if (LTTngControlServiceConstants
.SUBBUFFER_SIZE_ATTRIBUTE
.matcher(subLine
).matches()) {
1057 if (channelInfo
!= null) {
1058 channelInfo
.setSubBufferSize(Long
.valueOf(getAttributeValue(subLine
)));
1061 } else if (LTTngControlServiceConstants
.NUM_SUBBUFFERS_ATTRIBUTE
.matcher(subLine
).matches()) {
1062 if (channelInfo
!= null) {
1063 channelInfo
.setNumberOfSubBuffers(Integer
.valueOf(getAttributeValue(subLine
)));
1066 } else if (LTTngControlServiceConstants
.SWITCH_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
1067 if (channelInfo
!= null) {
1068 channelInfo
.setSwitchTimer(Long
.valueOf(getAttributeValue(subLine
)));
1071 } else if (LTTngControlServiceConstants
.READ_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
1072 if (channelInfo
!= null) {
1073 channelInfo
.setReadTimer(Long
.valueOf(getAttributeValue(subLine
)));
1076 } else if (LTTngControlServiceConstants
.OUTPUT_ATTRIBUTE
.matcher(subLine
).matches()) {
1077 if (channelInfo
!= null) {
1078 channelInfo
.setOutputType(getAttributeValue(subLine
));
1081 } else if (LTTngControlServiceConstants
.EVENT_SECTION_PATTERN
.matcher(subLine
).matches()) {
1082 List
<IEventInfo
> events
= new ArrayList
<IEventInfo
>();
1083 index
= parseEvents(output
, index
, events
);
1084 if (channelInfo
!= null) {
1085 channelInfo
.setEvents(events
);
1087 // we want to stay at the current index to be able to
1090 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(subLine
).matches()) {
1093 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(subLine
).matches()) {
1098 } else if (noKernelChannelMatcher
.matches() || noUstChannelMatcher
.matches()) {
1099 // domain indicates that no channels were found -> return
1109 * Parses the event information within a domain.
1112 * - a command output array
1113 * @param currentIndex
1114 * - current index in command output array
1116 * - list for returning event information
1117 * @return the new current index in command output array
1119 protected int parseEvents(String
[] output
, int currentIndex
, List
<IEventInfo
> events
) {
1120 int index
= currentIndex
;
1122 while (index
< output
.length
) {
1123 String line
= output
[index
];
1124 if (LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(line
).matches()) {
1127 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(line
).matches()) {
1130 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
).matches()) {
1135 Matcher matcher
= LTTngControlServiceConstants
.EVENT_PATTERN
.matcher(line
);
1136 Matcher matcher2
= LTTngControlServiceConstants
.WILDCARD_EVENT_PATTERN
.matcher(line
);
1138 if (matcher
.matches()) {
1139 IEventInfo eventInfo
= new EventInfo(matcher
.group(1).trim());
1140 eventInfo
.setLogLevel(matcher
.group(2).trim());
1141 eventInfo
.setEventType(matcher
.group(3).trim());
1142 eventInfo
.setState(matcher
.group(4));
1143 String filter
= matcher
.group(5);
1144 if (filter
!= null) {
1145 filter
= filter
.substring(1, filter
.length() - 1); // remove '[' and ']'
1146 eventInfo
.setFilterExpression(filter
);
1148 events
.add(eventInfo
);
1150 } else if (matcher2
.matches()) {
1151 IEventInfo eventInfo
= new EventInfo(matcher2
.group(1).trim());
1152 eventInfo
.setLogLevel(TraceLogLevel
.LEVEL_UNKNOWN
);
1153 eventInfo
.setEventType(matcher2
.group(2).trim());
1154 eventInfo
.setState(matcher2
.group(3));
1155 String filter
= matcher2
.group(4);
1156 if (filter
!= null) {
1157 filter
= filter
.substring(1, filter
.length() - 1); // remove '[' and ']'
1158 eventInfo
.setFilterExpression(filter
);
1161 if (eventInfo
.getEventType() == TraceEventType
.PROBE
) {
1162 IProbeEventInfo probeEvent
= new ProbeEventInfo(eventInfo
.getName());
1163 probeEvent
.setLogLevel(eventInfo
.getLogLevel());
1164 probeEvent
.setEventType(eventInfo
.getEventType());
1165 probeEvent
.setState(eventInfo
.getState());
1167 // Overwrite eventinfo
1168 eventInfo
= probeEvent
;
1170 // myevent2 (type: probe) [enabled]
1172 // myevent0 (type: probe) [enabled]
1174 // symbol: init_post
1176 while (index
< output
.length
) {
1177 String probeLine
= output
[index
];
1179 Matcher addrMatcher
= LTTngControlServiceConstants
.PROBE_ADDRESS_PATTERN
.matcher(probeLine
);
1180 Matcher offsetMatcher
= LTTngControlServiceConstants
.PROBE_OFFSET_PATTERN
.matcher(probeLine
);
1181 Matcher symbolMatcher
= LTTngControlServiceConstants
.PROBE_SYMBOL_PATTERN
.matcher(probeLine
);
1182 if (addrMatcher
.matches()) {
1183 String addr
= addrMatcher
.group(2).trim();
1184 probeEvent
.setAddress(addr
);
1185 } else if (offsetMatcher
.matches()) {
1186 String offset
= offsetMatcher
.group(2).trim();
1187 probeEvent
.setOffset(offset
);
1188 } else if (symbolMatcher
.matches()) {
1189 String symbol
= symbolMatcher
.group(2).trim();
1190 probeEvent
.setSymbol(symbol
);
1191 } else if ((LTTngControlServiceConstants
.EVENT_PATTERN
.matcher(probeLine
).matches()) || (LTTngControlServiceConstants
.WILDCARD_EVENT_PATTERN
.matcher(probeLine
).matches())) {
1193 } else if (LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(probeLine
).matches()) {
1195 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(probeLine
).matches()) {
1198 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(probeLine
).matches()) {
1204 events
.add(eventInfo
);
1206 events
.add(eventInfo
);
1213 // else if (line.matches(EVENT_NONE_PATTERN)) {
1223 * Parses a line with attributes: <attribute Name>: <attribute value>
1226 * - attribute line to parse
1227 * @return the attribute value as string
1229 protected String
getAttributeValue(String line
) {
1230 String
[] temp
= line
.split("\\: "); //$NON-NLS-1$
1235 * Parses the event information within a provider.
1238 * - a command output array
1239 * @param currentIndex
1240 * - current index in command output array
1242 * - list for returning event information
1243 * @return the new current index in command output array
1245 protected int getProviderEventInfo(String
[] output
, int currentIndex
, List
<IBaseEventInfo
> events
) {
1246 int index
= currentIndex
;
1247 IBaseEventInfo eventInfo
= null;
1248 while (index
< output
.length
) {
1249 String line
= output
[index
];
1250 Matcher matcher
= LTTngControlServiceConstants
.PROVIDER_EVENT_PATTERN
.matcher(line
);
1251 if (matcher
.matches()) {
1252 // sched_kthread_stop (loglevel: TRACE_EMERG0) (type: tracepoint)
1253 eventInfo
= new BaseEventInfo(matcher
.group(1).trim());
1254 eventInfo
.setLogLevel(matcher
.group(2).trim());
1255 eventInfo
.setEventType(matcher
.group(3).trim());
1256 events
.add(eventInfo
);
1258 } else if (LTTngControlServiceConstants
.EVENT_FIELD_PATTERN
.matcher(line
).matches()) {
1259 if (eventInfo
!= null) {
1260 List
<IFieldInfo
> fields
= new ArrayList
<IFieldInfo
>();
1261 index
= getFieldInfo(output
, index
, fields
);
1262 eventInfo
.setFields(fields
);
1267 else if (LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
).matches()) {
1278 * Parse a field's information.
1281 * A command output array
1282 * @param currentIndex
1283 * The current index in the command output array
1285 * List for returning the field information
1286 * @return The new current index in the command output array
1288 protected int getFieldInfo(String
[] output
, int currentIndex
, List
<IFieldInfo
> fields
) {
1289 int index
= currentIndex
;
1290 IFieldInfo fieldInfo
= null;
1291 while (index
< output
.length
) {
1292 String line
= output
[index
];
1293 Matcher matcher
= LTTngControlServiceConstants
.EVENT_FIELD_PATTERN
.matcher(line
);
1294 if (matcher
.matches()) {
1295 // field: content (string)
1296 fieldInfo
= new FieldInfo(matcher
.group(2).trim());
1297 fieldInfo
.setFieldType(matcher
.group(3).trim());
1298 fields
.add(fieldInfo
);
1299 } else if (LTTngControlServiceConstants
.PROVIDER_EVENT_PATTERN
.matcher(line
).matches()) {
1301 } else if (LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
).matches()) {
1310 * Formats a command parameter for the command execution i.e. adds quotes
1311 * at the beginning and end if necessary.
1312 * @param parameter - parameter to format
1313 * @return formated parameter
1315 protected String
formatParameter(String parameter
) {
1316 if (parameter
!= null) {
1317 StringBuffer newString
= new StringBuffer();
1318 newString
.append(parameter
);
1320 if (parameter
.contains(" ") || parameter
.contains("*")) { //$NON-NLS-1$ //$NON-NLS-2$
1321 newString
.insert(0, "\""); //$NON-NLS-1$
1322 newString
.append("\""); //$NON-NLS-1$
1324 return newString
.toString();
1330 * @param strings array of string that makes up a command line
1331 * @return string buffer with created command line
1333 protected StringBuffer
createCommand(String
... strings
) {
1334 StringBuffer command
= new StringBuffer();
1335 command
.append(LTTngControlServiceConstants
.CONTROL_COMMAND
);
1336 command
.append(getTracingGroupOption());
1337 command
.append(getVerboseOption());
1338 for (String string
: strings
) {
1339 command
.append(string
);
1345 * @return the tracing group option if configured in the preferences
1347 protected String
getTracingGroupOption() {
1348 if (!ControlPreferences
.getInstance().isDefaultTracingGroup() && !ControlPreferences
.getInstance().getTracingGroup().equals("")) { //$NON-NLS-1$
1349 return LTTngControlServiceConstants
.OPTION_TRACING_GROUP
+ ControlPreferences
.getInstance().getTracingGroup();
1351 return ""; //$NON-NLS-1$
1355 * @return the verbose option as configured in the preferences
1357 protected String
getVerboseOption() {
1358 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1359 String level
= ControlPreferences
.getInstance().getVerboseLevel();
1360 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_VERBOSE
.equals(level
)) {
1361 return LTTngControlServiceConstants
.OPTION_VERBOSE
;
1363 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_V_VERBOSE
.equals(level
)) {
1364 return LTTngControlServiceConstants
.OPTION_VERY_VERBOSE
;
1366 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_V_V_VERBOSE
.equals(level
)) {
1367 return LTTngControlServiceConstants
.OPTION_VERY_VERY_VERBOSE
;
1370 return ""; //$NON-NLS-1$
1374 * Method that logs the command and command result if logging is enabled as
1375 * well as forwards the command execution to the shell.
1378 * - the command to execute
1380 * - a progress monitor
1381 * @return the command result
1382 * @throws ExecutionException
1383 * If the command fails
1385 protected ICommandResult
executeCommand(String command
,
1386 IProgressMonitor monitor
) throws ExecutionException
{
1387 return executeCommand(command
, monitor
, true);
1391 * Method that logs the command and command result if logging is enabled as
1392 * well as forwards the command execution to the shell.
1395 * - the command to execute
1397 * - a progress monitor
1398 * @param checkForError
1399 * - true to verify command result, else false
1400 * @return the command result
1401 * @throws ExecutionException
1402 * in case of error result
1404 protected ICommandResult
executeCommand(String command
,
1405 IProgressMonitor monitor
, boolean checkForError
)
1406 throws ExecutionException
{
1407 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1408 ControlCommandLogger
.log(command
);
1411 ICommandResult result
= fCommandShell
.executeCommand(
1412 command
.toString(), monitor
);
1414 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1415 ControlCommandLogger
.log(formatOutput(result
));
1418 if (checkForError
&& isError(result
)) {
1419 throw new ExecutionException(Messages
.TraceControl_CommandError
1420 + " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$