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
;
18 import java
.util
.regex
.Pattern
;
20 import org
.eclipse
.core
.commands
.ExecutionException
;
21 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
22 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
23 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.Messages
;
24 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.logging
.ControlCommandLogger
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.IBaseEventInfo
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.IChannelInfo
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.IDomainInfo
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.IEventInfo
;
29 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.IProbeEventInfo
;
30 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.ISessionInfo
;
31 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.IUstProviderInfo
;
32 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.LogLevelType
;
33 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.TraceEventType
;
34 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.TraceLogLevel
;
35 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.BaseEventInfo
;
36 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.ChannelInfo
;
37 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.DomainInfo
;
38 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.EventInfo
;
39 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.ProbeEventInfo
;
40 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.SessionInfo
;
41 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.UstProviderInfo
;
42 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.preferences
.ControlPreferences
;
45 * <b><u>LTTngControlService</u></b>
47 * Service for sending LTTng trace control commands to remote host.
50 public class LTTngControlService
implements ILttngControlService
{
51 // ------------------------------------------------------------------------
53 // ------------------------------------------------------------------------
56 * The lttng tools command.
58 private final static String CONTROL_COMMAND
= "lttng"; //$NON-NLS-1$
60 * Command: lttng list.
62 private final static String COMMAND_LIST
= " list "; //$NON-NLS-1$
64 * Command to list kernel tracer information.
66 private final static String COMMAND_LIST_KERNEL
= COMMAND_LIST
+ "-k"; //$NON-NLS-1$
68 * Command to list user space trace information.
70 private final static String COMMAND_LIST_UST
= COMMAND_LIST
+ "-u"; //$NON-NLS-1$
72 * Command to create a session.
74 private final static String COMMAND_CREATE_SESSION
= " create "; //$NON-NLS-1$
76 * Command to destroy a session.
78 private final static String COMMAND_DESTROY_SESSION
= " destroy "; //$NON-NLS-1$
80 * Command to destroy a session.
82 private final static String COMMAND_START_SESSION
= " start "; //$NON-NLS-1$
84 * Command to destroy a session.
86 private final static String COMMAND_STOP_SESSION
= " stop "; //$NON-NLS-1$
88 * Command to enable a channel.
90 private final static String COMMAND_ENABLE_CHANNEL
= " enable-channel "; //$NON-NLS-1$
92 * Command to disable a channel.
94 private final static String COMMAND_DISABLE_CHANNEL
= " disable-channel "; //$NON-NLS-1$
96 * Command to enable a event.
98 private final static String COMMAND_ENABLE_EVENT
= " enable-event "; //$NON-NLS-1$
100 * Command to disable a event.
102 private final static String COMMAND_DISABLE_EVENT
= " disable-event "; //$NON-NLS-1$
104 * Command to add a context to channels and/or events
106 private final static String COMMAND_ADD_CONTEXT
= " add-context "; //$NON-NLS-1$
108 * Command to execute calibrate command to quantify LTTng overhead
110 private final static String COMMAND_CALIBRATE
= " calibrate "; //$NON-NLS-1$
112 // Command options constants
114 * Command line option to add tracing group of user.
116 private final static String OPTION_TRACING_GROUP
= " -g "; //$NON-NLS-1$
118 * Command line option for verbose output.
120 private final static String OPTION_VERBOSE
= " -v "; //$NON-NLS-1$
122 * Command line option for verbose output.
124 private final static String OPTION_VERY_VERBOSE
= " -vv "; //$NON-NLS-1$
126 * Command line option for verbose output.
128 private final static String OPTION_VERY_VERY_VERBOSE
= " -vvv "; //$NON-NLS-1$
130 * Command line option for output path.
132 private final static String OPTION_OUTPUT_PATH
= " -o "; //$NON-NLS-1$
134 * Command line option for kernel tracer.
136 private final static String OPTION_KERNEL
= " -k "; //$NON-NLS-1$
138 * Command line option for UST tracer.
140 private final static String OPTION_UST
= " -u "; //$NON-NLS-1$
142 * Command line option for specifying a session.
144 private final static String OPTION_SESSION
= " -s "; //$NON-NLS-1$
146 * Command line option for specifying a channel.
148 private final static String OPTION_CHANNEL
= " -c "; //$NON-NLS-1$
150 * Command line option for specifying a event.
152 private final static String OPTION_EVENT
= " -e "; //$NON-NLS-1$
154 * Command line option for specifying all events.
156 private final static String OPTION_ALL
= " -a "; //$NON-NLS-1$
158 * Command line option for specifying a context.
160 private final static String OPTION_CONTEXT_TYPE
= " -t "; //$NON-NLS-1$
162 * Command line option for specifying tracepoint events.
164 private final static String OPTION_TRACEPOINT
= " --tracepoint "; //$NON-NLS-1$
166 * Command line option for specifying syscall events.
168 private final static String OPTION_SYSCALL
= " --syscall "; //$NON-NLS-1$
170 * Command line option for specifying a dynamic probe.
172 private final static String OPTION_PROBE
= " --probe "; //$NON-NLS-1$
174 * Command line option for specifying a dynamic function entry/return probe.
176 private final static String OPTION_FUNCTION_PROBE
= " --function "; //$NON-NLS-1$
178 * Command line option for specifying a log level range.
180 private final static String OPTION_LOGLEVEL
= " --loglevel "; //$NON-NLS-1$
182 * Command line option for specifying a specific log level.
184 private final static String OPTION_LOGLEVEL_ONLY
= " --loglevel-only "; //$NON-NLS-1$
186 * Optional command line option for configuring a channel's overwrite mode.
188 private final static String OPTION_OVERWRITE
= " --overwrite "; //$NON-NLS-1$
190 * Optional command line option for configuring a channel's number of sub buffers.
192 private final static String OPTION_NUM_SUB_BUFFERS
= " --num-subbuf "; //$NON-NLS-1$
194 * Optional command line option for configuring a channel's sub buffer size.
196 private final static String OPTION_SUB_BUFFER_SIZE
= " --subbuf-size "; //$NON-NLS-1$
198 * Optional command line option for configuring a channel's switch timer interval.
200 private final static String OPTION_SWITCH_TIMER
= " --switch-timer "; //$NON-NLS-1$
202 * Optional command line option for configuring a channel's read timer interval.
204 private final static String OPTION_READ_TIMER
= " --read-timer "; //$NON-NLS-1$
206 * Command line option for printing the help of a specif command
208 private final static String OPTION_HELP
= " -h "; //$NON-NLS-1$
212 * Pattern to match for error output
214 private final static Pattern ERROR_PATTERN
= Pattern
.compile("\\s*Error\\:.*"); //$NON-NLS-1$
216 * Pattern to match for session information (lttng list)
218 private final static Pattern SESSION_PATTERN
= Pattern
.compile("\\s+(\\d+)\\)\\s+(.*)\\s+\\((.*)\\)\\s+\\[(active|inactive)\\].*"); //$NON-NLS-1$
220 * Pattern to match for session information (lttng list <session>)
222 private final static Pattern TRACE_SESSION_PATTERN
= Pattern
.compile("\\s*Tracing\\s+session\\s+(.*)\\:\\s+\\[(active|inactive)\\].*"); //$NON-NLS-1$
224 * Pattern to match for session path information (lttng list <session>)
226 private final static Pattern TRACE_SESSION_PATH_PATTERN
= Pattern
.compile("\\s*Trace\\s+path\\:\\s+(.*)"); //$NON-NLS-1$
228 * Pattern to match for kernel domain information (lttng list <session>)
230 private final static Pattern DOMAIN_KERNEL_PATTERN
= Pattern
.compile("=== Domain: Kernel ==="); //$NON-NLS-1$
232 * Pattern to match for ust domain information (lttng list <session>)
234 private final static Pattern DOMAIN_UST_GLOBAL_PATTERN
= Pattern
.compile("=== Domain: UST global ==="); //$NON-NLS-1$
236 * Pattern to match for channels section (lttng list <session>)
238 private final static Pattern CHANNELS_SECTION_PATTERN
= Pattern
.compile("\\s*Channels\\:"); //$NON-NLS-1$
240 * Pattern to match for channel information (lttng list <session>)
242 private final static Pattern CHANNEL_PATTERN
= Pattern
.compile("\\s*-\\s+(.*)\\:\\s+\\[(enabled|disabled)\\]"); //$NON-NLS-1$
244 * Pattern to match for events section information (lttng list <session>)
246 private final static Pattern EVENT_SECTION_PATTERN
= Pattern
.compile("\\s*Events\\:"); //$NON-NLS-1$
248 * Pattern to match for event information (no enabled events) (lttng list <session>)
250 // private final static String EVENT_NONE_PATTERN = "\\s+None"; //$NON-NLS-1$
252 * Pattern to match for event information (lttng list <session>)
254 private final static Pattern EVENT_PATTERN
= Pattern
.compile("\\s+(.*)\\s+\\(loglevel:\\s+(.*)\\s+\\(\\d*\\)\\)\\s+\\(type:\\s+(.*)\\)\\s+\\[(enabled|disabled)\\].*"); //$NON-NLS-1$
256 * Pattern to match a wildcarded event information (lttng list <session>)
258 private final static Pattern WILDCARD_EVENT_PATTERN
= Pattern
.compile("\\s+(.*)\\s+\\(type:\\s+(.*)\\)\\s+\\[(enabled|disabled)\\].*"); //$NON-NLS-1$
260 * Pattern to match a probe address information (lttng list <session>)
262 private final static Pattern PROBE_ADDRESS_PATTERN
= Pattern
.compile("\\s+(addr)\\:\\s+(0x[0-9a-fA-F]{1,8})"); //$NON-NLS-1$
264 * Pattern to match a probe OFFSET information (lttng list <session>)
266 private final static Pattern PROBE_OFFSET_PATTERN
= Pattern
.compile("\\s+(offset)\\:\\s+(0x[0-9a-fA-F]{1,8})"); //$NON-NLS-1$
268 * Pattern to match a probe SYMBOL information (lttng list <session>)
270 private final static Pattern PROBE_SYMBOL_PATTERN
= Pattern
.compile("\\s+(symbol)\\:\\s+(.+)"); //$NON-NLS-1$
272 * Pattern to match for channel (overwite mode) information (lttng list
275 private final static Pattern OVERWRITE_MODE_ATTRIBUTE
= Pattern
.compile("\\s+overwrite\\s+mode\\:.*"); //$NON-NLS-1$
277 * Pattern to match indicating false for overwrite mode
279 private final static String OVERWRITE_MODE_ATTRIBUTE_FALSE
= "0"; //$NON-NLS-1$
281 * Pattern to match for channel (sub-buffer size) information (lttng list
284 private final static Pattern SUBBUFFER_SIZE_ATTRIBUTE
= Pattern
.compile("\\s+subbufers\\s+size\\:.*"); //$NON-NLS-1$
286 * Pattern to match for channel (number of sub-buffers) information (lttng
289 private final static Pattern NUM_SUBBUFFERS_ATTRIBUTE
= Pattern
.compile("\\s+number\\s+of\\s+subbufers\\:.*"); //$NON-NLS-1$
291 * Pattern to match for channel (switch timer) information (lttng list
294 private final static Pattern SWITCH_TIMER_ATTRIBUTE
= Pattern
.compile("\\s+switch\\s+timer\\s+interval\\:.*"); //$NON-NLS-1$
296 * Pattern to match for channel (read timer) information (lttng list
299 private final static Pattern READ_TIMER_ATTRIBUTE
= Pattern
.compile("\\s+read\\s+timer\\s+interval\\:.*"); //$NON-NLS-1$
301 * Pattern to match for channel (output type) information (lttng list
304 private final static Pattern OUTPUT_ATTRIBUTE
= Pattern
.compile("\\s+output\\:.*"); //$NON-NLS-1$
306 * Pattern to match for provider information (lttng list -k/-u)
308 private final static Pattern PROVIDER_EVENT_PATTERN
= Pattern
.compile("\\s*(.*)\\s+\\(loglevel:\\s+(.*)\\s+\\(\\d*\\)\\)\\s+\\(type:\\s+(.*)\\)"); //$NON-NLS-1$
310 * Pattern to match for UST provider information (lttng list -u)
312 private final static Pattern UST_PROVIDER_PATTERN
= Pattern
.compile("\\s*PID\\:\\s+(\\d+)\\s+-\\s+Name\\:\\s+(.*)"); //$NON-NLS-1$
314 * Pattern to match for session information (lttng create <session name>)
316 private final static Pattern CREATE_SESSION_NAME_PATTERN
= Pattern
.compile("\\s*Session\\s+(.*)\\s+created\\."); //$NON-NLS-1$
318 * Pattern to match for session path information (lttng create <session name>)
320 private final static Pattern CREATE_SESSION_PATH_PATTERN
= Pattern
.compile("\\s*Traces\\s+will\\s+be\\s+written\\s+in\\s+(.*).*"); //$NON-NLS-1$
322 * Pattern to match for session command output for "session name not found".
324 private final static Pattern SESSION_NOT_FOUND_ERROR_PATTERN
= Pattern
.compile("\\s*Error:\\s+Session\\s+name\\s+not\\s+found"); //$NON-NLS-1$
326 * Pattern to match introduction line of context list.
328 private final static Pattern ADD_CONTEXT_HELP_CONTEXTS_INTRO
= Pattern
.compile("\\s*TYPE can\\s+be\\s+one\\s+of\\s+the\\s+strings\\s+below.*"); //$NON-NLS-1$
331 * Pattern to match introduction line of context list.
333 private final static Pattern ADD_CONTEXT_HELP_CONTEXTS_END_LINE
= Pattern
.compile("\\s*Example.*"); //$NON-NLS-1$
335 // ------------------------------------------------------------------------
337 // ------------------------------------------------------------------------
339 * The command shell implementation
341 private ICommandShell fCommandShell
= null;
343 // ------------------------------------------------------------------------
345 // ------------------------------------------------------------------------
351 * - the command shell implementation to use
353 public LTTngControlService(ICommandShell shell
) {
354 fCommandShell
= shell
;
357 // ------------------------------------------------------------------------
359 // ------------------------------------------------------------------------
365 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
366 * #getSessionNames(org.eclipse.core.runtime.IProgressMonitor)
369 public String
[] getSessionNames(IProgressMonitor monitor
) throws ExecutionException
{
370 StringBuffer command
= createCommand(COMMAND_LIST
);
372 ICommandResult result
= executeCommand(command
.toString(), monitor
);
375 // Available tracing sessions:
376 // 1) mysession1 (/home/user/lttng-traces/mysession1-20120123-083928)
378 // 2) mysession (/home/user/lttng-traces/mysession-20120123-083318)
381 // Use lttng list <session_name> for more details
383 ArrayList
<String
> retArray
= new ArrayList
<String
>();
385 while (index
< result
.getOutput().length
) {
386 String line
= result
.getOutput()[index
];
387 Matcher matcher
= SESSION_PATTERN
.matcher(line
);
388 if (matcher
.matches()) {
389 retArray
.add(matcher
.group(2).trim());
393 return retArray
.toArray(new String
[retArray
.size()]);
400 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
401 * #getSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
404 public ISessionInfo
getSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
405 StringBuffer command
= createCommand(COMMAND_LIST
, sessionName
);
406 ICommandResult result
= executeCommand(command
.toString(), monitor
);
411 // Tracing session mysession2: [inactive]
412 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
413 ISessionInfo sessionInfo
= new SessionInfo(sessionName
);
415 while (index
< result
.getOutput().length
) {
416 // Tracing session mysession2: [inactive]
417 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
419 // === Domain: Kernel ===
421 String line
= result
.getOutput()[index
];
422 Matcher matcher
= TRACE_SESSION_PATTERN
.matcher(line
);
423 if (matcher
.matches()) {
424 sessionInfo
.setSessionState(matcher
.group(2));
429 matcher
= TRACE_SESSION_PATH_PATTERN
.matcher(line
);
430 if (matcher
.matches()) {
431 sessionInfo
.setSessionPath(matcher
.group(1).trim());
436 matcher
= DOMAIN_KERNEL_PATTERN
.matcher(line
);
437 if (matcher
.matches()) {
439 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_KernelDomainDisplayName
);
440 sessionInfo
.addDomain(domainInfo
);
443 ArrayList
<IChannelInfo
> channels
= new ArrayList
<IChannelInfo
>();
444 index
= parseDomain(result
.getOutput(), index
, channels
);
447 domainInfo
.setChannels(channels
);
450 domainInfo
.setIsKernel(true);
454 matcher
= DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
);
455 if (matcher
.matches()) {
456 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_UstGlobalDomainDisplayName
);
457 sessionInfo
.addDomain(domainInfo
);
460 ArrayList
<IChannelInfo
> channels
= new ArrayList
<IChannelInfo
>();
461 index
= parseDomain(result
.getOutput(), index
, channels
);
464 domainInfo
.setChannels(channels
);
467 domainInfo
.setIsKernel(false);
479 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
480 * #getKernelProvider(org.eclipse.core.runtime.IProgressMonitor)
483 public List
<IBaseEventInfo
> getKernelProvider(IProgressMonitor monitor
) throws ExecutionException
{
484 StringBuffer command
= createCommand(COMMAND_LIST_KERNEL
);
485 ICommandResult result
= executeCommand(command
.toString(), monitor
);
489 // sched_kthread_stop (type: tracepoint)
490 List
<IBaseEventInfo
> events
= new ArrayList
<IBaseEventInfo
>();
491 getProviderEventInfo(result
.getOutput(), 0, events
);
499 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
503 public List
<IUstProviderInfo
> getUstProvider() throws ExecutionException
{
504 return getUstProvider(new NullProgressMonitor());
511 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
512 * #getUstProvider(org.eclipse.core.runtime.IProgressMonitor)
515 public List
<IUstProviderInfo
> getUstProvider(IProgressMonitor monitor
) throws ExecutionException
{
516 StringBuffer command
= createCommand(COMMAND_LIST_UST
);
518 ICommandResult result
= executeCommand(command
.toString(), monitor
);
524 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
525 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
527 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
530 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
531 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
533 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
535 List
<IUstProviderInfo
> allProviders
= new ArrayList
<IUstProviderInfo
>();
536 IUstProviderInfo provider
= null;
539 while (index
< result
.getOutput().length
) {
540 String line
= result
.getOutput()[index
];
541 Matcher matcher
= UST_PROVIDER_PATTERN
.matcher(line
);
542 if (matcher
.matches()) {
544 provider
= new UstProviderInfo(matcher
.group(2).trim());
545 provider
.setPid(Integer
.valueOf(matcher
.group(1).trim()));
546 List
<IBaseEventInfo
> events
= new ArrayList
<IBaseEventInfo
>();
547 index
= getProviderEventInfo(result
.getOutput(), ++index
, events
);
548 provider
.setEvents(events
);
549 allProviders
.add(provider
);
561 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#createSession(java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
564 public ISessionInfo
createSession(String sessionName
, String sessionPath
, IProgressMonitor monitor
) throws ExecutionException
{
566 String newName
= formatParameter(sessionName
);
567 String newPath
= formatParameter(sessionPath
);
569 StringBuffer command
= createCommand(COMMAND_CREATE_SESSION
, newName
);
571 if (newPath
!= null && !"".equals(newPath
)) { //$NON-NLS-1$
572 command
.append(OPTION_OUTPUT_PATH
);
573 command
.append(newPath
);
576 ICommandResult result
= executeCommand(command
.toString(), monitor
);
578 //Session myssession2 created.
579 //Traces will be written in /home/user/lttng-traces/myssession2-20120209-095418
580 String
[] output
= result
.getOutput();
582 // Get and verify session name
583 Matcher matcher
= CREATE_SESSION_NAME_PATTERN
.matcher(output
[0]);
586 if (matcher
.matches()) {
587 name
= String
.valueOf(matcher
.group(1).trim());
589 // Output format not expected
590 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
591 Messages
.TraceControl_UnexpectedCommandOutputFormat
+ ":\n" + //$NON-NLS-1$
592 formatOutput(result
));
595 if ((name
== null) || (!name
.equals(sessionName
))) {
596 // Unexpected name returned
597 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
598 Messages
.TraceControl_UnexpectedNameError
+ ": " + name
); //$NON-NLS-1$
601 // Get and verify session path
602 matcher
= CREATE_SESSION_PATH_PATTERN
.matcher(output
[1]);
605 if (matcher
.matches()) {
606 path
= String
.valueOf(matcher
.group(1).trim());
608 // Output format not expected
609 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
610 Messages
.TraceControl_UnexpectedCommandOutputFormat
+ ":\n" + //$NON-NLS-1$
611 formatOutput(result
));
614 if ((path
== null) || ((sessionPath
!= null) && (!path
.contains(sessionPath
)))) {
616 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
617 Messages
.TraceControl_UnexpectedPathError
+ ": " + name
); //$NON-NLS-1$
620 SessionInfo sessionInfo
= new SessionInfo(name
);
621 sessionInfo
.setSessionPath(path
);
627 public void destroySession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
628 String newName
= formatParameter(sessionName
);
630 StringBuffer command
= createCommand(COMMAND_DESTROY_SESSION
, newName
);
632 ICommandResult result
= executeCommand(command
.toString(), monitor
, false);
633 String
[] output
= result
.getOutput();
635 if (isError(result
) && ((output
== null) || (!SESSION_NOT_FOUND_ERROR_PATTERN
.matcher(output
[0]).matches()))) {
636 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$
638 //Session <sessionName> destroyed
643 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#startSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
646 public void startSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
648 String newSessionName
= formatParameter(sessionName
);
650 StringBuffer command
= createCommand(COMMAND_START_SESSION
, newSessionName
);
652 executeCommand(command
.toString(), monitor
);
654 //Session <sessionName> started
659 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#stopSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
662 public void stopSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
663 String newSessionName
= formatParameter(sessionName
);
664 StringBuffer command
= createCommand(COMMAND_STOP_SESSION
, newSessionName
);
666 executeCommand(command
.toString(), monitor
);
668 //Session <sessionName> stopped
674 * @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)
677 public void enableChannels(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IChannelInfo info
, IProgressMonitor monitor
) throws ExecutionException
{
679 // no channels to enable
680 if (channelNames
.isEmpty()) {
684 StringBuffer command
= createCommand(COMMAND_ENABLE_CHANNEL
);
686 for (Iterator
<String
> iterator
= channelNames
.iterator(); iterator
.hasNext();) {
687 String channel
= (String
) iterator
.next();
688 command
.append(channel
);
689 if (iterator
.hasNext()) {
695 command
.append(OPTION_KERNEL
);
697 command
.append(OPTION_UST
);
700 String newSessionName
= formatParameter(sessionName
);
701 command
.append(OPTION_SESSION
);
702 command
.append(newSessionName
);
705 // --discard Discard event when buffers are full (default)
707 // --overwrite Flight recorder mode
708 if (info
.isOverwriteMode()) {
709 command
.append(OPTION_OVERWRITE
);
711 // --subbuf-size SIZE Subbuffer size in bytes
712 // (default: 4096, kernel default: 262144)
713 command
.append(OPTION_SUB_BUFFER_SIZE
);
714 command
.append(String
.valueOf(info
.getSubBufferSize()));
716 // --num-subbuf NUM Number of subbufers
717 // (default: 8, kernel default: 4)
718 command
.append(OPTION_NUM_SUB_BUFFERS
);
719 command
.append(String
.valueOf(info
.getNumberOfSubBuffers()));
721 // --switch-timer USEC Switch timer interval in usec (default: 0)
722 command
.append(OPTION_SWITCH_TIMER
);
723 command
.append(String
.valueOf(info
.getSwitchTimer()));
725 // --read-timer USEC Read timer interval in usec (default: 200)
726 command
.append(OPTION_READ_TIMER
);
727 command
.append(String
.valueOf(info
.getReadTimer()));
730 executeCommand(command
.toString(), monitor
);
736 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#disableChannel(java.lang.String, java.util.List, org.eclipse.core.runtime.IProgressMonitor)
739 public void disableChannels(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
741 // no channels to enable
742 if (channelNames
.isEmpty()) {
746 StringBuffer command
= createCommand(COMMAND_DISABLE_CHANNEL
);
748 for (Iterator
<String
> iterator
= channelNames
.iterator(); iterator
.hasNext();) {
749 String channel
= (String
) iterator
.next();
750 command
.append(channel
);
751 if (iterator
.hasNext()) {
757 command
.append(OPTION_KERNEL
);
759 command
.append(OPTION_UST
);
762 String newSessionName
= formatParameter(sessionName
);
763 command
.append(OPTION_SESSION
);
764 command
.append(newSessionName
);
766 executeCommand(command
.toString(), monitor
);
771 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#enableEvent(java.lang.String, java.lang.String, java.util.List, boolean, org.eclipse.core.runtime.IProgressMonitor)
774 public void enableEvents(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
776 StringBuffer command
= createCommand(COMMAND_ENABLE_EVENT
);
778 if (eventNames
== null || eventNames
.isEmpty()) {
779 command
.append(OPTION_ALL
);
782 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
783 String event
= (String
) iterator
.next();
784 command
.append(event
);
785 if (iterator
.hasNext()) {
792 command
.append(OPTION_KERNEL
);
794 command
.append(OPTION_UST
);
797 String newSessionName
= formatParameter(sessionName
);
799 command
.append(OPTION_SESSION
);
800 command
.append(newSessionName
);
802 if (channelName
!= null) {
803 command
.append(OPTION_CHANNEL
);
804 command
.append(channelName
);
807 command
.append(OPTION_TRACEPOINT
);
809 executeCommand(command
.toString(), monitor
);
815 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#enableSyscalls(java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
818 public void enableSyscalls(String sessionName
, String channelName
, IProgressMonitor monitor
) throws ExecutionException
{
820 StringBuffer command
= createCommand(COMMAND_ENABLE_EVENT
);
822 command
.append(OPTION_ALL
);
823 command
.append(OPTION_KERNEL
);
825 String newSessionName
= formatParameter(sessionName
);
827 command
.append(OPTION_SESSION
);
828 command
.append(newSessionName
);
830 if (channelName
!= null) {
831 command
.append(OPTION_CHANNEL
);
832 command
.append(channelName
);
835 command
.append(OPTION_SYSCALL
);
837 executeCommand(command
.toString(), monitor
);
842 * @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)
845 public void enableProbe(String sessionName
, String channelName
, String eventName
, boolean isFunction
, String probe
, IProgressMonitor monitor
) throws ExecutionException
{
846 StringBuffer command
= createCommand(COMMAND_ENABLE_EVENT
);
848 command
.append(eventName
);
849 command
.append(OPTION_KERNEL
);
851 String newSessionName
= formatParameter(sessionName
);
852 command
.append(OPTION_SESSION
);
853 command
.append(newSessionName
);
855 if (channelName
!= null) {
856 command
.append(OPTION_CHANNEL
);
857 command
.append(channelName
);
860 command
.append(OPTION_FUNCTION_PROBE
);
862 command
.append(OPTION_PROBE
);
865 command
.append(probe
);
867 executeCommand(command
.toString(), monitor
);
872 * @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.ui.views.control.model.LogLevelType, org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceLogLevel, org.eclipse.core.runtime.IProgressMonitor)
875 public void enableLogLevel(String sessionName
, String channelName
, String eventName
, LogLevelType logLevelType
, TraceLogLevel level
, IProgressMonitor monitor
) throws ExecutionException
{
876 StringBuffer command
= createCommand(COMMAND_ENABLE_EVENT
);
878 command
.append(eventName
);
879 command
.append(OPTION_UST
);
881 String newSessionName
= formatParameter(sessionName
);
882 command
.append(OPTION_SESSION
);
883 command
.append(newSessionName
);
885 if (channelName
!= null) {
886 command
.append(OPTION_CHANNEL
);
887 command
.append(channelName
);
890 if (logLevelType
== LogLevelType
.LOGLEVEL
) {
891 command
.append(OPTION_LOGLEVEL
);
892 } else if (logLevelType
== LogLevelType
.LOGLEVEL_ONLY
) {
893 command
.append(OPTION_LOGLEVEL_ONLY
);
898 command
.append(level
.getInName());
900 executeCommand(command
.toString(), monitor
);
906 * @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)
909 public void disableEvent(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
910 StringBuffer command
= createCommand(COMMAND_DISABLE_EVENT
);
912 if (eventNames
== null) {
913 command
.append(OPTION_ALL
);
915 // no events to enable
916 if (eventNames
.isEmpty()) {
920 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
921 String event
= (String
) iterator
.next();
922 command
.append(event
);
923 if (iterator
.hasNext()) {
930 command
.append(OPTION_KERNEL
);
932 command
.append(OPTION_UST
);
935 String newSessionName
= formatParameter(sessionName
);
936 command
.append(OPTION_SESSION
);
937 command
.append(newSessionName
);
939 if (channelName
!= null) {
940 command
.append(OPTION_CHANNEL
);
941 command
.append(channelName
);
944 executeCommand(command
.toString(), monitor
);
949 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#getContexts(org.eclipse.core.runtime.IProgressMonitor)
952 public List
<String
> getContextList(IProgressMonitor monitor
) throws ExecutionException
{
954 StringBuffer command
= createCommand(COMMAND_ADD_CONTEXT
, OPTION_HELP
);
956 ICommandResult result
= executeCommand(command
.toString(), monitor
);
958 String
[] output
= result
.getOutput();
960 List
<String
> contexts
= new ArrayList
<String
>(0);
963 boolean inList
= false;
964 while (index
< output
.length
) {
965 String line
= result
.getOutput()[index
];
967 Matcher startMatcher
= ADD_CONTEXT_HELP_CONTEXTS_INTRO
.matcher(line
);
968 Matcher endMatcher
= ADD_CONTEXT_HELP_CONTEXTS_END_LINE
.matcher(line
);
970 if (startMatcher
.matches()) {
972 } else if (endMatcher
.matches()) {
974 } else if (inList
== true) {
975 String
[] tmp
= line
.split(","); //$NON-NLS-1$
976 for (int i
= 0; i
< tmp
.length
; i
++) {
977 contexts
.add(tmp
[i
].trim());
987 * @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)
990 public void addContexts(String sessionName
, String channelName
, String eventName
, boolean isKernel
, List
<String
> contextNames
, IProgressMonitor monitor
) throws ExecutionException
{
991 StringBuffer command
= createCommand(COMMAND_ADD_CONTEXT
);
993 String newSessionName
= formatParameter(sessionName
);
994 command
.append(OPTION_SESSION
);
995 command
.append(newSessionName
);
997 if (channelName
!= null) {
998 command
.append(OPTION_CHANNEL
);
999 command
.append(channelName
);
1002 if (eventName
!= null) {
1003 command
.append(OPTION_EVENT
);
1004 command
.append(eventName
);
1008 command
.append(OPTION_KERNEL
);
1010 command
.append(OPTION_UST
);
1013 for (Iterator
<String
> iterator
= contextNames
.iterator(); iterator
.hasNext();) {
1014 String context
= (String
) iterator
.next();
1015 command
.append(OPTION_CONTEXT_TYPE
);
1016 command
.append(context
);
1019 executeCommand(command
.toString(), monitor
);
1025 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#calibrate(boolean, org.eclipse.core.runtime.IProgressMonitor)
1028 public void calibrate(boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
1029 // String newSessionName = formatParameter(sessionName);
1030 StringBuffer command
= createCommand(COMMAND_CALIBRATE
);
1032 // command.append(OPTION_SESSION);
1033 // command.append(newSessionName);
1036 command
.append(OPTION_KERNEL
);
1038 command
.append(OPTION_UST
);
1041 command
.append(OPTION_FUNCTION_PROBE
);
1043 executeCommand(command
.toString(), monitor
);
1046 // ------------------------------------------------------------------------
1048 // ------------------------------------------------------------------------
1050 * Checks if command result is an error result.
1053 * - the command result to check
1054 * @return true if error else false
1056 private boolean isError(ICommandResult result
) {
1057 if ((result
.getResult()) != 0 || (result
.getOutput().length
< 1 || ERROR_PATTERN
.matcher(result
.getOutput()[0]).matches())) {
1064 * Formats the output string as single string.
1068 * @return - the formatted output
1070 private String
formatOutput(ICommandResult result
) {
1071 if ((result
== null) || result
.getOutput() == null || result
.getOutput().length
== 0) {
1072 return ""; //$NON-NLS-1$
1074 String
[] output
= result
.getOutput();
1075 StringBuffer ret
= new StringBuffer();
1076 ret
.append("Return Value: "); //$NON-NLS-1$
1077 ret
.append(result
.getResult());
1078 ret
.append("\n"); //$NON-NLS-1$
1079 for (int i
= 0; i
< output
.length
; i
++) {
1080 ret
.append(output
[i
] + "\n"); //$NON-NLS-1$
1082 return ret
.toString();
1086 * Parses the domain information.
1089 * - a command output array
1090 * @param currentIndex
1091 * - current index in command output array
1093 * - list for returning channel information
1094 * @return the new current index in command output array
1096 private int parseDomain(String
[] output
, int currentIndex
, List
<IChannelInfo
> channels
) {
1097 int index
= currentIndex
;
1101 // - channnel1: [enabled]
1104 // overwrite mode: 0
1105 // subbufers size: 262144
1106 // number of subbufers: 4
1107 // switch timer interval: 0
1108 // read timer interval: 200
1111 while (index
< output
.length
) {
1112 String line
= output
[index
];
1114 Matcher outerMatcher
= CHANNELS_SECTION_PATTERN
.matcher(line
);
1115 if (outerMatcher
.matches()) {
1116 IChannelInfo channelInfo
= null;
1117 while (index
< output
.length
) {
1118 String subLine
= output
[index
];
1120 Matcher innerMatcher
= CHANNEL_PATTERN
.matcher(subLine
);
1121 if (innerMatcher
.matches()) {
1122 channelInfo
= new ChannelInfo(""); //$NON-NLS-1$
1124 channelInfo
.setName(innerMatcher
.group(1));
1126 // get channel enablement
1127 channelInfo
.setState(innerMatcher
.group(2));
1130 channels
.add(channelInfo
);
1132 } else if (OVERWRITE_MODE_ATTRIBUTE
.matcher(subLine
).matches()) {
1133 String value
= getAttributeValue(subLine
);
1134 channelInfo
.setOverwriteMode(!OVERWRITE_MODE_ATTRIBUTE_FALSE
.equals(value
));
1135 } else if (SUBBUFFER_SIZE_ATTRIBUTE
.matcher(subLine
).matches()) {
1136 channelInfo
.setSubBufferSize(Long
.valueOf(getAttributeValue(subLine
)));
1138 } else if (NUM_SUBBUFFERS_ATTRIBUTE
.matcher(subLine
).matches()) {
1139 channelInfo
.setNumberOfSubBuffers(Integer
.valueOf(getAttributeValue(subLine
)));
1141 } else if (SWITCH_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
1142 channelInfo
.setSwitchTimer(Long
.valueOf(getAttributeValue(subLine
)));
1144 } else if (READ_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
1145 channelInfo
.setReadTimer(Long
.valueOf(getAttributeValue(subLine
)));
1147 } else if (OUTPUT_ATTRIBUTE
.matcher(subLine
).matches()) {
1148 channelInfo
.setOutputType(getAttributeValue(subLine
));
1150 } else if (EVENT_SECTION_PATTERN
.matcher(subLine
).matches()) {
1151 List
<IEventInfo
> events
= new ArrayList
<IEventInfo
>();
1152 index
= parseEvents(output
, index
, events
);
1153 channelInfo
.setEvents(events
);
1154 // we want to stay at the current index to be able to
1157 } else if (DOMAIN_KERNEL_PATTERN
.matcher(subLine
).matches()) {
1160 } else if (DOMAIN_UST_GLOBAL_PATTERN
.matcher(subLine
).matches()) {
1172 * Parses the event information within a domain.
1175 * - a command output array
1176 * @param currentIndex
1177 * - current index in command output array
1179 * - list for returning event information
1180 * @return the new current index in command output array
1182 private int parseEvents(String
[] output
, int currentIndex
, List
<IEventInfo
> events
) {
1183 int index
= currentIndex
;
1185 while (index
< output
.length
) {
1186 String line
= output
[index
];
1187 if (CHANNEL_PATTERN
.matcher(line
).matches()) {
1190 } else if (DOMAIN_KERNEL_PATTERN
.matcher(line
).matches()) {
1193 } else if (DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
).matches()) {
1198 Matcher matcher
= EVENT_PATTERN
.matcher(line
);
1199 Matcher matcher2
= WILDCARD_EVENT_PATTERN
.matcher(line
);
1201 if (matcher
.matches()) {
1202 IEventInfo eventInfo
= new EventInfo(matcher
.group(1).trim());
1203 eventInfo
.setLogLevel(matcher
.group(2).trim());
1204 eventInfo
.setEventType(matcher
.group(3).trim());
1205 eventInfo
.setState(matcher
.group(4));
1206 events
.add(eventInfo
);
1208 } else if (matcher2
.matches()) {
1209 IEventInfo eventInfo
= new EventInfo(matcher2
.group(1).trim());
1210 eventInfo
.setLogLevel(TraceLogLevel
.LEVEL_UNKNOWN
);
1211 eventInfo
.setEventType(matcher2
.group(2).trim());
1212 eventInfo
.setState(matcher2
.group(3));
1214 if (eventInfo
.getEventType() == TraceEventType
.PROBE
) {
1215 IProbeEventInfo probeEvent
= new ProbeEventInfo(eventInfo
.getName());
1216 probeEvent
.setLogLevel(eventInfo
.getLogLevel());
1217 probeEvent
.setEventType(eventInfo
.getEventType());
1218 probeEvent
.setState(eventInfo
.getState());
1220 // Overwrite eventinfo
1221 eventInfo
= probeEvent
;
1223 // myevent2 (type: probe) [enabled]
1225 // myevent0 (type: probe) [enabled]
1227 // symbol: init_post
1229 while (index
< output
.length
) {
1230 String probeLine
= output
[index
];
1232 Matcher addrMatcher
= PROBE_ADDRESS_PATTERN
.matcher(probeLine
);
1233 Matcher offsetMatcher
= PROBE_OFFSET_PATTERN
.matcher(probeLine
);
1234 Matcher symbolMatcher
= PROBE_SYMBOL_PATTERN
.matcher(probeLine
);
1235 if (addrMatcher
.matches()) {
1236 String addr
= addrMatcher
.group(2).trim();
1237 probeEvent
.setAddress(addr
);
1238 } else if (offsetMatcher
.matches()) {
1239 String offset
= offsetMatcher
.group(2).trim();
1240 probeEvent
.setOffset(offset
);
1241 } else if (symbolMatcher
.matches()) {
1242 String symbol
= symbolMatcher
.group(2).trim();
1243 probeEvent
.setSymbol(symbol
);
1244 } else if ((EVENT_PATTERN
.matcher(probeLine
).matches()) || (WILDCARD_EVENT_PATTERN
.matcher(probeLine
).matches())) {
1246 } else if (CHANNEL_PATTERN
.matcher(probeLine
).matches()) {
1248 } else if (DOMAIN_KERNEL_PATTERN
.matcher(probeLine
).matches()) {
1251 } else if (DOMAIN_UST_GLOBAL_PATTERN
.matcher(probeLine
).matches()) {
1257 events
.add(eventInfo
);
1259 events
.add(eventInfo
);
1266 // else if (line.matches(EVENT_NONE_PATTERN)) {
1276 * Parses a line with attributes: <attribute Name>: <attribute value>
1279 * - attribute line to parse
1280 * @return the attribute value as string
1282 private String
getAttributeValue(String line
) {
1283 String
[] temp
= line
.split("\\: "); //$NON-NLS-1$
1288 * Parses the event information within a provider.
1291 * - a command output array
1292 * @param currentIndex
1293 * - current index in command output array
1295 * - list for returning event information
1296 * @return the new current index in command output array
1298 private int getProviderEventInfo(String
[] output
, int currentIndex
, List
<IBaseEventInfo
> events
) {
1299 int index
= currentIndex
;
1300 while (index
< output
.length
) {
1301 String line
= output
[index
];
1302 Matcher matcher
= PROVIDER_EVENT_PATTERN
.matcher(line
);
1303 if (matcher
.matches()) {
1304 // sched_kthread_stop (loglevel: TRACE_EMERG0) (type:
1306 IBaseEventInfo eventInfo
= new BaseEventInfo(matcher
.group(1).trim());
1307 eventInfo
.setLogLevel(matcher
.group(2).trim());
1308 eventInfo
.setEventType(matcher
.group(3).trim());
1309 events
.add(eventInfo
);
1310 } else if (UST_PROVIDER_PATTERN
.matcher(line
).matches()) {
1319 * Formats a command parameter for the command execution i.e. adds quotes
1320 * at the beginning and end if necessary.
1321 * @param parameter - parameter to format
1322 * @return formated parameter
1324 private String
formatParameter(String parameter
) {
1325 if (parameter
!= null) {
1326 StringBuffer newString
= new StringBuffer();
1327 newString
.append(parameter
);
1329 if (parameter
.contains(" ")) { //$NON-NLS-1$
1330 newString
.insert(0, "\""); //$NON-NLS-1$
1331 newString
.append("\""); //$NON-NLS-1$
1333 return newString
.toString();
1339 * @param strings array of string that makes up a command line
1340 * @return string buffer with created command line
1342 private StringBuffer
createCommand(String
... strings
) {
1343 StringBuffer command
= new StringBuffer();
1344 command
.append(CONTROL_COMMAND
);
1345 command
.append(getTracingGroupOption());
1346 command
.append(getVerboseOption());
1347 for (String string
: strings
) {
1348 command
.append(string
);
1354 * @return the tracing group option if configured in the preferences
1356 private String
getTracingGroupOption() {
1357 if (!ControlPreferences
.getInstance().isDefaultTracingGroup() && !ControlPreferences
.getInstance().getTracingGroup().equals("")) { //$NON-NLS-1$
1358 return OPTION_TRACING_GROUP
+ ControlPreferences
.getInstance().getTracingGroup();
1360 return ""; //$NON-NLS-1$
1364 * @return the verbose option as configured in the preferences
1366 private String
getVerboseOption() {
1367 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1368 String level
= ControlPreferences
.getInstance().getVerboseLevel();
1369 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_VERBOSE
.equals(level
)) {
1370 return OPTION_VERBOSE
;
1372 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_V_VERBOSE
.equals(level
)) {
1373 return OPTION_VERY_VERBOSE
;
1375 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_V_V_VERBOSE
.equals(level
)) {
1376 return OPTION_VERY_VERY_VERBOSE
;
1379 return ""; //$NON-NLS-1$
1383 * Method that logs the command and command result if logging is enabled as well as forwards
1384 * the command execution to the shell.
1385 * @param command - the command to execute
1386 * @param monitor - a progress monitor
1387 * @return the command result
1388 * @throws ExecutionException
1390 private ICommandResult
executeCommand(String command
, IProgressMonitor monitor
) throws ExecutionException
{
1391 return executeCommand(command
, monitor
, true);
1395 * Method that logs the command and command result if logging is enabled as well as forwards
1396 * the command execution to the shell.
1397 * @param command - the command to execute
1398 * @param monitor - a progress monitor
1399 * @param - checkForError - true to verify command result, else false
1400 * @return the command result
1401 * @throws ExecutionException in case of error result
1403 private ICommandResult
executeCommand(String command
, IProgressMonitor monitor
, boolean checkForError
) throws ExecutionException
{
1404 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1405 ControlCommandLogger
.log(command
);
1408 ICommandResult result
= fCommandShell
.executeCommand(command
.toString(), monitor
);
1410 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1411 ControlCommandLogger
.log(formatOutput(result
));
1414 if (isError(result
)) {
1415 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$