1 /**********************************************************************
2 * Copyright (c) 2012, 2016 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 * Markus Schorn - Bug 448058: Use org.eclipse.remote in favor of RSE
15 **********************************************************************/
16 package org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.service
;
18 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
19 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.nullToEmptyString
;
21 import java
.util
.ArrayList
;
22 import java
.util
.Arrays
;
23 import java
.util
.Iterator
;
24 import java
.util
.List
;
25 import java
.util
.regex
.Matcher
;
26 import java
.util
.regex
.Pattern
;
28 import org
.eclipse
.core
.commands
.ExecutionException
;
29 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
30 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
31 import org
.eclipse
.jdt
.annotation
.NonNull
;
32 import org
.eclipse
.jdt
.annotation
.Nullable
;
33 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.IBaseEventInfo
;
34 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.IChannelInfo
;
35 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.IDomainInfo
;
36 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.IEventInfo
;
37 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.IFieldInfo
;
38 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.IProbeEventInfo
;
39 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.ISessionInfo
;
40 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.ISnapshotInfo
;
41 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.ITraceLogLevel
;
42 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.IUstProviderInfo
;
43 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.LogLevelType
;
44 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TraceDomainType
;
45 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TraceEventType
;
46 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TraceLogLevel
;
47 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.BaseEventInfo
;
48 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.BufferType
;
49 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.ChannelInfo
;
50 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.DomainInfo
;
51 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.EventInfo
;
52 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.FieldInfo
;
53 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.ProbeEventInfo
;
54 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.SessionInfo
;
55 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.SnapshotInfo
;
56 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.UstProviderInfo
;
57 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.logging
.ControlCommandLogger
;
58 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.messages
.Messages
;
59 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.preferences
.ControlPreferences
;
60 import org
.eclipse
.tracecompass
.tmf
.remote
.core
.shell
.ICommandInput
;
61 import org
.eclipse
.tracecompass
.tmf
.remote
.core
.shell
.ICommandResult
;
62 import org
.eclipse
.tracecompass
.tmf
.remote
.core
.shell
.ICommandShell
;
66 * Service for sending LTTng trace control commands to remote host.
69 * @author Bernd Hufmann
71 public class LTTngControlService
implements ILttngControlService
{
73 // ------------------------------------------------------------------------
75 // ------------------------------------------------------------------------
77 * The command shell implementation
79 private final @NonNull ICommandShell fCommandShell
;
84 private @NonNull LttngVersion fVersion
= LttngVersion
.NULL_VERSION
;
86 // ------------------------------------------------------------------------
88 // ------------------------------------------------------------------------
94 * - the command shell implementation to use
96 public LTTngControlService(@NonNull ICommandShell shell
) {
97 fCommandShell
= shell
;
100 // ------------------------------------------------------------------------
102 // ------------------------------------------------------------------------
105 public String
getVersionString() {
106 return nullToEmptyString(fVersion
.toString());
110 public LttngVersion
getVersion() {
115 * Sets the version of the LTTng 2.0 control service.
120 public void setVersion(@Nullable String version
) {
121 if (version
!= null) {
122 fVersion
= new LttngVersion(version
);
127 * Sets the version of the LTTng 2.x control service.
132 protected void setVersion(LttngVersion version
) {
133 if (version
!= null) {
139 public boolean isVersionSupported(String version
) {
140 LttngVersion tmp
= new LttngVersion(version
);
141 return (fVersion
.compareTo(tmp
) >= 0) ?
true : false;
145 * Returns the command shell implementation.
147 * @return the command shell implementation
149 protected ICommandShell
getCommandShell() {
150 return fCommandShell
;
153 // ------------------------------------------------------------------------
155 // ------------------------------------------------------------------------
158 public List
<String
> getSessionNames(IProgressMonitor monitor
) throws ExecutionException
{
159 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST
);
161 ICommandResult result
= executeCommand(command
, monitor
);
164 // Available tracing sessions:
165 // 1) mysession1 (/home/user/lttng-traces/mysession1-20120123-083928)
167 // 2) mysession (/home/user/lttng-traces/mysession-20120123-083318)
170 // Use lttng list <session_name> for more details
172 ArrayList
<String
> retArray
= new ArrayList
<>();
173 for (String line
: result
.getOutput()) {
174 Matcher matcher
= LTTngControlServiceConstants
.SESSION_PATTERN
.matcher(line
);
175 if (matcher
.matches()) {
176 retArray
.add(matcher
.group(2).trim());
183 * Check if there is a pattern to be ignored into a sequence of string
186 * an input list of Strings
188 * the pattern to search for
189 * @return if the pattern exist in the array of string
191 protected boolean ignoredPattern(List
<String
> input
, Pattern pattern
) {
192 for (String line
: input
) {
193 Matcher matcher
= pattern
.matcher(line
);
194 if (matcher
.matches()) {
202 public ISessionInfo
getSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
203 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST
, sessionName
);
204 ICommandResult result
= executeCommand(command
, monitor
);
209 // Tracing session mysession2: [inactive]
210 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
211 ISessionInfo sessionInfo
= new SessionInfo(sessionName
);
213 while (index
< result
.getOutput().size()) {
214 // Tracing session mysession2: [inactive]
215 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
217 // === Domain: Kernel ===
219 String line
= result
.getOutput().get(index
);
220 Matcher matcher
= LTTngControlServiceConstants
.TRACE_SESSION_PATTERN
.matcher(line
);
221 if (matcher
.matches()) {
222 sessionInfo
.setSessionState(matcher
.group(2));
227 matcher
= LTTngControlServiceConstants
.TRACE_SNAPSHOT_SESSION_PATTERN
.matcher(line
);
228 if (matcher
.matches()) {
229 sessionInfo
.setSessionState(matcher
.group(2));
230 // real name will be set later
231 ISnapshotInfo snapshotInfo
= new SnapshotInfo(""); //$NON-NLS-1$
232 sessionInfo
.setSnapshotInfo(snapshotInfo
);
237 if (!sessionInfo
.isSnapshotSession()) {
238 matcher
= LTTngControlServiceConstants
.TRACE_NETWORK_PATH_PATTERN
.matcher(line
);
239 if (matcher
.matches()) {
240 sessionInfo
.setStreamedTrace(true);
243 matcher
= LTTngControlServiceConstants
.TRACE_SESSION_PATH_PATTERN
.matcher(line
);
244 if (matcher
.matches()) {
245 sessionInfo
.setSessionPath(matcher
.group(1).trim());
251 matcher
= LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(line
);
252 if (matcher
.matches()) {
254 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_KernelDomainDisplayName
);
257 domainInfo
.setDomain(TraceDomainType
.KERNEL
);
260 ArrayList
<IChannelInfo
> channels
= new ArrayList
<>();
261 index
= parseDomain(result
.getOutput(), index
, channels
, domainInfo
);
263 if (channels
.size() > 0) {
265 sessionInfo
.addDomain(domainInfo
);
268 domainInfo
.setChannels(channels
);
273 matcher
= LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
);
274 if (matcher
.matches()) {
275 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_UstGlobalDomainDisplayName
);
278 domainInfo
.setDomain(TraceDomainType
.UST
);
281 ArrayList
<IChannelInfo
> channels
= new ArrayList
<>();
282 index
= parseDomain(result
.getOutput(), index
, channels
, domainInfo
);
284 if (channels
.size() > 0) {
286 sessionInfo
.addDomain(domainInfo
);
289 domainInfo
.setChannels(channels
);
293 matcher
= LTTngControlServiceConstants
.LIST_LIVE_TIMER_INTERVAL_PATTERN
.matcher(line
);
294 if (matcher
.matches()) {
295 long liveDelay
= Long
.parseLong(matcher
.group(1));
296 if ((liveDelay
> 0) && (liveDelay
<= LTTngControlServiceConstants
.MAX_LIVE_TIMER_INTERVAL
)) {
297 sessionInfo
.setLive(true);
298 sessionInfo
.setLiveUrl(SessionInfo
.DEFAULT_LIVE_NETWORK_URL
);
299 sessionInfo
.setLivePort(SessionInfo
.DEFAULT_LIVE_PORT
);
300 sessionInfo
.setLiveDelay(liveDelay
);
309 if (sessionInfo
.isSnapshotSession()) {
310 ISnapshotInfo snapshot
= getSnapshotInfo(sessionName
, monitor
);
311 sessionInfo
.setSnapshotInfo(snapshot
);
318 public ISnapshotInfo
getSnapshotInfo(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
319 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_SNAPSHOT
, LTTngControlServiceConstants
.COMMAND_LIST_SNAPSHOT_OUTPUT
, LTTngControlServiceConstants
.OPTION_SESSION
, sessionName
);
320 ICommandResult result
= executeCommand(command
, monitor
);
325 // [1] snapshot-1: /home/user/lttng-traces/my-20130909-114431
327 // [3] snapshot-3: net4://172.0.0.1/
328 ISnapshotInfo snapshotInfo
= new SnapshotInfo(""); //$NON-NLS-1$
330 while (index
< result
.getOutput().size()) {
331 String line
= result
.getOutput().get(index
);
332 Matcher matcher
= LTTngControlServiceConstants
.LIST_SNAPSHOT_OUTPUT_PATTERN
.matcher(line
);
333 if (matcher
.matches()) {
334 snapshotInfo
.setId(Integer
.valueOf(matcher
.group(1)));
335 snapshotInfo
.setName(matcher
.group(2));
336 snapshotInfo
.setSnapshotPath(matcher
.group(3));
338 Matcher matcher2
= LTTngControlServiceConstants
.SNAPSHOT_NETWORK_PATH_PATTERN
.matcher(snapshotInfo
.getSnapshotPath());
339 if (matcher2
.matches()) {
340 snapshotInfo
.setStreamedSnapshot(true);
353 public List
<IBaseEventInfo
> getKernelProvider(IProgressMonitor monitor
) throws ExecutionException
{
354 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST
, LTTngControlServiceConstants
.OPTION_KERNEL
);
355 ICommandResult result
= executeCommand(command
, monitor
, false);
357 List
<IBaseEventInfo
> events
= new ArrayList
<>();
359 // Ignore the following 2 cases:
360 // Spawning a session daemon
361 // Error: Unable to list kernel events
363 // Error: Unable to list kernel events
365 if (ignoredPattern(result
.getErrorOutput(), LTTngControlServiceConstants
.LIST_KERNEL_NO_KERNEL_PROVIDER_PATTERN
)) {
369 if (isError(result
)) {
370 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + result
.toString()); //$NON-NLS-1$ //$NON-NLS-2$
375 // sched_kthread_stop (type: tracepoint)
376 getProviderEventInfo(result
.getOutput(), 0, events
);
381 public List
<IUstProviderInfo
> getUstProvider() throws ExecutionException
{
382 return getUstProvider(new NullProgressMonitor());
386 public List
<IUstProviderInfo
> getUstProvider(IProgressMonitor monitor
) throws ExecutionException
{
387 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST
, LTTngControlServiceConstants
.OPTION_UST
);
389 if (isVersionSupported("2.1.0")) { //$NON-NLS-1$
390 command
.add(LTTngControlServiceConstants
.OPTION_FIELDS
);
393 ICommandResult result
= executeCommand(command
, monitor
, false);
394 List
<IUstProviderInfo
> allProviders
= new ArrayList
<>();
396 // Workaround for versions 2.0.x which causes a segmentation fault for
398 // if LTTng Tools is compiled without UST support.
399 if (!isVersionSupported("2.1.0") && (result
.getResult() != 0)) { //$NON-NLS-1$
403 // Ignore the following 2 cases:
404 // Spawning a session daemon
405 // Error: Unable to list UST events: Listing UST events failed
407 // Error: Unable to list UST events: Listing UST events failed
409 if (ignoredPattern(result
.getErrorOutput(), LTTngControlServiceConstants
.LIST_UST_NO_UST_PROVIDER_PATTERN
)) {
413 if (isError(result
)) {
414 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + result
.toString()); //$NON-NLS-1$ //$NON-NLS-2$
417 // Note that field print-outs exists for version >= 2.1.0
423 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
424 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
426 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
427 // field: doublefield (float)
428 // field: floatfield (float)
429 // field: stringfield (string)
432 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
433 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
435 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
436 // field: doublefield (float)
437 // field: floatfield (float)
438 // field: stringfield (string)
440 IUstProviderInfo provider
= null;
443 while (index
< result
.getOutput().size()) {
444 String line
= result
.getOutput().get(index
);
445 Matcher matcher
= LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
);
446 if (matcher
.matches()) {
447 provider
= new UstProviderInfo(matcher
.group(2).trim());
448 provider
.setPid(Integer
.valueOf(matcher
.group(1).trim()));
449 List
<IBaseEventInfo
> events
= new ArrayList
<>();
450 index
= getProviderEventInfo(result
.getOutput(), ++index
, events
);
451 provider
.setEvents(events
);
452 allProviders
.add(provider
);
461 public ISessionInfo
createSession(ISessionInfo sessionInfo
, IProgressMonitor monitor
) throws ExecutionException
{
462 if (sessionInfo
.isStreamedTrace()) {
463 return createStreamedSession(sessionInfo
, monitor
);
466 ICommandInput command
= prepareSessionCreationCommand(sessionInfo
);
468 ICommandResult result
= executeCommand(command
, monitor
);
470 // Session myssession2 created.
471 // Traces will be written in
472 // /home/user/lttng-traces/myssession2-20120209-095418
473 List
<String
> output
= result
.getOutput();
475 // Get and session name and path
479 for (String line
: output
) {
480 Matcher nameMatcher
= LTTngControlServiceConstants
.CREATE_SESSION_NAME_PATTERN
.matcher(line
);
481 Matcher pathMatcher
= LTTngControlServiceConstants
.CREATE_SESSION_PATH_PATTERN
.matcher(line
);
482 if (nameMatcher
.matches()) {
483 name
= String
.valueOf(nameMatcher
.group(1).trim());
484 } else if (pathMatcher
.matches()) {
485 path
= String
.valueOf(pathMatcher
.group(1).trim());
489 // Verify session name
490 if ((name
== null) || (!"".equals(sessionInfo
.getName()) && !name
.equals(sessionInfo
.getName()))) { //$NON-NLS-1$
491 // Unexpected name returned
492 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
493 Messages
.TraceControl_UnexpectedNameError
+ ": " + name
); //$NON-NLS-1$
496 sessionInfo
.setName(name
);
497 // Verify session path
498 if (!sessionInfo
.isSnapshotSession() &&
499 ((path
== null) || ((sessionInfo
.getSessionPath() != null) && (!path
.contains(sessionInfo
.getSessionPath()))))) {
501 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
502 Messages
.TraceControl_UnexpectedPathError
+ ": " + name
); //$NON-NLS-1$
505 if (sessionInfo
.isSnapshotSession()) {
506 // Make it a snapshot session - content of snapshot info need to
507 // set afterwards using getSession() or getSnapshotInfo()
508 sessionInfo
.setSnapshotInfo(new SnapshotInfo("")); //$NON-NLS-1$
510 sessionInfo
.setSessionPath(path
);
518 * Basic generation of command for session creation
521 * the session to create
522 * @return the basic command for command creation
524 protected @NonNull ICommandInput
prepareSessionCreationCommand(ISessionInfo sessionInfo
) {
525 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_CREATE_SESSION
);
526 if (!sessionInfo
.getName().isEmpty()) {
527 command
.add(sessionInfo
.getName());
530 String newPath
= sessionInfo
.getSessionPath();
531 if (newPath
!= null && !"".equals(newPath
)) { //$NON-NLS-1$
532 command
.add(LTTngControlServiceConstants
.OPTION_OUTPUT_PATH
);
533 command
.add(newPath
);
536 if (sessionInfo
.isSnapshotSession()) {
537 command
.add(LTTngControlServiceConstants
.OPTION_SNAPSHOT
);
542 private @NonNull ISessionInfo
createStreamedSession(ISessionInfo sessionInfo
, IProgressMonitor monitor
) throws ExecutionException
{
544 ICommandInput command
= prepareStreamedSessionCreationCommand(sessionInfo
);
546 ICommandResult result
= executeCommand(command
, monitor
);
549 List
<String
> output
= result
.getOutput();
551 // Get and session name and path
555 for (String line
: output
) {
556 Matcher nameMatcher
= LTTngControlServiceConstants
.CREATE_SESSION_NAME_PATTERN
.matcher(line
);
557 Matcher pathMatcher
= LTTngControlServiceConstants
.CREATE_SESSION_PATH_PATTERN
.matcher(line
);
559 if (nameMatcher
.matches()) {
560 name
= String
.valueOf(nameMatcher
.group(1).trim());
561 } else if (pathMatcher
.matches() && (sessionInfo
.getNetworkUrl() != null)) {
562 path
= String
.valueOf(pathMatcher
.group(1).trim());
566 // Verify session name
567 if ((name
== null) || (!"".equals(sessionInfo
.getName()) && !name
.equals(sessionInfo
.getName()))) { //$NON-NLS-1$
568 // Unexpected name returned
569 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
570 Messages
.TraceControl_UnexpectedNameError
+ ": " + name
); //$NON-NLS-1$
573 sessionInfo
.setName(name
);
575 sessionInfo
.setStreamedTrace(true);
577 // Verify session path
578 if (sessionInfo
.getNetworkUrl() != null) {
579 if (!sessionInfo
.isSnapshotSession() && (path
== null)) {
581 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
582 Messages
.TraceControl_UnexpectedPathError
+ ": " + name
); //$NON-NLS-1$
585 if (sessionInfo
.isSnapshotSession()) {
586 sessionInfo
.setStreamedTrace(false);
588 sessionInfo
.setSessionPath(path
);
589 // Check file protocol
590 Matcher matcher
= LTTngControlServiceConstants
.TRACE_FILE_PROTOCOL_PATTERN
.matcher(path
);
591 if (matcher
.matches()) {
592 sessionInfo
.setStreamedTrace(false);
597 // When using controlUrl and dataUrl the full session path is not known
598 // yet and will be set later on when listing the session
604 * Basic generation of command for streamed session creation
607 * the session to create
608 * @return the basic command for command creation
610 protected @NonNull ICommandInput
prepareStreamedSessionCreationCommand(ISessionInfo sessionInfo
) {
611 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_CREATE_SESSION
);
612 if (!sessionInfo
.getName().isEmpty()) {
613 command
.add(sessionInfo
.getName());
616 if (sessionInfo
.isSnapshotSession()) {
617 command
.add(LTTngControlServiceConstants
.OPTION_SNAPSHOT
);
618 } else if (sessionInfo
.isLive()) {
619 command
.add(LTTngControlServiceConstants
.OPTION_LIVE
);
620 if (sessionInfo
.getLiveDelay() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
621 command
.add(String
.valueOf(sessionInfo
.getLiveDelay()));
625 if (sessionInfo
.getNetworkUrl() != null) {
626 command
.add(LTTngControlServiceConstants
.OPTION_NETWORK_URL
);
627 command
.add(sessionInfo
.getNetworkUrl());
629 command
.add(LTTngControlServiceConstants
.OPTION_CONTROL_URL
);
630 command
.add(sessionInfo
.getControlUrl());
632 command
.add(LTTngControlServiceConstants
.OPTION_DATA_URL
);
633 command
.add(sessionInfo
.getDataUrl());
639 public void destroySession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
641 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_DESTROY_SESSION
, sessionName
);
643 ICommandResult result
= executeCommand(command
, monitor
, false);
644 boolean isError
= isError(result
);
645 if (isError
&& !ignoredPattern(result
.getErrorOutput(), LTTngControlServiceConstants
.SESSION_NOT_FOUND_ERROR_PATTERN
)) {
646 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + result
.toString()); //$NON-NLS-1$ //$NON-NLS-2$
649 // Session <sessionName> destroyed
653 public void startSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
655 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_START_SESSION
, sessionName
);
657 executeCommand(command
, monitor
);
659 // Session <sessionName> started
663 public void stopSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
664 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_STOP_SESSION
, sessionName
);
666 executeCommand(command
, monitor
);
668 // Session <sessionName> stopped
673 public void enableChannels(String sessionName
, List
<String
> channelNames
, TraceDomainType domain
, IChannelInfo info
, IProgressMonitor monitor
) throws ExecutionException
{
675 // no channels to enable
676 if (channelNames
.isEmpty()) {
680 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_CHANNEL
);
682 command
.add(toCsv(channelNames
));
684 command
.add(getDomainOption(domain
));
686 command
.add(LTTngControlServiceConstants
.OPTION_SESSION
);
687 command
.add(sessionName
);
690 // --discard Discard event when buffers are full (default)
692 // --overwrite Flight recorder mode
693 if (info
.isOverwriteMode()) {
694 command
.add(LTTngControlServiceConstants
.OPTION_OVERWRITE
);
696 // --subbuf-size SIZE Subbuffer size in bytes
697 // (default: 4096, kernel default: 262144)
698 if (info
.getSubBufferSize() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
699 command
.add(LTTngControlServiceConstants
.OPTION_SUB_BUFFER_SIZE
);
700 command
.add(String
.valueOf(info
.getSubBufferSize()));
703 // --num-subbuf NUM Number of subbufers
704 if (info
.getNumberOfSubBuffers() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
705 command
.add(LTTngControlServiceConstants
.OPTION_NUM_SUB_BUFFERS
);
706 command
.add(String
.valueOf(info
.getNumberOfSubBuffers()));
709 // --switch-timer USEC Switch timer interval in usec
710 if (info
.getSwitchTimer() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
711 command
.add(LTTngControlServiceConstants
.OPTION_SWITCH_TIMER
);
712 command
.add(String
.valueOf(info
.getSwitchTimer()));
715 // --read-timer USEC Read timer interval in usec
716 if (info
.getReadTimer() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
717 command
.add(LTTngControlServiceConstants
.OPTION_READ_TIMER
);
718 command
.add(String
.valueOf(info
.getReadTimer()));
721 if (isVersionSupported("2.2.0")) { //$NON-NLS-1$
722 // --buffers-uid Every application sharing the same UID use the
723 // same buffers --buffers-pid Buffers are allocated per PID
724 if (domain
.equals(TraceDomainType
.UST
)) {
725 if (info
.getBufferType() == BufferType
.BUFFER_PER_PID
) {
726 command
.add(LTTngControlServiceConstants
.OPTION_PER_PID_BUFFERS
);
728 } else if (info
.getBufferType() == BufferType
.BUFFER_PER_UID
) {
729 command
.add(LTTngControlServiceConstants
.OPTION_PER_UID_BUFFERS
);
733 // -C SIZE Maximum size of trace files in bytes
734 if (info
.getMaxSizeTraceFiles() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
735 command
.add(LTTngControlServiceConstants
.OPTION_MAX_SIZE_TRACE_FILES
);
736 command
.add(String
.valueOf(info
.getMaxSizeTraceFiles()));
739 // -W NUM Maximum number of trace files
740 if (info
.getMaxNumberTraceFiles() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
741 command
.add(LTTngControlServiceConstants
.OPTION_MAX_TRACE_FILES
);
742 command
.add(String
.valueOf(info
.getMaxNumberTraceFiles()));
747 executeCommand(command
, monitor
);
752 public void disableChannels(String sessionName
, List
<String
> channelNames
, TraceDomainType domain
, IProgressMonitor monitor
) throws ExecutionException
{
754 // no channels to enable
755 if (channelNames
.isEmpty()) {
759 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_DISABLE_CHANNEL
);
761 command
.add(toCsv(channelNames
));
763 command
.add(getDomainOption(domain
));
765 command
.add(LTTngControlServiceConstants
.OPTION_SESSION
);
766 command
.add(sessionName
);
768 executeCommand(command
, monitor
);
772 public void enableEvents(String sessionName
, String channelName
, List
<String
> eventNames
, TraceDomainType domain
, String filterExpression
, List
<String
> excludedEvents
, IProgressMonitor monitor
) throws ExecutionException
{
774 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
775 boolean isAllEvents
= ALL_EVENTS
.equals(eventNames
);
777 if (isAllEvents
|| (eventNames
== null) || (eventNames
.isEmpty())) {
778 command
.add(LTTngControlServiceConstants
.OPTION_ALL
);
780 command
.add(toCsv(eventNames
));
783 command
.add(getDomainOption(domain
));
785 command
.add(LTTngControlServiceConstants
.OPTION_SESSION
);
786 command
.add(sessionName
);
788 if (channelName
!= null) {
789 command
.add(LTTngControlServiceConstants
.OPTION_CHANNEL
);
790 command
.add(channelName
);
794 command
.add(LTTngControlServiceConstants
.OPTION_TRACEPOINT
);
797 if (filterExpression
!= null) {
798 command
.add(LTTngControlServiceConstants
.OPTION_FILTER
);
799 command
.add(filterExpression
);
802 if (excludedEvents
!= null && !excludedEvents
.isEmpty()) {
803 command
.add(LTTngControlServiceConstants
.OPTION_EXCLUDE
);
804 command
.add(toCsv(excludedEvents
));
807 executeCommand(command
, monitor
);
811 public void enableSyscalls(String sessionName
, String channelName
, List
<String
> syscallNames
, IProgressMonitor monitor
) throws ExecutionException
{
813 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
815 boolean isAllSyscalls
= ALL_EVENTS
.equals(syscallNames
);
817 if (isAllSyscalls
|| (syscallNames
== null) || (syscallNames
.isEmpty())) {
818 command
.add(LTTngControlServiceConstants
.OPTION_ALL
);
820 command
.add(toCsv(syscallNames
));
823 command
.add(LTTngControlServiceConstants
.OPTION_KERNEL
);
825 command
.add(LTTngControlServiceConstants
.OPTION_SESSION
);
826 command
.add(sessionName
);
828 if (channelName
!= null) {
829 command
.add(LTTngControlServiceConstants
.OPTION_CHANNEL
);
830 command
.add(channelName
);
833 command
.add(LTTngControlServiceConstants
.OPTION_SYSCALL
);
835 executeCommand(command
, monitor
);
839 public void enableProbe(String sessionName
, String channelName
, String eventName
, boolean isFunction
, String probe
, IProgressMonitor monitor
) throws ExecutionException
{
840 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
842 command
.add(eventName
);
843 command
.add(LTTngControlServiceConstants
.OPTION_KERNEL
);
845 command
.add(LTTngControlServiceConstants
.OPTION_SESSION
);
846 command
.add(sessionName
);
848 if (channelName
!= null) {
849 command
.add(LTTngControlServiceConstants
.OPTION_CHANNEL
);
850 command
.add(channelName
);
853 command
.add(LTTngControlServiceConstants
.OPTION_FUNCTION_PROBE
);
855 command
.add(LTTngControlServiceConstants
.OPTION_PROBE
);
860 executeCommand(command
, monitor
);
864 public void enableLogLevel(String sessionName
, String channelName
, List
<String
> eventNames
, LogLevelType logLevelType
, ITraceLogLevel level
, String filterExpression
, TraceDomainType domain
, IProgressMonitor monitor
) throws ExecutionException
{
865 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
867 // Checking if we should enable all events (with option '-a')
868 boolean isAllEvents
= ALL_EVENTS
.equals(eventNames
);
870 if (isAllEvents
|| (eventNames
== null) || (eventNames
.isEmpty())) {
871 command
.add(LTTngControlServiceConstants
.OPTION_ALL
);
873 command
.add(toCsv(eventNames
));
876 command
.add(getDomainOption(domain
));
878 command
.add(LTTngControlServiceConstants
.OPTION_SESSION
);
879 command
.add(sessionName
);
881 if (channelName
!= null) {
882 command
.add(LTTngControlServiceConstants
.OPTION_CHANNEL
);
883 command
.add(channelName
);
886 if (logLevelType
== LogLevelType
.LOGLEVEL
) {
887 command
.add(LTTngControlServiceConstants
.OPTION_LOGLEVEL
);
888 } else if (logLevelType
== LogLevelType
.LOGLEVEL_ONLY
) {
889 command
.add(LTTngControlServiceConstants
.OPTION_LOGLEVEL_ONLY
);
893 command
.add(level
.getInName());
894 executeCommand(command
, monitor
);
898 public void disableEvent(String sessionName
, String channelName
, List
<String
> eventNames
, TraceDomainType domain
, IProgressMonitor monitor
) throws ExecutionException
{
899 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_DISABLE_EVENT
);
901 if (eventNames
== null) {
902 command
.add(LTTngControlServiceConstants
.OPTION_ALL
);
904 // no events to disable
905 if (eventNames
.isEmpty()) {
909 StringBuffer eventNameParameter
= new StringBuffer();
910 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
911 String event
= iterator
.next();
912 eventNameParameter
.append(event
);
913 if (iterator
.hasNext()) {
914 eventNameParameter
.append(',');
917 command
.add(eventNameParameter
.toString());
920 command
.add(getDomainOption(domain
));
922 command
.add(LTTngControlServiceConstants
.OPTION_SESSION
);
923 command
.add(sessionName
);
925 if (channelName
!= null) {
926 command
.add(LTTngControlServiceConstants
.OPTION_CHANNEL
);
927 command
.add(channelName
);
930 executeCommand(command
, monitor
);
934 public List
<String
> getContextList(IProgressMonitor monitor
) throws ExecutionException
{
936 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_ADD_CONTEXT
, LTTngControlServiceConstants
.OPTION_HELP
);
938 ICommandResult result
= executeCommand(command
, monitor
);
940 List
<String
> output
= result
.getOutput();
942 List
<String
> contexts
= new ArrayList
<>(0);
945 boolean inList
= false;
946 while (index
< output
.size()) {
947 String line
= output
.get(index
);
949 Matcher startMatcher
= LTTngControlServiceConstants
.ADD_CONTEXT_HELP_CONTEXTS_INTRO
.matcher(line
);
950 Matcher endMatcher
= LTTngControlServiceConstants
.ADD_CONTEXT_HELP_CONTEXTS_END_LINE
.matcher(line
);
952 if (startMatcher
.matches()) {
954 } else if (endMatcher
.matches()) {
957 String
[] tmp
= line
.split(","); //$NON-NLS-1$
958 for (int i
= 0; i
< tmp
.length
; i
++) {
959 contexts
.add(tmp
[i
].trim());
968 public void addContexts(String sessionName
, String channelName
, String eventName
, TraceDomainType domain
, List
<String
> contextNames
, IProgressMonitor monitor
) throws ExecutionException
{
969 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_ADD_CONTEXT
);
971 command
.add(LTTngControlServiceConstants
.OPTION_SESSION
);
972 command
.add(sessionName
);
974 if (channelName
!= null) {
975 command
.add(LTTngControlServiceConstants
.OPTION_CHANNEL
);
976 command
.add(channelName
);
979 if (eventName
!= null) {
980 command
.add(LTTngControlServiceConstants
.OPTION_EVENT
);
981 command
.add(eventName
);
984 command
.add(getDomainOption(domain
));
986 for (Iterator
<String
> iterator
= contextNames
.iterator(); iterator
.hasNext();) {
987 String context
= iterator
.next();
988 command
.add(LTTngControlServiceConstants
.OPTION_CONTEXT_TYPE
);
989 command
.add(context
);
992 executeCommand(command
, monitor
);
997 public void recordSnapshot(String sessionName
, IProgressMonitor monitor
)
998 throws ExecutionException
{
999 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_SNAPSHOT
, LTTngControlServiceConstants
.COMMAND_RECORD_SNAPSHOT
);
1001 String newSessionName
= sessionName
;
1002 command
.add(LTTngControlServiceConstants
.OPTION_SESSION
);
1003 command
.add(newSessionName
);
1005 executeCommand(command
, monitor
);
1009 public void loadSession(String inputPath
, boolean isForce
, IProgressMonitor monitor
)
1010 throws ExecutionException
{
1011 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_LOAD_SESSION
);
1013 if (inputPath
!= null) {
1014 command
.add(LTTngControlServiceConstants
.OPTION_INPUT_PATH
);
1015 command
.add(inputPath
);
1019 command
.add(LTTngControlServiceConstants
.OPTION_FORCE
);
1021 executeCommand(command
, monitor
);
1025 public void saveSession(String session
, String outputPath
, boolean isForce
, IProgressMonitor monitor
) throws ExecutionException
{
1026 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_SAVE_SESSION
);
1028 if (outputPath
!= null) {
1029 command
.add(LTTngControlServiceConstants
.OPTION_OUTPUT_PATH
);
1030 command
.add(outputPath
);
1034 command
.add(LTTngControlServiceConstants
.OPTION_FORCE
);
1037 if (session
!= null) {
1038 command
.add(session
);
1040 executeCommand(command
, monitor
);
1044 public void runCommands(IProgressMonitor monitor
, List
<String
> commandLines
) throws ExecutionException
{
1045 for (String commandLine
: commandLines
) {
1046 if (monitor
.isCanceled()) {
1050 if (commandLine
.isEmpty() || commandLine
.startsWith("#")) { //$NON-NLS-1$
1053 String
[] args
= commandLine
.split("\\s+"); //$NON-NLS-1$
1054 ICommandInput command
= fCommandShell
.createCommand();
1055 command
.addAll(Arrays
.asList(args
));
1056 ICommandResult result
= executeCommand(command
, monitor
);
1058 if (isError(result
)) {
1059 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + result
.toString()); //$NON-NLS-1$ //$NON-NLS-2$
1064 // ------------------------------------------------------------------------
1066 // ------------------------------------------------------------------------
1068 private static @NonNull String
getDomainOption(TraceDomainType domain
) {
1071 return LTTngControlServiceConstants
.OPTION_KERNEL
;
1073 return LTTngControlServiceConstants
.OPTION_UST
;
1075 return LTTngControlServiceConstants
.OPTION_JUL
;
1077 return LTTngControlServiceConstants
.OPTION_LOG4J
;
1079 return LTTngControlServiceConstants
.OPTION_PYTHON
;
1082 return TraceDomainType
.UNKNOWN
.name();
1087 * Checks if command result is an error result.
1090 * - the command result to check
1091 * @return true if error else false
1093 protected boolean isError(ICommandResult result
) {
1094 // Check return code and length of returned strings
1096 if ((result
.getResult()) != 0) {
1100 // Look for error pattern
1101 for (String line
: result
.getErrorOutput()) {
1102 Matcher matcher
= LTTngControlServiceConstants
.ERROR_PATTERN
.matcher(line
);
1103 if (matcher
.matches()) {
1112 * Creates a comma separated string from list of names
1115 * List of name to convert
1116 * @return comma separated string
1118 protected String
toCsv(List
<String
> names
) {
1119 StringBuilder csvString
= new StringBuilder();
1120 for (Iterator
<String
> iterator
= names
.iterator(); iterator
.hasNext();) {
1121 String name
= iterator
.next();
1122 csvString
.append(name
);
1123 if (iterator
.hasNext()) {
1124 csvString
.append(',');
1127 return csvString
.toString();
1131 * Parses the domain information.
1134 * a command output list
1135 * @param currentIndex
1136 * current index in command output list
1138 * list for returning channel information
1140 * The domain information
1141 * @return the new current index in command output list
1143 protected int parseDomain(List
<String
> output
, int currentIndex
, List
<IChannelInfo
> channels
, IDomainInfo domainInfo
) {
1144 int index
= currentIndex
;
1146 // if kernel set the buffer type to shared
1147 if (domainInfo
.getDomain().equals(TraceDomainType
.KERNEL
)) {
1148 domainInfo
.setBufferType(BufferType
.BUFFER_SHARED
);
1153 // - channnel1: [enabled]
1156 // overwrite mode: 0
1157 // subbufers size: 262144
1158 // number of subbufers: 4
1159 // switch timer interval: 0
1160 // read timer interval: 200
1163 while (index
< output
.size()) {
1164 String line
= output
.get(index
);
1166 if (isVersionSupported("2.2.0")) { //$NON-NLS-1$
1167 Matcher bufferTypeMatcher
= LTTngControlServiceConstants
.BUFFER_TYPE_PATTERN
.matcher(line
);
1168 if (bufferTypeMatcher
.matches()) {
1169 String bufferTypeString
= getAttributeValue(line
);
1170 if (BufferType
.BUFFER_PER_PID
.getInName().equals(bufferTypeString
)) {
1171 domainInfo
.setBufferType(BufferType
.BUFFER_PER_PID
);
1172 } else if (BufferType
.BUFFER_PER_UID
.getInName().equals(bufferTypeString
)) {
1173 domainInfo
.setBufferType(BufferType
.BUFFER_PER_UID
);
1175 domainInfo
.setBufferType(BufferType
.BUFFER_TYPE_UNKNOWN
);
1179 domainInfo
.setBufferType(BufferType
.BUFFER_TYPE_UNKNOWN
);
1181 Matcher outerMatcher
= LTTngControlServiceConstants
.CHANNELS_SECTION_PATTERN
.matcher(line
);
1182 Matcher noKernelChannelMatcher
= LTTngControlServiceConstants
.DOMAIN_NO_KERNEL_CHANNEL_PATTERN
.matcher(line
);
1183 Matcher noUstChannelMatcher
= LTTngControlServiceConstants
.DOMAIN_NO_UST_CHANNEL_PATTERN
.matcher(line
);
1184 if (outerMatcher
.matches()) {
1185 IChannelInfo channelInfo
= null;
1186 while (index
< output
.size()) {
1187 String subLine
= output
.get(index
);
1189 Matcher innerMatcher
= LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(subLine
);
1190 if (innerMatcher
.matches()) {
1191 channelInfo
= new ChannelInfo(""); //$NON-NLS-1$
1193 channelInfo
.setName(innerMatcher
.group(1));
1195 // get channel enablement
1196 channelInfo
.setState(innerMatcher
.group(2));
1199 channelInfo
.setBufferType(domainInfo
.getBufferType());
1202 channels
.add(channelInfo
);
1204 } else if (LTTngControlServiceConstants
.OVERWRITE_MODE_ATTRIBUTE
.matcher(subLine
).matches()) {
1205 String value
= getAttributeValue(subLine
);
1206 if (channelInfo
!= null) {
1207 channelInfo
.setOverwriteMode(!LTTngControlServiceConstants
.OVERWRITE_MODE_ATTRIBUTE_FALSE
.equals(value
));
1209 } else if (LTTngControlServiceConstants
.SUBBUFFER_SIZE_ATTRIBUTE
.matcher(subLine
).matches()) {
1210 if (channelInfo
!= null) {
1211 channelInfo
.setSubBufferSize(Long
.valueOf(getAttributeValue(subLine
)));
1214 } else if (LTTngControlServiceConstants
.NUM_SUBBUFFERS_ATTRIBUTE
.matcher(subLine
).matches()) {
1215 if (channelInfo
!= null) {
1216 channelInfo
.setNumberOfSubBuffers(Integer
.valueOf(getAttributeValue(subLine
)));
1219 } else if (LTTngControlServiceConstants
.SWITCH_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
1220 if (channelInfo
!= null) {
1221 channelInfo
.setSwitchTimer(Long
.valueOf(getAttributeValue(subLine
)));
1224 } else if (LTTngControlServiceConstants
.READ_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
1225 if (channelInfo
!= null) {
1226 channelInfo
.setReadTimer(Long
.valueOf(getAttributeValue(subLine
)));
1229 } else if (LTTngControlServiceConstants
.OUTPUT_ATTRIBUTE
.matcher(subLine
).matches()) {
1230 if (channelInfo
!= null) {
1231 channelInfo
.setOutputType(getAttributeValue(subLine
));
1234 } else if (LTTngControlServiceConstants
.TRACE_FILE_COUNT_ATTRIBUTE
.matcher(subLine
).matches()) {
1235 if (channelInfo
!= null) {
1236 channelInfo
.setMaxNumberTraceFiles(Integer
.valueOf(getAttributeValue(subLine
)));
1239 } else if (LTTngControlServiceConstants
.TRACE_FILE_SIZE_ATTRIBUTE
.matcher(subLine
).matches()) {
1240 if (channelInfo
!= null) {
1241 channelInfo
.setMaxSizeTraceFiles(Long
.valueOf(getAttributeValue(subLine
)));
1243 } else if (LTTngControlServiceConstants
.EVENT_SECTION_PATTERN
.matcher(subLine
).matches()) {
1244 List
<IEventInfo
> events
= new ArrayList
<>();
1245 index
= parseEvents(output
, index
, events
);
1246 if (channelInfo
!= null) {
1247 channelInfo
.setEvents(events
);
1249 // we want to stay at the current index to be able to
1252 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(subLine
).matches()) {
1255 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(subLine
).matches()) {
1260 } else if (noKernelChannelMatcher
.matches() || noUstChannelMatcher
.matches()) {
1261 // domain indicates that no channels were found -> return
1271 * Parses the event information within a domain.
1274 * a command output list
1275 * @param currentIndex
1276 * current index in command output list
1278 * list for returning event information
1279 * @return the new current index in command output list
1281 protected int parseEvents(List
<String
> output
, int currentIndex
, List
<IEventInfo
> events
) {
1282 int index
= currentIndex
;
1284 while (index
< output
.size()) {
1285 String line
= output
.get(index
);
1286 if (LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(line
).matches()) {
1289 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(line
).matches()) {
1292 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
).matches()) {
1297 Matcher matcher
= LTTngControlServiceConstants
.EVENT_PATTERN
.matcher(line
);
1298 Matcher matcher2
= LTTngControlServiceConstants
.WILDCARD_EVENT_PATTERN
.matcher(line
);
1300 if (matcher
.matches()) {
1301 IEventInfo eventInfo
= new EventInfo(matcher
.group(1).trim());
1302 eventInfo
.setLogLevelType(matcher
.group(2).trim());
1303 eventInfo
.setLogLevel(matcher
.group(3).trim());
1304 eventInfo
.setEventType(matcher
.group(4).trim());
1305 eventInfo
.setState(matcher
.group(5));
1306 if (("[" + LTTngControlServiceConstants
.HAS_EXCLUSIONS
+ "]").equals(matcher
.group(6))) { //$NON-NLS-1$ //$NON-NLS-2$
1307 eventInfo
.setExcludedEvents(LTTngControlServiceConstants
.HAS_EXCLUSIONS
);
1309 if (("[" + LTTngControlServiceConstants
.WITH_FILTER
+ "]").equals(matcher
.group(7))) { //$NON-NLS-1$ //$NON-NLS-2$
1310 eventInfo
.setFilterExpression(LTTngControlServiceConstants
.WITH_FILTER
);
1312 events
.add(eventInfo
);
1314 } else if (matcher2
.matches()) {
1315 IEventInfo eventInfo
= new EventInfo(matcher2
.group(1).trim());
1316 eventInfo
.setLogLevel(TraceLogLevel
.LEVEL_UNKNOWN
);
1317 eventInfo
.setEventType(matcher2
.group(2).trim());
1318 eventInfo
.setState(matcher2
.group(3));
1319 if (("[" + LTTngControlServiceConstants
.HAS_EXCLUSIONS
+ "]").equals(matcher2
.group(4))) { //$NON-NLS-1$ //$NON-NLS-2$
1320 eventInfo
.setExcludedEvents(LTTngControlServiceConstants
.HAS_EXCLUSIONS
);
1322 if (("[" + LTTngControlServiceConstants
.WITH_FILTER
+ "]").equals(matcher2
.group(5))) { //$NON-NLS-1$ //$NON-NLS-2$
1323 eventInfo
.setFilterExpression(LTTngControlServiceConstants
.WITH_FILTER
);
1326 if ((eventInfo
.getEventType() == TraceEventType
.PROBE
) ||
1327 (eventInfo
.getEventType() == TraceEventType
.FUNCTION
)) {
1328 IProbeEventInfo probeEvent
= new ProbeEventInfo(eventInfo
.getName());
1329 probeEvent
.setLogLevel(eventInfo
.getLogLevel());
1330 probeEvent
.setEventType(eventInfo
.getEventType());
1331 probeEvent
.setState(eventInfo
.getState());
1333 // Overwrite eventinfo
1334 eventInfo
= probeEvent
;
1336 // myevent2 (type: probe) [enabled]
1338 // myevent0 (type: function) [enabled]
1340 // symbol: init_post
1342 while (index
< output
.size()) {
1343 String probeLine
= output
.get(index
);
1345 Matcher addrMatcher
= LTTngControlServiceConstants
.PROBE_ADDRESS_PATTERN
.matcher(probeLine
);
1346 Matcher offsetMatcher
= LTTngControlServiceConstants
.PROBE_OFFSET_PATTERN
.matcher(probeLine
);
1347 Matcher symbolMatcher
= LTTngControlServiceConstants
.PROBE_SYMBOL_PATTERN
.matcher(probeLine
);
1348 if (addrMatcher
.matches()) {
1349 String addr
= addrMatcher
.group(2).trim();
1350 probeEvent
.setAddress(addr
);
1351 } else if (offsetMatcher
.matches()) {
1352 String offset
= offsetMatcher
.group(2).trim();
1353 probeEvent
.setOffset(offset
);
1354 } else if (symbolMatcher
.matches()) {
1355 String symbol
= symbolMatcher
.group(2).trim();
1356 probeEvent
.setSymbol(symbol
);
1357 } else if ((LTTngControlServiceConstants
.EVENT_PATTERN
.matcher(probeLine
).matches()) || (LTTngControlServiceConstants
.WILDCARD_EVENT_PATTERN
.matcher(probeLine
).matches())) {
1359 } else if (LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(probeLine
).matches()) {
1361 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(probeLine
).matches()) {
1364 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(probeLine
).matches()) {
1370 events
.add(eventInfo
);
1372 events
.add(eventInfo
);
1385 * Parses a line with attributes: <attribute Name>: <attribute value>
1388 * - attribute line to parse
1389 * @return the attribute value as string
1391 protected String
getAttributeValue(String line
) {
1392 String
[] temp
= line
.split("\\: "); //$NON-NLS-1$
1397 * Parses the event information within a provider.
1400 * a command output list
1401 * @param currentIndex
1402 * current index in command output list
1404 * list for returning event information
1405 * @return the new current index in command output list
1407 protected int getProviderEventInfo(List
<String
> output
, int currentIndex
, List
<IBaseEventInfo
> events
) {
1408 int index
= currentIndex
;
1409 IBaseEventInfo eventInfo
= null;
1410 while (index
< output
.size()) {
1411 String line
= output
.get(index
);
1412 Matcher matcher
= LTTngControlServiceConstants
.PROVIDER_EVENT_PATTERN
.matcher(line
);
1413 if (matcher
.matches()) {
1414 // sched_kthread_stop (loglevel: TRACE_EMERG0) (type:
1416 eventInfo
= new BaseEventInfo(matcher
.group(1).trim());
1417 eventInfo
.setLogLevel(matcher
.group(2).trim());
1418 eventInfo
.setEventType(matcher
.group(3).trim());
1419 events
.add(eventInfo
);
1421 } else if (LTTngControlServiceConstants
.EVENT_FIELD_PATTERN
.matcher(line
).matches()) {
1422 if (eventInfo
!= null) {
1423 List
<IFieldInfo
> fields
= new ArrayList
<>();
1424 index
= getFieldInfo(output
, index
, fields
);
1425 eventInfo
.setFields(fields
);
1429 } else if (LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
).matches()) {
1439 * Parse a field's information.
1442 * A command output list
1443 * @param currentIndex
1444 * The current index in the command output list
1446 * List for returning the field information
1447 * @return The new current index in the command output list
1449 protected int getFieldInfo(List
<String
> output
, int currentIndex
, List
<IFieldInfo
> fields
) {
1450 int index
= currentIndex
;
1451 IFieldInfo fieldInfo
= null;
1452 while (index
< output
.size()) {
1453 String line
= output
.get(index
);
1454 Matcher matcher
= LTTngControlServiceConstants
.EVENT_FIELD_PATTERN
.matcher(line
);
1455 if (matcher
.matches()) {
1456 // field: content (string)
1457 fieldInfo
= new FieldInfo(matcher
.group(2).trim());
1458 fieldInfo
.setFieldType(matcher
.group(3).trim());
1459 fields
.add(fieldInfo
);
1460 } else if (LTTngControlServiceConstants
.PROVIDER_EVENT_PATTERN
.matcher(line
).matches()) {
1462 } else if (LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
).matches()) {
1471 * Creates a command input instance
1474 * array of string that makes up a command line
1475 * @return {@link ICommandInput} instance
1477 protected @NonNull ICommandInput
createCommand(String
... segments
) {
1478 ICommandInput command
= fCommandShell
.createCommand();
1479 command
.add(LTTngControlServiceConstants
.CONTROL_COMMAND
);
1480 List
<@NonNull String
> groupOption
= getTracingGroupOption();
1481 if (!groupOption
.isEmpty()) {
1482 command
.addAll(groupOption
);
1484 String verboseOption
= getVerboseOption();
1485 if (!verboseOption
.isEmpty()) {
1486 command
.add(verboseOption
);
1488 for (String string
: segments
) {
1489 command
.add(checkNotNull(string
));
1495 * @return the tracing group option if configured in the preferences
1497 protected @NonNull List
<@NonNull String
> getTracingGroupOption() {
1498 List
<@NonNull String
> groupOption
= new ArrayList
<>();
1499 if (!ControlPreferences
.getInstance().isDefaultTracingGroup() && !ControlPreferences
.getInstance().getTracingGroup().equals("")) { //$NON-NLS-1$
1500 groupOption
.add(LTTngControlServiceConstants
.OPTION_TRACING_GROUP
);
1501 groupOption
.add(ControlPreferences
.getInstance().getTracingGroup());
1507 * @return the verbose option as configured in the preferences
1509 protected String
getVerboseOption() {
1510 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1511 String level
= ControlPreferences
.getInstance().getVerboseLevel();
1512 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_VERBOSE
.equals(level
)) {
1513 return LTTngControlServiceConstants
.OPTION_VERBOSE
;
1515 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_V_VERBOSE
.equals(level
)) {
1516 return LTTngControlServiceConstants
.OPTION_VERY_VERBOSE
;
1518 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_V_V_VERBOSE
.equals(level
)) {
1519 return LTTngControlServiceConstants
.OPTION_VERY_VERY_VERBOSE
;
1522 return ""; //$NON-NLS-1$
1526 * Method that logs the command and command result if logging is enabled as
1527 * well as forwards the command execution to the shell.
1530 * - the command to execute
1532 * - a progress monitor
1533 * @return the command result
1534 * @throws ExecutionException
1535 * If the command fails
1537 protected ICommandResult
executeCommand(@NonNull ICommandInput command
,
1538 @Nullable IProgressMonitor monitor
) throws ExecutionException
{
1539 return executeCommand(command
, monitor
, true);
1543 * Method that logs the command and command result if logging is enabled as
1544 * well as forwards the command execution to the shell.
1547 * - the command to execute
1549 * - a progress monitor
1550 * @param checkForError
1551 * - true to verify command result, else false
1552 * @return the command result
1553 * @throws ExecutionException
1554 * in case of error result
1556 protected ICommandResult
executeCommand(@NonNull ICommandInput command
,
1557 @Nullable IProgressMonitor monitor
, boolean checkForError
)
1558 throws ExecutionException
{
1559 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1560 ControlCommandLogger
.log(command
.toString());
1563 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
1565 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1566 ControlCommandLogger
.log(result
.toString());
1569 if (checkForError
&& isError(result
)) {
1570 throw new ExecutionException(Messages
.TraceControl_CommandError
1571 + " " + command
.toString() + "\n" + result
.toString()); //$NON-NLS-1$ //$NON-NLS-2$