1 /**********************************************************************
2 * Copyright (c) 2012 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12 package org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.service
;
14 import java
.util
.ArrayList
;
15 import java
.util
.Iterator
;
16 import java
.util
.List
;
17 import java
.util
.regex
.Matcher
;
19 import org
.eclipse
.core
.commands
.ExecutionException
;
20 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
21 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
22 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.IBaseEventInfo
;
23 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.IChannelInfo
;
24 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.IDomainInfo
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.IEventInfo
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.IFieldInfo
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.IProbeEventInfo
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.ISessionInfo
;
29 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.IUstProviderInfo
;
30 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.LogLevelType
;
31 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.TraceEventType
;
32 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.TraceLogLevel
;
33 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.BaseEventInfo
;
34 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.ChannelInfo
;
35 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.DomainInfo
;
36 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.EventInfo
;
37 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.FieldInfo
;
38 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.ProbeEventInfo
;
39 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.SessionInfo
;
40 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.UstProviderInfo
;
41 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.logging
.ControlCommandLogger
;
42 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.messages
.Messages
;
43 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.preferences
.ControlPreferences
;
44 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.remote
.ICommandResult
;
45 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.remote
.ICommandShell
;
46 import org
.osgi
.framework
.Version
;
50 * Service for sending LTTng trace control commands to remote host.
53 * @author Bernd Hufmann
55 public class LTTngControlService
implements ILttngControlService
{
57 // ------------------------------------------------------------------------
59 // ------------------------------------------------------------------------
61 * The command shell implementation
63 protected ICommandShell fCommandShell
= null;
68 protected Version fVersion
= null;
70 // ------------------------------------------------------------------------
72 // ------------------------------------------------------------------------
78 * - the command shell implementation to use
80 public LTTngControlService(ICommandShell shell
) {
81 fCommandShell
= shell
;
84 // ------------------------------------------------------------------------
86 // ------------------------------------------------------------------------
89 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#getVersion()
92 public String
getVersion() {
93 if (fVersion
== null) {
94 return "Unknown"; //$NON-NLS-1$
96 return fVersion
.toString();
100 * Sets the version of the LTTng 2.0 control service.
101 * @param version - a version to set
103 public void setVersion(String version
) {
104 fVersion
= new Version(version
);
109 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#isVersionSupported(java.lang.String)
112 public boolean isVersionSupported(String version
) {
113 Version tmp
= new Version(version
);
114 return (fVersion
!= null && fVersion
.compareTo(tmp
) >= 0) ?
true : false;
117 // ------------------------------------------------------------------------
119 // ------------------------------------------------------------------------
125 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
126 * #getSessionNames(org.eclipse.core.runtime.IProgressMonitor)
129 public String
[] getSessionNames(IProgressMonitor monitor
) throws ExecutionException
{
130 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST
);
132 ICommandResult result
= executeCommand(command
.toString(), monitor
);
135 // Available tracing sessions:
136 // 1) mysession1 (/home/user/lttng-traces/mysession1-20120123-083928) [inactive]
137 // 2) mysession (/home/user/lttng-traces/mysession-20120123-083318) [inactive]
139 // Use lttng list <session_name> for more details
141 ArrayList
<String
> retArray
= new ArrayList
<String
>();
143 while (index
< result
.getOutput().length
) {
144 String line
= result
.getOutput()[index
];
145 Matcher matcher
= LTTngControlServiceConstants
.SESSION_PATTERN
.matcher(line
);
146 if (matcher
.matches()) {
147 retArray
.add(matcher
.group(2).trim());
151 return retArray
.toArray(new String
[retArray
.size()]);
158 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
159 * #getSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
162 public ISessionInfo
getSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
163 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST
, sessionName
);
164 ICommandResult result
= executeCommand(command
.toString(), monitor
);
169 // Tracing session mysession2: [inactive]
170 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
171 ISessionInfo sessionInfo
= new SessionInfo(sessionName
);
173 while (index
< result
.getOutput().length
) {
174 // Tracing session mysession2: [inactive]
175 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
177 // === Domain: Kernel ===
179 String line
= result
.getOutput()[index
];
180 Matcher matcher
= LTTngControlServiceConstants
.TRACE_SESSION_PATTERN
.matcher(line
);
181 if (matcher
.matches()) {
182 sessionInfo
.setSessionState(matcher
.group(2));
187 matcher
= LTTngControlServiceConstants
.TRACE_NETWORK_PATH_PATTERN
.matcher(line
);
188 if (matcher
.matches()) {
189 sessionInfo
.setStreamedTrace(true);
192 matcher
= LTTngControlServiceConstants
.TRACE_SESSION_PATH_PATTERN
.matcher(line
);
193 if (matcher
.matches()) {
194 sessionInfo
.setSessionPath(matcher
.group(1).trim());
199 matcher
= LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(line
);
200 if (matcher
.matches()) {
202 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_KernelDomainDisplayName
);
203 sessionInfo
.addDomain(domainInfo
);
206 ArrayList
<IChannelInfo
> channels
= new ArrayList
<IChannelInfo
>();
207 index
= parseDomain(result
.getOutput(), index
, channels
);
210 domainInfo
.setChannels(channels
);
213 domainInfo
.setIsKernel(true);
217 matcher
= LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
);
218 if (matcher
.matches()) {
219 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_UstGlobalDomainDisplayName
);
220 sessionInfo
.addDomain(domainInfo
);
223 ArrayList
<IChannelInfo
> channels
= new ArrayList
<IChannelInfo
>();
224 index
= parseDomain(result
.getOutput(), index
, channels
);
227 domainInfo
.setChannels(channels
);
230 domainInfo
.setIsKernel(false);
242 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
243 * #getKernelProvider(org.eclipse.core.runtime.IProgressMonitor)
246 public List
<IBaseEventInfo
> getKernelProvider(IProgressMonitor monitor
) throws ExecutionException
{
247 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST_KERNEL
);
248 ICommandResult result
= executeCommand(command
.toString(), monitor
, false);
250 List
<IBaseEventInfo
> events
= new ArrayList
<IBaseEventInfo
>();
252 if (result
.getOutput() != null) {
253 // Ignore the following 2 cases:
254 // Spawning a session daemon
255 // Error: Unable to list kernel events
257 // Error: Unable to list kernel events
260 if ((result
.getOutput().length
> 0) && (LTTngControlServiceConstants
.LIST_KERNEL_NO_KERNEL_PROVIDER_PATTERN
.matcher(result
.getOutput()[0]).matches()) ||
261 ((result
.getOutput().length
> 1) && (LTTngControlServiceConstants
.LIST_KERNEL_NO_KERNEL_PROVIDER_PATTERN
.matcher(result
.getOutput()[1]).matches()))) {
266 if (isError(result
)) {
267 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$
272 // sched_kthread_stop (type: tracepoint)
273 getProviderEventInfo(result
.getOutput(), 0, events
);
281 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
285 public List
<IUstProviderInfo
> getUstProvider() throws ExecutionException
{
286 return getUstProvider(new NullProgressMonitor());
293 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
294 * #getUstProvider(org.eclipse.core.runtime.IProgressMonitor)
297 public List
<IUstProviderInfo
> getUstProvider(IProgressMonitor monitor
) throws ExecutionException
{
298 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST_UST
);
300 if (isVersionSupported("2.1.0")) { //$NON-NLS-1$
301 command
.append(LTTngControlServiceConstants
.OPTION_FIELDS
);
304 ICommandResult result
= executeCommand(command
.toString(), monitor
);
306 // Note that field print-outs exists for version >= 2.1.0
312 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
313 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
315 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
316 // field: doublefield (float)
317 // field: floatfield (float)
318 // field: stringfield (string)
321 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
322 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
324 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
325 // field: doublefield (float)
326 // field: floatfield (float)
327 // field: stringfield (string)
329 List
<IUstProviderInfo
> allProviders
= new ArrayList
<IUstProviderInfo
>();
330 IUstProviderInfo provider
= null;
333 while (index
< result
.getOutput().length
) {
334 String line
= result
.getOutput()[index
];
335 Matcher matcher
= LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
);
336 if (matcher
.matches()) {
337 provider
= new UstProviderInfo(matcher
.group(2).trim());
338 provider
.setPid(Integer
.valueOf(matcher
.group(1).trim()));
339 List
<IBaseEventInfo
> events
= new ArrayList
<IBaseEventInfo
>();
340 index
= getProviderEventInfo(result
.getOutput(), ++index
, events
);
341 provider
.setEvents(events
);
342 allProviders
.add(provider
);
353 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#createSession(java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
356 public ISessionInfo
createSession(String sessionName
, String sessionPath
, IProgressMonitor monitor
) throws ExecutionException
{
357 return createSession(sessionName
, sessionPath
, false, false, monitor
);
361 public ISessionInfo
createSession(String sessionName
, String sessionPath
, boolean noConsumer
, boolean disableConsumer
,
362 IProgressMonitor monitor
) throws ExecutionException
{
364 String newName
= formatParameter(sessionName
);
365 String newPath
= formatParameter(sessionPath
);
367 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_CREATE_SESSION
, newName
);
369 if (newPath
!= null && !"".equals(newPath
)) { //$NON-NLS-1$
370 command
.append(LTTngControlServiceConstants
.OPTION_OUTPUT_PATH
);
371 command
.append(newPath
);
375 command
.append(LTTngControlServiceConstants
.OPTION_NO_CONSUMER
);
376 } else if (disableConsumer
) {
377 command
.append(LTTngControlServiceConstants
.OPTION_DISABLE_CONSUMER
);
380 ICommandResult result
= executeCommand(command
.toString(), monitor
);
382 //Session myssession2 created.
383 //Traces will be written in /home/user/lttng-traces/myssession2-20120209-095418
384 String
[] output
= result
.getOutput();
386 // Get and verify session name
387 Matcher matcher
= LTTngControlServiceConstants
.CREATE_SESSION_NAME_PATTERN
.matcher(output
[0]);
390 if (matcher
.matches()) {
391 name
= String
.valueOf(matcher
.group(1).trim());
393 // Output format not expected
394 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
395 Messages
.TraceControl_UnexpectedCommandOutputFormat
+ ":\n" + //$NON-NLS-1$
396 formatOutput(result
));
399 if ((name
== null) || (!"".equals(sessionName
) && !name
.equals(sessionName
))) { //$NON-NLS-1$
400 // Unexpected name returned
401 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
402 Messages
.TraceControl_UnexpectedNameError
+ ": " + name
); //$NON-NLS-1$
405 SessionInfo sessionInfo
= new SessionInfo(name
);
408 // Get and verify session path
409 matcher
= LTTngControlServiceConstants
.CREATE_SESSION_PATH_PATTERN
.matcher(output
[1]);
412 if (matcher
.matches()) {
413 path
= String
.valueOf(matcher
.group(1).trim());
415 // Output format not expected
416 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
417 Messages
.TraceControl_UnexpectedCommandOutputFormat
+ ":\n" + //$NON-NLS-1$
418 formatOutput(result
));
421 if ((path
== null) || ((sessionPath
!= null) && (!path
.contains(sessionPath
)))) {
423 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
424 Messages
.TraceControl_UnexpectedPathError
+ ": " + name
); //$NON-NLS-1$
426 sessionInfo
.setSessionPath(path
);
435 * @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)
438 public ISessionInfo
createSession(String sessionName
, String networkUrl
, String controlUrl
,
439 String dataUrl
, boolean noConsumer
, boolean disableConsumer
, IProgressMonitor monitor
) throws ExecutionException
{
441 String newName
= formatParameter(sessionName
);
442 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_CREATE_SESSION
, newName
);
444 if (networkUrl
!= null) {
445 command
.append(LTTngControlServiceConstants
.OPTION_NETWORK_URL
);
446 command
.append(networkUrl
);
448 command
.append(LTTngControlServiceConstants
.OPTION_CONTROL_URL
);
449 command
.append(controlUrl
);
451 command
.append(LTTngControlServiceConstants
.OPTION_DATA_URL
);
452 command
.append(dataUrl
);
456 command
.append(LTTngControlServiceConstants
.OPTION_NO_CONSUMER
);
457 } else if (disableConsumer
) {
458 command
.append(LTTngControlServiceConstants
.OPTION_DISABLE_CONSUMER
);
461 ICommandResult result
= executeCommand(command
.toString(), monitor
);
463 //Session myssession2 created.
464 //Traces will be written in /home/user/lttng-traces/myssession2-20120209-095418
465 String
[] output
= result
.getOutput();
467 // Get and verify session name
468 Matcher matcher
= LTTngControlServiceConstants
.CREATE_SESSION_NAME_PATTERN
.matcher(output
[0]);
471 if (matcher
.matches()) {
472 name
= String
.valueOf(matcher
.group(1).trim());
474 // Output format not expected
475 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
476 Messages
.TraceControl_UnexpectedCommandOutputFormat
+ ":\n" + //$NON-NLS-1$
477 formatOutput(result
));
479 // Get and verify session path
480 matcher
= LTTngControlServiceConstants
.CREATE_SESSION_PATH_PATTERN
.matcher(output
[1]);
483 SessionInfo sessionInfo
= new SessionInfo(name
);
484 if (!noConsumer
&& (networkUrl
!= null)) {
485 if (matcher
.matches()) {
486 path
= String
.valueOf(matcher
.group(1).trim());
488 // Output format not expected
489 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
490 Messages
.TraceControl_UnexpectedCommandOutputFormat
+ ":\n" + //$NON-NLS-1$
491 formatOutput(result
));
496 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
497 Messages
.TraceControl_UnexpectedPathError
+ ": " + name
); //$NON-NLS-1$
499 sessionInfo
.setSessionPath(path
);
501 sessionInfo
.setStreamedTrace(true);
507 public void destroySession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
508 String newName
= formatParameter(sessionName
);
510 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_DESTROY_SESSION
, newName
);
512 ICommandResult result
= executeCommand(command
.toString(), monitor
, false);
513 String
[] output
= result
.getOutput();
515 if (isError(result
) && ((output
== null) || (!LTTngControlServiceConstants
.SESSION_NOT_FOUND_ERROR_PATTERN
.matcher(output
[0]).matches()))) {
516 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$
518 //Session <sessionName> destroyed
523 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#startSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
526 public void startSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
528 String newSessionName
= formatParameter(sessionName
);
530 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_START_SESSION
, newSessionName
);
532 executeCommand(command
.toString(), monitor
);
534 //Session <sessionName> started
539 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#stopSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
542 public void stopSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
543 String newSessionName
= formatParameter(sessionName
);
544 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_STOP_SESSION
, newSessionName
);
546 executeCommand(command
.toString(), monitor
);
548 //Session <sessionName> stopped
554 * @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)
557 public void enableChannels(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IChannelInfo info
, IProgressMonitor monitor
) throws ExecutionException
{
559 // no channels to enable
560 if (channelNames
.isEmpty()) {
564 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_CHANNEL
);
566 for (Iterator
<String
> iterator
= channelNames
.iterator(); iterator
.hasNext();) {
567 String channel
= iterator
.next();
568 command
.append(channel
);
569 if (iterator
.hasNext()) {
575 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
577 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
580 String newSessionName
= formatParameter(sessionName
);
581 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
582 command
.append(newSessionName
);
585 // --discard Discard event when buffers are full (default)
587 // --overwrite Flight recorder mode
588 if (info
.isOverwriteMode()) {
589 command
.append(LTTngControlServiceConstants
.OPTION_OVERWRITE
);
591 // --subbuf-size SIZE Subbuffer size in bytes
592 // (default: 4096, kernel default: 262144)
593 command
.append(LTTngControlServiceConstants
.OPTION_SUB_BUFFER_SIZE
);
594 command
.append(String
.valueOf(info
.getSubBufferSize()));
596 // --num-subbuf NUM Number of subbufers
597 // (default: 8, kernel default: 4)
598 command
.append(LTTngControlServiceConstants
.OPTION_NUM_SUB_BUFFERS
);
599 command
.append(String
.valueOf(info
.getNumberOfSubBuffers()));
601 // --switch-timer USEC Switch timer interval in usec (default: 0)
602 command
.append(LTTngControlServiceConstants
.OPTION_SWITCH_TIMER
);
603 command
.append(String
.valueOf(info
.getSwitchTimer()));
605 // --read-timer USEC Read timer interval in usec (default: 200)
606 command
.append(LTTngControlServiceConstants
.OPTION_READ_TIMER
);
607 command
.append(String
.valueOf(info
.getReadTimer()));
610 executeCommand(command
.toString(), monitor
);
616 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#disableChannel(java.lang.String, java.util.List, org.eclipse.core.runtime.IProgressMonitor)
619 public void disableChannels(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
621 // no channels to enable
622 if (channelNames
.isEmpty()) {
626 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_DISABLE_CHANNEL
);
628 for (Iterator
<String
> iterator
= channelNames
.iterator(); iterator
.hasNext();) {
629 String channel
= iterator
.next();
630 command
.append(channel
);
631 if (iterator
.hasNext()) {
637 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
639 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
642 String newSessionName
= formatParameter(sessionName
);
643 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
644 command
.append(newSessionName
);
646 executeCommand(command
.toString(), monitor
);
651 * @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)
654 public void enableEvents(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, String filterExpression
, IProgressMonitor monitor
) throws ExecutionException
{
656 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
658 if (eventNames
== null || eventNames
.isEmpty()) {
659 command
.append(LTTngControlServiceConstants
.OPTION_ALL
);
662 StringBuffer eventNameParameter
= new StringBuffer();
663 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
664 String event
= iterator
.next();
665 eventNameParameter
.append(event
);
666 if (iterator
.hasNext()) {
667 eventNameParameter
.append(',');
670 command
.append(formatParameter(eventNameParameter
.toString()));
674 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
676 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
679 String newSessionName
= formatParameter(sessionName
);
681 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
682 command
.append(newSessionName
);
684 if (channelName
!= null) {
685 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
686 command
.append(channelName
);
689 command
.append(LTTngControlServiceConstants
.OPTION_TRACEPOINT
);
691 if (filterExpression
!= null) {
692 command
.append(LTTngControlServiceConstants
.OPTION_FILTER
);
693 command
.append('\'');
694 command
.append(filterExpression
);
695 command
.append('\'');
698 executeCommand(command
.toString(), monitor
);
704 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#enableSyscalls(java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
707 public void enableSyscalls(String sessionName
, String channelName
, IProgressMonitor monitor
) throws ExecutionException
{
709 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
711 command
.append(LTTngControlServiceConstants
.OPTION_ALL
);
712 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
714 String newSessionName
= formatParameter(sessionName
);
716 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
717 command
.append(newSessionName
);
719 if (channelName
!= null) {
720 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
721 command
.append(channelName
);
724 command
.append(LTTngControlServiceConstants
.OPTION_SYSCALL
);
726 executeCommand(command
.toString(), monitor
);
731 * @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)
734 public void enableProbe(String sessionName
, String channelName
, String eventName
, boolean isFunction
, String probe
, IProgressMonitor monitor
) throws ExecutionException
{
735 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
737 command
.append(eventName
);
738 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
740 String newSessionName
= formatParameter(sessionName
);
741 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
742 command
.append(newSessionName
);
744 if (channelName
!= null) {
745 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
746 command
.append(channelName
);
749 command
.append(LTTngControlServiceConstants
.OPTION_FUNCTION_PROBE
);
751 command
.append(LTTngControlServiceConstants
.OPTION_PROBE
);
754 command
.append(probe
);
756 executeCommand(command
.toString(), monitor
);
761 * @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)
764 public void enableLogLevel(String sessionName
, String channelName
, String eventName
, LogLevelType logLevelType
, TraceLogLevel level
, String filterExpression
, IProgressMonitor monitor
) throws ExecutionException
{
765 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
767 command
.append(eventName
);
768 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
770 String newSessionName
= formatParameter(sessionName
);
771 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
772 command
.append(newSessionName
);
774 if (channelName
!= null) {
775 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
776 command
.append(channelName
);
779 if (logLevelType
== LogLevelType
.LOGLEVEL
) {
780 command
.append(LTTngControlServiceConstants
.OPTION_LOGLEVEL
);
781 } else if (logLevelType
== LogLevelType
.LOGLEVEL_ONLY
) {
782 command
.append(LTTngControlServiceConstants
.OPTION_LOGLEVEL_ONLY
);
787 command
.append(level
.getInName());
789 executeCommand(command
.toString(), monitor
);
796 * @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)
799 public void disableEvent(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
800 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_DISABLE_EVENT
);
802 if (eventNames
== null) {
803 command
.append(LTTngControlServiceConstants
.OPTION_ALL
);
805 // no events to disable
806 if (eventNames
.isEmpty()) {
810 StringBuffer eventNameParameter
= new StringBuffer();
811 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
812 String event
= iterator
.next();
813 eventNameParameter
.append(event
);
814 if (iterator
.hasNext()) {
815 eventNameParameter
.append(',');
818 command
.append(formatParameter(eventNameParameter
.toString()));
822 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
824 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
827 String newSessionName
= formatParameter(sessionName
);
828 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
829 command
.append(newSessionName
);
831 if (channelName
!= null) {
832 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
833 command
.append(channelName
);
836 executeCommand(command
.toString(), monitor
);
841 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#getContexts(org.eclipse.core.runtime.IProgressMonitor)
844 public List
<String
> getContextList(IProgressMonitor monitor
) throws ExecutionException
{
846 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ADD_CONTEXT
, LTTngControlServiceConstants
.OPTION_HELP
);
848 ICommandResult result
= executeCommand(command
.toString(), monitor
);
850 String
[] output
= result
.getOutput();
852 List
<String
> contexts
= new ArrayList
<String
>(0);
855 boolean inList
= false;
856 while (index
< output
.length
) {
857 String line
= result
.getOutput()[index
];
859 Matcher startMatcher
= LTTngControlServiceConstants
.ADD_CONTEXT_HELP_CONTEXTS_INTRO
.matcher(line
);
860 Matcher endMatcher
= LTTngControlServiceConstants
.ADD_CONTEXT_HELP_CONTEXTS_END_LINE
.matcher(line
);
862 if (startMatcher
.matches()) {
864 } else if (endMatcher
.matches()) {
866 } else if (inList
== true) {
867 String
[] tmp
= line
.split(","); //$NON-NLS-1$
868 for (int i
= 0; i
< tmp
.length
; i
++) {
869 contexts
.add(tmp
[i
].trim());
879 * @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)
882 public void addContexts(String sessionName
, String channelName
, String eventName
, boolean isKernel
, List
<String
> contextNames
, IProgressMonitor monitor
) throws ExecutionException
{
883 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ADD_CONTEXT
);
885 String newSessionName
= formatParameter(sessionName
);
886 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
887 command
.append(newSessionName
);
889 if (channelName
!= null) {
890 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
891 command
.append(channelName
);
894 if (eventName
!= null) {
895 command
.append(LTTngControlServiceConstants
.OPTION_EVENT
);
896 command
.append(eventName
);
900 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
902 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
905 for (Iterator
<String
> iterator
= contextNames
.iterator(); iterator
.hasNext();) {
906 String context
= iterator
.next();
907 command
.append(LTTngControlServiceConstants
.OPTION_CONTEXT_TYPE
);
908 command
.append(context
);
911 executeCommand(command
.toString(), monitor
);
917 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#calibrate(boolean, org.eclipse.core.runtime.IProgressMonitor)
920 public void calibrate(boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
921 // String newSessionName = formatParameter(sessionName);
922 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_CALIBRATE
);
924 // command.append(OPTION_SESSION);
925 // command.append(newSessionName);
928 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
930 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
933 command
.append(LTTngControlServiceConstants
.OPTION_FUNCTION_PROBE
);
935 executeCommand(command
.toString(), monitor
);
938 // ------------------------------------------------------------------------
940 // ------------------------------------------------------------------------
942 * Checks if command result is an error result.
945 * - the command result to check
946 * @return true if error else false
948 protected boolean isError(ICommandResult result
) {
949 if ((result
.getResult()) != 0 || (result
.getOutput().length
< 1 || LTTngControlServiceConstants
.ERROR_PATTERN
.matcher(result
.getOutput()[0]).matches())) {
956 * Formats the output string as single string.
960 * @return - the formatted output
962 public static String
formatOutput(ICommandResult result
) {
963 if ((result
== null) || result
.getOutput() == null || result
.getOutput().length
== 0) {
964 return ""; //$NON-NLS-1$
966 String
[] output
= result
.getOutput();
967 StringBuffer ret
= new StringBuffer();
968 ret
.append("Return Value: "); //$NON-NLS-1$
969 ret
.append(result
.getResult());
970 ret
.append("\n"); //$NON-NLS-1$
971 for (int i
= 0; i
< output
.length
; i
++) {
972 ret
.append(output
[i
] + "\n"); //$NON-NLS-1$
974 return ret
.toString();
978 * Parses the domain information.
981 * - a command output array
982 * @param currentIndex
983 * - current index in command output array
985 * - list for returning channel information
986 * @return the new current index in command output array
988 protected int parseDomain(String
[] output
, int currentIndex
, List
<IChannelInfo
> channels
) {
989 int index
= currentIndex
;
993 // - channnel1: [enabled]
997 // subbufers size: 262144
998 // number of subbufers: 4
999 // switch timer interval: 0
1000 // read timer interval: 200
1003 while (index
< output
.length
) {
1004 String line
= output
[index
];
1006 Matcher outerMatcher
= LTTngControlServiceConstants
.CHANNELS_SECTION_PATTERN
.matcher(line
);
1007 if (outerMatcher
.matches()) {
1008 IChannelInfo channelInfo
= null;
1009 while (index
< output
.length
) {
1010 String subLine
= output
[index
];
1012 Matcher innerMatcher
= LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(subLine
);
1013 if (innerMatcher
.matches()) {
1014 channelInfo
= new ChannelInfo(""); //$NON-NLS-1$
1016 channelInfo
.setName(innerMatcher
.group(1));
1018 // get channel enablement
1019 channelInfo
.setState(innerMatcher
.group(2));
1022 channels
.add(channelInfo
);
1024 } else if (LTTngControlServiceConstants
.OVERWRITE_MODE_ATTRIBUTE
.matcher(subLine
).matches()) {
1025 String value
= getAttributeValue(subLine
);
1026 if (channelInfo
!= null) {
1027 channelInfo
.setOverwriteMode(!LTTngControlServiceConstants
.OVERWRITE_MODE_ATTRIBUTE_FALSE
.equals(value
));
1029 } else if (LTTngControlServiceConstants
.SUBBUFFER_SIZE_ATTRIBUTE
.matcher(subLine
).matches()) {
1030 if (channelInfo
!= null) {
1031 channelInfo
.setSubBufferSize(Long
.valueOf(getAttributeValue(subLine
)));
1034 } else if (LTTngControlServiceConstants
.NUM_SUBBUFFERS_ATTRIBUTE
.matcher(subLine
).matches()) {
1035 if (channelInfo
!= null) {
1036 channelInfo
.setNumberOfSubBuffers(Integer
.valueOf(getAttributeValue(subLine
)));
1039 } else if (LTTngControlServiceConstants
.SWITCH_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
1040 if (channelInfo
!= null) {
1041 channelInfo
.setSwitchTimer(Long
.valueOf(getAttributeValue(subLine
)));
1044 } else if (LTTngControlServiceConstants
.READ_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
1045 if (channelInfo
!= null) {
1046 channelInfo
.setReadTimer(Long
.valueOf(getAttributeValue(subLine
)));
1049 } else if (LTTngControlServiceConstants
.OUTPUT_ATTRIBUTE
.matcher(subLine
).matches()) {
1050 if (channelInfo
!= null) {
1051 channelInfo
.setOutputType(getAttributeValue(subLine
));
1054 } else if (LTTngControlServiceConstants
.EVENT_SECTION_PATTERN
.matcher(subLine
).matches()) {
1055 List
<IEventInfo
> events
= new ArrayList
<IEventInfo
>();
1056 index
= parseEvents(output
, index
, events
);
1057 if (channelInfo
!= null) {
1058 channelInfo
.setEvents(events
);
1060 // we want to stay at the current index to be able to
1063 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(subLine
).matches()) {
1066 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(subLine
).matches()) {
1078 * Parses the event information within a domain.
1081 * - a command output array
1082 * @param currentIndex
1083 * - current index in command output array
1085 * - list for returning event information
1086 * @return the new current index in command output array
1088 protected int parseEvents(String
[] output
, int currentIndex
, List
<IEventInfo
> events
) {
1089 int index
= currentIndex
;
1091 while (index
< output
.length
) {
1092 String line
= output
[index
];
1093 if (LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(line
).matches()) {
1096 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(line
).matches()) {
1099 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
).matches()) {
1104 Matcher matcher
= LTTngControlServiceConstants
.EVENT_PATTERN
.matcher(line
);
1105 Matcher matcher2
= LTTngControlServiceConstants
.WILDCARD_EVENT_PATTERN
.matcher(line
);
1107 if (matcher
.matches()) {
1108 IEventInfo eventInfo
= new EventInfo(matcher
.group(1).trim());
1109 eventInfo
.setLogLevel(matcher
.group(2).trim());
1110 eventInfo
.setEventType(matcher
.group(3).trim());
1111 eventInfo
.setState(matcher
.group(4));
1112 String filter
= matcher
.group(5);
1113 if (filter
!= null) {
1114 filter
= filter
.substring(1, filter
.length() - 1); // remove '[' and ']'
1115 eventInfo
.setFilterExpression(filter
);
1117 events
.add(eventInfo
);
1119 } else if (matcher2
.matches()) {
1120 IEventInfo eventInfo
= new EventInfo(matcher2
.group(1).trim());
1121 eventInfo
.setLogLevel(TraceLogLevel
.LEVEL_UNKNOWN
);
1122 eventInfo
.setEventType(matcher2
.group(2).trim());
1123 eventInfo
.setState(matcher2
.group(3));
1124 String filter
= matcher2
.group(4);
1125 if (filter
!= null) {
1126 filter
= filter
.substring(1, filter
.length() - 1); // remove '[' and ']'
1127 eventInfo
.setFilterExpression(filter
);
1130 if (eventInfo
.getEventType() == TraceEventType
.PROBE
) {
1131 IProbeEventInfo probeEvent
= new ProbeEventInfo(eventInfo
.getName());
1132 probeEvent
.setLogLevel(eventInfo
.getLogLevel());
1133 probeEvent
.setEventType(eventInfo
.getEventType());
1134 probeEvent
.setState(eventInfo
.getState());
1136 // Overwrite eventinfo
1137 eventInfo
= probeEvent
;
1139 // myevent2 (type: probe) [enabled]
1141 // myevent0 (type: probe) [enabled]
1143 // symbol: init_post
1145 while (index
< output
.length
) {
1146 String probeLine
= output
[index
];
1148 Matcher addrMatcher
= LTTngControlServiceConstants
.PROBE_ADDRESS_PATTERN
.matcher(probeLine
);
1149 Matcher offsetMatcher
= LTTngControlServiceConstants
.PROBE_OFFSET_PATTERN
.matcher(probeLine
);
1150 Matcher symbolMatcher
= LTTngControlServiceConstants
.PROBE_SYMBOL_PATTERN
.matcher(probeLine
);
1151 if (addrMatcher
.matches()) {
1152 String addr
= addrMatcher
.group(2).trim();
1153 probeEvent
.setAddress(addr
);
1154 } else if (offsetMatcher
.matches()) {
1155 String offset
= offsetMatcher
.group(2).trim();
1156 probeEvent
.setOffset(offset
);
1157 } else if (symbolMatcher
.matches()) {
1158 String symbol
= symbolMatcher
.group(2).trim();
1159 probeEvent
.setSymbol(symbol
);
1160 } else if ((LTTngControlServiceConstants
.EVENT_PATTERN
.matcher(probeLine
).matches()) || (LTTngControlServiceConstants
.WILDCARD_EVENT_PATTERN
.matcher(probeLine
).matches())) {
1162 } else if (LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(probeLine
).matches()) {
1164 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(probeLine
).matches()) {
1167 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(probeLine
).matches()) {
1173 events
.add(eventInfo
);
1175 events
.add(eventInfo
);
1182 // else if (line.matches(EVENT_NONE_PATTERN)) {
1192 * Parses a line with attributes: <attribute Name>: <attribute value>
1195 * - attribute line to parse
1196 * @return the attribute value as string
1198 protected String
getAttributeValue(String line
) {
1199 String
[] temp
= line
.split("\\: "); //$NON-NLS-1$
1204 * Parses the event information within a provider.
1207 * - a command output array
1208 * @param currentIndex
1209 * - current index in command output array
1211 * - list for returning event information
1212 * @return the new current index in command output array
1214 protected int getProviderEventInfo(String
[] output
, int currentIndex
, List
<IBaseEventInfo
> events
) {
1215 int index
= currentIndex
;
1216 IBaseEventInfo eventInfo
= null;
1217 while (index
< output
.length
) {
1218 String line
= output
[index
];
1219 Matcher matcher
= LTTngControlServiceConstants
.PROVIDER_EVENT_PATTERN
.matcher(line
);
1220 if (matcher
.matches()) {
1221 // sched_kthread_stop (loglevel: TRACE_EMERG0) (type: tracepoint)
1222 eventInfo
= new BaseEventInfo(matcher
.group(1).trim());
1223 eventInfo
.setLogLevel(matcher
.group(2).trim());
1224 eventInfo
.setEventType(matcher
.group(3).trim());
1225 events
.add(eventInfo
);
1227 } else if (LTTngControlServiceConstants
.EVENT_FIELD_PATTERN
.matcher(line
).matches()) {
1228 if (eventInfo
!= null) {
1229 List
<IFieldInfo
> fields
= new ArrayList
<IFieldInfo
>();
1230 index
= getFieldInfo(output
, index
, fields
);
1231 eventInfo
.setFields(fields
);
1236 else if (LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
).matches()) {
1247 * Parse a field's information.
1250 * A command output array
1251 * @param currentIndex
1252 * The current index in the command output array
1254 * List for returning the field information
1255 * @return The new current index in the command output array
1257 protected int getFieldInfo(String
[] output
, int currentIndex
, List
<IFieldInfo
> fields
) {
1258 int index
= currentIndex
;
1259 IFieldInfo fieldInfo
= null;
1260 while (index
< output
.length
) {
1261 String line
= output
[index
];
1262 Matcher matcher
= LTTngControlServiceConstants
.EVENT_FIELD_PATTERN
.matcher(line
);
1263 if (matcher
.matches()) {
1264 // field: content (string)
1265 fieldInfo
= new FieldInfo(matcher
.group(2).trim());
1266 fieldInfo
.setFieldType(matcher
.group(3).trim());
1267 fields
.add(fieldInfo
);
1268 } else if (LTTngControlServiceConstants
.PROVIDER_EVENT_PATTERN
.matcher(line
).matches()) {
1270 } else if (LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
).matches()) {
1279 * Formats a command parameter for the command execution i.e. adds quotes
1280 * at the beginning and end if necessary.
1281 * @param parameter - parameter to format
1282 * @return formated parameter
1284 protected String
formatParameter(String parameter
) {
1285 if (parameter
!= null) {
1286 StringBuffer newString
= new StringBuffer();
1287 newString
.append(parameter
);
1289 if (parameter
.contains(" ") || parameter
.contains("*")) { //$NON-NLS-1$ //$NON-NLS-2$
1290 newString
.insert(0, "\""); //$NON-NLS-1$
1291 newString
.append("\""); //$NON-NLS-1$
1293 return newString
.toString();
1299 * @param strings array of string that makes up a command line
1300 * @return string buffer with created command line
1302 protected StringBuffer
createCommand(String
... strings
) {
1303 StringBuffer command
= new StringBuffer();
1304 command
.append(LTTngControlServiceConstants
.CONTROL_COMMAND
);
1305 command
.append(getTracingGroupOption());
1306 command
.append(getVerboseOption());
1307 for (String string
: strings
) {
1308 command
.append(string
);
1314 * @return the tracing group option if configured in the preferences
1316 protected String
getTracingGroupOption() {
1317 if (!ControlPreferences
.getInstance().isDefaultTracingGroup() && !ControlPreferences
.getInstance().getTracingGroup().equals("")) { //$NON-NLS-1$
1318 return LTTngControlServiceConstants
.OPTION_TRACING_GROUP
+ ControlPreferences
.getInstance().getTracingGroup();
1320 return ""; //$NON-NLS-1$
1324 * @return the verbose option as configured in the preferences
1326 protected String
getVerboseOption() {
1327 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1328 String level
= ControlPreferences
.getInstance().getVerboseLevel();
1329 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_VERBOSE
.equals(level
)) {
1330 return LTTngControlServiceConstants
.OPTION_VERBOSE
;
1332 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_V_VERBOSE
.equals(level
)) {
1333 return LTTngControlServiceConstants
.OPTION_VERY_VERBOSE
;
1335 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_V_V_VERBOSE
.equals(level
)) {
1336 return LTTngControlServiceConstants
.OPTION_VERY_VERY_VERBOSE
;
1339 return ""; //$NON-NLS-1$
1343 * Method that logs the command and command result if logging is enabled as
1344 * well as forwards the command execution to the shell.
1347 * - the command to execute
1349 * - a progress monitor
1350 * @return the command result
1351 * @throws ExecutionException
1352 * If the command fails
1354 protected ICommandResult
executeCommand(String command
,
1355 IProgressMonitor monitor
) throws ExecutionException
{
1356 return executeCommand(command
, monitor
, true);
1360 * Method that logs the command and command result if logging is enabled as
1361 * well as forwards the command execution to the shell.
1364 * - the command to execute
1366 * - a progress monitor
1367 * @param checkForError
1368 * - true to verify command result, else false
1369 * @return the command result
1370 * @throws ExecutionException
1371 * in case of error result
1373 protected ICommandResult
executeCommand(String command
,
1374 IProgressMonitor monitor
, boolean checkForError
)
1375 throws ExecutionException
{
1376 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1377 ControlCommandLogger
.log(command
);
1380 ICommandResult result
= fCommandShell
.executeCommand(
1381 command
.toString(), monitor
);
1383 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1384 ControlCommandLogger
.log(formatOutput(result
));
1387 if (checkForError
&& isError(result
)) {
1388 throw new ExecutionException(Messages
.TraceControl_CommandError
1389 + " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$