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
);
204 sessionInfo
.addDomain(domainInfo
);
207 ArrayList
<IChannelInfo
> channels
= new ArrayList
<IChannelInfo
>();
208 index
= parseDomain(result
.getOutput(), index
, channels
);
211 domainInfo
.setChannels(channels
);
214 domainInfo
.setIsKernel(true);
218 matcher
= LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
);
219 if (matcher
.matches()) {
220 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_UstGlobalDomainDisplayName
);
221 sessionInfo
.addDomain(domainInfo
);
224 ArrayList
<IChannelInfo
> channels
= new ArrayList
<IChannelInfo
>();
225 index
= parseDomain(result
.getOutput(), index
, channels
);
228 domainInfo
.setChannels(channels
);
231 domainInfo
.setIsKernel(false);
243 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
244 * #getKernelProvider(org.eclipse.core.runtime.IProgressMonitor)
247 public List
<IBaseEventInfo
> getKernelProvider(IProgressMonitor monitor
) throws ExecutionException
{
248 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST_KERNEL
);
249 ICommandResult result
= executeCommand(command
.toString(), monitor
, false);
251 List
<IBaseEventInfo
> events
= new ArrayList
<IBaseEventInfo
>();
253 if (result
.getOutput() != null) {
254 // Ignore the following 2 cases:
255 // Spawning a session daemon
256 // Error: Unable to list kernel events
258 // Error: Unable to list kernel events
261 if ((result
.getOutput().length
> 0) && (LTTngControlServiceConstants
.LIST_KERNEL_NO_KERNEL_PROVIDER_PATTERN
.matcher(result
.getOutput()[0]).matches()) ||
262 ((result
.getOutput().length
> 1) && (LTTngControlServiceConstants
.LIST_KERNEL_NO_KERNEL_PROVIDER_PATTERN
.matcher(result
.getOutput()[1]).matches()))) {
267 if (isError(result
)) {
268 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$
273 // sched_kthread_stop (type: tracepoint)
274 getProviderEventInfo(result
.getOutput(), 0, events
);
282 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
286 public List
<IUstProviderInfo
> getUstProvider() throws ExecutionException
{
287 return getUstProvider(new NullProgressMonitor());
294 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
295 * #getUstProvider(org.eclipse.core.runtime.IProgressMonitor)
298 public List
<IUstProviderInfo
> getUstProvider(IProgressMonitor monitor
) throws ExecutionException
{
299 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST_UST
);
301 if (isVersionSupported("2.1.0")) { //$NON-NLS-1$
302 command
.append(LTTngControlServiceConstants
.OPTION_FIELDS
);
305 ICommandResult result
= executeCommand(command
.toString(), monitor
);
307 // Note that field print-outs exists for version >= 2.1.0
313 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
314 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
316 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
317 // field: doublefield (float)
318 // field: floatfield (float)
319 // field: stringfield (string)
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)
330 List
<IUstProviderInfo
> allProviders
= new ArrayList
<IUstProviderInfo
>();
331 IUstProviderInfo provider
= null;
334 while (index
< result
.getOutput().length
) {
335 String line
= result
.getOutput()[index
];
336 Matcher matcher
= LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
);
337 if (matcher
.matches()) {
338 provider
= new UstProviderInfo(matcher
.group(2).trim());
339 provider
.setPid(Integer
.valueOf(matcher
.group(1).trim()));
340 List
<IBaseEventInfo
> events
= new ArrayList
<IBaseEventInfo
>();
341 index
= getProviderEventInfo(result
.getOutput(), ++index
, events
);
342 provider
.setEvents(events
);
343 allProviders
.add(provider
);
354 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#createSession(java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
357 public ISessionInfo
createSession(String sessionName
, String sessionPath
, IProgressMonitor monitor
) throws ExecutionException
{
358 return createSession(sessionName
, sessionPath
, false, false, monitor
);
362 public ISessionInfo
createSession(String sessionName
, String sessionPath
, boolean noConsumer
, boolean disableConsumer
,
363 IProgressMonitor monitor
) throws ExecutionException
{
365 String newName
= formatParameter(sessionName
);
366 String newPath
= formatParameter(sessionPath
);
368 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_CREATE_SESSION
, newName
);
370 if (newPath
!= null && !"".equals(newPath
)) { //$NON-NLS-1$
371 command
.append(LTTngControlServiceConstants
.OPTION_OUTPUT_PATH
);
372 command
.append(newPath
);
376 command
.append(LTTngControlServiceConstants
.OPTION_NO_CONSUMER
);
377 } else if (disableConsumer
) {
378 command
.append(LTTngControlServiceConstants
.OPTION_DISABLE_CONSUMER
);
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 verify session name
388 Matcher matcher
= LTTngControlServiceConstants
.CREATE_SESSION_NAME_PATTERN
.matcher(output
[0]);
391 if (matcher
.matches()) {
392 name
= String
.valueOf(matcher
.group(1).trim());
394 // Output format not expected
395 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
396 Messages
.TraceControl_UnexpectedCommandOutputFormat
+ ":\n" + //$NON-NLS-1$
397 formatOutput(result
));
400 if ((name
== null) || (!"".equals(sessionName
) && !name
.equals(sessionName
))) { //$NON-NLS-1$
401 // Unexpected name returned
402 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
403 Messages
.TraceControl_UnexpectedNameError
+ ": " + name
); //$NON-NLS-1$
406 SessionInfo sessionInfo
= new SessionInfo(name
);
409 // Get and verify session path
410 matcher
= LTTngControlServiceConstants
.CREATE_SESSION_PATH_PATTERN
.matcher(output
[1]);
413 if (matcher
.matches()) {
414 path
= String
.valueOf(matcher
.group(1).trim());
416 // Output format not expected
417 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
418 Messages
.TraceControl_UnexpectedCommandOutputFormat
+ ":\n" + //$NON-NLS-1$
419 formatOutput(result
));
422 if ((path
== null) || ((sessionPath
!= null) && (!path
.contains(sessionPath
)))) {
424 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
425 Messages
.TraceControl_UnexpectedPathError
+ ": " + name
); //$NON-NLS-1$
427 sessionInfo
.setSessionPath(path
);
436 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#createSession(java.lang.String, java.lang.String, java.lang.String, java.lang.String, boolean, boolean, org.eclipse.core.runtime.IProgressMonitor)
439 public ISessionInfo
createSession(String sessionName
, String networkUrl
, String controlUrl
,
440 String dataUrl
, boolean noConsumer
, boolean disableConsumer
, IProgressMonitor monitor
) throws ExecutionException
{
442 String newName
= formatParameter(sessionName
);
443 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_CREATE_SESSION
, newName
);
445 if (networkUrl
!= null) {
446 command
.append(LTTngControlServiceConstants
.OPTION_NETWORK_URL
);
447 command
.append(networkUrl
);
449 command
.append(LTTngControlServiceConstants
.OPTION_CONTROL_URL
);
450 command
.append(controlUrl
);
452 command
.append(LTTngControlServiceConstants
.OPTION_DATA_URL
);
453 command
.append(dataUrl
);
457 command
.append(LTTngControlServiceConstants
.OPTION_NO_CONSUMER
);
458 } else if (disableConsumer
) {
459 command
.append(LTTngControlServiceConstants
.OPTION_DISABLE_CONSUMER
);
462 ICommandResult result
= executeCommand(command
.toString(), monitor
);
464 //Session myssession2 created.
465 //Traces will be written in /home/user/lttng-traces/myssession2-20120209-095418
466 String
[] output
= result
.getOutput();
468 // Get and verify session name
469 Matcher matcher
= LTTngControlServiceConstants
.CREATE_SESSION_NAME_PATTERN
.matcher(output
[0]);
472 if (matcher
.matches()) {
473 name
= String
.valueOf(matcher
.group(1).trim());
475 // Output format not expected
476 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
477 Messages
.TraceControl_UnexpectedCommandOutputFormat
+ ":\n" + //$NON-NLS-1$
478 formatOutput(result
));
480 // Get and verify session path
481 matcher
= LTTngControlServiceConstants
.CREATE_SESSION_PATH_PATTERN
.matcher(output
[1]);
484 SessionInfo sessionInfo
= new SessionInfo(name
);
485 if (!noConsumer
&& (networkUrl
!= null)) {
486 if (matcher
.matches()) {
487 path
= String
.valueOf(matcher
.group(1).trim());
489 // Output format not expected
490 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
491 Messages
.TraceControl_UnexpectedCommandOutputFormat
+ ":\n" + //$NON-NLS-1$
492 formatOutput(result
));
497 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
498 Messages
.TraceControl_UnexpectedPathError
+ ": " + name
); //$NON-NLS-1$
500 sessionInfo
.setSessionPath(path
);
502 sessionInfo
.setStreamedTrace(true);
508 public void destroySession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
509 String newName
= formatParameter(sessionName
);
511 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_DESTROY_SESSION
, newName
);
513 ICommandResult result
= executeCommand(command
.toString(), monitor
, false);
514 String
[] output
= result
.getOutput();
516 if (isError(result
) && ((output
== null) || (!LTTngControlServiceConstants
.SESSION_NOT_FOUND_ERROR_PATTERN
.matcher(output
[0]).matches()))) {
517 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$
519 //Session <sessionName> destroyed
524 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#startSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
527 public void startSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
529 String newSessionName
= formatParameter(sessionName
);
531 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_START_SESSION
, newSessionName
);
533 executeCommand(command
.toString(), monitor
);
535 //Session <sessionName> started
540 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#stopSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
543 public void stopSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
544 String newSessionName
= formatParameter(sessionName
);
545 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_STOP_SESSION
, newSessionName
);
547 executeCommand(command
.toString(), monitor
);
549 //Session <sessionName> stopped
555 * @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)
558 public void enableChannels(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IChannelInfo info
, IProgressMonitor monitor
) throws ExecutionException
{
560 // no channels to enable
561 if (channelNames
.isEmpty()) {
565 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_CHANNEL
);
567 for (Iterator
<String
> iterator
= channelNames
.iterator(); iterator
.hasNext();) {
568 String channel
= iterator
.next();
569 command
.append(channel
);
570 if (iterator
.hasNext()) {
576 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
578 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
581 String newSessionName
= formatParameter(sessionName
);
582 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
583 command
.append(newSessionName
);
586 // --discard Discard event when buffers are full (default)
588 // --overwrite Flight recorder mode
589 if (info
.isOverwriteMode()) {
590 command
.append(LTTngControlServiceConstants
.OPTION_OVERWRITE
);
592 // --subbuf-size SIZE Subbuffer size in bytes
593 // (default: 4096, kernel default: 262144)
594 command
.append(LTTngControlServiceConstants
.OPTION_SUB_BUFFER_SIZE
);
595 command
.append(String
.valueOf(info
.getSubBufferSize()));
597 // --num-subbuf NUM Number of subbufers
598 // (default: 8, kernel default: 4)
599 command
.append(LTTngControlServiceConstants
.OPTION_NUM_SUB_BUFFERS
);
600 command
.append(String
.valueOf(info
.getNumberOfSubBuffers()));
602 // --switch-timer USEC Switch timer interval in usec (default: 0)
603 command
.append(LTTngControlServiceConstants
.OPTION_SWITCH_TIMER
);
604 command
.append(String
.valueOf(info
.getSwitchTimer()));
606 // --read-timer USEC Read timer interval in usec (default: 200)
607 command
.append(LTTngControlServiceConstants
.OPTION_READ_TIMER
);
608 command
.append(String
.valueOf(info
.getReadTimer()));
611 executeCommand(command
.toString(), monitor
);
617 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#disableChannel(java.lang.String, java.util.List, org.eclipse.core.runtime.IProgressMonitor)
620 public void disableChannels(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
622 // no channels to enable
623 if (channelNames
.isEmpty()) {
627 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_DISABLE_CHANNEL
);
629 for (Iterator
<String
> iterator
= channelNames
.iterator(); iterator
.hasNext();) {
630 String channel
= iterator
.next();
631 command
.append(channel
);
632 if (iterator
.hasNext()) {
638 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
640 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
643 String newSessionName
= formatParameter(sessionName
);
644 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
645 command
.append(newSessionName
);
647 executeCommand(command
.toString(), monitor
);
652 * @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)
655 public void enableEvents(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, String filterExpression
, IProgressMonitor monitor
) throws ExecutionException
{
657 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
659 if (eventNames
== null || eventNames
.isEmpty()) {
660 command
.append(LTTngControlServiceConstants
.OPTION_ALL
);
663 StringBuffer eventNameParameter
= new StringBuffer();
664 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
665 String event
= iterator
.next();
666 eventNameParameter
.append(event
);
667 if (iterator
.hasNext()) {
668 eventNameParameter
.append(',');
671 command
.append(formatParameter(eventNameParameter
.toString()));
675 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
677 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
680 String newSessionName
= formatParameter(sessionName
);
682 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
683 command
.append(newSessionName
);
685 if (channelName
!= null) {
686 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
687 command
.append(channelName
);
690 command
.append(LTTngControlServiceConstants
.OPTION_TRACEPOINT
);
692 if (filterExpression
!= null) {
693 command
.append(LTTngControlServiceConstants
.OPTION_FILTER
);
694 command
.append('\'');
695 command
.append(filterExpression
);
696 command
.append('\'');
699 executeCommand(command
.toString(), monitor
);
705 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#enableSyscalls(java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
708 public void enableSyscalls(String sessionName
, String channelName
, IProgressMonitor monitor
) throws ExecutionException
{
710 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
712 command
.append(LTTngControlServiceConstants
.OPTION_ALL
);
713 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
715 String newSessionName
= formatParameter(sessionName
);
717 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
718 command
.append(newSessionName
);
720 if (channelName
!= null) {
721 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
722 command
.append(channelName
);
725 command
.append(LTTngControlServiceConstants
.OPTION_SYSCALL
);
727 executeCommand(command
.toString(), monitor
);
732 * @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)
735 public void enableProbe(String sessionName
, String channelName
, String eventName
, boolean isFunction
, String probe
, IProgressMonitor monitor
) throws ExecutionException
{
736 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
738 command
.append(eventName
);
739 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
741 String newSessionName
= formatParameter(sessionName
);
742 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
743 command
.append(newSessionName
);
745 if (channelName
!= null) {
746 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
747 command
.append(channelName
);
750 command
.append(LTTngControlServiceConstants
.OPTION_FUNCTION_PROBE
);
752 command
.append(LTTngControlServiceConstants
.OPTION_PROBE
);
755 command
.append(probe
);
757 executeCommand(command
.toString(), monitor
);
762 * @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)
765 public void enableLogLevel(String sessionName
, String channelName
, String eventName
, LogLevelType logLevelType
, TraceLogLevel level
, String filterExpression
, IProgressMonitor monitor
) throws ExecutionException
{
766 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
768 command
.append(eventName
);
769 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
771 String newSessionName
= formatParameter(sessionName
);
772 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
773 command
.append(newSessionName
);
775 if (channelName
!= null) {
776 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
777 command
.append(channelName
);
780 if (logLevelType
== LogLevelType
.LOGLEVEL
) {
781 command
.append(LTTngControlServiceConstants
.OPTION_LOGLEVEL
);
782 } else if (logLevelType
== LogLevelType
.LOGLEVEL_ONLY
) {
783 command
.append(LTTngControlServiceConstants
.OPTION_LOGLEVEL_ONLY
);
788 command
.append(level
.getInName());
790 executeCommand(command
.toString(), monitor
);
797 * @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)
800 public void disableEvent(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
801 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_DISABLE_EVENT
);
803 if (eventNames
== null) {
804 command
.append(LTTngControlServiceConstants
.OPTION_ALL
);
806 // no events to disable
807 if (eventNames
.isEmpty()) {
811 StringBuffer eventNameParameter
= new StringBuffer();
812 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
813 String event
= iterator
.next();
814 eventNameParameter
.append(event
);
815 if (iterator
.hasNext()) {
816 eventNameParameter
.append(',');
819 command
.append(formatParameter(eventNameParameter
.toString()));
823 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
825 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
828 String newSessionName
= formatParameter(sessionName
);
829 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
830 command
.append(newSessionName
);
832 if (channelName
!= null) {
833 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
834 command
.append(channelName
);
837 executeCommand(command
.toString(), monitor
);
842 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#getContexts(org.eclipse.core.runtime.IProgressMonitor)
845 public List
<String
> getContextList(IProgressMonitor monitor
) throws ExecutionException
{
847 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ADD_CONTEXT
, LTTngControlServiceConstants
.OPTION_HELP
);
849 ICommandResult result
= executeCommand(command
.toString(), monitor
);
851 String
[] output
= result
.getOutput();
853 List
<String
> contexts
= new ArrayList
<String
>(0);
856 boolean inList
= false;
857 while (index
< output
.length
) {
858 String line
= result
.getOutput()[index
];
860 Matcher startMatcher
= LTTngControlServiceConstants
.ADD_CONTEXT_HELP_CONTEXTS_INTRO
.matcher(line
);
861 Matcher endMatcher
= LTTngControlServiceConstants
.ADD_CONTEXT_HELP_CONTEXTS_END_LINE
.matcher(line
);
863 if (startMatcher
.matches()) {
865 } else if (endMatcher
.matches()) {
867 } else if (inList
== true) {
868 String
[] tmp
= line
.split(","); //$NON-NLS-1$
869 for (int i
= 0; i
< tmp
.length
; i
++) {
870 contexts
.add(tmp
[i
].trim());
880 * @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)
883 public void addContexts(String sessionName
, String channelName
, String eventName
, boolean isKernel
, List
<String
> contextNames
, IProgressMonitor monitor
) throws ExecutionException
{
884 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ADD_CONTEXT
);
886 String newSessionName
= formatParameter(sessionName
);
887 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
888 command
.append(newSessionName
);
890 if (channelName
!= null) {
891 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
892 command
.append(channelName
);
895 if (eventName
!= null) {
896 command
.append(LTTngControlServiceConstants
.OPTION_EVENT
);
897 command
.append(eventName
);
901 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
903 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
906 for (Iterator
<String
> iterator
= contextNames
.iterator(); iterator
.hasNext();) {
907 String context
= iterator
.next();
908 command
.append(LTTngControlServiceConstants
.OPTION_CONTEXT_TYPE
);
909 command
.append(context
);
912 executeCommand(command
.toString(), monitor
);
918 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#calibrate(boolean, org.eclipse.core.runtime.IProgressMonitor)
921 public void calibrate(boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
922 // String newSessionName = formatParameter(sessionName);
923 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_CALIBRATE
);
925 // command.append(OPTION_SESSION);
926 // command.append(newSessionName);
929 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
931 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
934 command
.append(LTTngControlServiceConstants
.OPTION_FUNCTION_PROBE
);
936 executeCommand(command
.toString(), monitor
);
939 // ------------------------------------------------------------------------
941 // ------------------------------------------------------------------------
943 * Checks if command result is an error result.
946 * - the command result to check
947 * @return true if error else false
949 protected boolean isError(ICommandResult result
) {
950 if ((result
.getResult()) != 0 || (result
.getOutput().length
< 1 || LTTngControlServiceConstants
.ERROR_PATTERN
.matcher(result
.getOutput()[0]).matches())) {
957 * Formats the output string as single string.
961 * @return - the formatted output
963 public static String
formatOutput(ICommandResult result
) {
964 if ((result
== null) || result
.getOutput() == null || result
.getOutput().length
== 0) {
965 return ""; //$NON-NLS-1$
967 String
[] output
= result
.getOutput();
968 StringBuffer ret
= new StringBuffer();
969 ret
.append("Return Value: "); //$NON-NLS-1$
970 ret
.append(result
.getResult());
971 ret
.append("\n"); //$NON-NLS-1$
972 for (int i
= 0; i
< output
.length
; i
++) {
973 ret
.append(output
[i
] + "\n"); //$NON-NLS-1$
975 return ret
.toString();
979 * Parses the domain information.
982 * - a command output array
983 * @param currentIndex
984 * - current index in command output array
986 * - list for returning channel information
987 * @return the new current index in command output array
989 protected int parseDomain(String
[] output
, int currentIndex
, List
<IChannelInfo
> channels
) {
990 int index
= currentIndex
;
994 // - channnel1: [enabled]
998 // subbufers size: 262144
999 // number of subbufers: 4
1000 // switch timer interval: 0
1001 // read timer interval: 200
1004 while (index
< output
.length
) {
1005 String line
= output
[index
];
1007 Matcher outerMatcher
= LTTngControlServiceConstants
.CHANNELS_SECTION_PATTERN
.matcher(line
);
1008 if (outerMatcher
.matches()) {
1009 IChannelInfo channelInfo
= null;
1010 while (index
< output
.length
) {
1011 String subLine
= output
[index
];
1013 Matcher innerMatcher
= LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(subLine
);
1014 if (innerMatcher
.matches()) {
1015 channelInfo
= new ChannelInfo(""); //$NON-NLS-1$
1017 channelInfo
.setName(innerMatcher
.group(1));
1019 // get channel enablement
1020 channelInfo
.setState(innerMatcher
.group(2));
1023 channels
.add(channelInfo
);
1025 } else if (LTTngControlServiceConstants
.OVERWRITE_MODE_ATTRIBUTE
.matcher(subLine
).matches()) {
1026 String value
= getAttributeValue(subLine
);
1027 if (channelInfo
!= null) {
1028 channelInfo
.setOverwriteMode(!LTTngControlServiceConstants
.OVERWRITE_MODE_ATTRIBUTE_FALSE
.equals(value
));
1030 } else if (LTTngControlServiceConstants
.SUBBUFFER_SIZE_ATTRIBUTE
.matcher(subLine
).matches()) {
1031 if (channelInfo
!= null) {
1032 channelInfo
.setSubBufferSize(Long
.valueOf(getAttributeValue(subLine
)));
1035 } else if (LTTngControlServiceConstants
.NUM_SUBBUFFERS_ATTRIBUTE
.matcher(subLine
).matches()) {
1036 if (channelInfo
!= null) {
1037 channelInfo
.setNumberOfSubBuffers(Integer
.valueOf(getAttributeValue(subLine
)));
1040 } else if (LTTngControlServiceConstants
.SWITCH_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
1041 if (channelInfo
!= null) {
1042 channelInfo
.setSwitchTimer(Long
.valueOf(getAttributeValue(subLine
)));
1045 } else if (LTTngControlServiceConstants
.READ_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
1046 if (channelInfo
!= null) {
1047 channelInfo
.setReadTimer(Long
.valueOf(getAttributeValue(subLine
)));
1050 } else if (LTTngControlServiceConstants
.OUTPUT_ATTRIBUTE
.matcher(subLine
).matches()) {
1051 if (channelInfo
!= null) {
1052 channelInfo
.setOutputType(getAttributeValue(subLine
));
1055 } else if (LTTngControlServiceConstants
.EVENT_SECTION_PATTERN
.matcher(subLine
).matches()) {
1056 List
<IEventInfo
> events
= new ArrayList
<IEventInfo
>();
1057 index
= parseEvents(output
, index
, events
);
1058 if (channelInfo
!= null) {
1059 channelInfo
.setEvents(events
);
1061 // we want to stay at the current index to be able to
1064 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(subLine
).matches()) {
1067 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(subLine
).matches()) {
1079 * Parses the event information within a domain.
1082 * - a command output array
1083 * @param currentIndex
1084 * - current index in command output array
1086 * - list for returning event information
1087 * @return the new current index in command output array
1089 protected int parseEvents(String
[] output
, int currentIndex
, List
<IEventInfo
> events
) {
1090 int index
= currentIndex
;
1092 while (index
< output
.length
) {
1093 String line
= output
[index
];
1094 if (LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(line
).matches()) {
1097 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(line
).matches()) {
1100 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
).matches()) {
1105 Matcher matcher
= LTTngControlServiceConstants
.EVENT_PATTERN
.matcher(line
);
1106 Matcher matcher2
= LTTngControlServiceConstants
.WILDCARD_EVENT_PATTERN
.matcher(line
);
1108 if (matcher
.matches()) {
1109 IEventInfo eventInfo
= new EventInfo(matcher
.group(1).trim());
1110 eventInfo
.setLogLevel(matcher
.group(2).trim());
1111 eventInfo
.setEventType(matcher
.group(3).trim());
1112 eventInfo
.setState(matcher
.group(4));
1113 String filter
= matcher
.group(5);
1114 if (filter
!= null) {
1115 filter
= filter
.substring(1, filter
.length() - 1); // remove '[' and ']'
1116 eventInfo
.setFilterExpression(filter
);
1118 events
.add(eventInfo
);
1120 } else if (matcher2
.matches()) {
1121 IEventInfo eventInfo
= new EventInfo(matcher2
.group(1).trim());
1122 eventInfo
.setLogLevel(TraceLogLevel
.LEVEL_UNKNOWN
);
1123 eventInfo
.setEventType(matcher2
.group(2).trim());
1124 eventInfo
.setState(matcher2
.group(3));
1125 String filter
= matcher2
.group(4);
1126 if (filter
!= null) {
1127 filter
= filter
.substring(1, filter
.length() - 1); // remove '[' and ']'
1128 eventInfo
.setFilterExpression(filter
);
1131 if (eventInfo
.getEventType() == TraceEventType
.PROBE
) {
1132 IProbeEventInfo probeEvent
= new ProbeEventInfo(eventInfo
.getName());
1133 probeEvent
.setLogLevel(eventInfo
.getLogLevel());
1134 probeEvent
.setEventType(eventInfo
.getEventType());
1135 probeEvent
.setState(eventInfo
.getState());
1137 // Overwrite eventinfo
1138 eventInfo
= probeEvent
;
1140 // myevent2 (type: probe) [enabled]
1142 // myevent0 (type: probe) [enabled]
1144 // symbol: init_post
1146 while (index
< output
.length
) {
1147 String probeLine
= output
[index
];
1149 Matcher addrMatcher
= LTTngControlServiceConstants
.PROBE_ADDRESS_PATTERN
.matcher(probeLine
);
1150 Matcher offsetMatcher
= LTTngControlServiceConstants
.PROBE_OFFSET_PATTERN
.matcher(probeLine
);
1151 Matcher symbolMatcher
= LTTngControlServiceConstants
.PROBE_SYMBOL_PATTERN
.matcher(probeLine
);
1152 if (addrMatcher
.matches()) {
1153 String addr
= addrMatcher
.group(2).trim();
1154 probeEvent
.setAddress(addr
);
1155 } else if (offsetMatcher
.matches()) {
1156 String offset
= offsetMatcher
.group(2).trim();
1157 probeEvent
.setOffset(offset
);
1158 } else if (symbolMatcher
.matches()) {
1159 String symbol
= symbolMatcher
.group(2).trim();
1160 probeEvent
.setSymbol(symbol
);
1161 } else if ((LTTngControlServiceConstants
.EVENT_PATTERN
.matcher(probeLine
).matches()) || (LTTngControlServiceConstants
.WILDCARD_EVENT_PATTERN
.matcher(probeLine
).matches())) {
1163 } else if (LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(probeLine
).matches()) {
1165 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(probeLine
).matches()) {
1168 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(probeLine
).matches()) {
1174 events
.add(eventInfo
);
1176 events
.add(eventInfo
);
1183 // else if (line.matches(EVENT_NONE_PATTERN)) {
1193 * Parses a line with attributes: <attribute Name>: <attribute value>
1196 * - attribute line to parse
1197 * @return the attribute value as string
1199 protected String
getAttributeValue(String line
) {
1200 String
[] temp
= line
.split("\\: "); //$NON-NLS-1$
1205 * Parses the event information within a provider.
1208 * - a command output array
1209 * @param currentIndex
1210 * - current index in command output array
1212 * - list for returning event information
1213 * @return the new current index in command output array
1215 protected int getProviderEventInfo(String
[] output
, int currentIndex
, List
<IBaseEventInfo
> events
) {
1216 int index
= currentIndex
;
1217 IBaseEventInfo eventInfo
= null;
1218 while (index
< output
.length
) {
1219 String line
= output
[index
];
1220 Matcher matcher
= LTTngControlServiceConstants
.PROVIDER_EVENT_PATTERN
.matcher(line
);
1221 if (matcher
.matches()) {
1222 // sched_kthread_stop (loglevel: TRACE_EMERG0) (type: tracepoint)
1223 eventInfo
= new BaseEventInfo(matcher
.group(1).trim());
1224 eventInfo
.setLogLevel(matcher
.group(2).trim());
1225 eventInfo
.setEventType(matcher
.group(3).trim());
1226 events
.add(eventInfo
);
1228 } else if (LTTngControlServiceConstants
.EVENT_FIELD_PATTERN
.matcher(line
).matches()) {
1229 if (eventInfo
!= null) {
1230 List
<IFieldInfo
> fields
= new ArrayList
<IFieldInfo
>();
1231 index
= getFieldInfo(output
, index
, fields
);
1232 eventInfo
.setFields(fields
);
1237 else if (LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
).matches()) {
1248 * Parse a field's information.
1251 * A command output array
1252 * @param currentIndex
1253 * The current index in the command output array
1255 * List for returning the field information
1256 * @return The new current index in the command output array
1258 protected int getFieldInfo(String
[] output
, int currentIndex
, List
<IFieldInfo
> fields
) {
1259 int index
= currentIndex
;
1260 IFieldInfo fieldInfo
= null;
1261 while (index
< output
.length
) {
1262 String line
= output
[index
];
1263 Matcher matcher
= LTTngControlServiceConstants
.EVENT_FIELD_PATTERN
.matcher(line
);
1264 if (matcher
.matches()) {
1265 // field: content (string)
1266 fieldInfo
= new FieldInfo(matcher
.group(2).trim());
1267 fieldInfo
.setFieldType(matcher
.group(3).trim());
1268 fields
.add(fieldInfo
);
1269 } else if (LTTngControlServiceConstants
.PROVIDER_EVENT_PATTERN
.matcher(line
).matches()) {
1271 } else if (LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
).matches()) {
1280 * Formats a command parameter for the command execution i.e. adds quotes
1281 * at the beginning and end if necessary.
1282 * @param parameter - parameter to format
1283 * @return formated parameter
1285 protected String
formatParameter(String parameter
) {
1286 if (parameter
!= null) {
1287 StringBuffer newString
= new StringBuffer();
1288 newString
.append(parameter
);
1290 if (parameter
.contains(" ") || parameter
.contains("*")) { //$NON-NLS-1$ //$NON-NLS-2$
1291 newString
.insert(0, "\""); //$NON-NLS-1$
1292 newString
.append("\""); //$NON-NLS-1$
1294 return newString
.toString();
1300 * @param strings array of string that makes up a command line
1301 * @return string buffer with created command line
1303 protected StringBuffer
createCommand(String
... strings
) {
1304 StringBuffer command
= new StringBuffer();
1305 command
.append(LTTngControlServiceConstants
.CONTROL_COMMAND
);
1306 command
.append(getTracingGroupOption());
1307 command
.append(getVerboseOption());
1308 for (String string
: strings
) {
1309 command
.append(string
);
1315 * @return the tracing group option if configured in the preferences
1317 protected String
getTracingGroupOption() {
1318 if (!ControlPreferences
.getInstance().isDefaultTracingGroup() && !ControlPreferences
.getInstance().getTracingGroup().equals("")) { //$NON-NLS-1$
1319 return LTTngControlServiceConstants
.OPTION_TRACING_GROUP
+ ControlPreferences
.getInstance().getTracingGroup();
1321 return ""; //$NON-NLS-1$
1325 * @return the verbose option as configured in the preferences
1327 protected String
getVerboseOption() {
1328 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1329 String level
= ControlPreferences
.getInstance().getVerboseLevel();
1330 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_VERBOSE
.equals(level
)) {
1331 return LTTngControlServiceConstants
.OPTION_VERBOSE
;
1333 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_V_VERBOSE
.equals(level
)) {
1334 return LTTngControlServiceConstants
.OPTION_VERY_VERBOSE
;
1336 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_V_V_VERBOSE
.equals(level
)) {
1337 return LTTngControlServiceConstants
.OPTION_VERY_VERY_VERBOSE
;
1340 return ""; //$NON-NLS-1$
1344 * Method that logs the command and command result if logging is enabled as
1345 * well as forwards the command execution to the shell.
1348 * - the command to execute
1350 * - a progress monitor
1351 * @return the command result
1352 * @throws ExecutionException
1353 * If the command fails
1355 protected ICommandResult
executeCommand(String command
,
1356 IProgressMonitor monitor
) throws ExecutionException
{
1357 return executeCommand(command
, monitor
, true);
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 * @param checkForError
1369 * - true to verify command result, else false
1370 * @return the command result
1371 * @throws ExecutionException
1372 * in case of error result
1374 protected ICommandResult
executeCommand(String command
,
1375 IProgressMonitor monitor
, boolean checkForError
)
1376 throws ExecutionException
{
1377 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1378 ControlCommandLogger
.log(command
);
1381 ICommandResult result
= fCommandShell
.executeCommand(
1382 command
.toString(), monitor
);
1384 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1385 ControlCommandLogger
.log(formatOutput(result
));
1388 if (checkForError
&& isError(result
)) {
1389 throw new ExecutionException(Messages
.TraceControl_CommandError
1390 + " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$