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
.IFieldInfo
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.IProbeEventInfo
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.ISessionInfo
;
29 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.IUstProviderInfo
;
30 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.LogLevelType
;
31 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.TraceEventType
;
32 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.TraceLogLevel
;
33 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.BaseEventInfo
;
34 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.ChannelInfo
;
35 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.DomainInfo
;
36 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.EventInfo
;
37 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.FieldInfo
;
38 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.ProbeEventInfo
;
39 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.SessionInfo
;
40 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.UstProviderInfo
;
41 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.logging
.ControlCommandLogger
;
42 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.messages
.Messages
;
43 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.preferences
.ControlPreferences
;
44 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.remote
.ICommandResult
;
45 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.remote
.ICommandShell
;
46 import org
.osgi
.framework
.Version
;
50 * Service for sending LTTng trace control commands to remote host.
53 * @author Bernd Hufmann
55 public class LTTngControlService
implements ILttngControlService
{
57 // ------------------------------------------------------------------------
59 // ------------------------------------------------------------------------
61 * The command shell implementation
63 protected ICommandShell fCommandShell
= null;
68 protected Version fVersion
= null;
70 // ------------------------------------------------------------------------
72 // ------------------------------------------------------------------------
78 * - the command shell implementation to use
80 public LTTngControlService(ICommandShell shell
) {
81 fCommandShell
= shell
;
84 // ------------------------------------------------------------------------
86 // ------------------------------------------------------------------------
89 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#getVersion()
92 public String
getVersion() {
93 if (fVersion
== null) {
94 return "Unknown"; //$NON-NLS-1$
96 return fVersion
.toString();
100 * Sets the version of the LTTng 2.0 control service.
101 * @param version - a version to set
103 public void setVersion(String version
) {
104 fVersion
= new Version(version
);
109 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#isVersionSupported(java.lang.String)
112 public boolean isVersionSupported(String version
) {
113 Version tmp
= new Version(version
);
114 return (fVersion
!= null && fVersion
.compareTo(tmp
) >= 0) ?
true : false;
117 // ------------------------------------------------------------------------
119 // ------------------------------------------------------------------------
125 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
126 * #getSessionNames(org.eclipse.core.runtime.IProgressMonitor)
129 public String
[] getSessionNames(IProgressMonitor monitor
) throws ExecutionException
{
130 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST
);
132 ICommandResult result
= executeCommand(command
.toString(), monitor
);
135 // Available tracing sessions:
136 // 1) mysession1 (/home/user/lttng-traces/mysession1-20120123-083928) [inactive]
137 // 2) mysession (/home/user/lttng-traces/mysession-20120123-083318) [inactive]
139 // Use lttng list <session_name> for more details
141 ArrayList
<String
> retArray
= new ArrayList
<String
>();
143 while (index
< result
.getOutput().length
) {
144 String line
= result
.getOutput()[index
];
145 Matcher matcher
= LTTngControlServiceConstants
.SESSION_PATTERN
.matcher(line
);
146 if (matcher
.matches()) {
147 retArray
.add(matcher
.group(2).trim());
151 return retArray
.toArray(new String
[retArray
.size()]);
158 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
159 * #getSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
162 public ISessionInfo
getSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
163 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST
, sessionName
);
164 ICommandResult result
= executeCommand(command
.toString(), monitor
);
169 // Tracing session mysession2: [inactive]
170 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
171 ISessionInfo sessionInfo
= new SessionInfo(sessionName
);
173 while (index
< result
.getOutput().length
) {
174 // Tracing session mysession2: [inactive]
175 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
177 // === Domain: Kernel ===
179 String line
= result
.getOutput()[index
];
180 Matcher matcher
= LTTngControlServiceConstants
.TRACE_SESSION_PATTERN
.matcher(line
);
181 if (matcher
.matches()) {
182 sessionInfo
.setSessionState(matcher
.group(2));
187 matcher
= LTTngControlServiceConstants
.TRACE_SESSION_PATH_PATTERN
.matcher(line
);
188 if (matcher
.matches()) {
189 sessionInfo
.setSessionPath(matcher
.group(1).trim());
194 matcher
= LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(line
);
195 if (matcher
.matches()) {
197 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_KernelDomainDisplayName
);
198 sessionInfo
.addDomain(domainInfo
);
201 ArrayList
<IChannelInfo
> channels
= new ArrayList
<IChannelInfo
>();
202 index
= parseDomain(result
.getOutput(), index
, channels
);
205 domainInfo
.setChannels(channels
);
208 domainInfo
.setIsKernel(true);
212 matcher
= LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
);
213 if (matcher
.matches()) {
214 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_UstGlobalDomainDisplayName
);
215 sessionInfo
.addDomain(domainInfo
);
218 ArrayList
<IChannelInfo
> channels
= new ArrayList
<IChannelInfo
>();
219 index
= parseDomain(result
.getOutput(), index
, channels
);
222 domainInfo
.setChannels(channels
);
225 domainInfo
.setIsKernel(false);
237 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
238 * #getKernelProvider(org.eclipse.core.runtime.IProgressMonitor)
241 public List
<IBaseEventInfo
> getKernelProvider(IProgressMonitor monitor
) throws ExecutionException
{
242 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST_KERNEL
);
243 ICommandResult result
= executeCommand(command
.toString(), monitor
, false);
245 List
<IBaseEventInfo
> events
= new ArrayList
<IBaseEventInfo
>();
247 if (result
.getOutput() != null) {
248 // Ignore the following 2 cases:
249 // Spawning a session daemon
250 // Error: Unable to list kernel events
252 // Error: Unable to list kernel events
255 if ((result
.getOutput().length
> 0) && (LTTngControlServiceConstants
.LIST_KERNEL_NO_KERNEL_PROVIDER_PATTERN
.matcher(result
.getOutput()[0]).matches()) ||
256 ((result
.getOutput().length
> 1) && (LTTngControlServiceConstants
.LIST_KERNEL_NO_KERNEL_PROVIDER_PATTERN
.matcher(result
.getOutput()[1]).matches()))) {
261 if (isError(result
)) {
262 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$
267 // sched_kthread_stop (type: tracepoint)
268 getProviderEventInfo(result
.getOutput(), 0, events
);
276 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
280 public List
<IUstProviderInfo
> getUstProvider() throws ExecutionException
{
281 return getUstProvider(new NullProgressMonitor());
288 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
289 * #getUstProvider(org.eclipse.core.runtime.IProgressMonitor)
292 public List
<IUstProviderInfo
> getUstProvider(IProgressMonitor monitor
) throws ExecutionException
{
293 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST_UST
);
295 if (isVersionSupported("2.1.0")) { //$NON-NLS-1$
296 command
.append(LTTngControlServiceConstants
.OPTION_FIELDS
);
299 ICommandResult result
= executeCommand(command
.toString(), monitor
);
301 // Note that field print-outs exists for version >= 2.1.0
307 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
308 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
310 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
311 // field: doublefield (float)
312 // field: floatfield (float)
313 // field: stringfield (string)
316 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
317 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
319 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
320 // field: doublefield (float)
321 // field: floatfield (float)
322 // field: stringfield (string)
324 List
<IUstProviderInfo
> allProviders
= new ArrayList
<IUstProviderInfo
>();
325 IUstProviderInfo provider
= null;
328 while (index
< result
.getOutput().length
) {
329 String line
= result
.getOutput()[index
];
330 Matcher matcher
= LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
);
331 if (matcher
.matches()) {
332 provider
= new UstProviderInfo(matcher
.group(2).trim());
333 provider
.setPid(Integer
.valueOf(matcher
.group(1).trim()));
334 List
<IBaseEventInfo
> events
= new ArrayList
<IBaseEventInfo
>();
335 index
= getProviderEventInfo(result
.getOutput(), ++index
, events
);
336 provider
.setEvents(events
);
337 allProviders
.add(provider
);
348 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#createSession(java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
351 public ISessionInfo
createSession(String sessionName
, String sessionPath
, IProgressMonitor monitor
) throws ExecutionException
{
353 String newName
= formatParameter(sessionName
);
354 String newPath
= formatParameter(sessionPath
);
356 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_CREATE_SESSION
, newName
);
358 if (newPath
!= null && !"".equals(newPath
)) { //$NON-NLS-1$
359 command
.append(LTTngControlServiceConstants
.OPTION_OUTPUT_PATH
);
360 command
.append(newPath
);
363 ICommandResult result
= executeCommand(command
.toString(), monitor
);
365 //Session myssession2 created.
366 //Traces will be written in /home/user/lttng-traces/myssession2-20120209-095418
367 String
[] output
= result
.getOutput();
369 // Get and verify session name
370 Matcher matcher
= LTTngControlServiceConstants
.CREATE_SESSION_NAME_PATTERN
.matcher(output
[0]);
373 if (matcher
.matches()) {
374 name
= String
.valueOf(matcher
.group(1).trim());
376 // Output format not expected
377 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
378 Messages
.TraceControl_UnexpectedCommandOutputFormat
+ ":\n" + //$NON-NLS-1$
379 formatOutput(result
));
382 if ((name
== null) || (!name
.equals(sessionName
))) {
383 // Unexpected name returned
384 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
385 Messages
.TraceControl_UnexpectedNameError
+ ": " + name
); //$NON-NLS-1$
388 // Get and verify session path
389 matcher
= LTTngControlServiceConstants
.CREATE_SESSION_PATH_PATTERN
.matcher(output
[1]);
392 if (matcher
.matches()) {
393 path
= String
.valueOf(matcher
.group(1).trim());
395 // Output format not expected
396 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
397 Messages
.TraceControl_UnexpectedCommandOutputFormat
+ ":\n" + //$NON-NLS-1$
398 formatOutput(result
));
401 if ((path
== null) || ((sessionPath
!= null) && (!path
.contains(sessionPath
)))) {
403 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
404 Messages
.TraceControl_UnexpectedPathError
+ ": " + name
); //$NON-NLS-1$
407 SessionInfo sessionInfo
= new SessionInfo(name
);
408 sessionInfo
.setSessionPath(path
);
414 public void destroySession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
415 String newName
= formatParameter(sessionName
);
417 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_DESTROY_SESSION
, newName
);
419 ICommandResult result
= executeCommand(command
.toString(), monitor
, false);
420 String
[] output
= result
.getOutput();
422 if (isError(result
) && ((output
== null) || (!LTTngControlServiceConstants
.SESSION_NOT_FOUND_ERROR_PATTERN
.matcher(output
[0]).matches()))) {
423 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$
425 //Session <sessionName> destroyed
430 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#startSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
433 public void startSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
435 String newSessionName
= formatParameter(sessionName
);
437 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_START_SESSION
, newSessionName
);
439 executeCommand(command
.toString(), monitor
);
441 //Session <sessionName> started
446 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#stopSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
449 public void stopSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
450 String newSessionName
= formatParameter(sessionName
);
451 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_STOP_SESSION
, newSessionName
);
453 executeCommand(command
.toString(), monitor
);
455 //Session <sessionName> stopped
461 * @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)
464 public void enableChannels(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IChannelInfo info
, IProgressMonitor monitor
) throws ExecutionException
{
466 // no channels to enable
467 if (channelNames
.isEmpty()) {
471 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_CHANNEL
);
473 for (Iterator
<String
> iterator
= channelNames
.iterator(); iterator
.hasNext();) {
474 String channel
= iterator
.next();
475 command
.append(channel
);
476 if (iterator
.hasNext()) {
482 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
484 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
487 String newSessionName
= formatParameter(sessionName
);
488 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
489 command
.append(newSessionName
);
492 // --discard Discard event when buffers are full (default)
494 // --overwrite Flight recorder mode
495 if (info
.isOverwriteMode()) {
496 command
.append(LTTngControlServiceConstants
.OPTION_OVERWRITE
);
498 // --subbuf-size SIZE Subbuffer size in bytes
499 // (default: 4096, kernel default: 262144)
500 command
.append(LTTngControlServiceConstants
.OPTION_SUB_BUFFER_SIZE
);
501 command
.append(String
.valueOf(info
.getSubBufferSize()));
503 // --num-subbuf NUM Number of subbufers
504 // (default: 8, kernel default: 4)
505 command
.append(LTTngControlServiceConstants
.OPTION_NUM_SUB_BUFFERS
);
506 command
.append(String
.valueOf(info
.getNumberOfSubBuffers()));
508 // --switch-timer USEC Switch timer interval in usec (default: 0)
509 command
.append(LTTngControlServiceConstants
.OPTION_SWITCH_TIMER
);
510 command
.append(String
.valueOf(info
.getSwitchTimer()));
512 // --read-timer USEC Read timer interval in usec (default: 200)
513 command
.append(LTTngControlServiceConstants
.OPTION_READ_TIMER
);
514 command
.append(String
.valueOf(info
.getReadTimer()));
517 executeCommand(command
.toString(), monitor
);
523 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#disableChannel(java.lang.String, java.util.List, org.eclipse.core.runtime.IProgressMonitor)
526 public void disableChannels(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
528 // no channels to enable
529 if (channelNames
.isEmpty()) {
533 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_DISABLE_CHANNEL
);
535 for (Iterator
<String
> iterator
= channelNames
.iterator(); iterator
.hasNext();) {
536 String channel
= iterator
.next();
537 command
.append(channel
);
538 if (iterator
.hasNext()) {
544 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
546 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
549 String newSessionName
= formatParameter(sessionName
);
550 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
551 command
.append(newSessionName
);
553 executeCommand(command
.toString(), monitor
);
558 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#enableEvents(java.lang.String, java.lang.String, java.util.List, boolean, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
561 public void enableEvents(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, String filterExpression
, IProgressMonitor monitor
) throws ExecutionException
{
563 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
565 if (eventNames
== null || eventNames
.isEmpty()) {
566 command
.append(LTTngControlServiceConstants
.OPTION_ALL
);
569 StringBuffer eventNameParameter
= new StringBuffer();
570 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
571 String event
= iterator
.next();
572 eventNameParameter
.append(event
);
573 if (iterator
.hasNext()) {
574 eventNameParameter
.append(',');
577 command
.append(formatParameter(eventNameParameter
.toString()));
581 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
583 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
586 String newSessionName
= formatParameter(sessionName
);
588 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
589 command
.append(newSessionName
);
591 if (channelName
!= null) {
592 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
593 command
.append(channelName
);
596 command
.append(LTTngControlServiceConstants
.OPTION_TRACEPOINT
);
598 if (filterExpression
!= null) {
599 command
.append(LTTngControlServiceConstants
.OPTION_FILTER
);
600 command
.append('\'');
601 command
.append(filterExpression
);
602 command
.append('\'');
605 executeCommand(command
.toString(), monitor
);
611 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#enableSyscalls(java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
614 public void enableSyscalls(String sessionName
, String channelName
, IProgressMonitor monitor
) throws ExecutionException
{
616 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
618 command
.append(LTTngControlServiceConstants
.OPTION_ALL
);
619 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
621 String newSessionName
= formatParameter(sessionName
);
623 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
624 command
.append(newSessionName
);
626 if (channelName
!= null) {
627 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
628 command
.append(channelName
);
631 command
.append(LTTngControlServiceConstants
.OPTION_SYSCALL
);
633 executeCommand(command
.toString(), monitor
);
638 * @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)
641 public void enableProbe(String sessionName
, String channelName
, String eventName
, boolean isFunction
, String probe
, IProgressMonitor monitor
) throws ExecutionException
{
642 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
644 command
.append(eventName
);
645 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
647 String newSessionName
= formatParameter(sessionName
);
648 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
649 command
.append(newSessionName
);
651 if (channelName
!= null) {
652 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
653 command
.append(channelName
);
656 command
.append(LTTngControlServiceConstants
.OPTION_FUNCTION_PROBE
);
658 command
.append(LTTngControlServiceConstants
.OPTION_PROBE
);
661 command
.append(probe
);
663 executeCommand(command
.toString(), monitor
);
668 * @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.core.control.model.LogLevelType, org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceLogLevel, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
671 public void enableLogLevel(String sessionName
, String channelName
, String eventName
, LogLevelType logLevelType
, TraceLogLevel level
, String filterExpression
, IProgressMonitor monitor
) throws ExecutionException
{
672 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
674 command
.append(eventName
);
675 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
677 String newSessionName
= formatParameter(sessionName
);
678 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
679 command
.append(newSessionName
);
681 if (channelName
!= null) {
682 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
683 command
.append(channelName
);
686 if (logLevelType
== LogLevelType
.LOGLEVEL
) {
687 command
.append(LTTngControlServiceConstants
.OPTION_LOGLEVEL
);
688 } else if (logLevelType
== LogLevelType
.LOGLEVEL_ONLY
) {
689 command
.append(LTTngControlServiceConstants
.OPTION_LOGLEVEL_ONLY
);
694 command
.append(level
.getInName());
696 executeCommand(command
.toString(), monitor
);
703 * @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)
706 public void disableEvent(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
707 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_DISABLE_EVENT
);
709 if (eventNames
== null) {
710 command
.append(LTTngControlServiceConstants
.OPTION_ALL
);
712 // no events to disable
713 if (eventNames
.isEmpty()) {
717 StringBuffer eventNameParameter
= new StringBuffer();
718 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
719 String event
= iterator
.next();
720 eventNameParameter
.append(event
);
721 if (iterator
.hasNext()) {
722 eventNameParameter
.append(',');
725 command
.append(formatParameter(eventNameParameter
.toString()));
729 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
731 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
734 String newSessionName
= formatParameter(sessionName
);
735 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
736 command
.append(newSessionName
);
738 if (channelName
!= null) {
739 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
740 command
.append(channelName
);
743 executeCommand(command
.toString(), monitor
);
748 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#getContexts(org.eclipse.core.runtime.IProgressMonitor)
751 public List
<String
> getContextList(IProgressMonitor monitor
) throws ExecutionException
{
753 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ADD_CONTEXT
, LTTngControlServiceConstants
.OPTION_HELP
);
755 ICommandResult result
= executeCommand(command
.toString(), monitor
);
757 String
[] output
= result
.getOutput();
759 List
<String
> contexts
= new ArrayList
<String
>(0);
762 boolean inList
= false;
763 while (index
< output
.length
) {
764 String line
= result
.getOutput()[index
];
766 Matcher startMatcher
= LTTngControlServiceConstants
.ADD_CONTEXT_HELP_CONTEXTS_INTRO
.matcher(line
);
767 Matcher endMatcher
= LTTngControlServiceConstants
.ADD_CONTEXT_HELP_CONTEXTS_END_LINE
.matcher(line
);
769 if (startMatcher
.matches()) {
771 } else if (endMatcher
.matches()) {
773 } else if (inList
== true) {
774 String
[] tmp
= line
.split(","); //$NON-NLS-1$
775 for (int i
= 0; i
< tmp
.length
; i
++) {
776 contexts
.add(tmp
[i
].trim());
786 * @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)
789 public void addContexts(String sessionName
, String channelName
, String eventName
, boolean isKernel
, List
<String
> contextNames
, IProgressMonitor monitor
) throws ExecutionException
{
790 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ADD_CONTEXT
);
792 String newSessionName
= formatParameter(sessionName
);
793 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
794 command
.append(newSessionName
);
796 if (channelName
!= null) {
797 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
798 command
.append(channelName
);
801 if (eventName
!= null) {
802 command
.append(LTTngControlServiceConstants
.OPTION_EVENT
);
803 command
.append(eventName
);
807 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
809 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
812 for (Iterator
<String
> iterator
= contextNames
.iterator(); iterator
.hasNext();) {
813 String context
= iterator
.next();
814 command
.append(LTTngControlServiceConstants
.OPTION_CONTEXT_TYPE
);
815 command
.append(context
);
818 executeCommand(command
.toString(), monitor
);
824 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#calibrate(boolean, org.eclipse.core.runtime.IProgressMonitor)
827 public void calibrate(boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
828 // String newSessionName = formatParameter(sessionName);
829 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_CALIBRATE
);
831 // command.append(OPTION_SESSION);
832 // command.append(newSessionName);
835 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
837 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
840 command
.append(LTTngControlServiceConstants
.OPTION_FUNCTION_PROBE
);
842 executeCommand(command
.toString(), monitor
);
845 // ------------------------------------------------------------------------
847 // ------------------------------------------------------------------------
849 * Checks if command result is an error result.
852 * - the command result to check
853 * @return true if error else false
855 protected boolean isError(ICommandResult result
) {
856 if ((result
.getResult()) != 0 || (result
.getOutput().length
< 1 || LTTngControlServiceConstants
.ERROR_PATTERN
.matcher(result
.getOutput()[0]).matches())) {
863 * Formats the output string as single string.
867 * @return - the formatted output
869 public static String
formatOutput(ICommandResult result
) {
870 if ((result
== null) || result
.getOutput() == null || result
.getOutput().length
== 0) {
871 return ""; //$NON-NLS-1$
873 String
[] output
= result
.getOutput();
874 StringBuffer ret
= new StringBuffer();
875 ret
.append("Return Value: "); //$NON-NLS-1$
876 ret
.append(result
.getResult());
877 ret
.append("\n"); //$NON-NLS-1$
878 for (int i
= 0; i
< output
.length
; i
++) {
879 ret
.append(output
[i
] + "\n"); //$NON-NLS-1$
881 return ret
.toString();
885 * Parses the domain information.
888 * - a command output array
889 * @param currentIndex
890 * - current index in command output array
892 * - list for returning channel information
893 * @return the new current index in command output array
895 protected int parseDomain(String
[] output
, int currentIndex
, List
<IChannelInfo
> channels
) {
896 int index
= currentIndex
;
900 // - channnel1: [enabled]
904 // subbufers size: 262144
905 // number of subbufers: 4
906 // switch timer interval: 0
907 // read timer interval: 200
910 while (index
< output
.length
) {
911 String line
= output
[index
];
913 Matcher outerMatcher
= LTTngControlServiceConstants
.CHANNELS_SECTION_PATTERN
.matcher(line
);
914 if (outerMatcher
.matches()) {
915 IChannelInfo channelInfo
= null;
916 while (index
< output
.length
) {
917 String subLine
= output
[index
];
919 Matcher innerMatcher
= LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(subLine
);
920 if (innerMatcher
.matches()) {
921 channelInfo
= new ChannelInfo(""); //$NON-NLS-1$
923 channelInfo
.setName(innerMatcher
.group(1));
925 // get channel enablement
926 channelInfo
.setState(innerMatcher
.group(2));
929 channels
.add(channelInfo
);
931 } else if (LTTngControlServiceConstants
.OVERWRITE_MODE_ATTRIBUTE
.matcher(subLine
).matches()) {
932 String value
= getAttributeValue(subLine
);
933 if (channelInfo
!= null) {
934 channelInfo
.setOverwriteMode(!LTTngControlServiceConstants
.OVERWRITE_MODE_ATTRIBUTE_FALSE
.equals(value
));
936 } else if (LTTngControlServiceConstants
.SUBBUFFER_SIZE_ATTRIBUTE
.matcher(subLine
).matches()) {
937 if (channelInfo
!= null) {
938 channelInfo
.setSubBufferSize(Long
.valueOf(getAttributeValue(subLine
)));
941 } else if (LTTngControlServiceConstants
.NUM_SUBBUFFERS_ATTRIBUTE
.matcher(subLine
).matches()) {
942 if (channelInfo
!= null) {
943 channelInfo
.setNumberOfSubBuffers(Integer
.valueOf(getAttributeValue(subLine
)));
946 } else if (LTTngControlServiceConstants
.SWITCH_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
947 if (channelInfo
!= null) {
948 channelInfo
.setSwitchTimer(Long
.valueOf(getAttributeValue(subLine
)));
951 } else if (LTTngControlServiceConstants
.READ_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
952 if (channelInfo
!= null) {
953 channelInfo
.setReadTimer(Long
.valueOf(getAttributeValue(subLine
)));
956 } else if (LTTngControlServiceConstants
.OUTPUT_ATTRIBUTE
.matcher(subLine
).matches()) {
957 if (channelInfo
!= null) {
958 channelInfo
.setOutputType(getAttributeValue(subLine
));
961 } else if (LTTngControlServiceConstants
.EVENT_SECTION_PATTERN
.matcher(subLine
).matches()) {
962 List
<IEventInfo
> events
= new ArrayList
<IEventInfo
>();
963 index
= parseEvents(output
, index
, events
);
964 if (channelInfo
!= null) {
965 channelInfo
.setEvents(events
);
967 // we want to stay at the current index to be able to
970 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(subLine
).matches()) {
973 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(subLine
).matches()) {
985 * Parses the event information within a domain.
988 * - a command output array
989 * @param currentIndex
990 * - current index in command output array
992 * - list for returning event information
993 * @return the new current index in command output array
995 protected int parseEvents(String
[] output
, int currentIndex
, List
<IEventInfo
> events
) {
996 int index
= currentIndex
;
998 while (index
< output
.length
) {
999 String line
= output
[index
];
1000 if (LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(line
).matches()) {
1003 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(line
).matches()) {
1006 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
).matches()) {
1011 Matcher matcher
= LTTngControlServiceConstants
.EVENT_PATTERN
.matcher(line
);
1012 Matcher matcher2
= LTTngControlServiceConstants
.WILDCARD_EVENT_PATTERN
.matcher(line
);
1014 if (matcher
.matches()) {
1015 IEventInfo eventInfo
= new EventInfo(matcher
.group(1).trim());
1016 eventInfo
.setLogLevel(matcher
.group(2).trim());
1017 eventInfo
.setEventType(matcher
.group(3).trim());
1018 eventInfo
.setState(matcher
.group(4));
1019 String filter
= matcher
.group(5);
1020 if (filter
!= null) {
1021 filter
= filter
.substring(1, filter
.length() - 1); // remove '[' and ']'
1022 eventInfo
.setFilterExpression(filter
);
1024 events
.add(eventInfo
);
1026 } else if (matcher2
.matches()) {
1027 IEventInfo eventInfo
= new EventInfo(matcher2
.group(1).trim());
1028 eventInfo
.setLogLevel(TraceLogLevel
.LEVEL_UNKNOWN
);
1029 eventInfo
.setEventType(matcher2
.group(2).trim());
1030 eventInfo
.setState(matcher2
.group(3));
1031 String filter
= matcher2
.group(4);
1032 if (filter
!= null) {
1033 filter
= filter
.substring(1, filter
.length() - 1); // remove '[' and ']'
1034 eventInfo
.setFilterExpression(filter
);
1037 if (eventInfo
.getEventType() == TraceEventType
.PROBE
) {
1038 IProbeEventInfo probeEvent
= new ProbeEventInfo(eventInfo
.getName());
1039 probeEvent
.setLogLevel(eventInfo
.getLogLevel());
1040 probeEvent
.setEventType(eventInfo
.getEventType());
1041 probeEvent
.setState(eventInfo
.getState());
1043 // Overwrite eventinfo
1044 eventInfo
= probeEvent
;
1046 // myevent2 (type: probe) [enabled]
1048 // myevent0 (type: probe) [enabled]
1050 // symbol: init_post
1052 while (index
< output
.length
) {
1053 String probeLine
= output
[index
];
1055 Matcher addrMatcher
= LTTngControlServiceConstants
.PROBE_ADDRESS_PATTERN
.matcher(probeLine
);
1056 Matcher offsetMatcher
= LTTngControlServiceConstants
.PROBE_OFFSET_PATTERN
.matcher(probeLine
);
1057 Matcher symbolMatcher
= LTTngControlServiceConstants
.PROBE_SYMBOL_PATTERN
.matcher(probeLine
);
1058 if (addrMatcher
.matches()) {
1059 String addr
= addrMatcher
.group(2).trim();
1060 probeEvent
.setAddress(addr
);
1061 } else if (offsetMatcher
.matches()) {
1062 String offset
= offsetMatcher
.group(2).trim();
1063 probeEvent
.setOffset(offset
);
1064 } else if (symbolMatcher
.matches()) {
1065 String symbol
= symbolMatcher
.group(2).trim();
1066 probeEvent
.setSymbol(symbol
);
1067 } else if ((LTTngControlServiceConstants
.EVENT_PATTERN
.matcher(probeLine
).matches()) || (LTTngControlServiceConstants
.WILDCARD_EVENT_PATTERN
.matcher(probeLine
).matches())) {
1069 } else if (LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(probeLine
).matches()) {
1071 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(probeLine
).matches()) {
1074 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(probeLine
).matches()) {
1080 events
.add(eventInfo
);
1082 events
.add(eventInfo
);
1089 // else if (line.matches(EVENT_NONE_PATTERN)) {
1099 * Parses a line with attributes: <attribute Name>: <attribute value>
1102 * - attribute line to parse
1103 * @return the attribute value as string
1105 protected String
getAttributeValue(String line
) {
1106 String
[] temp
= line
.split("\\: "); //$NON-NLS-1$
1111 * Parses the event information within a provider.
1114 * - a command output array
1115 * @param currentIndex
1116 * - current index in command output array
1118 * - list for returning event information
1119 * @return the new current index in command output array
1121 protected int getProviderEventInfo(String
[] output
, int currentIndex
, List
<IBaseEventInfo
> events
) {
1122 int index
= currentIndex
;
1123 IBaseEventInfo eventInfo
= null;
1124 while (index
< output
.length
) {
1125 String line
= output
[index
];
1126 Matcher matcher
= LTTngControlServiceConstants
.PROVIDER_EVENT_PATTERN
.matcher(line
);
1127 if (matcher
.matches()) {
1128 // sched_kthread_stop (loglevel: TRACE_EMERG0) (type: tracepoint)
1129 eventInfo
= new BaseEventInfo(matcher
.group(1).trim());
1130 eventInfo
.setLogLevel(matcher
.group(2).trim());
1131 eventInfo
.setEventType(matcher
.group(3).trim());
1132 events
.add(eventInfo
);
1134 } else if (LTTngControlServiceConstants
.EVENT_FIELD_PATTERN
.matcher(line
).matches()) {
1135 if (eventInfo
!= null) {
1136 List
<IFieldInfo
> fields
= new ArrayList
<IFieldInfo
>();
1137 index
= getFieldInfo(output
, index
, fields
);
1138 eventInfo
.setFields(fields
);
1143 else if (LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
).matches()) {
1153 protected int getFieldInfo(String
[] output
, int currentIndex
, List
<IFieldInfo
> fields
) {
1154 int index
= currentIndex
;
1155 IFieldInfo fieldInfo
= null;
1156 while (index
< output
.length
) {
1157 String line
= output
[index
];
1158 Matcher matcher
= LTTngControlServiceConstants
.EVENT_FIELD_PATTERN
.matcher(line
);
1159 if (matcher
.matches()) {
1160 // field: content (string)
1161 fieldInfo
= new FieldInfo(matcher
.group(2).trim());
1162 fieldInfo
.setFieldType(matcher
.group(3).trim());
1163 fields
.add(fieldInfo
);
1164 } else if (LTTngControlServiceConstants
.PROVIDER_EVENT_PATTERN
.matcher(line
).matches()) {
1166 } else if (LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
).matches()) {
1177 * Formats a command parameter for the command execution i.e. adds quotes
1178 * at the beginning and end if necessary.
1179 * @param parameter - parameter to format
1180 * @return formated parameter
1182 protected String
formatParameter(String parameter
) {
1183 if (parameter
!= null) {
1184 StringBuffer newString
= new StringBuffer();
1185 newString
.append(parameter
);
1187 if (parameter
.contains(" ") || parameter
.contains("*")) { //$NON-NLS-1$ //$NON-NLS-2$
1188 newString
.insert(0, "\""); //$NON-NLS-1$
1189 newString
.append("\""); //$NON-NLS-1$
1191 return newString
.toString();
1197 * @param strings array of string that makes up a command line
1198 * @return string buffer with created command line
1200 protected StringBuffer
createCommand(String
... strings
) {
1201 StringBuffer command
= new StringBuffer();
1202 command
.append(LTTngControlServiceConstants
.CONTROL_COMMAND
);
1203 command
.append(getTracingGroupOption());
1204 command
.append(getVerboseOption());
1205 for (String string
: strings
) {
1206 command
.append(string
);
1212 * @return the tracing group option if configured in the preferences
1214 protected String
getTracingGroupOption() {
1215 if (!ControlPreferences
.getInstance().isDefaultTracingGroup() && !ControlPreferences
.getInstance().getTracingGroup().equals("")) { //$NON-NLS-1$
1216 return LTTngControlServiceConstants
.OPTION_TRACING_GROUP
+ ControlPreferences
.getInstance().getTracingGroup();
1218 return ""; //$NON-NLS-1$
1222 * @return the verbose option as configured in the preferences
1224 protected String
getVerboseOption() {
1225 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1226 String level
= ControlPreferences
.getInstance().getVerboseLevel();
1227 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_VERBOSE
.equals(level
)) {
1228 return LTTngControlServiceConstants
.OPTION_VERBOSE
;
1230 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_V_VERBOSE
.equals(level
)) {
1231 return LTTngControlServiceConstants
.OPTION_VERY_VERBOSE
;
1233 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_V_V_VERBOSE
.equals(level
)) {
1234 return LTTngControlServiceConstants
.OPTION_VERY_VERY_VERBOSE
;
1237 return ""; //$NON-NLS-1$
1241 * Method that logs the command and command result if logging is enabled as
1242 * well as forwards the command execution to the shell.
1245 * - the command to execute
1247 * - a progress monitor
1248 * @return the command result
1249 * @throws ExecutionException
1250 * If the command fails
1252 protected ICommandResult
executeCommand(String command
,
1253 IProgressMonitor monitor
) throws ExecutionException
{
1254 return executeCommand(command
, monitor
, true);
1258 * Method that logs the command and command result if logging is enabled as
1259 * well as forwards the command execution to the shell.
1262 * - the command to execute
1264 * - a progress monitor
1265 * @param checkForError
1266 * - true to verify command result, else false
1267 * @return the command result
1268 * @throws ExecutionException
1269 * in case of error result
1271 protected ICommandResult
executeCommand(String command
,
1272 IProgressMonitor monitor
, boolean checkForError
)
1273 throws ExecutionException
{
1274 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1275 ControlCommandLogger
.log(command
);
1278 ICommandResult result
= fCommandShell
.executeCommand(
1279 command
.toString(), monitor
);
1281 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1282 ControlCommandLogger
.log(formatOutput(result
));
1285 if (checkForError
&& isError(result
)) {
1286 throw new ExecutionException(Messages
.TraceControl_CommandError
1287 + " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$