1 /**********************************************************************
2 * Copyright (c) 2012, 2014 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 * Bernd Hufmann - Updated for support of LTTng Tools 2.1
12 * Simon Delisle - Updated for support of LTTng Tools 2.2
13 * Marc-Andre Laperle - Support for creating a live session
14 **********************************************************************/
15 package org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.service
;
17 import java
.util
.ArrayList
;
18 import java
.util
.Iterator
;
19 import java
.util
.List
;
20 import java
.util
.regex
.Matcher
;
22 import org
.eclipse
.core
.commands
.ExecutionException
;
23 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
24 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.IBaseEventInfo
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.IChannelInfo
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.IDomainInfo
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.IEventInfo
;
29 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.IFieldInfo
;
30 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.IProbeEventInfo
;
31 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.ISessionInfo
;
32 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.ISnapshotInfo
;
33 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.IUstProviderInfo
;
34 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.LogLevelType
;
35 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.TraceEventType
;
36 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.TraceLogLevel
;
37 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.impl
.BaseEventInfo
;
38 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.impl
.BufferType
;
39 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.impl
.ChannelInfo
;
40 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.impl
.DomainInfo
;
41 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.impl
.EventInfo
;
42 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.impl
.FieldInfo
;
43 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.impl
.ProbeEventInfo
;
44 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.impl
.SessionInfo
;
45 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.impl
.SnapshotInfo
;
46 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.impl
.UstProviderInfo
;
47 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.logging
.ControlCommandLogger
;
48 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.messages
.Messages
;
49 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.preferences
.ControlPreferences
;
50 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.remote
.ICommandResult
;
51 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.remote
.ICommandShell
;
55 * Service for sending LTTng trace control commands to remote host.
58 * @author Bernd Hufmann
60 public class LTTngControlService
implements ILttngControlService
{
62 // ------------------------------------------------------------------------
64 // ------------------------------------------------------------------------
66 * The command shell implementation
68 private final ICommandShell fCommandShell
;
73 private LttngVersion fVersion
= null;
75 // ------------------------------------------------------------------------
77 // ------------------------------------------------------------------------
83 * - the command shell implementation to use
85 public LTTngControlService(ICommandShell shell
) {
86 fCommandShell
= shell
;
89 // ------------------------------------------------------------------------
91 // ------------------------------------------------------------------------
94 public String
getVersion() {
95 if (fVersion
== null) {
96 return "Unknown"; //$NON-NLS-1$
98 return fVersion
.toString();
102 * Sets the version of the LTTng 2.0 control service.
103 * @param version - a version to set
105 public void setVersion(String version
) {
106 fVersion
= new LttngVersion(version
);
110 public boolean isVersionSupported(String version
) {
111 LttngVersion tmp
= new LttngVersion(version
);
112 return (fVersion
!= null && fVersion
.compareTo(tmp
) >= 0) ?
true : false;
116 * Returns the command shell implementation.
118 * @return the command shell implementation
120 protected ICommandShell
getCommandShell() {
121 return fCommandShell
;
124 // ------------------------------------------------------------------------
126 // ------------------------------------------------------------------------
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
<>();
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()]);
155 public ISessionInfo
getSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
156 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST
, sessionName
);
157 ICommandResult result
= executeCommand(command
.toString(), monitor
);
162 // Tracing session mysession2: [inactive]
163 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
164 ISessionInfo sessionInfo
= new SessionInfo(sessionName
);
166 while (index
< result
.getOutput().length
) {
167 // Tracing session mysession2: [inactive]
168 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
170 // === Domain: Kernel ===
172 String line
= result
.getOutput()[index
];
173 Matcher matcher
= LTTngControlServiceConstants
.TRACE_SESSION_PATTERN
.matcher(line
);
174 if (matcher
.matches()) {
175 sessionInfo
.setSessionState(matcher
.group(2));
180 matcher
= LTTngControlServiceConstants
.TRACE_SNAPSHOT_SESSION_PATTERN
.matcher(line
);
181 if (matcher
.matches()) {
182 sessionInfo
.setSessionState(matcher
.group(2));
183 // real name will be set later
184 ISnapshotInfo snapshotInfo
= new SnapshotInfo(""); //$NON-NLS-1$
185 sessionInfo
.setSnapshotInfo(snapshotInfo
);
190 if (!sessionInfo
.isSnapshotSession()) {
191 matcher
= LTTngControlServiceConstants
.TRACE_NETWORK_PATH_PATTERN
.matcher(line
);
192 if (matcher
.matches()) {
193 sessionInfo
.setStreamedTrace(true);
196 matcher
= LTTngControlServiceConstants
.TRACE_SESSION_PATH_PATTERN
.matcher(line
);
197 if (matcher
.matches()) {
198 sessionInfo
.setSessionPath(matcher
.group(1).trim());
204 matcher
= LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(line
);
205 if (matcher
.matches()) {
207 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_KernelDomainDisplayName
);
210 domainInfo
.setIsKernel(true);
213 ArrayList
<IChannelInfo
> channels
= new ArrayList
<>();
214 index
= parseDomain(result
.getOutput(), index
, channels
, domainInfo
);
216 if (channels
.size() > 0) {
218 sessionInfo
.addDomain(domainInfo
);
221 domainInfo
.setChannels(channels
);
226 matcher
= LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
);
227 if (matcher
.matches()) {
228 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_UstGlobalDomainDisplayName
);
231 domainInfo
.setIsKernel(false);
234 ArrayList
<IChannelInfo
> channels
= new ArrayList
<>();
235 index
= parseDomain(result
.getOutput(), index
, channels
, domainInfo
);
237 if (channels
.size() > 0) {
239 sessionInfo
.addDomain(domainInfo
);
242 domainInfo
.setChannels(channels
);
249 if (sessionInfo
.isSnapshotSession()) {
250 ISnapshotInfo snapshot
= getSnapshotInfo(sessionName
, monitor
);
251 sessionInfo
.setSnapshotInfo(snapshot
);
258 public ISnapshotInfo
getSnapshotInfo(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
259 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST_SNAPSHOT_OUTPUT
, LTTngControlServiceConstants
.OPTION_SESSION
, sessionName
);
260 ICommandResult result
= executeCommand(command
.toString(), monitor
);
265 // [1] snapshot-1: /home/user/lttng-traces/my-20130909-114431
267 // [3] snapshot-3: net4://172.0.0.1/
268 ISnapshotInfo snapshotInfo
= new SnapshotInfo(""); //$NON-NLS-1$
270 while (index
< result
.getOutput().length
) {
271 String line
= result
.getOutput()[index
];
272 Matcher matcher
= LTTngControlServiceConstants
.LIST_SNAPSHOT_OUTPUT_PATTERN
.matcher(line
);
273 if (matcher
.matches()) {
274 snapshotInfo
.setId(Integer
.valueOf(matcher
.group(1)));
275 snapshotInfo
.setName(matcher
.group(2));
276 snapshotInfo
.setSnapshotPath(matcher
.group(3));
278 Matcher matcher2
= LTTngControlServiceConstants
.SNAPSHOT_NETWORK_PATH_PATTERN
.matcher(snapshotInfo
.getSnapshotPath());
279 if (matcher2
.matches()) {
280 snapshotInfo
.setStreamedSnapshot(true);
293 public List
<IBaseEventInfo
> getKernelProvider(IProgressMonitor monitor
) throws ExecutionException
{
294 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST_KERNEL
);
295 ICommandResult result
= executeCommand(command
.toString(), monitor
, false);
297 List
<IBaseEventInfo
> events
= new ArrayList
<>();
299 if (result
.getOutput() != null) {
300 // Ignore the following 2 cases:
301 // Spawning a session daemon
302 // Error: Unable to list kernel events
304 // Error: Unable to list kernel events
307 while (index
< result
.getOutput().length
) {
308 String line
= result
.getOutput()[index
];
309 Matcher matcher
= LTTngControlServiceConstants
.LIST_KERNEL_NO_KERNEL_PROVIDER_PATTERN
.matcher(line
);
310 if (matcher
.matches()) {
317 if (isError(result
)) {
318 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$
323 // sched_kthread_stop (type: tracepoint)
324 getProviderEventInfo(result
.getOutput(), 0, events
);
329 public List
<IUstProviderInfo
> getUstProvider() throws ExecutionException
{
330 return getUstProvider(new NullProgressMonitor());
334 public List
<IUstProviderInfo
> getUstProvider(IProgressMonitor monitor
) throws ExecutionException
{
335 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST_UST
);
337 if (isVersionSupported("2.1.0")) { //$NON-NLS-1$
338 command
.append(LTTngControlServiceConstants
.OPTION_FIELDS
);
341 ICommandResult result
= executeCommand(command
.toString(), monitor
, false);
342 List
<IUstProviderInfo
> allProviders
= new ArrayList
<>();
344 // Workaround for versions 2.0.x which causes a segmentation fault for this command
345 // if LTTng Tools is compiled without UST support.
346 if (!isVersionSupported("2.1.0") && (result
.getResult() != 0)) { //$NON-NLS-1$
350 if (result
.getOutput() != null) {
351 // Ignore the following 2 cases:
352 // Spawning a session daemon
353 // Error: Unable to list UST events: Listing UST events failed
355 // Error: Unable to list UST events: Listing UST events failed
358 while (index
< result
.getOutput().length
) {
359 String line
= result
.getOutput()[index
];
360 Matcher matcher
= LTTngControlServiceConstants
.LIST_UST_NO_UST_PROVIDER_PATTERN
.matcher(line
);
361 if (matcher
.matches()) {
368 if (isError(result
)) {
369 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$
372 // Note that field print-outs exists for version >= 2.1.0
378 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
379 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
381 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
382 // field: doublefield (float)
383 // field: floatfield (float)
384 // field: stringfield (string)
387 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
388 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
390 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
391 // field: doublefield (float)
392 // field: floatfield (float)
393 // field: stringfield (string)
395 IUstProviderInfo provider
= null;
398 while (index
< result
.getOutput().length
) {
399 String line
= result
.getOutput()[index
];
400 Matcher matcher
= LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
);
401 if (matcher
.matches()) {
402 provider
= new UstProviderInfo(matcher
.group(2).trim());
403 provider
.setPid(Integer
.valueOf(matcher
.group(1).trim()));
404 List
<IBaseEventInfo
> events
= new ArrayList
<>();
405 index
= getProviderEventInfo(result
.getOutput(), ++index
, events
);
406 provider
.setEvents(events
);
407 allProviders
.add(provider
);
416 public ISessionInfo
createSession(ISessionInfo sessionInfo
, IProgressMonitor monitor
) throws ExecutionException
{
417 if (sessionInfo
.isStreamedTrace()) {
418 return createStreamedSession(sessionInfo
, monitor
);
421 String newName
= formatParameter(sessionInfo
.getName());
422 String newPath
= formatParameter(sessionInfo
.getSessionPath());
424 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_CREATE_SESSION
, newName
);
426 if (newPath
!= null && !"".equals(newPath
)) { //$NON-NLS-1$
427 command
.append(LTTngControlServiceConstants
.OPTION_OUTPUT_PATH
);
428 command
.append(newPath
);
431 if (sessionInfo
.isSnapshotSession()) {
432 command
.append(LTTngControlServiceConstants
.OPTION_SNAPSHOT
);
435 ICommandResult result
= executeCommand(command
.toString(), monitor
);
437 //Session myssession2 created.
438 //Traces will be written in /home/user/lttng-traces/myssession2-20120209-095418
439 String
[] output
= result
.getOutput();
441 // Get and session name and path
446 while (index
< output
.length
) {
447 String line
= output
[index
];
448 Matcher nameMatcher
= LTTngControlServiceConstants
.CREATE_SESSION_NAME_PATTERN
.matcher(line
);
449 Matcher pathMatcher
= LTTngControlServiceConstants
.CREATE_SESSION_PATH_PATTERN
.matcher(line
);
450 if (nameMatcher
.matches()) {
451 name
= String
.valueOf(nameMatcher
.group(1).trim());
452 } else if (pathMatcher
.matches()) {
453 path
= String
.valueOf(pathMatcher
.group(1).trim());
458 // Verify session name
459 if ((name
== null) || (!"".equals(sessionInfo
.getName()) && !name
.equals(sessionInfo
.getName()))) { //$NON-NLS-1$
460 // Unexpected name returned
461 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
462 Messages
.TraceControl_UnexpectedNameError
+ ": " + name
); //$NON-NLS-1$
465 sessionInfo
.setName(name
);
466 // Verify session path
467 if (!sessionInfo
.isSnapshotSession() &&
468 ((path
== null) || ((sessionInfo
.getSessionPath() != null) && (!path
.contains(sessionInfo
.getSessionPath()))))) {
470 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
471 Messages
.TraceControl_UnexpectedPathError
+ ": " + name
); //$NON-NLS-1$
474 if (sessionInfo
.isSnapshotSession()) {
475 // Make it a snapshot session - content of snapshot info need to
476 // set afterwards using getSession() or getSnapshotInfo()
477 sessionInfo
.setSnapshotInfo(new SnapshotInfo("")); //$NON-NLS-1$
479 sessionInfo
.setSessionPath(path
);
486 private ISessionInfo
createStreamedSession(ISessionInfo sessionInfo
, IProgressMonitor monitor
) throws ExecutionException
{
488 String newName
= formatParameter(sessionInfo
.getName());
489 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_CREATE_SESSION
, newName
);
491 if (sessionInfo
.isSnapshotSession()) {
492 command
.append(LTTngControlServiceConstants
.OPTION_SNAPSHOT
);
493 } else if (sessionInfo
.isLive()) {
494 command
.append(LTTngControlServiceConstants
.OPTION_LIVE
);
495 if (sessionInfo
.getLiveDelay() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
496 command
.append(sessionInfo
.getLiveDelay());
500 if (sessionInfo
.getNetworkUrl() != null) {
501 command
.append(LTTngControlServiceConstants
.OPTION_NETWORK_URL
);
502 command
.append(sessionInfo
.getNetworkUrl());
504 command
.append(LTTngControlServiceConstants
.OPTION_CONTROL_URL
);
505 command
.append(sessionInfo
.getControlUrl());
507 command
.append(LTTngControlServiceConstants
.OPTION_DATA_URL
);
508 command
.append(sessionInfo
.getDataUrl());
511 ICommandResult result
= executeCommand(command
.toString(), monitor
);
514 String
[] output
= result
.getOutput();
516 // Get and session name and path
521 while (index
< output
.length
) {
522 String line
= output
[index
];
523 Matcher nameMatcher
= LTTngControlServiceConstants
.CREATE_SESSION_NAME_PATTERN
.matcher(line
);
524 Matcher pathMatcher
= LTTngControlServiceConstants
.CREATE_SESSION_PATH_PATTERN
.matcher(line
);
526 if (nameMatcher
.matches()) {
527 name
= String
.valueOf(nameMatcher
.group(1).trim());
528 } else if (pathMatcher
.matches() && (sessionInfo
.getNetworkUrl() != null)) {
529 path
= String
.valueOf(pathMatcher
.group(1).trim());
534 // Verify session name
535 if ((name
== null) || (!"".equals(sessionInfo
.getName()) && !name
.equals(sessionInfo
.getName()))) { //$NON-NLS-1$
536 // Unexpected name returned
537 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
538 Messages
.TraceControl_UnexpectedNameError
+ ": " + name
); //$NON-NLS-1$
541 sessionInfo
.setName(name
);
543 sessionInfo
.setStreamedTrace(true);
545 // Verify session path
546 if (sessionInfo
.getNetworkUrl() != null) {
547 if (!sessionInfo
.isSnapshotSession() && (path
== null)) {
549 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
550 Messages
.TraceControl_UnexpectedPathError
+ ": " + name
); //$NON-NLS-1$
553 if (sessionInfo
.isSnapshotSession()) {
554 sessionInfo
.setStreamedTrace(false);
556 sessionInfo
.setSessionPath(path
);
557 // Check file protocol
558 Matcher matcher
= LTTngControlServiceConstants
.TRACE_FILE_PROTOCOL_PATTERN
.matcher(path
);
559 if (matcher
.matches()) {
560 sessionInfo
.setStreamedTrace(false);
565 // When using controlUrl and dataUrl the full session path is not known yet
566 // and will be set later on when listing the session
572 public void destroySession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
573 String newName
= formatParameter(sessionName
);
575 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_DESTROY_SESSION
, newName
);
577 ICommandResult result
= executeCommand(command
.toString(), monitor
, false);
578 String
[] output
= result
.getOutput();
580 boolean isError
= isError(result
);
581 if (isError
&& (output
!= null)) {
583 while (index
< output
.length
) {
584 String line
= output
[index
];
585 Matcher matcher
= LTTngControlServiceConstants
.SESSION_NOT_FOUND_ERROR_PATTERN
.matcher(line
);
586 if (matcher
.matches()) {
587 // Don't treat this as an error
595 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$
598 //Session <sessionName> destroyed
602 public void startSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
604 String newSessionName
= formatParameter(sessionName
);
606 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_START_SESSION
, newSessionName
);
608 executeCommand(command
.toString(), monitor
);
610 //Session <sessionName> started
614 public void stopSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
615 String newSessionName
= formatParameter(sessionName
);
616 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_STOP_SESSION
, newSessionName
);
618 executeCommand(command
.toString(), monitor
);
620 //Session <sessionName> stopped
625 public void enableChannels(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IChannelInfo info
, IProgressMonitor monitor
) throws ExecutionException
{
627 // no channels to enable
628 if (channelNames
.isEmpty()) {
632 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_CHANNEL
);
634 for (Iterator
<String
> iterator
= channelNames
.iterator(); iterator
.hasNext();) {
635 String channel
= iterator
.next();
636 command
.append(channel
);
637 if (iterator
.hasNext()) {
643 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
645 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
648 String newSessionName
= formatParameter(sessionName
);
649 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
650 command
.append(newSessionName
);
653 // --discard Discard event when buffers are full (default)
655 // --overwrite Flight recorder mode
656 if (info
.isOverwriteMode()) {
657 command
.append(LTTngControlServiceConstants
.OPTION_OVERWRITE
);
659 // --subbuf-size SIZE Subbuffer size in bytes
660 // (default: 4096, kernel default: 262144)
661 if (info
.getSubBufferSize() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
662 command
.append(LTTngControlServiceConstants
.OPTION_SUB_BUFFER_SIZE
);
663 command
.append(String
.valueOf(info
.getSubBufferSize()));
666 // --num-subbuf NUM Number of subbufers
667 if (info
.getNumberOfSubBuffers() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
668 command
.append(LTTngControlServiceConstants
.OPTION_NUM_SUB_BUFFERS
);
669 command
.append(String
.valueOf(info
.getNumberOfSubBuffers()));
672 // --switch-timer USEC Switch timer interval in usec
673 if (info
.getSwitchTimer() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
674 command
.append(LTTngControlServiceConstants
.OPTION_SWITCH_TIMER
);
675 command
.append(String
.valueOf(info
.getSwitchTimer()));
678 // --read-timer USEC Read timer interval in usec
679 if (info
.getReadTimer() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
680 command
.append(LTTngControlServiceConstants
.OPTION_READ_TIMER
);
681 command
.append(String
.valueOf(info
.getReadTimer()));
684 if (isVersionSupported("2.2.0")) { //$NON-NLS-1$
685 // --buffers-uid Every application sharing the same UID use the same buffers
686 // --buffers-pid Buffers are allocated per PID
688 if (info
.getBufferType() == BufferType
.BUFFER_PER_PID
) {
689 command
.append(LTTngControlServiceConstants
.OPTION_PER_PID_BUFFERS
);
691 } else if (info
.getBufferType() == BufferType
.BUFFER_PER_UID
) {
692 command
.append(LTTngControlServiceConstants
.OPTION_PER_UID_BUFFERS
);
696 // -C SIZE Maximum size of trace files in bytes
697 if (info
.getMaxSizeTraceFiles() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
698 command
.append(LTTngControlServiceConstants
.OPTION_MAX_SIZE_TRACE_FILES
);
699 command
.append(String
.valueOf(info
.getMaxSizeTraceFiles()));
702 // -W NUM Maximum number of trace files
703 if (info
.getMaxNumberTraceFiles() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
704 command
.append(LTTngControlServiceConstants
.OPTION_MAX_TRACE_FILES
);
705 command
.append(String
.valueOf(info
.getMaxNumberTraceFiles()));
710 executeCommand(command
.toString(), monitor
);
715 public void disableChannels(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
717 // no channels to enable
718 if (channelNames
.isEmpty()) {
722 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_DISABLE_CHANNEL
);
724 for (Iterator
<String
> iterator
= channelNames
.iterator(); iterator
.hasNext();) {
725 String channel
= iterator
.next();
726 command
.append(channel
);
727 if (iterator
.hasNext()) {
733 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
735 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
738 String newSessionName
= formatParameter(sessionName
);
739 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
740 command
.append(newSessionName
);
742 executeCommand(command
.toString(), monitor
);
746 public void enableEvents(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, String filterExpression
, IProgressMonitor monitor
) throws ExecutionException
{
748 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
750 if (eventNames
== null || eventNames
.isEmpty()) {
751 command
.append(LTTngControlServiceConstants
.OPTION_ALL
);
754 StringBuffer eventNameParameter
= new StringBuffer();
755 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
756 String event
= iterator
.next();
757 eventNameParameter
.append(event
);
758 if (iterator
.hasNext()) {
759 eventNameParameter
.append(',');
762 command
.append(formatParameter(eventNameParameter
.toString()));
766 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
768 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
771 String newSessionName
= formatParameter(sessionName
);
773 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
774 command
.append(newSessionName
);
776 if (channelName
!= null) {
777 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
778 command
.append(channelName
);
781 command
.append(LTTngControlServiceConstants
.OPTION_TRACEPOINT
);
783 if (filterExpression
!= null) {
784 command
.append(LTTngControlServiceConstants
.OPTION_FILTER
);
785 command
.append('\'');
786 command
.append(filterExpression
);
787 command
.append('\'');
790 executeCommand(command
.toString(), monitor
);
795 public void enableSyscalls(String sessionName
, String channelName
, IProgressMonitor monitor
) throws ExecutionException
{
797 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
799 command
.append(LTTngControlServiceConstants
.OPTION_ALL
);
800 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
802 String newSessionName
= formatParameter(sessionName
);
804 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
805 command
.append(newSessionName
);
807 if (channelName
!= null) {
808 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
809 command
.append(channelName
);
812 command
.append(LTTngControlServiceConstants
.OPTION_SYSCALL
);
814 executeCommand(command
.toString(), monitor
);
818 public void enableProbe(String sessionName
, String channelName
, String eventName
, boolean isFunction
, String probe
, IProgressMonitor monitor
) throws ExecutionException
{
819 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
821 command
.append(eventName
);
822 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
824 String newSessionName
= formatParameter(sessionName
);
825 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
826 command
.append(newSessionName
);
828 if (channelName
!= null) {
829 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
830 command
.append(channelName
);
833 command
.append(LTTngControlServiceConstants
.OPTION_FUNCTION_PROBE
);
835 command
.append(LTTngControlServiceConstants
.OPTION_PROBE
);
838 command
.append(probe
);
840 executeCommand(command
.toString(), monitor
);
844 public void enableLogLevel(String sessionName
, String channelName
, String eventName
, LogLevelType logLevelType
, TraceLogLevel level
, String filterExpression
, IProgressMonitor monitor
) throws ExecutionException
{
845 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
847 command
.append(eventName
);
848 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
850 String newSessionName
= formatParameter(sessionName
);
851 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
852 command
.append(newSessionName
);
854 if (channelName
!= null) {
855 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
856 command
.append(channelName
);
859 if (logLevelType
== LogLevelType
.LOGLEVEL
) {
860 command
.append(LTTngControlServiceConstants
.OPTION_LOGLEVEL
);
861 } else if (logLevelType
== LogLevelType
.LOGLEVEL_ONLY
) {
862 command
.append(LTTngControlServiceConstants
.OPTION_LOGLEVEL_ONLY
);
867 command
.append(level
.getInName());
869 executeCommand(command
.toString(), monitor
);
873 public void disableEvent(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
874 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_DISABLE_EVENT
);
876 if (eventNames
== null) {
877 command
.append(LTTngControlServiceConstants
.OPTION_ALL
);
879 // no events to disable
880 if (eventNames
.isEmpty()) {
884 StringBuffer eventNameParameter
= new StringBuffer();
885 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
886 String event
= iterator
.next();
887 eventNameParameter
.append(event
);
888 if (iterator
.hasNext()) {
889 eventNameParameter
.append(',');
892 command
.append(formatParameter(eventNameParameter
.toString()));
896 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
898 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
901 String newSessionName
= formatParameter(sessionName
);
902 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
903 command
.append(newSessionName
);
905 if (channelName
!= null) {
906 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
907 command
.append(channelName
);
910 executeCommand(command
.toString(), monitor
);
914 public List
<String
> getContextList(IProgressMonitor monitor
) throws ExecutionException
{
916 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ADD_CONTEXT
, LTTngControlServiceConstants
.OPTION_HELP
);
918 ICommandResult result
= executeCommand(command
.toString(), monitor
);
920 String
[] output
= result
.getOutput();
922 List
<String
> contexts
= new ArrayList
<>(0);
925 boolean inList
= false;
926 while (index
< output
.length
) {
927 String line
= result
.getOutput()[index
];
929 Matcher startMatcher
= LTTngControlServiceConstants
.ADD_CONTEXT_HELP_CONTEXTS_INTRO
.matcher(line
);
930 Matcher endMatcher
= LTTngControlServiceConstants
.ADD_CONTEXT_HELP_CONTEXTS_END_LINE
.matcher(line
);
932 if (startMatcher
.matches()) {
934 } else if (endMatcher
.matches()) {
936 } else if (inList
== true) {
937 String
[] tmp
= line
.split(","); //$NON-NLS-1$
938 for (int i
= 0; i
< tmp
.length
; i
++) {
939 contexts
.add(tmp
[i
].trim());
948 public void addContexts(String sessionName
, String channelName
, String eventName
, boolean isKernel
, List
<String
> contextNames
, IProgressMonitor monitor
) throws ExecutionException
{
949 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ADD_CONTEXT
);
951 String newSessionName
= formatParameter(sessionName
);
952 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
953 command
.append(newSessionName
);
955 if (channelName
!= null) {
956 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
957 command
.append(channelName
);
960 if (eventName
!= null) {
961 command
.append(LTTngControlServiceConstants
.OPTION_EVENT
);
962 command
.append(eventName
);
966 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
968 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
971 for (Iterator
<String
> iterator
= contextNames
.iterator(); iterator
.hasNext();) {
972 String context
= iterator
.next();
973 command
.append(LTTngControlServiceConstants
.OPTION_CONTEXT_TYPE
);
974 command
.append(context
);
977 executeCommand(command
.toString(), monitor
);
982 public void calibrate(boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
983 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_CALIBRATE
);
986 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
988 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
991 command
.append(LTTngControlServiceConstants
.OPTION_FUNCTION_PROBE
);
993 executeCommand(command
.toString(), monitor
);
997 public void recordSnapshot(String sessionName
, IProgressMonitor monitor
)
998 throws ExecutionException
{
999 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_RECORD_SNAPSHOT
);
1001 String newSessionName
= formatParameter(sessionName
);
1002 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
1003 command
.append(newSessionName
);
1005 executeCommand(command
.toString(), monitor
);
1009 public void runCommands(IProgressMonitor monitor
, List
<String
> commands
) throws ExecutionException
{
1010 for (String command
: commands
) {
1011 if (monitor
.isCanceled()) {
1015 if (command
.isEmpty() || command
.startsWith("#")) { //$NON-NLS-1$
1018 executeCommand(command
, monitor
);
1022 // ------------------------------------------------------------------------
1024 // ------------------------------------------------------------------------
1027 * Checks if command result is an error result.
1030 * - the command result to check
1031 * @return true if error else false
1033 protected boolean isError(ICommandResult result
) {
1034 // Check return code and length of returned strings
1035 if ((result
.getResult()) != 0 || (result
.getOutput().length
< 1)) {
1039 // Look for error pattern
1041 while (index
< result
.getOutput().length
) {
1042 String line
= result
.getOutput()[index
];
1043 Matcher matcher
= LTTngControlServiceConstants
.ERROR_PATTERN
.matcher(line
);
1044 if (matcher
.matches()) {
1054 * Formats the output string as single string.
1058 * @return - the formatted output
1060 public static String
formatOutput(ICommandResult result
) {
1061 if ((result
== null) || result
.getOutput() == null || result
.getOutput().length
== 0) {
1062 return ""; //$NON-NLS-1$
1064 String
[] output
= result
.getOutput();
1065 StringBuffer ret
= new StringBuffer();
1066 ret
.append("Return Value: "); //$NON-NLS-1$
1067 ret
.append(result
.getResult());
1068 ret
.append("\n"); //$NON-NLS-1$
1069 for (int i
= 0; i
< output
.length
; i
++) {
1070 ret
.append(output
[i
]).append("\n"); //$NON-NLS-1$
1072 return ret
.toString();
1076 * Parses the domain information.
1079 * - a command output array
1080 * @param currentIndex
1081 * - current index in command output array
1083 * - list for returning channel information
1085 * - The domain information
1086 * @return the new current index in command output array
1088 protected int parseDomain(String
[] output
, int currentIndex
, List
<IChannelInfo
> channels
, IDomainInfo domainInfo
) {
1089 int index
= currentIndex
;
1091 // if kernel set the buffer type to shared
1092 if (domainInfo
.isKernel()) {
1093 domainInfo
.setBufferType(BufferType
.BUFFER_SHARED
);
1098 // - channnel1: [enabled]
1101 // overwrite mode: 0
1102 // subbufers size: 262144
1103 // number of subbufers: 4
1104 // switch timer interval: 0
1105 // read timer interval: 200
1108 while (index
< output
.length
) {
1109 String line
= output
[index
];
1111 if (isVersionSupported("2.2.0")) { //$NON-NLS-1$
1112 Matcher bufferTypeMatcher
= LTTngControlServiceConstants
.BUFFER_TYPE_PATTERN
.matcher(line
);
1113 if (bufferTypeMatcher
.matches()) {
1114 String bufferTypeString
= getAttributeValue(line
);
1115 if (BufferType
.BUFFER_PER_PID
.getInName().equals(bufferTypeString
)) {
1116 domainInfo
.setBufferType(BufferType
.BUFFER_PER_PID
);
1117 } else if (BufferType
.BUFFER_PER_UID
.getInName().equals(bufferTypeString
)) {
1118 domainInfo
.setBufferType(BufferType
.BUFFER_PER_UID
);
1120 domainInfo
.setBufferType(BufferType
.BUFFER_TYPE_UNKNOWN
);
1124 domainInfo
.setBufferType(BufferType
.BUFFER_TYPE_UNKNOWN
);
1126 Matcher outerMatcher
= LTTngControlServiceConstants
.CHANNELS_SECTION_PATTERN
.matcher(line
);
1127 Matcher noKernelChannelMatcher
= LTTngControlServiceConstants
.DOMAIN_NO_KERNEL_CHANNEL_PATTERN
.matcher(line
);
1128 Matcher noUstChannelMatcher
= LTTngControlServiceConstants
.DOMAIN_NO_UST_CHANNEL_PATTERN
.matcher(line
);
1129 if (outerMatcher
.matches()) {
1130 IChannelInfo channelInfo
= null;
1131 while (index
< output
.length
) {
1132 String subLine
= output
[index
];
1134 Matcher innerMatcher
= LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(subLine
);
1135 if (innerMatcher
.matches()) {
1136 channelInfo
= new ChannelInfo(""); //$NON-NLS-1$
1138 channelInfo
.setName(innerMatcher
.group(1));
1140 // get channel enablement
1141 channelInfo
.setState(innerMatcher
.group(2));
1144 channelInfo
.setBufferType(domainInfo
.getBufferType());
1147 channels
.add(channelInfo
);
1149 } else if (LTTngControlServiceConstants
.OVERWRITE_MODE_ATTRIBUTE
.matcher(subLine
).matches()) {
1150 String value
= getAttributeValue(subLine
);
1151 if (channelInfo
!= null) {
1152 channelInfo
.setOverwriteMode(!LTTngControlServiceConstants
.OVERWRITE_MODE_ATTRIBUTE_FALSE
.equals(value
));
1154 } else if (LTTngControlServiceConstants
.SUBBUFFER_SIZE_ATTRIBUTE
.matcher(subLine
).matches()) {
1155 if (channelInfo
!= null) {
1156 channelInfo
.setSubBufferSize(Long
.valueOf(getAttributeValue(subLine
)));
1159 } else if (LTTngControlServiceConstants
.NUM_SUBBUFFERS_ATTRIBUTE
.matcher(subLine
).matches()) {
1160 if (channelInfo
!= null) {
1161 channelInfo
.setNumberOfSubBuffers(Integer
.valueOf(getAttributeValue(subLine
)));
1164 } else if (LTTngControlServiceConstants
.SWITCH_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
1165 if (channelInfo
!= null) {
1166 channelInfo
.setSwitchTimer(Long
.valueOf(getAttributeValue(subLine
)));
1169 } else if (LTTngControlServiceConstants
.READ_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
1170 if (channelInfo
!= null) {
1171 channelInfo
.setReadTimer(Long
.valueOf(getAttributeValue(subLine
)));
1174 } else if (LTTngControlServiceConstants
.OUTPUT_ATTRIBUTE
.matcher(subLine
).matches()) {
1175 if (channelInfo
!= null) {
1176 channelInfo
.setOutputType(getAttributeValue(subLine
));
1179 } else if (LTTngControlServiceConstants
.EVENT_SECTION_PATTERN
.matcher(subLine
).matches()) {
1180 List
<IEventInfo
> events
= new ArrayList
<>();
1181 index
= parseEvents(output
, index
, events
);
1182 if (channelInfo
!= null) {
1183 channelInfo
.setEvents(events
);
1185 // we want to stay at the current index to be able to
1188 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(subLine
).matches()) {
1191 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(subLine
).matches()) {
1196 } else if (noKernelChannelMatcher
.matches() || noUstChannelMatcher
.matches()) {
1197 // domain indicates that no channels were found -> return
1207 * Parses the event information within a domain.
1210 * - a command output array
1211 * @param currentIndex
1212 * - current index in command output array
1214 * - list for returning event information
1215 * @return the new current index in command output array
1217 protected int parseEvents(String
[] output
, int currentIndex
, List
<IEventInfo
> events
) {
1218 int index
= currentIndex
;
1220 while (index
< output
.length
) {
1221 String line
= output
[index
];
1222 if (LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(line
).matches()) {
1225 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(line
).matches()) {
1228 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
).matches()) {
1233 Matcher matcher
= LTTngControlServiceConstants
.EVENT_PATTERN
.matcher(line
);
1234 Matcher matcher2
= LTTngControlServiceConstants
.WILDCARD_EVENT_PATTERN
.matcher(line
);
1236 if (matcher
.matches()) {
1237 IEventInfo eventInfo
= new EventInfo(matcher
.group(1).trim());
1238 eventInfo
.setLogLevelType(matcher
.group(2).trim());
1239 eventInfo
.setLogLevel(matcher
.group(3).trim());
1240 eventInfo
.setEventType(matcher
.group(4).trim());
1241 eventInfo
.setState(matcher
.group(5));
1242 String filter
= matcher
.group(6);
1243 if (filter
!= null) {
1244 filter
= filter
.substring(1, filter
.length() - 1); // remove '[' and ']'
1245 eventInfo
.setFilterExpression(filter
);
1247 events
.add(eventInfo
);
1249 } else if (matcher2
.matches()) {
1250 IEventInfo eventInfo
= new EventInfo(matcher2
.group(1).trim());
1251 eventInfo
.setLogLevel(TraceLogLevel
.LEVEL_UNKNOWN
);
1252 eventInfo
.setEventType(matcher2
.group(2).trim());
1253 eventInfo
.setState(matcher2
.group(3));
1254 String filter
= matcher2
.group(4);
1255 if (filter
!= null) {
1256 filter
= filter
.substring(1, filter
.length() - 1); // remove '[' and ']'
1257 eventInfo
.setFilterExpression(filter
);
1260 if ((eventInfo
.getEventType() == TraceEventType
.PROBE
) ||
1261 (eventInfo
.getEventType() == TraceEventType
.FUNCTION
)){
1262 IProbeEventInfo probeEvent
= new ProbeEventInfo(eventInfo
.getName());
1263 probeEvent
.setLogLevel(eventInfo
.getLogLevel());
1264 probeEvent
.setEventType(eventInfo
.getEventType());
1265 probeEvent
.setState(eventInfo
.getState());
1267 // Overwrite eventinfo
1268 eventInfo
= probeEvent
;
1270 // myevent2 (type: probe) [enabled]
1272 // myevent0 (type: function) [enabled]
1274 // symbol: init_post
1276 while (index
< output
.length
) {
1277 String probeLine
= output
[index
];
1279 Matcher addrMatcher
= LTTngControlServiceConstants
.PROBE_ADDRESS_PATTERN
.matcher(probeLine
);
1280 Matcher offsetMatcher
= LTTngControlServiceConstants
.PROBE_OFFSET_PATTERN
.matcher(probeLine
);
1281 Matcher symbolMatcher
= LTTngControlServiceConstants
.PROBE_SYMBOL_PATTERN
.matcher(probeLine
);
1282 if (addrMatcher
.matches()) {
1283 String addr
= addrMatcher
.group(2).trim();
1284 probeEvent
.setAddress(addr
);
1285 } else if (offsetMatcher
.matches()) {
1286 String offset
= offsetMatcher
.group(2).trim();
1287 probeEvent
.setOffset(offset
);
1288 } else if (symbolMatcher
.matches()) {
1289 String symbol
= symbolMatcher
.group(2).trim();
1290 probeEvent
.setSymbol(symbol
);
1291 } else if ((LTTngControlServiceConstants
.EVENT_PATTERN
.matcher(probeLine
).matches()) || (LTTngControlServiceConstants
.WILDCARD_EVENT_PATTERN
.matcher(probeLine
).matches())) {
1293 } else if (LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(probeLine
).matches()) {
1295 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(probeLine
).matches()) {
1298 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(probeLine
).matches()) {
1304 events
.add(eventInfo
);
1306 events
.add(eventInfo
);
1319 * Parses a line with attributes: <attribute Name>: <attribute value>
1322 * - attribute line to parse
1323 * @return the attribute value as string
1325 protected String
getAttributeValue(String line
) {
1326 String
[] temp
= line
.split("\\: "); //$NON-NLS-1$
1331 * Parses the event information within a provider.
1334 * - a command output array
1335 * @param currentIndex
1336 * - current index in command output array
1338 * - list for returning event information
1339 * @return the new current index in command output array
1341 protected int getProviderEventInfo(String
[] output
, int currentIndex
, List
<IBaseEventInfo
> events
) {
1342 int index
= currentIndex
;
1343 IBaseEventInfo eventInfo
= null;
1344 while (index
< output
.length
) {
1345 String line
= output
[index
];
1346 Matcher matcher
= LTTngControlServiceConstants
.PROVIDER_EVENT_PATTERN
.matcher(line
);
1347 if (matcher
.matches()) {
1348 // sched_kthread_stop (loglevel: TRACE_EMERG0) (type: tracepoint)
1349 eventInfo
= new BaseEventInfo(matcher
.group(1).trim());
1350 eventInfo
.setLogLevel(matcher
.group(2).trim());
1351 eventInfo
.setEventType(matcher
.group(3).trim());
1352 events
.add(eventInfo
);
1354 } else if (LTTngControlServiceConstants
.EVENT_FIELD_PATTERN
.matcher(line
).matches()) {
1355 if (eventInfo
!= null) {
1356 List
<IFieldInfo
> fields
= new ArrayList
<>();
1357 index
= getFieldInfo(output
, index
, fields
);
1358 eventInfo
.setFields(fields
);
1363 else if (LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
).matches()) {
1374 * Parse a field's information.
1377 * A command output array
1378 * @param currentIndex
1379 * The current index in the command output array
1381 * List for returning the field information
1382 * @return The new current index in the command output array
1384 protected int getFieldInfo(String
[] output
, int currentIndex
, List
<IFieldInfo
> fields
) {
1385 int index
= currentIndex
;
1386 IFieldInfo fieldInfo
= null;
1387 while (index
< output
.length
) {
1388 String line
= output
[index
];
1389 Matcher matcher
= LTTngControlServiceConstants
.EVENT_FIELD_PATTERN
.matcher(line
);
1390 if (matcher
.matches()) {
1391 // field: content (string)
1392 fieldInfo
= new FieldInfo(matcher
.group(2).trim());
1393 fieldInfo
.setFieldType(matcher
.group(3).trim());
1394 fields
.add(fieldInfo
);
1395 } else if (LTTngControlServiceConstants
.PROVIDER_EVENT_PATTERN
.matcher(line
).matches()) {
1397 } else if (LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
).matches()) {
1406 * Formats a command parameter for the command execution i.e. adds quotes
1407 * at the beginning and end if necessary.
1408 * @param parameter - parameter to format
1409 * @return formated parameter
1411 protected String
formatParameter(String parameter
) {
1412 if (parameter
!= null) {
1413 StringBuffer newString
= new StringBuffer();
1414 newString
.append(parameter
);
1416 if (parameter
.contains(" ") || parameter
.contains("*")) { //$NON-NLS-1$ //$NON-NLS-2$
1417 newString
.insert(0, "\""); //$NON-NLS-1$
1418 newString
.append("\""); //$NON-NLS-1$
1420 return newString
.toString();
1426 * @param strings array of string that makes up a command line
1427 * @return string buffer with created command line
1429 protected StringBuffer
createCommand(String
... strings
) {
1430 StringBuffer command
= new StringBuffer();
1431 command
.append(LTTngControlServiceConstants
.CONTROL_COMMAND
);
1432 command
.append(getTracingGroupOption());
1433 command
.append(getVerboseOption());
1434 for (String string
: strings
) {
1435 command
.append(string
);
1441 * @return the tracing group option if configured in the preferences
1443 protected String
getTracingGroupOption() {
1444 if (!ControlPreferences
.getInstance().isDefaultTracingGroup() && !ControlPreferences
.getInstance().getTracingGroup().equals("")) { //$NON-NLS-1$
1445 return LTTngControlServiceConstants
.OPTION_TRACING_GROUP
+ ControlPreferences
.getInstance().getTracingGroup();
1447 return ""; //$NON-NLS-1$
1451 * @return the verbose option as configured in the preferences
1453 protected String
getVerboseOption() {
1454 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1455 String level
= ControlPreferences
.getInstance().getVerboseLevel();
1456 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_VERBOSE
.equals(level
)) {
1457 return LTTngControlServiceConstants
.OPTION_VERBOSE
;
1459 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_V_VERBOSE
.equals(level
)) {
1460 return LTTngControlServiceConstants
.OPTION_VERY_VERBOSE
;
1462 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_V_V_VERBOSE
.equals(level
)) {
1463 return LTTngControlServiceConstants
.OPTION_VERY_VERY_VERBOSE
;
1466 return ""; //$NON-NLS-1$
1470 * Method that logs the command and command result if logging is enabled as
1471 * well as forwards the command execution to the shell.
1474 * - the command to execute
1476 * - a progress monitor
1477 * @return the command result
1478 * @throws ExecutionException
1479 * If the command fails
1481 protected ICommandResult
executeCommand(String command
,
1482 IProgressMonitor monitor
) throws ExecutionException
{
1483 return executeCommand(command
, monitor
, true);
1487 * Method that logs the command and command result if logging is enabled as
1488 * well as forwards the command execution to the shell.
1491 * - the command to execute
1493 * - a progress monitor
1494 * @param checkForError
1495 * - true to verify command result, else false
1496 * @return the command result
1497 * @throws ExecutionException
1498 * in case of error result
1500 protected ICommandResult
executeCommand(String command
,
1501 IProgressMonitor monitor
, boolean checkForError
)
1502 throws ExecutionException
{
1503 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1504 ControlCommandLogger
.log(command
);
1507 ICommandResult result
= fCommandShell
.executeCommand(
1508 command
.toString(), monitor
);
1510 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1511 ControlCommandLogger
.log(formatOutput(result
));
1514 if (checkForError
&& isError(result
)) {
1515 throw new ExecutionException(Messages
.TraceControl_CommandError
1516 + " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$