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
= (String
) 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
= (String
) 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 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
527 String event
= (String
) iterator
.next();
528 command
.append(event
);
529 if (iterator
.hasNext()) {
536 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
538 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
541 String newSessionName
= formatParameter(sessionName
);
543 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
544 command
.append(newSessionName
);
546 if (channelName
!= null) {
547 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
548 command
.append(channelName
);
551 command
.append(LTTngControlServiceConstants
.OPTION_TRACEPOINT
);
553 executeCommand(command
.toString(), monitor
);
559 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#enableSyscalls(java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
562 public void enableSyscalls(String sessionName
, String channelName
, IProgressMonitor monitor
) throws ExecutionException
{
564 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
566 command
.append(LTTngControlServiceConstants
.OPTION_ALL
);
567 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
569 String newSessionName
= formatParameter(sessionName
);
571 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
572 command
.append(newSessionName
);
574 if (channelName
!= null) {
575 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
576 command
.append(channelName
);
579 command
.append(LTTngControlServiceConstants
.OPTION_SYSCALL
);
581 executeCommand(command
.toString(), monitor
);
586 * @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)
589 public void enableProbe(String sessionName
, String channelName
, String eventName
, boolean isFunction
, String probe
, IProgressMonitor monitor
) throws ExecutionException
{
590 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
592 command
.append(eventName
);
593 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
595 String newSessionName
= formatParameter(sessionName
);
596 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
597 command
.append(newSessionName
);
599 if (channelName
!= null) {
600 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
601 command
.append(channelName
);
604 command
.append(LTTngControlServiceConstants
.OPTION_FUNCTION_PROBE
);
606 command
.append(LTTngControlServiceConstants
.OPTION_PROBE
);
609 command
.append(probe
);
611 executeCommand(command
.toString(), monitor
);
616 * @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)
619 public void enableLogLevel(String sessionName
, String channelName
, String eventName
, LogLevelType logLevelType
, TraceLogLevel level
, IProgressMonitor monitor
) throws ExecutionException
{
620 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
622 command
.append(eventName
);
623 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
625 String newSessionName
= formatParameter(sessionName
);
626 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
627 command
.append(newSessionName
);
629 if (channelName
!= null) {
630 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
631 command
.append(channelName
);
634 if (logLevelType
== LogLevelType
.LOGLEVEL
) {
635 command
.append(LTTngControlServiceConstants
.OPTION_LOGLEVEL
);
636 } else if (logLevelType
== LogLevelType
.LOGLEVEL_ONLY
) {
637 command
.append(LTTngControlServiceConstants
.OPTION_LOGLEVEL_ONLY
);
642 command
.append(level
.getInName());
644 executeCommand(command
.toString(), monitor
);
650 * @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)
653 public void disableEvent(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
654 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_DISABLE_EVENT
);
656 if (eventNames
== null) {
657 command
.append(LTTngControlServiceConstants
.OPTION_ALL
);
659 // no events to enable
660 if (eventNames
.isEmpty()) {
664 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
665 String event
= (String
) iterator
.next();
666 command
.append(event
);
667 if (iterator
.hasNext()) {
674 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
676 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
679 String newSessionName
= formatParameter(sessionName
);
680 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
681 command
.append(newSessionName
);
683 if (channelName
!= null) {
684 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
685 command
.append(channelName
);
688 executeCommand(command
.toString(), monitor
);
693 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#getContexts(org.eclipse.core.runtime.IProgressMonitor)
696 public List
<String
> getContextList(IProgressMonitor monitor
) throws ExecutionException
{
698 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ADD_CONTEXT
, LTTngControlServiceConstants
.OPTION_HELP
);
700 ICommandResult result
= executeCommand(command
.toString(), monitor
);
702 String
[] output
= result
.getOutput();
704 List
<String
> contexts
= new ArrayList
<String
>(0);
707 boolean inList
= false;
708 while (index
< output
.length
) {
709 String line
= result
.getOutput()[index
];
711 Matcher startMatcher
= LTTngControlServiceConstants
.ADD_CONTEXT_HELP_CONTEXTS_INTRO
.matcher(line
);
712 Matcher endMatcher
= LTTngControlServiceConstants
.ADD_CONTEXT_HELP_CONTEXTS_END_LINE
.matcher(line
);
714 if (startMatcher
.matches()) {
716 } else if (endMatcher
.matches()) {
718 } else if (inList
== true) {
719 String
[] tmp
= line
.split(","); //$NON-NLS-1$
720 for (int i
= 0; i
< tmp
.length
; i
++) {
721 contexts
.add(tmp
[i
].trim());
731 * @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)
734 public void addContexts(String sessionName
, String channelName
, String eventName
, boolean isKernel
, List
<String
> contextNames
, IProgressMonitor monitor
) throws ExecutionException
{
735 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ADD_CONTEXT
);
737 String newSessionName
= formatParameter(sessionName
);
738 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
739 command
.append(newSessionName
);
741 if (channelName
!= null) {
742 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
743 command
.append(channelName
);
746 if (eventName
!= null) {
747 command
.append(LTTngControlServiceConstants
.OPTION_EVENT
);
748 command
.append(eventName
);
752 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
754 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
757 for (Iterator
<String
> iterator
= contextNames
.iterator(); iterator
.hasNext();) {
758 String context
= (String
) iterator
.next();
759 command
.append(LTTngControlServiceConstants
.OPTION_CONTEXT_TYPE
);
760 command
.append(context
);
763 executeCommand(command
.toString(), monitor
);
769 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#calibrate(boolean, org.eclipse.core.runtime.IProgressMonitor)
772 public void calibrate(boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
773 // String newSessionName = formatParameter(sessionName);
774 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_CALIBRATE
);
776 // command.append(OPTION_SESSION);
777 // command.append(newSessionName);
780 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
782 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
785 command
.append(LTTngControlServiceConstants
.OPTION_FUNCTION_PROBE
);
787 executeCommand(command
.toString(), monitor
);
790 // ------------------------------------------------------------------------
792 // ------------------------------------------------------------------------
794 * Checks if command result is an error result.
797 * - the command result to check
798 * @return true if error else false
800 protected boolean isError(ICommandResult result
) {
801 if ((result
.getResult()) != 0 || (result
.getOutput().length
< 1 || LTTngControlServiceConstants
.ERROR_PATTERN
.matcher(result
.getOutput()[0]).matches())) {
808 * Formats the output string as single string.
812 * @return - the formatted output
814 protected String
formatOutput(ICommandResult result
) {
815 if ((result
== null) || result
.getOutput() == null || result
.getOutput().length
== 0) {
816 return ""; //$NON-NLS-1$
818 String
[] output
= result
.getOutput();
819 StringBuffer ret
= new StringBuffer();
820 ret
.append("Return Value: "); //$NON-NLS-1$
821 ret
.append(result
.getResult());
822 ret
.append("\n"); //$NON-NLS-1$
823 for (int i
= 0; i
< output
.length
; i
++) {
824 ret
.append(output
[i
] + "\n"); //$NON-NLS-1$
826 return ret
.toString();
830 * Parses the domain information.
833 * - a command output array
834 * @param currentIndex
835 * - current index in command output array
837 * - list for returning channel information
838 * @return the new current index in command output array
840 protected int parseDomain(String
[] output
, int currentIndex
, List
<IChannelInfo
> channels
) {
841 int index
= currentIndex
;
845 // - channnel1: [enabled]
849 // subbufers size: 262144
850 // number of subbufers: 4
851 // switch timer interval: 0
852 // read timer interval: 200
855 while (index
< output
.length
) {
856 String line
= output
[index
];
858 Matcher outerMatcher
= LTTngControlServiceConstants
.CHANNELS_SECTION_PATTERN
.matcher(line
);
859 if (outerMatcher
.matches()) {
860 IChannelInfo channelInfo
= null;
861 while (index
< output
.length
) {
862 String subLine
= output
[index
];
864 Matcher innerMatcher
= LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(subLine
);
865 if (innerMatcher
.matches()) {
866 channelInfo
= new ChannelInfo(""); //$NON-NLS-1$
868 channelInfo
.setName(innerMatcher
.group(1));
870 // get channel enablement
871 channelInfo
.setState(innerMatcher
.group(2));
874 channels
.add(channelInfo
);
876 } else if (LTTngControlServiceConstants
.OVERWRITE_MODE_ATTRIBUTE
.matcher(subLine
).matches()) {
877 String value
= getAttributeValue(subLine
);
878 channelInfo
.setOverwriteMode(!LTTngControlServiceConstants
.OVERWRITE_MODE_ATTRIBUTE_FALSE
.equals(value
));
879 } else if (LTTngControlServiceConstants
.SUBBUFFER_SIZE_ATTRIBUTE
.matcher(subLine
).matches()) {
880 channelInfo
.setSubBufferSize(Long
.valueOf(getAttributeValue(subLine
)));
882 } else if (LTTngControlServiceConstants
.NUM_SUBBUFFERS_ATTRIBUTE
.matcher(subLine
).matches()) {
883 channelInfo
.setNumberOfSubBuffers(Integer
.valueOf(getAttributeValue(subLine
)));
885 } else if (LTTngControlServiceConstants
.SWITCH_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
886 channelInfo
.setSwitchTimer(Long
.valueOf(getAttributeValue(subLine
)));
888 } else if (LTTngControlServiceConstants
.READ_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
889 channelInfo
.setReadTimer(Long
.valueOf(getAttributeValue(subLine
)));
891 } else if (LTTngControlServiceConstants
.OUTPUT_ATTRIBUTE
.matcher(subLine
).matches()) {
892 channelInfo
.setOutputType(getAttributeValue(subLine
));
894 } else if (LTTngControlServiceConstants
.EVENT_SECTION_PATTERN
.matcher(subLine
).matches()) {
895 List
<IEventInfo
> events
= new ArrayList
<IEventInfo
>();
896 index
= parseEvents(output
, index
, events
);
897 channelInfo
.setEvents(events
);
898 // we want to stay at the current index to be able to
901 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(subLine
).matches()) {
904 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(subLine
).matches()) {
916 * Parses the event information within a domain.
919 * - a command output array
920 * @param currentIndex
921 * - current index in command output array
923 * - list for returning event information
924 * @return the new current index in command output array
926 protected int parseEvents(String
[] output
, int currentIndex
, List
<IEventInfo
> events
) {
927 int index
= currentIndex
;
929 while (index
< output
.length
) {
930 String line
= output
[index
];
931 if (LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(line
).matches()) {
934 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(line
).matches()) {
937 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
).matches()) {
942 Matcher matcher
= LTTngControlServiceConstants
.EVENT_PATTERN
.matcher(line
);
943 Matcher matcher2
= LTTngControlServiceConstants
.WILDCARD_EVENT_PATTERN
.matcher(line
);
945 if (matcher
.matches()) {
946 IEventInfo eventInfo
= new EventInfo(matcher
.group(1).trim());
947 eventInfo
.setLogLevel(matcher
.group(2).trim());
948 eventInfo
.setEventType(matcher
.group(3).trim());
949 eventInfo
.setState(matcher
.group(4));
950 events
.add(eventInfo
);
952 } else if (matcher2
.matches()) {
953 IEventInfo eventInfo
= new EventInfo(matcher2
.group(1).trim());
954 eventInfo
.setLogLevel(TraceLogLevel
.LEVEL_UNKNOWN
);
955 eventInfo
.setEventType(matcher2
.group(2).trim());
956 eventInfo
.setState(matcher2
.group(3));
958 if (eventInfo
.getEventType() == TraceEventType
.PROBE
) {
959 IProbeEventInfo probeEvent
= new ProbeEventInfo(eventInfo
.getName());
960 probeEvent
.setLogLevel(eventInfo
.getLogLevel());
961 probeEvent
.setEventType(eventInfo
.getEventType());
962 probeEvent
.setState(eventInfo
.getState());
964 // Overwrite eventinfo
965 eventInfo
= probeEvent
;
967 // myevent2 (type: probe) [enabled]
969 // myevent0 (type: probe) [enabled]
973 while (index
< output
.length
) {
974 String probeLine
= output
[index
];
976 Matcher addrMatcher
= LTTngControlServiceConstants
.PROBE_ADDRESS_PATTERN
.matcher(probeLine
);
977 Matcher offsetMatcher
= LTTngControlServiceConstants
.PROBE_OFFSET_PATTERN
.matcher(probeLine
);
978 Matcher symbolMatcher
= LTTngControlServiceConstants
.PROBE_SYMBOL_PATTERN
.matcher(probeLine
);
979 if (addrMatcher
.matches()) {
980 String addr
= addrMatcher
.group(2).trim();
981 probeEvent
.setAddress(addr
);
982 } else if (offsetMatcher
.matches()) {
983 String offset
= offsetMatcher
.group(2).trim();
984 probeEvent
.setOffset(offset
);
985 } else if (symbolMatcher
.matches()) {
986 String symbol
= symbolMatcher
.group(2).trim();
987 probeEvent
.setSymbol(symbol
);
988 } else if ((LTTngControlServiceConstants
.EVENT_PATTERN
.matcher(probeLine
).matches()) || (LTTngControlServiceConstants
.WILDCARD_EVENT_PATTERN
.matcher(probeLine
).matches())) {
990 } else if (LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(probeLine
).matches()) {
992 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(probeLine
).matches()) {
995 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(probeLine
).matches()) {
1001 events
.add(eventInfo
);
1003 events
.add(eventInfo
);
1010 // else if (line.matches(EVENT_NONE_PATTERN)) {
1020 * Parses a line with attributes: <attribute Name>: <attribute value>
1023 * - attribute line to parse
1024 * @return the attribute value as string
1026 protected String
getAttributeValue(String line
) {
1027 String
[] temp
= line
.split("\\: "); //$NON-NLS-1$
1032 * Parses the event information within a provider.
1035 * - a command output array
1036 * @param currentIndex
1037 * - current index in command output array
1039 * - list for returning event information
1040 * @return the new current index in command output array
1042 protected int getProviderEventInfo(String
[] output
, int currentIndex
, List
<IBaseEventInfo
> events
) {
1043 int index
= currentIndex
;
1044 while (index
< output
.length
) {
1045 String line
= output
[index
];
1046 Matcher matcher
= LTTngControlServiceConstants
.PROVIDER_EVENT_PATTERN
.matcher(line
);
1047 if (matcher
.matches()) {
1048 // sched_kthread_stop (loglevel: TRACE_EMERG0) (type:
1050 IBaseEventInfo eventInfo
= new BaseEventInfo(matcher
.group(1).trim());
1051 eventInfo
.setLogLevel(matcher
.group(2).trim());
1052 eventInfo
.setEventType(matcher
.group(3).trim());
1053 events
.add(eventInfo
);
1054 } else if (LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
).matches()) {
1063 * Formats a command parameter for the command execution i.e. adds quotes
1064 * at the beginning and end if necessary.
1065 * @param parameter - parameter to format
1066 * @return formated parameter
1068 protected String
formatParameter(String parameter
) {
1069 if (parameter
!= null) {
1070 StringBuffer newString
= new StringBuffer();
1071 newString
.append(parameter
);
1073 if (parameter
.contains(" ")) { //$NON-NLS-1$
1074 newString
.insert(0, "\""); //$NON-NLS-1$
1075 newString
.append("\""); //$NON-NLS-1$
1077 return newString
.toString();
1083 * @param strings array of string that makes up a command line
1084 * @return string buffer with created command line
1086 protected StringBuffer
createCommand(String
... strings
) {
1087 StringBuffer command
= new StringBuffer();
1088 command
.append(LTTngControlServiceConstants
.CONTROL_COMMAND
);
1089 command
.append(getTracingGroupOption());
1090 command
.append(getVerboseOption());
1091 for (String string
: strings
) {
1092 command
.append(string
);
1098 * @return the tracing group option if configured in the preferences
1100 protected String
getTracingGroupOption() {
1101 if (!ControlPreferences
.getInstance().isDefaultTracingGroup() && !ControlPreferences
.getInstance().getTracingGroup().equals("")) { //$NON-NLS-1$
1102 return LTTngControlServiceConstants
.OPTION_TRACING_GROUP
+ ControlPreferences
.getInstance().getTracingGroup();
1104 return ""; //$NON-NLS-1$
1108 * @return the verbose option as configured in the preferences
1110 protected String
getVerboseOption() {
1111 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1112 String level
= ControlPreferences
.getInstance().getVerboseLevel();
1113 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_VERBOSE
.equals(level
)) {
1114 return LTTngControlServiceConstants
.OPTION_VERBOSE
;
1116 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_V_VERBOSE
.equals(level
)) {
1117 return LTTngControlServiceConstants
.OPTION_VERY_VERBOSE
;
1119 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_V_V_VERBOSE
.equals(level
)) {
1120 return LTTngControlServiceConstants
.OPTION_VERY_VERY_VERBOSE
;
1123 return ""; //$NON-NLS-1$
1127 * Method that logs the command and command result if logging is enabled as well as forwards
1128 * the command execution to the shell.
1129 * @param command - the command to execute
1130 * @param monitor - a progress monitor
1131 * @return the command result
1132 * @throws ExecutionException
1134 protected ICommandResult
executeCommand(String command
, IProgressMonitor monitor
) throws ExecutionException
{
1135 return executeCommand(command
, monitor
, true);
1139 * Method that logs the command and command result if logging is enabled as well as forwards
1140 * the command execution to the shell.
1141 * @param command - the command to execute
1142 * @param monitor - a progress monitor
1143 * @param - checkForError - true to verify command result, else false
1144 * @return the command result
1145 * @throws ExecutionException in case of error result
1147 protected ICommandResult
executeCommand(String command
, IProgressMonitor monitor
, boolean checkForError
) throws ExecutionException
{
1148 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1149 ControlCommandLogger
.log(command
);
1152 ICommandResult result
= fCommandShell
.executeCommand(command
.toString(), monitor
);
1154 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1155 ControlCommandLogger
.log(formatOutput(result
));
1158 if (isError(result
)) {
1159 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$