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
.IProbeEventInfo
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.ISessionInfo
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.IUstProviderInfo
;
29 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.LogLevelType
;
30 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.TraceEventType
;
31 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.TraceLogLevel
;
32 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.BaseEventInfo
;
33 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.ChannelInfo
;
34 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.DomainInfo
;
35 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.EventInfo
;
36 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.ProbeEventInfo
;
37 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.SessionInfo
;
38 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.UstProviderInfo
;
39 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.logging
.ControlCommandLogger
;
40 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.messages
.Messages
;
41 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.preferences
.ControlPreferences
;
42 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.remote
.ICommandResult
;
43 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.remote
.ICommandShell
;
47 * Service for sending LTTng trace control commands to remote host.
50 * @author Bernd Hufmann
52 public class LTTngControlService
implements ILttngControlService
{
55 // ------------------------------------------------------------------------
57 // ------------------------------------------------------------------------
59 * The command shell implementation
61 protected ICommandShell fCommandShell
= null;
66 protected String fVersion
= "Unknown"; //$NON-NLS-1$
68 // ------------------------------------------------------------------------
70 // ------------------------------------------------------------------------
76 * - the command shell implementation to use
78 public LTTngControlService(ICommandShell shell
) {
79 fCommandShell
= shell
;
82 // ------------------------------------------------------------------------
84 // ------------------------------------------------------------------------
87 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#getVersion()
90 public String
getVersion() {
95 * Sets the version of the LTTng 2.0 control service.
96 * @param version - a version to set
98 public void setVersion(String version
) {
101 // ------------------------------------------------------------------------
103 // ------------------------------------------------------------------------
109 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
110 * #getSessionNames(org.eclipse.core.runtime.IProgressMonitor)
113 public String
[] getSessionNames(IProgressMonitor monitor
) throws ExecutionException
{
114 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST
);
116 ICommandResult result
= executeCommand(command
.toString(), monitor
);
119 // Available tracing sessions:
120 // 1) mysession1 (/home/user/lttng-traces/mysession1-20120123-083928)
122 // 2) mysession (/home/user/lttng-traces/mysession-20120123-083318)
125 // Use lttng list <session_name> for more details
127 ArrayList
<String
> retArray
= new ArrayList
<String
>();
129 while (index
< result
.getOutput().length
) {
130 String line
= result
.getOutput()[index
];
131 Matcher matcher
= LTTngControlServiceConstants
.SESSION_PATTERN
.matcher(line
);
132 if (matcher
.matches()) {
133 retArray
.add(matcher
.group(2).trim());
137 return retArray
.toArray(new String
[retArray
.size()]);
144 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
145 * #getSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
148 public ISessionInfo
getSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
149 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST
, sessionName
);
150 ICommandResult result
= executeCommand(command
.toString(), monitor
);
155 // Tracing session mysession2: [inactive]
156 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
157 ISessionInfo sessionInfo
= new SessionInfo(sessionName
);
159 while (index
< result
.getOutput().length
) {
160 // Tracing session mysession2: [inactive]
161 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
163 // === Domain: Kernel ===
165 String line
= result
.getOutput()[index
];
166 Matcher matcher
= LTTngControlServiceConstants
.TRACE_SESSION_PATTERN
.matcher(line
);
167 if (matcher
.matches()) {
168 sessionInfo
.setSessionState(matcher
.group(2));
173 matcher
= LTTngControlServiceConstants
.TRACE_SESSION_PATH_PATTERN
.matcher(line
);
174 if (matcher
.matches()) {
175 sessionInfo
.setSessionPath(matcher
.group(1).trim());
180 matcher
= LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(line
);
181 if (matcher
.matches()) {
183 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_KernelDomainDisplayName
);
184 sessionInfo
.addDomain(domainInfo
);
187 ArrayList
<IChannelInfo
> channels
= new ArrayList
<IChannelInfo
>();
188 index
= parseDomain(result
.getOutput(), index
, channels
);
191 domainInfo
.setChannels(channels
);
194 domainInfo
.setIsKernel(true);
198 matcher
= LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
);
199 if (matcher
.matches()) {
200 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_UstGlobalDomainDisplayName
);
201 sessionInfo
.addDomain(domainInfo
);
204 ArrayList
<IChannelInfo
> channels
= new ArrayList
<IChannelInfo
>();
205 index
= parseDomain(result
.getOutput(), index
, channels
);
208 domainInfo
.setChannels(channels
);
211 domainInfo
.setIsKernel(false);
223 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
224 * #getKernelProvider(org.eclipse.core.runtime.IProgressMonitor)
227 public List
<IBaseEventInfo
> getKernelProvider(IProgressMonitor monitor
) throws ExecutionException
{
228 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST_KERNEL
);
229 ICommandResult result
= executeCommand(command
.toString(), monitor
);
233 // sched_kthread_stop (type: tracepoint)
234 List
<IBaseEventInfo
> events
= new ArrayList
<IBaseEventInfo
>();
235 getProviderEventInfo(result
.getOutput(), 0, events
);
243 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
247 public List
<IUstProviderInfo
> getUstProvider() throws ExecutionException
{
248 return getUstProvider(new NullProgressMonitor());
255 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
256 * #getUstProvider(org.eclipse.core.runtime.IProgressMonitor)
259 public List
<IUstProviderInfo
> getUstProvider(IProgressMonitor monitor
) throws ExecutionException
{
260 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST_UST
);
262 ICommandResult result
= executeCommand(command
.toString(), monitor
);
268 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
269 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
271 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
274 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
275 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
277 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
279 List
<IUstProviderInfo
> allProviders
= new ArrayList
<IUstProviderInfo
>();
280 IUstProviderInfo provider
= null;
283 while (index
< result
.getOutput().length
) {
284 String line
= result
.getOutput()[index
];
285 Matcher matcher
= LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
);
286 if (matcher
.matches()) {
288 provider
= new UstProviderInfo(matcher
.group(2).trim());
289 provider
.setPid(Integer
.valueOf(matcher
.group(1).trim()));
290 List
<IBaseEventInfo
> events
= new ArrayList
<IBaseEventInfo
>();
291 index
= getProviderEventInfo(result
.getOutput(), ++index
, events
);
292 provider
.setEvents(events
);
293 allProviders
.add(provider
);
305 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#createSession(java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
308 public ISessionInfo
createSession(String sessionName
, String sessionPath
, IProgressMonitor monitor
) throws ExecutionException
{
310 String newName
= formatParameter(sessionName
);
311 String newPath
= formatParameter(sessionPath
);
313 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_CREATE_SESSION
, newName
);
315 if (newPath
!= null && !"".equals(newPath
)) { //$NON-NLS-1$
316 command
.append(LTTngControlServiceConstants
.OPTION_OUTPUT_PATH
);
317 command
.append(newPath
);
320 ICommandResult result
= executeCommand(command
.toString(), monitor
);
322 //Session myssession2 created.
323 //Traces will be written in /home/user/lttng-traces/myssession2-20120209-095418
324 String
[] output
= result
.getOutput();
326 // Get and verify session name
327 Matcher matcher
= LTTngControlServiceConstants
.CREATE_SESSION_NAME_PATTERN
.matcher(output
[0]);
330 if (matcher
.matches()) {
331 name
= String
.valueOf(matcher
.group(1).trim());
333 // Output format not expected
334 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
335 Messages
.TraceControl_UnexpectedCommandOutputFormat
+ ":\n" + //$NON-NLS-1$
336 formatOutput(result
));
339 if ((name
== null) || (!name
.equals(sessionName
))) {
340 // Unexpected name returned
341 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
342 Messages
.TraceControl_UnexpectedNameError
+ ": " + name
); //$NON-NLS-1$
345 // Get and verify session path
346 matcher
= LTTngControlServiceConstants
.CREATE_SESSION_PATH_PATTERN
.matcher(output
[1]);
349 if (matcher
.matches()) {
350 path
= String
.valueOf(matcher
.group(1).trim());
352 // Output format not expected
353 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
354 Messages
.TraceControl_UnexpectedCommandOutputFormat
+ ":\n" + //$NON-NLS-1$
355 formatOutput(result
));
358 if ((path
== null) || ((sessionPath
!= null) && (!path
.contains(sessionPath
)))) {
360 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
361 Messages
.TraceControl_UnexpectedPathError
+ ": " + name
); //$NON-NLS-1$
364 SessionInfo sessionInfo
= new SessionInfo(name
);
365 sessionInfo
.setSessionPath(path
);
371 public void destroySession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
372 String newName
= formatParameter(sessionName
);
374 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_DESTROY_SESSION
, newName
);
376 ICommandResult result
= executeCommand(command
.toString(), monitor
, false);
377 String
[] output
= result
.getOutput();
379 if (isError(result
) && ((output
== null) || (!LTTngControlServiceConstants
.SESSION_NOT_FOUND_ERROR_PATTERN
.matcher(output
[0]).matches()))) {
380 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$
382 //Session <sessionName> destroyed
387 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#startSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
390 public void startSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
392 String newSessionName
= formatParameter(sessionName
);
394 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_START_SESSION
, newSessionName
);
396 executeCommand(command
.toString(), monitor
);
398 //Session <sessionName> started
403 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#stopSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
406 public void stopSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
407 String newSessionName
= formatParameter(sessionName
);
408 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_STOP_SESSION
, newSessionName
);
410 executeCommand(command
.toString(), monitor
);
412 //Session <sessionName> stopped
418 * @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)
421 public void enableChannels(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IChannelInfo info
, IProgressMonitor monitor
) throws ExecutionException
{
423 // no channels to enable
424 if (channelNames
.isEmpty()) {
428 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_CHANNEL
);
430 for (Iterator
<String
> iterator
= channelNames
.iterator(); iterator
.hasNext();) {
431 String channel
= iterator
.next();
432 command
.append(channel
);
433 if (iterator
.hasNext()) {
439 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
441 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
444 String newSessionName
= formatParameter(sessionName
);
445 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
446 command
.append(newSessionName
);
449 // --discard Discard event when buffers are full (default)
451 // --overwrite Flight recorder mode
452 if (info
.isOverwriteMode()) {
453 command
.append(LTTngControlServiceConstants
.OPTION_OVERWRITE
);
455 // --subbuf-size SIZE Subbuffer size in bytes
456 // (default: 4096, kernel default: 262144)
457 command
.append(LTTngControlServiceConstants
.OPTION_SUB_BUFFER_SIZE
);
458 command
.append(String
.valueOf(info
.getSubBufferSize()));
460 // --num-subbuf NUM Number of subbufers
461 // (default: 8, kernel default: 4)
462 command
.append(LTTngControlServiceConstants
.OPTION_NUM_SUB_BUFFERS
);
463 command
.append(String
.valueOf(info
.getNumberOfSubBuffers()));
465 // --switch-timer USEC Switch timer interval in usec (default: 0)
466 command
.append(LTTngControlServiceConstants
.OPTION_SWITCH_TIMER
);
467 command
.append(String
.valueOf(info
.getSwitchTimer()));
469 // --read-timer USEC Read timer interval in usec (default: 200)
470 command
.append(LTTngControlServiceConstants
.OPTION_READ_TIMER
);
471 command
.append(String
.valueOf(info
.getReadTimer()));
474 executeCommand(command
.toString(), monitor
);
480 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#disableChannel(java.lang.String, java.util.List, org.eclipse.core.runtime.IProgressMonitor)
483 public void disableChannels(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
485 // no channels to enable
486 if (channelNames
.isEmpty()) {
490 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_DISABLE_CHANNEL
);
492 for (Iterator
<String
> iterator
= channelNames
.iterator(); iterator
.hasNext();) {
493 String channel
= iterator
.next();
494 command
.append(channel
);
495 if (iterator
.hasNext()) {
501 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
503 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
506 String newSessionName
= formatParameter(sessionName
);
507 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
508 command
.append(newSessionName
);
510 executeCommand(command
.toString(), monitor
);
515 * @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)
518 public void enableEvents(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
520 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
522 if (eventNames
== null || eventNames
.isEmpty()) {
523 command
.append(LTTngControlServiceConstants
.OPTION_ALL
);
526 StringBuffer eventNameParameter
= new StringBuffer();
527 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
528 String event
= iterator
.next();
529 eventNameParameter
.append(event
);
530 if (iterator
.hasNext()) {
531 eventNameParameter
.append(',');
534 command
.append(formatParameter(eventNameParameter
.toString()));
538 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
540 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
543 String newSessionName
= formatParameter(sessionName
);
545 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
546 command
.append(newSessionName
);
548 if (channelName
!= null) {
549 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
550 command
.append(channelName
);
553 command
.append(LTTngControlServiceConstants
.OPTION_TRACEPOINT
);
555 executeCommand(command
.toString(), monitor
);
561 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#enableSyscalls(java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
564 public void enableSyscalls(String sessionName
, String channelName
, IProgressMonitor monitor
) throws ExecutionException
{
566 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
568 command
.append(LTTngControlServiceConstants
.OPTION_ALL
);
569 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
571 String newSessionName
= formatParameter(sessionName
);
573 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
574 command
.append(newSessionName
);
576 if (channelName
!= null) {
577 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
578 command
.append(channelName
);
581 command
.append(LTTngControlServiceConstants
.OPTION_SYSCALL
);
583 executeCommand(command
.toString(), monitor
);
588 * @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)
591 public void enableProbe(String sessionName
, String channelName
, String eventName
, boolean isFunction
, String probe
, IProgressMonitor monitor
) throws ExecutionException
{
592 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
594 command
.append(eventName
);
595 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
597 String newSessionName
= formatParameter(sessionName
);
598 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
599 command
.append(newSessionName
);
601 if (channelName
!= null) {
602 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
603 command
.append(channelName
);
606 command
.append(LTTngControlServiceConstants
.OPTION_FUNCTION_PROBE
);
608 command
.append(LTTngControlServiceConstants
.OPTION_PROBE
);
611 command
.append(probe
);
613 executeCommand(command
.toString(), monitor
);
618 * @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)
621 public void enableLogLevel(String sessionName
, String channelName
, String eventName
, LogLevelType logLevelType
, TraceLogLevel level
, IProgressMonitor monitor
) throws ExecutionException
{
622 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
624 command
.append(eventName
);
625 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
627 String newSessionName
= formatParameter(sessionName
);
628 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
629 command
.append(newSessionName
);
631 if (channelName
!= null) {
632 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
633 command
.append(channelName
);
636 if (logLevelType
== LogLevelType
.LOGLEVEL
) {
637 command
.append(LTTngControlServiceConstants
.OPTION_LOGLEVEL
);
638 } else if (logLevelType
== LogLevelType
.LOGLEVEL_ONLY
) {
639 command
.append(LTTngControlServiceConstants
.OPTION_LOGLEVEL_ONLY
);
644 command
.append(level
.getInName());
646 executeCommand(command
.toString(), monitor
);
652 * @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)
655 public void disableEvent(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
656 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_DISABLE_EVENT
);
658 if (eventNames
== null) {
659 command
.append(LTTngControlServiceConstants
.OPTION_ALL
);
661 // no events to disable
662 if (eventNames
.isEmpty()) {
666 StringBuffer eventNameParameter
= new StringBuffer();
667 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
668 String event
= iterator
.next();
669 eventNameParameter
.append(event
);
670 if (iterator
.hasNext()) {
671 eventNameParameter
.append(',');
674 command
.append(formatParameter(eventNameParameter
.toString()));
678 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
680 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
683 String newSessionName
= formatParameter(sessionName
);
684 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
685 command
.append(newSessionName
);
687 if (channelName
!= null) {
688 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
689 command
.append(channelName
);
692 executeCommand(command
.toString(), monitor
);
697 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#getContexts(org.eclipse.core.runtime.IProgressMonitor)
700 public List
<String
> getContextList(IProgressMonitor monitor
) throws ExecutionException
{
702 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ADD_CONTEXT
, LTTngControlServiceConstants
.OPTION_HELP
);
704 ICommandResult result
= executeCommand(command
.toString(), monitor
);
706 String
[] output
= result
.getOutput();
708 List
<String
> contexts
= new ArrayList
<String
>(0);
711 boolean inList
= false;
712 while (index
< output
.length
) {
713 String line
= result
.getOutput()[index
];
715 Matcher startMatcher
= LTTngControlServiceConstants
.ADD_CONTEXT_HELP_CONTEXTS_INTRO
.matcher(line
);
716 Matcher endMatcher
= LTTngControlServiceConstants
.ADD_CONTEXT_HELP_CONTEXTS_END_LINE
.matcher(line
);
718 if (startMatcher
.matches()) {
720 } else if (endMatcher
.matches()) {
722 } else if (inList
== true) {
723 String
[] tmp
= line
.split(","); //$NON-NLS-1$
724 for (int i
= 0; i
< tmp
.length
; i
++) {
725 contexts
.add(tmp
[i
].trim());
735 * @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)
738 public void addContexts(String sessionName
, String channelName
, String eventName
, boolean isKernel
, List
<String
> contextNames
, IProgressMonitor monitor
) throws ExecutionException
{
739 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ADD_CONTEXT
);
741 String newSessionName
= formatParameter(sessionName
);
742 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
743 command
.append(newSessionName
);
745 if (channelName
!= null) {
746 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
747 command
.append(channelName
);
750 if (eventName
!= null) {
751 command
.append(LTTngControlServiceConstants
.OPTION_EVENT
);
752 command
.append(eventName
);
756 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
758 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
761 for (Iterator
<String
> iterator
= contextNames
.iterator(); iterator
.hasNext();) {
762 String context
= iterator
.next();
763 command
.append(LTTngControlServiceConstants
.OPTION_CONTEXT_TYPE
);
764 command
.append(context
);
767 executeCommand(command
.toString(), monitor
);
773 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#calibrate(boolean, org.eclipse.core.runtime.IProgressMonitor)
776 public void calibrate(boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
777 // String newSessionName = formatParameter(sessionName);
778 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_CALIBRATE
);
780 // command.append(OPTION_SESSION);
781 // command.append(newSessionName);
784 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
786 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
789 command
.append(LTTngControlServiceConstants
.OPTION_FUNCTION_PROBE
);
791 executeCommand(command
.toString(), monitor
);
794 // ------------------------------------------------------------------------
796 // ------------------------------------------------------------------------
798 * Checks if command result is an error result.
801 * - the command result to check
802 * @return true if error else false
804 protected boolean isError(ICommandResult result
) {
805 if ((result
.getResult()) != 0 || (result
.getOutput().length
< 1 || LTTngControlServiceConstants
.ERROR_PATTERN
.matcher(result
.getOutput()[0]).matches())) {
812 * Formats the output string as single string.
816 * @return - the formatted output
818 public static String
formatOutput(ICommandResult result
) {
819 if ((result
== null) || result
.getOutput() == null || result
.getOutput().length
== 0) {
820 return ""; //$NON-NLS-1$
822 String
[] output
= result
.getOutput();
823 StringBuffer ret
= new StringBuffer();
824 ret
.append("Return Value: "); //$NON-NLS-1$
825 ret
.append(result
.getResult());
826 ret
.append("\n"); //$NON-NLS-1$
827 for (int i
= 0; i
< output
.length
; i
++) {
828 ret
.append(output
[i
] + "\n"); //$NON-NLS-1$
830 return ret
.toString();
834 * Parses the domain information.
837 * - a command output array
838 * @param currentIndex
839 * - current index in command output array
841 * - list for returning channel information
842 * @return the new current index in command output array
844 protected int parseDomain(String
[] output
, int currentIndex
, List
<IChannelInfo
> channels
) {
845 int index
= currentIndex
;
849 // - channnel1: [enabled]
853 // subbufers size: 262144
854 // number of subbufers: 4
855 // switch timer interval: 0
856 // read timer interval: 200
859 while (index
< output
.length
) {
860 String line
= output
[index
];
862 Matcher outerMatcher
= LTTngControlServiceConstants
.CHANNELS_SECTION_PATTERN
.matcher(line
);
863 if (outerMatcher
.matches()) {
864 IChannelInfo channelInfo
= null;
865 while (index
< output
.length
) {
866 String subLine
= output
[index
];
868 Matcher innerMatcher
= LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(subLine
);
869 if (innerMatcher
.matches()) {
870 channelInfo
= new ChannelInfo(""); //$NON-NLS-1$
872 channelInfo
.setName(innerMatcher
.group(1));
874 // get channel enablement
875 channelInfo
.setState(innerMatcher
.group(2));
878 channels
.add(channelInfo
);
880 } else if (LTTngControlServiceConstants
.OVERWRITE_MODE_ATTRIBUTE
.matcher(subLine
).matches()) {
881 String value
= getAttributeValue(subLine
);
882 channelInfo
.setOverwriteMode(!LTTngControlServiceConstants
.OVERWRITE_MODE_ATTRIBUTE_FALSE
.equals(value
));
883 } else if (LTTngControlServiceConstants
.SUBBUFFER_SIZE_ATTRIBUTE
.matcher(subLine
).matches()) {
884 channelInfo
.setSubBufferSize(Long
.valueOf(getAttributeValue(subLine
)));
886 } else if (LTTngControlServiceConstants
.NUM_SUBBUFFERS_ATTRIBUTE
.matcher(subLine
).matches()) {
887 channelInfo
.setNumberOfSubBuffers(Integer
.valueOf(getAttributeValue(subLine
)));
889 } else if (LTTngControlServiceConstants
.SWITCH_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
890 channelInfo
.setSwitchTimer(Long
.valueOf(getAttributeValue(subLine
)));
892 } else if (LTTngControlServiceConstants
.READ_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
893 channelInfo
.setReadTimer(Long
.valueOf(getAttributeValue(subLine
)));
895 } else if (LTTngControlServiceConstants
.OUTPUT_ATTRIBUTE
.matcher(subLine
).matches()) {
896 channelInfo
.setOutputType(getAttributeValue(subLine
));
898 } else if (LTTngControlServiceConstants
.EVENT_SECTION_PATTERN
.matcher(subLine
).matches()) {
899 List
<IEventInfo
> events
= new ArrayList
<IEventInfo
>();
900 index
= parseEvents(output
, index
, events
);
901 channelInfo
.setEvents(events
);
902 // we want to stay at the current index to be able to
905 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(subLine
).matches()) {
908 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(subLine
).matches()) {
920 * Parses the event information within a domain.
923 * - a command output array
924 * @param currentIndex
925 * - current index in command output array
927 * - list for returning event information
928 * @return the new current index in command output array
930 protected int parseEvents(String
[] output
, int currentIndex
, List
<IEventInfo
> events
) {
931 int index
= currentIndex
;
933 while (index
< output
.length
) {
934 String line
= output
[index
];
935 if (LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(line
).matches()) {
938 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(line
).matches()) {
941 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
).matches()) {
946 Matcher matcher
= LTTngControlServiceConstants
.EVENT_PATTERN
.matcher(line
);
947 Matcher matcher2
= LTTngControlServiceConstants
.WILDCARD_EVENT_PATTERN
.matcher(line
);
949 if (matcher
.matches()) {
950 IEventInfo eventInfo
= new EventInfo(matcher
.group(1).trim());
951 eventInfo
.setLogLevel(matcher
.group(2).trim());
952 eventInfo
.setEventType(matcher
.group(3).trim());
953 eventInfo
.setState(matcher
.group(4));
954 events
.add(eventInfo
);
956 } else if (matcher2
.matches()) {
957 IEventInfo eventInfo
= new EventInfo(matcher2
.group(1).trim());
958 eventInfo
.setLogLevel(TraceLogLevel
.LEVEL_UNKNOWN
);
959 eventInfo
.setEventType(matcher2
.group(2).trim());
960 eventInfo
.setState(matcher2
.group(3));
962 if (eventInfo
.getEventType() == TraceEventType
.PROBE
) {
963 IProbeEventInfo probeEvent
= new ProbeEventInfo(eventInfo
.getName());
964 probeEvent
.setLogLevel(eventInfo
.getLogLevel());
965 probeEvent
.setEventType(eventInfo
.getEventType());
966 probeEvent
.setState(eventInfo
.getState());
968 // Overwrite eventinfo
969 eventInfo
= probeEvent
;
971 // myevent2 (type: probe) [enabled]
973 // myevent0 (type: probe) [enabled]
977 while (index
< output
.length
) {
978 String probeLine
= output
[index
];
980 Matcher addrMatcher
= LTTngControlServiceConstants
.PROBE_ADDRESS_PATTERN
.matcher(probeLine
);
981 Matcher offsetMatcher
= LTTngControlServiceConstants
.PROBE_OFFSET_PATTERN
.matcher(probeLine
);
982 Matcher symbolMatcher
= LTTngControlServiceConstants
.PROBE_SYMBOL_PATTERN
.matcher(probeLine
);
983 if (addrMatcher
.matches()) {
984 String addr
= addrMatcher
.group(2).trim();
985 probeEvent
.setAddress(addr
);
986 } else if (offsetMatcher
.matches()) {
987 String offset
= offsetMatcher
.group(2).trim();
988 probeEvent
.setOffset(offset
);
989 } else if (symbolMatcher
.matches()) {
990 String symbol
= symbolMatcher
.group(2).trim();
991 probeEvent
.setSymbol(symbol
);
992 } else if ((LTTngControlServiceConstants
.EVENT_PATTERN
.matcher(probeLine
).matches()) || (LTTngControlServiceConstants
.WILDCARD_EVENT_PATTERN
.matcher(probeLine
).matches())) {
994 } else if (LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(probeLine
).matches()) {
996 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(probeLine
).matches()) {
999 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(probeLine
).matches()) {
1005 events
.add(eventInfo
);
1007 events
.add(eventInfo
);
1014 // else if (line.matches(EVENT_NONE_PATTERN)) {
1024 * Parses a line with attributes: <attribute Name>: <attribute value>
1027 * - attribute line to parse
1028 * @return the attribute value as string
1030 protected String
getAttributeValue(String line
) {
1031 String
[] temp
= line
.split("\\: "); //$NON-NLS-1$
1036 * Parses the event information within a provider.
1039 * - a command output array
1040 * @param currentIndex
1041 * - current index in command output array
1043 * - list for returning event information
1044 * @return the new current index in command output array
1046 protected int getProviderEventInfo(String
[] output
, int currentIndex
, List
<IBaseEventInfo
> events
) {
1047 int index
= currentIndex
;
1048 while (index
< output
.length
) {
1049 String line
= output
[index
];
1050 Matcher matcher
= LTTngControlServiceConstants
.PROVIDER_EVENT_PATTERN
.matcher(line
);
1051 if (matcher
.matches()) {
1052 // sched_kthread_stop (loglevel: TRACE_EMERG0) (type:
1054 IBaseEventInfo eventInfo
= new BaseEventInfo(matcher
.group(1).trim());
1055 eventInfo
.setLogLevel(matcher
.group(2).trim());
1056 eventInfo
.setEventType(matcher
.group(3).trim());
1057 events
.add(eventInfo
);
1058 } else if (LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
).matches()) {
1067 * Formats a command parameter for the command execution i.e. adds quotes
1068 * at the beginning and end if necessary.
1069 * @param parameter - parameter to format
1070 * @return formated parameter
1072 protected String
formatParameter(String parameter
) {
1073 if (parameter
!= null) {
1074 StringBuffer newString
= new StringBuffer();
1075 newString
.append(parameter
);
1077 if (parameter
.contains(" ") || parameter
.contains("*")) { //$NON-NLS-1$ //$NON-NLS-2$
1078 newString
.insert(0, "\""); //$NON-NLS-1$
1079 newString
.append("\""); //$NON-NLS-1$
1081 return newString
.toString();
1087 * @param strings array of string that makes up a command line
1088 * @return string buffer with created command line
1090 protected StringBuffer
createCommand(String
... strings
) {
1091 StringBuffer command
= new StringBuffer();
1092 command
.append(LTTngControlServiceConstants
.CONTROL_COMMAND
);
1093 command
.append(getTracingGroupOption());
1094 command
.append(getVerboseOption());
1095 for (String string
: strings
) {
1096 command
.append(string
);
1102 * @return the tracing group option if configured in the preferences
1104 protected String
getTracingGroupOption() {
1105 if (!ControlPreferences
.getInstance().isDefaultTracingGroup() && !ControlPreferences
.getInstance().getTracingGroup().equals("")) { //$NON-NLS-1$
1106 return LTTngControlServiceConstants
.OPTION_TRACING_GROUP
+ ControlPreferences
.getInstance().getTracingGroup();
1108 return ""; //$NON-NLS-1$
1112 * @return the verbose option as configured in the preferences
1114 protected String
getVerboseOption() {
1115 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1116 String level
= ControlPreferences
.getInstance().getVerboseLevel();
1117 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_VERBOSE
.equals(level
)) {
1118 return LTTngControlServiceConstants
.OPTION_VERBOSE
;
1120 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_V_VERBOSE
.equals(level
)) {
1121 return LTTngControlServiceConstants
.OPTION_VERY_VERBOSE
;
1123 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_V_V_VERBOSE
.equals(level
)) {
1124 return LTTngControlServiceConstants
.OPTION_VERY_VERY_VERBOSE
;
1127 return ""; //$NON-NLS-1$
1131 * Method that logs the command and command result if logging is enabled as
1132 * well as forwards the command execution to the shell.
1135 * - the command to execute
1137 * - a progress monitor
1138 * @return the command result
1139 * @throws ExecutionException
1141 protected ICommandResult
executeCommand(String command
,
1142 IProgressMonitor monitor
) throws ExecutionException
{
1143 return executeCommand(command
, monitor
, true);
1147 * Method that logs the command and command result if logging is enabled as
1148 * well as forwards the command execution to the shell.
1151 * - the command to execute
1153 * - a progress monitor
1154 * @param checkForError
1155 * - true to verify command result, else false
1156 * @return the command result
1157 * @throws ExecutionException
1158 * in case of error result
1160 protected ICommandResult
executeCommand(String command
,
1161 IProgressMonitor monitor
, boolean checkForError
)
1162 throws ExecutionException
{
1163 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1164 ControlCommandLogger
.log(command
);
1167 ICommandResult result
= fCommandShell
.executeCommand(
1168 command
.toString(), monitor
);
1170 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1171 ControlCommandLogger
.log(formatOutput(result
));
1174 if (isError(result
)) {
1175 throw new ExecutionException(Messages
.TraceControl_CommandError
1176 + " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$