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
.ui
.views
.control
.Messages
;
23 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.logging
.ControlCommandLogger
;
24 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.IBaseEventInfo
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.IChannelInfo
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.IDomainInfo
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.IEventInfo
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.IProbeEventInfo
;
29 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.ISessionInfo
;
30 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.IUstProviderInfo
;
31 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.LogLevelType
;
32 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.TraceEventType
;
33 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.TraceLogLevel
;
34 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.BaseEventInfo
;
35 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.ChannelInfo
;
36 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.DomainInfo
;
37 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.EventInfo
;
38 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.ProbeEventInfo
;
39 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.SessionInfo
;
40 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.UstProviderInfo
;
41 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.preferences
.ControlPreferences
;
44 * <b><u>LTTngControlService</u></b>
46 * Service for sending LTTng trace control commands to remote host.
49 public class LTTngControlService
implements ILttngControlService
{
52 // ------------------------------------------------------------------------
54 // ------------------------------------------------------------------------
56 * The command shell implementation
58 protected ICommandShell fCommandShell
= null;
60 protected String fVersion
= "Unknown"; //$NON-NLS-1$
62 // ------------------------------------------------------------------------
64 // ------------------------------------------------------------------------
70 * - the command shell implementation to use
72 public LTTngControlService(ICommandShell shell
) {
73 fCommandShell
= shell
;
76 // ------------------------------------------------------------------------
78 // ------------------------------------------------------------------------
81 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#getVersion()
84 public String
getVersion() {
88 public void setVersion(String version
) {
91 // ------------------------------------------------------------------------
93 // ------------------------------------------------------------------------
99 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
100 * #getSessionNames(org.eclipse.core.runtime.IProgressMonitor)
103 public String
[] getSessionNames(IProgressMonitor monitor
) throws ExecutionException
{
104 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST
);
106 ICommandResult result
= executeCommand(command
.toString(), monitor
);
109 // Available tracing sessions:
110 // 1) mysession1 (/home/user/lttng-traces/mysession1-20120123-083928)
112 // 2) mysession (/home/user/lttng-traces/mysession-20120123-083318)
115 // Use lttng list <session_name> for more details
117 ArrayList
<String
> retArray
= new ArrayList
<String
>();
119 while (index
< result
.getOutput().length
) {
120 String line
= result
.getOutput()[index
];
121 Matcher matcher
= LTTngControlServiceConstants
.SESSION_PATTERN
.matcher(line
);
122 if (matcher
.matches()) {
123 retArray
.add(matcher
.group(2).trim());
127 return retArray
.toArray(new String
[retArray
.size()]);
134 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
135 * #getSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
138 public ISessionInfo
getSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
139 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST
, sessionName
);
140 ICommandResult result
= executeCommand(command
.toString(), monitor
);
145 // Tracing session mysession2: [inactive]
146 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
147 ISessionInfo sessionInfo
= new SessionInfo(sessionName
);
149 while (index
< result
.getOutput().length
) {
150 // Tracing session mysession2: [inactive]
151 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
153 // === Domain: Kernel ===
155 String line
= result
.getOutput()[index
];
156 Matcher matcher
= LTTngControlServiceConstants
.TRACE_SESSION_PATTERN
.matcher(line
);
157 if (matcher
.matches()) {
158 sessionInfo
.setSessionState(matcher
.group(2));
163 matcher
= LTTngControlServiceConstants
.TRACE_SESSION_PATH_PATTERN
.matcher(line
);
164 if (matcher
.matches()) {
165 sessionInfo
.setSessionPath(matcher
.group(1).trim());
170 matcher
= LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(line
);
171 if (matcher
.matches()) {
173 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_KernelDomainDisplayName
);
174 sessionInfo
.addDomain(domainInfo
);
177 ArrayList
<IChannelInfo
> channels
= new ArrayList
<IChannelInfo
>();
178 index
= parseDomain(result
.getOutput(), index
, channels
);
181 domainInfo
.setChannels(channels
);
184 domainInfo
.setIsKernel(true);
188 matcher
= LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
);
189 if (matcher
.matches()) {
190 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_UstGlobalDomainDisplayName
);
191 sessionInfo
.addDomain(domainInfo
);
194 ArrayList
<IChannelInfo
> channels
= new ArrayList
<IChannelInfo
>();
195 index
= parseDomain(result
.getOutput(), index
, channels
);
198 domainInfo
.setChannels(channels
);
201 domainInfo
.setIsKernel(false);
213 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
214 * #getKernelProvider(org.eclipse.core.runtime.IProgressMonitor)
217 public List
<IBaseEventInfo
> getKernelProvider(IProgressMonitor monitor
) throws ExecutionException
{
218 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST_KERNEL
);
219 ICommandResult result
= executeCommand(command
.toString(), monitor
);
223 // sched_kthread_stop (type: tracepoint)
224 List
<IBaseEventInfo
> events
= new ArrayList
<IBaseEventInfo
>();
225 getProviderEventInfo(result
.getOutput(), 0, events
);
233 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
237 public List
<IUstProviderInfo
> getUstProvider() throws ExecutionException
{
238 return getUstProvider(new NullProgressMonitor());
245 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
246 * #getUstProvider(org.eclipse.core.runtime.IProgressMonitor)
249 public List
<IUstProviderInfo
> getUstProvider(IProgressMonitor monitor
) throws ExecutionException
{
250 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST_UST
);
252 ICommandResult result
= executeCommand(command
.toString(), monitor
);
258 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
259 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
261 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
264 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
265 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
267 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
269 List
<IUstProviderInfo
> allProviders
= new ArrayList
<IUstProviderInfo
>();
270 IUstProviderInfo provider
= null;
273 while (index
< result
.getOutput().length
) {
274 String line
= result
.getOutput()[index
];
275 Matcher matcher
= LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
);
276 if (matcher
.matches()) {
278 provider
= new UstProviderInfo(matcher
.group(2).trim());
279 provider
.setPid(Integer
.valueOf(matcher
.group(1).trim()));
280 List
<IBaseEventInfo
> events
= new ArrayList
<IBaseEventInfo
>();
281 index
= getProviderEventInfo(result
.getOutput(), ++index
, events
);
282 provider
.setEvents(events
);
283 allProviders
.add(provider
);
295 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#createSession(java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
298 public ISessionInfo
createSession(String sessionName
, String sessionPath
, IProgressMonitor monitor
) throws ExecutionException
{
300 String newName
= formatParameter(sessionName
);
301 String newPath
= formatParameter(sessionPath
);
303 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_CREATE_SESSION
, newName
);
305 if (newPath
!= null && !"".equals(newPath
)) { //$NON-NLS-1$
306 command
.append(LTTngControlServiceConstants
.OPTION_OUTPUT_PATH
);
307 command
.append(newPath
);
310 ICommandResult result
= executeCommand(command
.toString(), monitor
);
312 //Session myssession2 created.
313 //Traces will be written in /home/user/lttng-traces/myssession2-20120209-095418
314 String
[] output
= result
.getOutput();
316 // Get and verify session name
317 Matcher matcher
= LTTngControlServiceConstants
.CREATE_SESSION_NAME_PATTERN
.matcher(output
[0]);
320 if (matcher
.matches()) {
321 name
= String
.valueOf(matcher
.group(1).trim());
323 // Output format not expected
324 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
325 Messages
.TraceControl_UnexpectedCommandOutputFormat
+ ":\n" + //$NON-NLS-1$
326 formatOutput(result
));
329 if ((name
== null) || (!name
.equals(sessionName
))) {
330 // Unexpected name returned
331 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
332 Messages
.TraceControl_UnexpectedNameError
+ ": " + name
); //$NON-NLS-1$
335 // Get and verify session path
336 matcher
= LTTngControlServiceConstants
.CREATE_SESSION_PATH_PATTERN
.matcher(output
[1]);
339 if (matcher
.matches()) {
340 path
= String
.valueOf(matcher
.group(1).trim());
342 // Output format not expected
343 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
344 Messages
.TraceControl_UnexpectedCommandOutputFormat
+ ":\n" + //$NON-NLS-1$
345 formatOutput(result
));
348 if ((path
== null) || ((sessionPath
!= null) && (!path
.contains(sessionPath
)))) {
350 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
351 Messages
.TraceControl_UnexpectedPathError
+ ": " + name
); //$NON-NLS-1$
354 SessionInfo sessionInfo
= new SessionInfo(name
);
355 sessionInfo
.setSessionPath(path
);
361 public void destroySession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
362 String newName
= formatParameter(sessionName
);
364 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_DESTROY_SESSION
, newName
);
366 ICommandResult result
= executeCommand(command
.toString(), monitor
, false);
367 String
[] output
= result
.getOutput();
369 if (isError(result
) && ((output
== null) || (!LTTngControlServiceConstants
.SESSION_NOT_FOUND_ERROR_PATTERN
.matcher(output
[0]).matches()))) {
370 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$
372 //Session <sessionName> destroyed
377 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#startSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
380 public void startSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
382 String newSessionName
= formatParameter(sessionName
);
384 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_START_SESSION
, newSessionName
);
386 executeCommand(command
.toString(), monitor
);
388 //Session <sessionName> started
393 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#stopSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
396 public void stopSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
397 String newSessionName
= formatParameter(sessionName
);
398 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_STOP_SESSION
, newSessionName
);
400 executeCommand(command
.toString(), monitor
);
402 //Session <sessionName> stopped
408 * @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)
411 public void enableChannels(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IChannelInfo info
, IProgressMonitor monitor
) throws ExecutionException
{
413 // no channels to enable
414 if (channelNames
.isEmpty()) {
418 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_CHANNEL
);
420 for (Iterator
<String
> iterator
= channelNames
.iterator(); iterator
.hasNext();) {
421 String channel
= (String
) iterator
.next();
422 command
.append(channel
);
423 if (iterator
.hasNext()) {
429 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
431 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
434 String newSessionName
= formatParameter(sessionName
);
435 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
436 command
.append(newSessionName
);
439 // --discard Discard event when buffers are full (default)
441 // --overwrite Flight recorder mode
442 if (info
.isOverwriteMode()) {
443 command
.append(LTTngControlServiceConstants
.OPTION_OVERWRITE
);
445 // --subbuf-size SIZE Subbuffer size in bytes
446 // (default: 4096, kernel default: 262144)
447 command
.append(LTTngControlServiceConstants
.OPTION_SUB_BUFFER_SIZE
);
448 command
.append(String
.valueOf(info
.getSubBufferSize()));
450 // --num-subbuf NUM Number of subbufers
451 // (default: 8, kernel default: 4)
452 command
.append(LTTngControlServiceConstants
.OPTION_NUM_SUB_BUFFERS
);
453 command
.append(String
.valueOf(info
.getNumberOfSubBuffers()));
455 // --switch-timer USEC Switch timer interval in usec (default: 0)
456 command
.append(LTTngControlServiceConstants
.OPTION_SWITCH_TIMER
);
457 command
.append(String
.valueOf(info
.getSwitchTimer()));
459 // --read-timer USEC Read timer interval in usec (default: 200)
460 command
.append(LTTngControlServiceConstants
.OPTION_READ_TIMER
);
461 command
.append(String
.valueOf(info
.getReadTimer()));
464 executeCommand(command
.toString(), monitor
);
470 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#disableChannel(java.lang.String, java.util.List, org.eclipse.core.runtime.IProgressMonitor)
473 public void disableChannels(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
475 // no channels to enable
476 if (channelNames
.isEmpty()) {
480 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_DISABLE_CHANNEL
);
482 for (Iterator
<String
> iterator
= channelNames
.iterator(); iterator
.hasNext();) {
483 String channel
= (String
) iterator
.next();
484 command
.append(channel
);
485 if (iterator
.hasNext()) {
491 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
493 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
496 String newSessionName
= formatParameter(sessionName
);
497 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
498 command
.append(newSessionName
);
500 executeCommand(command
.toString(), monitor
);
505 * @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)
508 public void enableEvents(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
510 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
512 if (eventNames
== null || eventNames
.isEmpty()) {
513 command
.append(LTTngControlServiceConstants
.OPTION_ALL
);
516 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
517 String event
= (String
) iterator
.next();
518 command
.append(event
);
519 if (iterator
.hasNext()) {
526 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
528 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
531 String newSessionName
= formatParameter(sessionName
);
533 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
534 command
.append(newSessionName
);
536 if (channelName
!= null) {
537 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
538 command
.append(channelName
);
541 command
.append(LTTngControlServiceConstants
.OPTION_TRACEPOINT
);
543 executeCommand(command
.toString(), monitor
);
549 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#enableSyscalls(java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
552 public void enableSyscalls(String sessionName
, String channelName
, IProgressMonitor monitor
) throws ExecutionException
{
554 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
556 command
.append(LTTngControlServiceConstants
.OPTION_ALL
);
557 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
559 String newSessionName
= formatParameter(sessionName
);
561 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
562 command
.append(newSessionName
);
564 if (channelName
!= null) {
565 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
566 command
.append(channelName
);
569 command
.append(LTTngControlServiceConstants
.OPTION_SYSCALL
);
571 executeCommand(command
.toString(), monitor
);
576 * @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)
579 public void enableProbe(String sessionName
, String channelName
, String eventName
, boolean isFunction
, String probe
, IProgressMonitor monitor
) throws ExecutionException
{
580 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
582 command
.append(eventName
);
583 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
585 String newSessionName
= formatParameter(sessionName
);
586 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
587 command
.append(newSessionName
);
589 if (channelName
!= null) {
590 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
591 command
.append(channelName
);
594 command
.append(LTTngControlServiceConstants
.OPTION_FUNCTION_PROBE
);
596 command
.append(LTTngControlServiceConstants
.OPTION_PROBE
);
599 command
.append(probe
);
601 executeCommand(command
.toString(), monitor
);
606 * @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)
609 public void enableLogLevel(String sessionName
, String channelName
, String eventName
, LogLevelType logLevelType
, TraceLogLevel level
, IProgressMonitor monitor
) throws ExecutionException
{
610 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
612 command
.append(eventName
);
613 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
615 String newSessionName
= formatParameter(sessionName
);
616 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
617 command
.append(newSessionName
);
619 if (channelName
!= null) {
620 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
621 command
.append(channelName
);
624 if (logLevelType
== LogLevelType
.LOGLEVEL
) {
625 command
.append(LTTngControlServiceConstants
.OPTION_LOGLEVEL
);
626 } else if (logLevelType
== LogLevelType
.LOGLEVEL_ONLY
) {
627 command
.append(LTTngControlServiceConstants
.OPTION_LOGLEVEL_ONLY
);
632 command
.append(level
.getInName());
634 executeCommand(command
.toString(), monitor
);
640 * @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)
643 public void disableEvent(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
644 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_DISABLE_EVENT
);
646 if (eventNames
== null) {
647 command
.append(LTTngControlServiceConstants
.OPTION_ALL
);
649 // no events to enable
650 if (eventNames
.isEmpty()) {
654 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
655 String event
= (String
) iterator
.next();
656 command
.append(event
);
657 if (iterator
.hasNext()) {
664 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
666 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
669 String newSessionName
= formatParameter(sessionName
);
670 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
671 command
.append(newSessionName
);
673 if (channelName
!= null) {
674 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
675 command
.append(channelName
);
678 executeCommand(command
.toString(), monitor
);
683 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#getContexts(org.eclipse.core.runtime.IProgressMonitor)
686 public List
<String
> getContextList(IProgressMonitor monitor
) throws ExecutionException
{
688 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ADD_CONTEXT
, LTTngControlServiceConstants
.OPTION_HELP
);
690 ICommandResult result
= executeCommand(command
.toString(), monitor
);
692 String
[] output
= result
.getOutput();
694 List
<String
> contexts
= new ArrayList
<String
>(0);
697 boolean inList
= false;
698 while (index
< output
.length
) {
699 String line
= result
.getOutput()[index
];
701 Matcher startMatcher
= LTTngControlServiceConstants
.ADD_CONTEXT_HELP_CONTEXTS_INTRO
.matcher(line
);
702 Matcher endMatcher
= LTTngControlServiceConstants
.ADD_CONTEXT_HELP_CONTEXTS_END_LINE
.matcher(line
);
704 if (startMatcher
.matches()) {
706 } else if (endMatcher
.matches()) {
708 } else if (inList
== true) {
709 String
[] tmp
= line
.split(","); //$NON-NLS-1$
710 for (int i
= 0; i
< tmp
.length
; i
++) {
711 contexts
.add(tmp
[i
].trim());
721 * @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)
724 public void addContexts(String sessionName
, String channelName
, String eventName
, boolean isKernel
, List
<String
> contextNames
, IProgressMonitor monitor
) throws ExecutionException
{
725 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ADD_CONTEXT
);
727 String newSessionName
= formatParameter(sessionName
);
728 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
729 command
.append(newSessionName
);
731 if (channelName
!= null) {
732 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
733 command
.append(channelName
);
736 if (eventName
!= null) {
737 command
.append(LTTngControlServiceConstants
.OPTION_EVENT
);
738 command
.append(eventName
);
742 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
744 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
747 for (Iterator
<String
> iterator
= contextNames
.iterator(); iterator
.hasNext();) {
748 String context
= (String
) iterator
.next();
749 command
.append(LTTngControlServiceConstants
.OPTION_CONTEXT_TYPE
);
750 command
.append(context
);
753 executeCommand(command
.toString(), monitor
);
759 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#calibrate(boolean, org.eclipse.core.runtime.IProgressMonitor)
762 public void calibrate(boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
763 // String newSessionName = formatParameter(sessionName);
764 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_CALIBRATE
);
766 // command.append(OPTION_SESSION);
767 // command.append(newSessionName);
770 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
772 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
775 command
.append(LTTngControlServiceConstants
.OPTION_FUNCTION_PROBE
);
777 executeCommand(command
.toString(), monitor
);
780 // ------------------------------------------------------------------------
782 // ------------------------------------------------------------------------
784 * Checks if command result is an error result.
787 * - the command result to check
788 * @return true if error else false
790 protected boolean isError(ICommandResult result
) {
791 if ((result
.getResult()) != 0 || (result
.getOutput().length
< 1 || LTTngControlServiceConstants
.ERROR_PATTERN
.matcher(result
.getOutput()[0]).matches())) {
798 * Formats the output string as single string.
802 * @return - the formatted output
804 protected String
formatOutput(ICommandResult result
) {
805 if ((result
== null) || result
.getOutput() == null || result
.getOutput().length
== 0) {
806 return ""; //$NON-NLS-1$
808 String
[] output
= result
.getOutput();
809 StringBuffer ret
= new StringBuffer();
810 ret
.append("Return Value: "); //$NON-NLS-1$
811 ret
.append(result
.getResult());
812 ret
.append("\n"); //$NON-NLS-1$
813 for (int i
= 0; i
< output
.length
; i
++) {
814 ret
.append(output
[i
] + "\n"); //$NON-NLS-1$
816 return ret
.toString();
820 * Parses the domain information.
823 * - a command output array
824 * @param currentIndex
825 * - current index in command output array
827 * - list for returning channel information
828 * @return the new current index in command output array
830 protected int parseDomain(String
[] output
, int currentIndex
, List
<IChannelInfo
> channels
) {
831 int index
= currentIndex
;
835 // - channnel1: [enabled]
839 // subbufers size: 262144
840 // number of subbufers: 4
841 // switch timer interval: 0
842 // read timer interval: 200
845 while (index
< output
.length
) {
846 String line
= output
[index
];
848 Matcher outerMatcher
= LTTngControlServiceConstants
.CHANNELS_SECTION_PATTERN
.matcher(line
);
849 if (outerMatcher
.matches()) {
850 IChannelInfo channelInfo
= null;
851 while (index
< output
.length
) {
852 String subLine
= output
[index
];
854 Matcher innerMatcher
= LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(subLine
);
855 if (innerMatcher
.matches()) {
856 channelInfo
= new ChannelInfo(""); //$NON-NLS-1$
858 channelInfo
.setName(innerMatcher
.group(1));
860 // get channel enablement
861 channelInfo
.setState(innerMatcher
.group(2));
864 channels
.add(channelInfo
);
866 } else if (LTTngControlServiceConstants
.OVERWRITE_MODE_ATTRIBUTE
.matcher(subLine
).matches()) {
867 String value
= getAttributeValue(subLine
);
868 channelInfo
.setOverwriteMode(!LTTngControlServiceConstants
.OVERWRITE_MODE_ATTRIBUTE_FALSE
.equals(value
));
869 } else if (LTTngControlServiceConstants
.SUBBUFFER_SIZE_ATTRIBUTE
.matcher(subLine
).matches()) {
870 channelInfo
.setSubBufferSize(Long
.valueOf(getAttributeValue(subLine
)));
872 } else if (LTTngControlServiceConstants
.NUM_SUBBUFFERS_ATTRIBUTE
.matcher(subLine
).matches()) {
873 channelInfo
.setNumberOfSubBuffers(Integer
.valueOf(getAttributeValue(subLine
)));
875 } else if (LTTngControlServiceConstants
.SWITCH_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
876 channelInfo
.setSwitchTimer(Long
.valueOf(getAttributeValue(subLine
)));
878 } else if (LTTngControlServiceConstants
.READ_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
879 channelInfo
.setReadTimer(Long
.valueOf(getAttributeValue(subLine
)));
881 } else if (LTTngControlServiceConstants
.OUTPUT_ATTRIBUTE
.matcher(subLine
).matches()) {
882 channelInfo
.setOutputType(getAttributeValue(subLine
));
884 } else if (LTTngControlServiceConstants
.EVENT_SECTION_PATTERN
.matcher(subLine
).matches()) {
885 List
<IEventInfo
> events
= new ArrayList
<IEventInfo
>();
886 index
= parseEvents(output
, index
, events
);
887 channelInfo
.setEvents(events
);
888 // we want to stay at the current index to be able to
891 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(subLine
).matches()) {
894 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(subLine
).matches()) {
906 * Parses the event information within a domain.
909 * - a command output array
910 * @param currentIndex
911 * - current index in command output array
913 * - list for returning event information
914 * @return the new current index in command output array
916 protected int parseEvents(String
[] output
, int currentIndex
, List
<IEventInfo
> events
) {
917 int index
= currentIndex
;
919 while (index
< output
.length
) {
920 String line
= output
[index
];
921 if (LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(line
).matches()) {
924 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(line
).matches()) {
927 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
).matches()) {
932 Matcher matcher
= LTTngControlServiceConstants
.EVENT_PATTERN
.matcher(line
);
933 Matcher matcher2
= LTTngControlServiceConstants
.WILDCARD_EVENT_PATTERN
.matcher(line
);
935 if (matcher
.matches()) {
936 IEventInfo eventInfo
= new EventInfo(matcher
.group(1).trim());
937 eventInfo
.setLogLevel(matcher
.group(2).trim());
938 eventInfo
.setEventType(matcher
.group(3).trim());
939 eventInfo
.setState(matcher
.group(4));
940 events
.add(eventInfo
);
942 } else if (matcher2
.matches()) {
943 IEventInfo eventInfo
= new EventInfo(matcher2
.group(1).trim());
944 eventInfo
.setLogLevel(TraceLogLevel
.LEVEL_UNKNOWN
);
945 eventInfo
.setEventType(matcher2
.group(2).trim());
946 eventInfo
.setState(matcher2
.group(3));
948 if (eventInfo
.getEventType() == TraceEventType
.PROBE
) {
949 IProbeEventInfo probeEvent
= new ProbeEventInfo(eventInfo
.getName());
950 probeEvent
.setLogLevel(eventInfo
.getLogLevel());
951 probeEvent
.setEventType(eventInfo
.getEventType());
952 probeEvent
.setState(eventInfo
.getState());
954 // Overwrite eventinfo
955 eventInfo
= probeEvent
;
957 // myevent2 (type: probe) [enabled]
959 // myevent0 (type: probe) [enabled]
963 while (index
< output
.length
) {
964 String probeLine
= output
[index
];
966 Matcher addrMatcher
= LTTngControlServiceConstants
.PROBE_ADDRESS_PATTERN
.matcher(probeLine
);
967 Matcher offsetMatcher
= LTTngControlServiceConstants
.PROBE_OFFSET_PATTERN
.matcher(probeLine
);
968 Matcher symbolMatcher
= LTTngControlServiceConstants
.PROBE_SYMBOL_PATTERN
.matcher(probeLine
);
969 if (addrMatcher
.matches()) {
970 String addr
= addrMatcher
.group(2).trim();
971 probeEvent
.setAddress(addr
);
972 } else if (offsetMatcher
.matches()) {
973 String offset
= offsetMatcher
.group(2).trim();
974 probeEvent
.setOffset(offset
);
975 } else if (symbolMatcher
.matches()) {
976 String symbol
= symbolMatcher
.group(2).trim();
977 probeEvent
.setSymbol(symbol
);
978 } else if ((LTTngControlServiceConstants
.EVENT_PATTERN
.matcher(probeLine
).matches()) || (LTTngControlServiceConstants
.WILDCARD_EVENT_PATTERN
.matcher(probeLine
).matches())) {
980 } else if (LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(probeLine
).matches()) {
982 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(probeLine
).matches()) {
985 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(probeLine
).matches()) {
991 events
.add(eventInfo
);
993 events
.add(eventInfo
);
1000 // else if (line.matches(EVENT_NONE_PATTERN)) {
1010 * Parses a line with attributes: <attribute Name>: <attribute value>
1013 * - attribute line to parse
1014 * @return the attribute value as string
1016 protected String
getAttributeValue(String line
) {
1017 String
[] temp
= line
.split("\\: "); //$NON-NLS-1$
1022 * Parses the event information within a provider.
1025 * - a command output array
1026 * @param currentIndex
1027 * - current index in command output array
1029 * - list for returning event information
1030 * @return the new current index in command output array
1032 protected int getProviderEventInfo(String
[] output
, int currentIndex
, List
<IBaseEventInfo
> events
) {
1033 int index
= currentIndex
;
1034 while (index
< output
.length
) {
1035 String line
= output
[index
];
1036 Matcher matcher
= LTTngControlServiceConstants
.PROVIDER_EVENT_PATTERN
.matcher(line
);
1037 if (matcher
.matches()) {
1038 // sched_kthread_stop (loglevel: TRACE_EMERG0) (type:
1040 IBaseEventInfo eventInfo
= new BaseEventInfo(matcher
.group(1).trim());
1041 eventInfo
.setLogLevel(matcher
.group(2).trim());
1042 eventInfo
.setEventType(matcher
.group(3).trim());
1043 events
.add(eventInfo
);
1044 } else if (LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
).matches()) {
1053 * Formats a command parameter for the command execution i.e. adds quotes
1054 * at the beginning and end if necessary.
1055 * @param parameter - parameter to format
1056 * @return formated parameter
1058 protected String
formatParameter(String parameter
) {
1059 if (parameter
!= null) {
1060 StringBuffer newString
= new StringBuffer();
1061 newString
.append(parameter
);
1063 if (parameter
.contains(" ")) { //$NON-NLS-1$
1064 newString
.insert(0, "\""); //$NON-NLS-1$
1065 newString
.append("\""); //$NON-NLS-1$
1067 return newString
.toString();
1073 * @param strings array of string that makes up a command line
1074 * @return string buffer with created command line
1076 protected StringBuffer
createCommand(String
... strings
) {
1077 StringBuffer command
= new StringBuffer();
1078 command
.append(LTTngControlServiceConstants
.CONTROL_COMMAND
);
1079 command
.append(getTracingGroupOption());
1080 command
.append(getVerboseOption());
1081 for (String string
: strings
) {
1082 command
.append(string
);
1088 * @return the tracing group option if configured in the preferences
1090 protected String
getTracingGroupOption() {
1091 if (!ControlPreferences
.getInstance().isDefaultTracingGroup() && !ControlPreferences
.getInstance().getTracingGroup().equals("")) { //$NON-NLS-1$
1092 return LTTngControlServiceConstants
.OPTION_TRACING_GROUP
+ ControlPreferences
.getInstance().getTracingGroup();
1094 return ""; //$NON-NLS-1$
1098 * @return the verbose option as configured in the preferences
1100 protected String
getVerboseOption() {
1101 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1102 String level
= ControlPreferences
.getInstance().getVerboseLevel();
1103 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_VERBOSE
.equals(level
)) {
1104 return LTTngControlServiceConstants
.OPTION_VERBOSE
;
1106 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_V_VERBOSE
.equals(level
)) {
1107 return LTTngControlServiceConstants
.OPTION_VERY_VERBOSE
;
1109 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_V_V_VERBOSE
.equals(level
)) {
1110 return LTTngControlServiceConstants
.OPTION_VERY_VERY_VERBOSE
;
1113 return ""; //$NON-NLS-1$
1117 * Method that logs the command and command result if logging is enabled as well as forwards
1118 * the command execution to the shell.
1119 * @param command - the command to execute
1120 * @param monitor - a progress monitor
1121 * @return the command result
1122 * @throws ExecutionException
1124 protected ICommandResult
executeCommand(String command
, IProgressMonitor monitor
) throws ExecutionException
{
1125 return executeCommand(command
, monitor
, true);
1129 * Method that logs the command and command result if logging is enabled as well as forwards
1130 * the command execution to the shell.
1131 * @param command - the command to execute
1132 * @param monitor - a progress monitor
1133 * @param - checkForError - true to verify command result, else false
1134 * @return the command result
1135 * @throws ExecutionException in case of error result
1137 protected ICommandResult
executeCommand(String command
, IProgressMonitor monitor
, boolean checkForError
) throws ExecutionException
{
1138 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1139 ControlCommandLogger
.log(command
);
1142 ICommandResult result
= fCommandShell
.executeCommand(command
.toString(), monitor
);
1144 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1145 ControlCommandLogger
.log(formatOutput(result
));
1148 if (isError(result
)) {
1149 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$