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
, false);
231 List
<IBaseEventInfo
> events
= new ArrayList
<IBaseEventInfo
>();
233 if (result
.getOutput() != null) {
234 // Ignore the following 2 cases:
235 // Spawning a session daemon
236 // Error: Unable to list kernel events
238 // Error: Unable to list kernel events
240 if ((result
.getOutput().length
== 1) && (LTTngControlServiceConstants
.LIST_KERNEL_NO_KERNEL_PROVIDER_PATTERN
.matcher(result
.getOutput()[0]).matches()) ||
241 ((result
.getOutput().length
> 1) && (LTTngControlServiceConstants
.LIST_KERNEL_NO_KERNEL_PROVIDER_PATTERN
.matcher(result
.getOutput()[1]).matches()))) {
246 if (isError(result
)) {
247 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$
252 // sched_kthread_stop (type: tracepoint)
253 getProviderEventInfo(result
.getOutput(), 0, events
);
261 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
265 public List
<IUstProviderInfo
> getUstProvider() throws ExecutionException
{
266 return getUstProvider(new NullProgressMonitor());
273 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
274 * #getUstProvider(org.eclipse.core.runtime.IProgressMonitor)
277 public List
<IUstProviderInfo
> getUstProvider(IProgressMonitor monitor
) throws ExecutionException
{
278 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST_UST
);
280 ICommandResult result
= executeCommand(command
.toString(), monitor
);
286 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
287 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
289 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
292 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
293 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
295 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
297 List
<IUstProviderInfo
> allProviders
= new ArrayList
<IUstProviderInfo
>();
298 IUstProviderInfo provider
= null;
301 while (index
< result
.getOutput().length
) {
302 String line
= result
.getOutput()[index
];
303 Matcher matcher
= LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
);
304 if (matcher
.matches()) {
306 provider
= new UstProviderInfo(matcher
.group(2).trim());
307 provider
.setPid(Integer
.valueOf(matcher
.group(1).trim()));
308 List
<IBaseEventInfo
> events
= new ArrayList
<IBaseEventInfo
>();
309 index
= getProviderEventInfo(result
.getOutput(), ++index
, events
);
310 provider
.setEvents(events
);
311 allProviders
.add(provider
);
323 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#createSession(java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
326 public ISessionInfo
createSession(String sessionName
, String sessionPath
, IProgressMonitor monitor
) throws ExecutionException
{
328 String newName
= formatParameter(sessionName
);
329 String newPath
= formatParameter(sessionPath
);
331 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_CREATE_SESSION
, newName
);
333 if (newPath
!= null && !"".equals(newPath
)) { //$NON-NLS-1$
334 command
.append(LTTngControlServiceConstants
.OPTION_OUTPUT_PATH
);
335 command
.append(newPath
);
338 ICommandResult result
= executeCommand(command
.toString(), monitor
);
340 //Session myssession2 created.
341 //Traces will be written in /home/user/lttng-traces/myssession2-20120209-095418
342 String
[] output
= result
.getOutput();
344 // Get and verify session name
345 Matcher matcher
= LTTngControlServiceConstants
.CREATE_SESSION_NAME_PATTERN
.matcher(output
[0]);
348 if (matcher
.matches()) {
349 name
= String
.valueOf(matcher
.group(1).trim());
351 // Output format not expected
352 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
353 Messages
.TraceControl_UnexpectedCommandOutputFormat
+ ":\n" + //$NON-NLS-1$
354 formatOutput(result
));
357 if ((name
== null) || (!name
.equals(sessionName
))) {
358 // Unexpected name returned
359 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
360 Messages
.TraceControl_UnexpectedNameError
+ ": " + name
); //$NON-NLS-1$
363 // Get and verify session path
364 matcher
= LTTngControlServiceConstants
.CREATE_SESSION_PATH_PATTERN
.matcher(output
[1]);
367 if (matcher
.matches()) {
368 path
= String
.valueOf(matcher
.group(1).trim());
370 // Output format not expected
371 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
372 Messages
.TraceControl_UnexpectedCommandOutputFormat
+ ":\n" + //$NON-NLS-1$
373 formatOutput(result
));
376 if ((path
== null) || ((sessionPath
!= null) && (!path
.contains(sessionPath
)))) {
378 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
379 Messages
.TraceControl_UnexpectedPathError
+ ": " + name
); //$NON-NLS-1$
382 SessionInfo sessionInfo
= new SessionInfo(name
);
383 sessionInfo
.setSessionPath(path
);
389 public void destroySession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
390 String newName
= formatParameter(sessionName
);
392 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_DESTROY_SESSION
, newName
);
394 ICommandResult result
= executeCommand(command
.toString(), monitor
, false);
395 String
[] output
= result
.getOutput();
397 if (isError(result
) && ((output
== null) || (!LTTngControlServiceConstants
.SESSION_NOT_FOUND_ERROR_PATTERN
.matcher(output
[0]).matches()))) {
398 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$
400 //Session <sessionName> destroyed
405 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#startSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
408 public void startSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
410 String newSessionName
= formatParameter(sessionName
);
412 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_START_SESSION
, newSessionName
);
414 executeCommand(command
.toString(), monitor
);
416 //Session <sessionName> started
421 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#stopSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
424 public void stopSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
425 String newSessionName
= formatParameter(sessionName
);
426 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_STOP_SESSION
, newSessionName
);
428 executeCommand(command
.toString(), monitor
);
430 //Session <sessionName> stopped
436 * @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)
439 public void enableChannels(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IChannelInfo info
, IProgressMonitor monitor
) throws ExecutionException
{
441 // no channels to enable
442 if (channelNames
.isEmpty()) {
446 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_CHANNEL
);
448 for (Iterator
<String
> iterator
= channelNames
.iterator(); iterator
.hasNext();) {
449 String channel
= iterator
.next();
450 command
.append(channel
);
451 if (iterator
.hasNext()) {
457 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
459 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
462 String newSessionName
= formatParameter(sessionName
);
463 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
464 command
.append(newSessionName
);
467 // --discard Discard event when buffers are full (default)
469 // --overwrite Flight recorder mode
470 if (info
.isOverwriteMode()) {
471 command
.append(LTTngControlServiceConstants
.OPTION_OVERWRITE
);
473 // --subbuf-size SIZE Subbuffer size in bytes
474 // (default: 4096, kernel default: 262144)
475 command
.append(LTTngControlServiceConstants
.OPTION_SUB_BUFFER_SIZE
);
476 command
.append(String
.valueOf(info
.getSubBufferSize()));
478 // --num-subbuf NUM Number of subbufers
479 // (default: 8, kernel default: 4)
480 command
.append(LTTngControlServiceConstants
.OPTION_NUM_SUB_BUFFERS
);
481 command
.append(String
.valueOf(info
.getNumberOfSubBuffers()));
483 // --switch-timer USEC Switch timer interval in usec (default: 0)
484 command
.append(LTTngControlServiceConstants
.OPTION_SWITCH_TIMER
);
485 command
.append(String
.valueOf(info
.getSwitchTimer()));
487 // --read-timer USEC Read timer interval in usec (default: 200)
488 command
.append(LTTngControlServiceConstants
.OPTION_READ_TIMER
);
489 command
.append(String
.valueOf(info
.getReadTimer()));
492 executeCommand(command
.toString(), monitor
);
498 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#disableChannel(java.lang.String, java.util.List, org.eclipse.core.runtime.IProgressMonitor)
501 public void disableChannels(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
503 // no channels to enable
504 if (channelNames
.isEmpty()) {
508 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_DISABLE_CHANNEL
);
510 for (Iterator
<String
> iterator
= channelNames
.iterator(); iterator
.hasNext();) {
511 String channel
= iterator
.next();
512 command
.append(channel
);
513 if (iterator
.hasNext()) {
519 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
521 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
524 String newSessionName
= formatParameter(sessionName
);
525 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
526 command
.append(newSessionName
);
528 executeCommand(command
.toString(), monitor
);
533 * @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)
536 public void enableEvents(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
538 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
540 if (eventNames
== null || eventNames
.isEmpty()) {
541 command
.append(LTTngControlServiceConstants
.OPTION_ALL
);
544 StringBuffer eventNameParameter
= new StringBuffer();
545 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
546 String event
= iterator
.next();
547 eventNameParameter
.append(event
);
548 if (iterator
.hasNext()) {
549 eventNameParameter
.append(',');
552 command
.append(formatParameter(eventNameParameter
.toString()));
556 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
558 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
561 String newSessionName
= formatParameter(sessionName
);
563 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
564 command
.append(newSessionName
);
566 if (channelName
!= null) {
567 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
568 command
.append(channelName
);
571 command
.append(LTTngControlServiceConstants
.OPTION_TRACEPOINT
);
573 executeCommand(command
.toString(), monitor
);
579 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#enableSyscalls(java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
582 public void enableSyscalls(String sessionName
, String channelName
, IProgressMonitor monitor
) throws ExecutionException
{
584 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
586 command
.append(LTTngControlServiceConstants
.OPTION_ALL
);
587 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
589 String newSessionName
= formatParameter(sessionName
);
591 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
592 command
.append(newSessionName
);
594 if (channelName
!= null) {
595 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
596 command
.append(channelName
);
599 command
.append(LTTngControlServiceConstants
.OPTION_SYSCALL
);
601 executeCommand(command
.toString(), monitor
);
606 * @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)
609 public void enableProbe(String sessionName
, String channelName
, String eventName
, boolean isFunction
, String probe
, IProgressMonitor monitor
) throws ExecutionException
{
610 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
612 command
.append(eventName
);
613 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
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 command
.append(LTTngControlServiceConstants
.OPTION_FUNCTION_PROBE
);
626 command
.append(LTTngControlServiceConstants
.OPTION_PROBE
);
629 command
.append(probe
);
631 executeCommand(command
.toString(), monitor
);
636 * @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)
639 public void enableLogLevel(String sessionName
, String channelName
, String eventName
, LogLevelType logLevelType
, TraceLogLevel level
, IProgressMonitor monitor
) throws ExecutionException
{
640 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
642 command
.append(eventName
);
643 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
645 String newSessionName
= formatParameter(sessionName
);
646 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
647 command
.append(newSessionName
);
649 if (channelName
!= null) {
650 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
651 command
.append(channelName
);
654 if (logLevelType
== LogLevelType
.LOGLEVEL
) {
655 command
.append(LTTngControlServiceConstants
.OPTION_LOGLEVEL
);
656 } else if (logLevelType
== LogLevelType
.LOGLEVEL_ONLY
) {
657 command
.append(LTTngControlServiceConstants
.OPTION_LOGLEVEL_ONLY
);
662 command
.append(level
.getInName());
664 executeCommand(command
.toString(), monitor
);
670 * @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)
673 public void disableEvent(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
674 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_DISABLE_EVENT
);
676 if (eventNames
== null) {
677 command
.append(LTTngControlServiceConstants
.OPTION_ALL
);
679 // no events to disable
680 if (eventNames
.isEmpty()) {
684 StringBuffer eventNameParameter
= new StringBuffer();
685 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
686 String event
= iterator
.next();
687 eventNameParameter
.append(event
);
688 if (iterator
.hasNext()) {
689 eventNameParameter
.append(',');
692 command
.append(formatParameter(eventNameParameter
.toString()));
696 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
698 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
701 String newSessionName
= formatParameter(sessionName
);
702 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
703 command
.append(newSessionName
);
705 if (channelName
!= null) {
706 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
707 command
.append(channelName
);
710 executeCommand(command
.toString(), monitor
);
715 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#getContexts(org.eclipse.core.runtime.IProgressMonitor)
718 public List
<String
> getContextList(IProgressMonitor monitor
) throws ExecutionException
{
720 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ADD_CONTEXT
, LTTngControlServiceConstants
.OPTION_HELP
);
722 ICommandResult result
= executeCommand(command
.toString(), monitor
);
724 String
[] output
= result
.getOutput();
726 List
<String
> contexts
= new ArrayList
<String
>(0);
729 boolean inList
= false;
730 while (index
< output
.length
) {
731 String line
= result
.getOutput()[index
];
733 Matcher startMatcher
= LTTngControlServiceConstants
.ADD_CONTEXT_HELP_CONTEXTS_INTRO
.matcher(line
);
734 Matcher endMatcher
= LTTngControlServiceConstants
.ADD_CONTEXT_HELP_CONTEXTS_END_LINE
.matcher(line
);
736 if (startMatcher
.matches()) {
738 } else if (endMatcher
.matches()) {
740 } else if (inList
== true) {
741 String
[] tmp
= line
.split(","); //$NON-NLS-1$
742 for (int i
= 0; i
< tmp
.length
; i
++) {
743 contexts
.add(tmp
[i
].trim());
753 * @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)
756 public void addContexts(String sessionName
, String channelName
, String eventName
, boolean isKernel
, List
<String
> contextNames
, IProgressMonitor monitor
) throws ExecutionException
{
757 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ADD_CONTEXT
);
759 String newSessionName
= formatParameter(sessionName
);
760 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
761 command
.append(newSessionName
);
763 if (channelName
!= null) {
764 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
765 command
.append(channelName
);
768 if (eventName
!= null) {
769 command
.append(LTTngControlServiceConstants
.OPTION_EVENT
);
770 command
.append(eventName
);
774 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
776 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
779 for (Iterator
<String
> iterator
= contextNames
.iterator(); iterator
.hasNext();) {
780 String context
= iterator
.next();
781 command
.append(LTTngControlServiceConstants
.OPTION_CONTEXT_TYPE
);
782 command
.append(context
);
785 executeCommand(command
.toString(), monitor
);
791 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#calibrate(boolean, org.eclipse.core.runtime.IProgressMonitor)
794 public void calibrate(boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
795 // String newSessionName = formatParameter(sessionName);
796 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_CALIBRATE
);
798 // command.append(OPTION_SESSION);
799 // command.append(newSessionName);
802 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
804 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
807 command
.append(LTTngControlServiceConstants
.OPTION_FUNCTION_PROBE
);
809 executeCommand(command
.toString(), monitor
);
812 // ------------------------------------------------------------------------
814 // ------------------------------------------------------------------------
816 * Checks if command result is an error result.
819 * - the command result to check
820 * @return true if error else false
822 protected boolean isError(ICommandResult result
) {
823 if ((result
.getResult()) != 0 || (result
.getOutput().length
< 1 || LTTngControlServiceConstants
.ERROR_PATTERN
.matcher(result
.getOutput()[0]).matches())) {
830 * Formats the output string as single string.
834 * @return - the formatted output
836 public static String
formatOutput(ICommandResult result
) {
837 if ((result
== null) || result
.getOutput() == null || result
.getOutput().length
== 0) {
838 return ""; //$NON-NLS-1$
840 String
[] output
= result
.getOutput();
841 StringBuffer ret
= new StringBuffer();
842 ret
.append("Return Value: "); //$NON-NLS-1$
843 ret
.append(result
.getResult());
844 ret
.append("\n"); //$NON-NLS-1$
845 for (int i
= 0; i
< output
.length
; i
++) {
846 ret
.append(output
[i
] + "\n"); //$NON-NLS-1$
848 return ret
.toString();
852 * Parses the domain information.
855 * - a command output array
856 * @param currentIndex
857 * - current index in command output array
859 * - list for returning channel information
860 * @return the new current index in command output array
862 protected int parseDomain(String
[] output
, int currentIndex
, List
<IChannelInfo
> channels
) {
863 int index
= currentIndex
;
867 // - channnel1: [enabled]
871 // subbufers size: 262144
872 // number of subbufers: 4
873 // switch timer interval: 0
874 // read timer interval: 200
877 while (index
< output
.length
) {
878 String line
= output
[index
];
880 Matcher outerMatcher
= LTTngControlServiceConstants
.CHANNELS_SECTION_PATTERN
.matcher(line
);
881 if (outerMatcher
.matches()) {
882 IChannelInfo channelInfo
= null;
883 while (index
< output
.length
) {
884 String subLine
= output
[index
];
886 Matcher innerMatcher
= LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(subLine
);
887 if (innerMatcher
.matches()) {
888 channelInfo
= new ChannelInfo(""); //$NON-NLS-1$
890 channelInfo
.setName(innerMatcher
.group(1));
892 // get channel enablement
893 channelInfo
.setState(innerMatcher
.group(2));
896 channels
.add(channelInfo
);
898 } else if (LTTngControlServiceConstants
.OVERWRITE_MODE_ATTRIBUTE
.matcher(subLine
).matches()) {
899 String value
= getAttributeValue(subLine
);
900 if (channelInfo
!= null) {
901 channelInfo
.setOverwriteMode(!LTTngControlServiceConstants
.OVERWRITE_MODE_ATTRIBUTE_FALSE
.equals(value
));
903 } else if (LTTngControlServiceConstants
.SUBBUFFER_SIZE_ATTRIBUTE
.matcher(subLine
).matches()) {
904 if (channelInfo
!= null) {
905 channelInfo
.setSubBufferSize(Long
.valueOf(getAttributeValue(subLine
)));
908 } else if (LTTngControlServiceConstants
.NUM_SUBBUFFERS_ATTRIBUTE
.matcher(subLine
).matches()) {
909 if (channelInfo
!= null) {
910 channelInfo
.setNumberOfSubBuffers(Integer
.valueOf(getAttributeValue(subLine
)));
913 } else if (LTTngControlServiceConstants
.SWITCH_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
914 if (channelInfo
!= null) {
915 channelInfo
.setSwitchTimer(Long
.valueOf(getAttributeValue(subLine
)));
918 } else if (LTTngControlServiceConstants
.READ_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
919 if (channelInfo
!= null) {
920 channelInfo
.setReadTimer(Long
.valueOf(getAttributeValue(subLine
)));
923 } else if (LTTngControlServiceConstants
.OUTPUT_ATTRIBUTE
.matcher(subLine
).matches()) {
924 if (channelInfo
!= null) {
925 channelInfo
.setOutputType(getAttributeValue(subLine
));
928 } else if (LTTngControlServiceConstants
.EVENT_SECTION_PATTERN
.matcher(subLine
).matches()) {
929 List
<IEventInfo
> events
= new ArrayList
<IEventInfo
>();
930 index
= parseEvents(output
, index
, events
);
931 if (channelInfo
!= null) {
932 channelInfo
.setEvents(events
);
934 // we want to stay at the current index to be able to
937 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(subLine
).matches()) {
940 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(subLine
).matches()) {
952 * Parses the event information within a domain.
955 * - a command output array
956 * @param currentIndex
957 * - current index in command output array
959 * - list for returning event information
960 * @return the new current index in command output array
962 protected int parseEvents(String
[] output
, int currentIndex
, List
<IEventInfo
> events
) {
963 int index
= currentIndex
;
965 while (index
< output
.length
) {
966 String line
= output
[index
];
967 if (LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(line
).matches()) {
970 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(line
).matches()) {
973 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
).matches()) {
978 Matcher matcher
= LTTngControlServiceConstants
.EVENT_PATTERN
.matcher(line
);
979 Matcher matcher2
= LTTngControlServiceConstants
.WILDCARD_EVENT_PATTERN
.matcher(line
);
981 if (matcher
.matches()) {
982 IEventInfo eventInfo
= new EventInfo(matcher
.group(1).trim());
983 eventInfo
.setLogLevel(matcher
.group(2).trim());
984 eventInfo
.setEventType(matcher
.group(3).trim());
985 eventInfo
.setState(matcher
.group(4));
986 events
.add(eventInfo
);
988 } else if (matcher2
.matches()) {
989 IEventInfo eventInfo
= new EventInfo(matcher2
.group(1).trim());
990 eventInfo
.setLogLevel(TraceLogLevel
.LEVEL_UNKNOWN
);
991 eventInfo
.setEventType(matcher2
.group(2).trim());
992 eventInfo
.setState(matcher2
.group(3));
994 if (eventInfo
.getEventType() == TraceEventType
.PROBE
) {
995 IProbeEventInfo probeEvent
= new ProbeEventInfo(eventInfo
.getName());
996 probeEvent
.setLogLevel(eventInfo
.getLogLevel());
997 probeEvent
.setEventType(eventInfo
.getEventType());
998 probeEvent
.setState(eventInfo
.getState());
1000 // Overwrite eventinfo
1001 eventInfo
= probeEvent
;
1003 // myevent2 (type: probe) [enabled]
1005 // myevent0 (type: probe) [enabled]
1007 // symbol: init_post
1009 while (index
< output
.length
) {
1010 String probeLine
= output
[index
];
1012 Matcher addrMatcher
= LTTngControlServiceConstants
.PROBE_ADDRESS_PATTERN
.matcher(probeLine
);
1013 Matcher offsetMatcher
= LTTngControlServiceConstants
.PROBE_OFFSET_PATTERN
.matcher(probeLine
);
1014 Matcher symbolMatcher
= LTTngControlServiceConstants
.PROBE_SYMBOL_PATTERN
.matcher(probeLine
);
1015 if (addrMatcher
.matches()) {
1016 String addr
= addrMatcher
.group(2).trim();
1017 probeEvent
.setAddress(addr
);
1018 } else if (offsetMatcher
.matches()) {
1019 String offset
= offsetMatcher
.group(2).trim();
1020 probeEvent
.setOffset(offset
);
1021 } else if (symbolMatcher
.matches()) {
1022 String symbol
= symbolMatcher
.group(2).trim();
1023 probeEvent
.setSymbol(symbol
);
1024 } else if ((LTTngControlServiceConstants
.EVENT_PATTERN
.matcher(probeLine
).matches()) || (LTTngControlServiceConstants
.WILDCARD_EVENT_PATTERN
.matcher(probeLine
).matches())) {
1026 } else if (LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(probeLine
).matches()) {
1028 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(probeLine
).matches()) {
1031 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(probeLine
).matches()) {
1037 events
.add(eventInfo
);
1039 events
.add(eventInfo
);
1046 // else if (line.matches(EVENT_NONE_PATTERN)) {
1056 * Parses a line with attributes: <attribute Name>: <attribute value>
1059 * - attribute line to parse
1060 * @return the attribute value as string
1062 protected String
getAttributeValue(String line
) {
1063 String
[] temp
= line
.split("\\: "); //$NON-NLS-1$
1068 * Parses the event information within a provider.
1071 * - a command output array
1072 * @param currentIndex
1073 * - current index in command output array
1075 * - list for returning event information
1076 * @return the new current index in command output array
1078 protected int getProviderEventInfo(String
[] output
, int currentIndex
, List
<IBaseEventInfo
> events
) {
1079 int index
= currentIndex
;
1080 while (index
< output
.length
) {
1081 String line
= output
[index
];
1082 Matcher matcher
= LTTngControlServiceConstants
.PROVIDER_EVENT_PATTERN
.matcher(line
);
1083 if (matcher
.matches()) {
1084 // sched_kthread_stop (loglevel: TRACE_EMERG0) (type:
1086 IBaseEventInfo eventInfo
= new BaseEventInfo(matcher
.group(1).trim());
1087 eventInfo
.setLogLevel(matcher
.group(2).trim());
1088 eventInfo
.setEventType(matcher
.group(3).trim());
1089 events
.add(eventInfo
);
1090 } else if (LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
).matches()) {
1099 * Formats a command parameter for the command execution i.e. adds quotes
1100 * at the beginning and end if necessary.
1101 * @param parameter - parameter to format
1102 * @return formated parameter
1104 protected String
formatParameter(String parameter
) {
1105 if (parameter
!= null) {
1106 StringBuffer newString
= new StringBuffer();
1107 newString
.append(parameter
);
1109 if (parameter
.contains(" ") || parameter
.contains("*")) { //$NON-NLS-1$ //$NON-NLS-2$
1110 newString
.insert(0, "\""); //$NON-NLS-1$
1111 newString
.append("\""); //$NON-NLS-1$
1113 return newString
.toString();
1119 * @param strings array of string that makes up a command line
1120 * @return string buffer with created command line
1122 protected StringBuffer
createCommand(String
... strings
) {
1123 StringBuffer command
= new StringBuffer();
1124 command
.append(LTTngControlServiceConstants
.CONTROL_COMMAND
);
1125 command
.append(getTracingGroupOption());
1126 command
.append(getVerboseOption());
1127 for (String string
: strings
) {
1128 command
.append(string
);
1134 * @return the tracing group option if configured in the preferences
1136 protected String
getTracingGroupOption() {
1137 if (!ControlPreferences
.getInstance().isDefaultTracingGroup() && !ControlPreferences
.getInstance().getTracingGroup().equals("")) { //$NON-NLS-1$
1138 return LTTngControlServiceConstants
.OPTION_TRACING_GROUP
+ ControlPreferences
.getInstance().getTracingGroup();
1140 return ""; //$NON-NLS-1$
1144 * @return the verbose option as configured in the preferences
1146 protected String
getVerboseOption() {
1147 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1148 String level
= ControlPreferences
.getInstance().getVerboseLevel();
1149 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_VERBOSE
.equals(level
)) {
1150 return LTTngControlServiceConstants
.OPTION_VERBOSE
;
1152 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_V_VERBOSE
.equals(level
)) {
1153 return LTTngControlServiceConstants
.OPTION_VERY_VERBOSE
;
1155 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_V_V_VERBOSE
.equals(level
)) {
1156 return LTTngControlServiceConstants
.OPTION_VERY_VERY_VERBOSE
;
1159 return ""; //$NON-NLS-1$
1163 * Method that logs the command and command result if logging is enabled as
1164 * well as forwards the command execution to the shell.
1167 * - the command to execute
1169 * - a progress monitor
1170 * @return the command result
1171 * @throws ExecutionException
1173 protected ICommandResult
executeCommand(String command
,
1174 IProgressMonitor monitor
) throws ExecutionException
{
1175 return executeCommand(command
, monitor
, true);
1179 * Method that logs the command and command result if logging is enabled as
1180 * well as forwards the command execution to the shell.
1183 * - the command to execute
1185 * - a progress monitor
1186 * @param checkForError
1187 * - true to verify command result, else false
1188 * @return the command result
1189 * @throws ExecutionException
1190 * in case of error result
1192 protected ICommandResult
executeCommand(String command
,
1193 IProgressMonitor monitor
, boolean checkForError
)
1194 throws ExecutionException
{
1195 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1196 ControlCommandLogger
.log(command
);
1199 ICommandResult result
= fCommandShell
.executeCommand(
1200 command
.toString(), monitor
);
1202 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1203 ControlCommandLogger
.log(formatOutput(result
));
1206 if (checkForError
&& isError(result
)) {
1207 throw new ExecutionException(Messages
.TraceControl_CommandError
1208 + " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$