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
.IUstProviderInfo
;
42 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.LogLevelType
;
43 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TraceEventType
;
44 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TraceLogLevel
;
45 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.BaseEventInfo
;
46 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.BufferType
;
47 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.ChannelInfo
;
48 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.DomainInfo
;
49 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.EventInfo
;
50 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.FieldInfo
;
51 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.ProbeEventInfo
;
52 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.SessionInfo
;
53 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.SnapshotInfo
;
54 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.UstProviderInfo
;
55 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.logging
.ControlCommandLogger
;
56 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.messages
.Messages
;
57 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.preferences
.ControlPreferences
;
58 import org
.eclipse
.tracecompass
.tmf
.remote
.core
.shell
.ICommandInput
;
59 import org
.eclipse
.tracecompass
.tmf
.remote
.core
.shell
.ICommandResult
;
60 import org
.eclipse
.tracecompass
.tmf
.remote
.core
.shell
.ICommandShell
;
64 * Service for sending LTTng trace control commands to remote host.
67 * @author Bernd Hufmann
69 public class LTTngControlService
implements ILttngControlService
{
71 // ------------------------------------------------------------------------
73 // ------------------------------------------------------------------------
75 * The command shell implementation
77 private final @NonNull ICommandShell fCommandShell
;
82 private @NonNull LttngVersion fVersion
= LttngVersion
.NULL_VERSION
;
84 // ------------------------------------------------------------------------
86 // ------------------------------------------------------------------------
92 * - the command shell implementation to use
94 public LTTngControlService(@NonNull ICommandShell shell
) {
95 fCommandShell
= shell
;
98 // ------------------------------------------------------------------------
100 // ------------------------------------------------------------------------
103 public String
getVersionString() {
104 return nullToEmptyString(fVersion
.toString());
108 public LttngVersion
getVersion() {
113 * Sets the version of the LTTng 2.0 control service.
118 public void setVersion(@Nullable String version
) {
119 if (version
!= null) {
120 fVersion
= new LttngVersion(version
);
125 * Sets the version of the LTTng 2.x control service.
130 protected void setVersion(LttngVersion version
) {
131 if (version
!= null) {
137 public boolean isVersionSupported(String version
) {
138 LttngVersion tmp
= new LttngVersion(version
);
139 return (fVersion
.compareTo(tmp
) >= 0) ?
true : false;
143 * Returns the command shell implementation.
145 * @return the command shell implementation
147 protected ICommandShell
getCommandShell() {
148 return fCommandShell
;
151 // ------------------------------------------------------------------------
153 // ------------------------------------------------------------------------
156 public List
<String
> getSessionNames(IProgressMonitor monitor
) throws ExecutionException
{
157 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST
);
159 ICommandResult result
= executeCommand(command
, monitor
);
162 // Available tracing sessions:
163 // 1) mysession1 (/home/user/lttng-traces/mysession1-20120123-083928)
165 // 2) mysession (/home/user/lttng-traces/mysession-20120123-083318)
168 // Use lttng list <session_name> for more details
170 ArrayList
<String
> retArray
= new ArrayList
<>();
171 for (String line
: result
.getOutput()) {
172 Matcher matcher
= LTTngControlServiceConstants
.SESSION_PATTERN
.matcher(line
);
173 if (matcher
.matches()) {
174 retArray
.add(matcher
.group(2).trim());
181 * Check if there is a pattern to be ignored into a sequence of string
184 * an input list of Strings
186 * the pattern to search for
187 * @return if the pattern exist in the array of string
189 protected boolean ignoredPattern(List
<String
> input
, Pattern pattern
) {
190 for (String line
: input
) {
191 Matcher matcher
= pattern
.matcher(line
);
192 if (matcher
.matches()) {
200 public ISessionInfo
getSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
201 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST
, sessionName
);
202 ICommandResult result
= executeCommand(command
, monitor
);
207 // Tracing session mysession2: [inactive]
208 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
209 ISessionInfo sessionInfo
= new SessionInfo(sessionName
);
211 while (index
< result
.getOutput().size()) {
212 // Tracing session mysession2: [inactive]
213 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
215 // === Domain: Kernel ===
217 String line
= result
.getOutput().get(index
);
218 Matcher matcher
= LTTngControlServiceConstants
.TRACE_SESSION_PATTERN
.matcher(line
);
219 if (matcher
.matches()) {
220 sessionInfo
.setSessionState(matcher
.group(2));
225 matcher
= LTTngControlServiceConstants
.TRACE_SNAPSHOT_SESSION_PATTERN
.matcher(line
);
226 if (matcher
.matches()) {
227 sessionInfo
.setSessionState(matcher
.group(2));
228 // real name will be set later
229 ISnapshotInfo snapshotInfo
= new SnapshotInfo(""); //$NON-NLS-1$
230 sessionInfo
.setSnapshotInfo(snapshotInfo
);
235 if (!sessionInfo
.isSnapshotSession()) {
236 matcher
= LTTngControlServiceConstants
.TRACE_NETWORK_PATH_PATTERN
.matcher(line
);
237 if (matcher
.matches()) {
238 sessionInfo
.setStreamedTrace(true);
241 matcher
= LTTngControlServiceConstants
.TRACE_SESSION_PATH_PATTERN
.matcher(line
);
242 if (matcher
.matches()) {
243 sessionInfo
.setSessionPath(matcher
.group(1).trim());
249 matcher
= LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(line
);
250 if (matcher
.matches()) {
252 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_KernelDomainDisplayName
);
255 domainInfo
.setIsKernel(true);
258 ArrayList
<IChannelInfo
> channels
= new ArrayList
<>();
259 index
= parseDomain(result
.getOutput(), index
, channels
, domainInfo
);
261 if (channels
.size() > 0) {
263 sessionInfo
.addDomain(domainInfo
);
266 domainInfo
.setChannels(channels
);
271 matcher
= LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
);
272 if (matcher
.matches()) {
273 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_UstGlobalDomainDisplayName
);
276 domainInfo
.setIsKernel(false);
279 ArrayList
<IChannelInfo
> channels
= new ArrayList
<>();
280 index
= parseDomain(result
.getOutput(), index
, channels
, domainInfo
);
282 if (channels
.size() > 0) {
284 sessionInfo
.addDomain(domainInfo
);
287 domainInfo
.setChannels(channels
);
291 matcher
= LTTngControlServiceConstants
.LIST_LIVE_TIMER_INTERVAL_PATTERN
.matcher(line
);
292 if (matcher
.matches()) {
293 long liveDelay
= Long
.parseLong(matcher
.group(1));
294 if ((liveDelay
> 0) && (liveDelay
<= LTTngControlServiceConstants
.MAX_LIVE_TIMER_INTERVAL
)) {
295 sessionInfo
.setLive(true);
296 sessionInfo
.setLiveUrl(SessionInfo
.DEFAULT_LIVE_NETWORK_URL
);
297 sessionInfo
.setLivePort(SessionInfo
.DEFAULT_LIVE_PORT
);
298 sessionInfo
.setLiveDelay(liveDelay
);
307 if (sessionInfo
.isSnapshotSession()) {
308 ISnapshotInfo snapshot
= getSnapshotInfo(sessionName
, monitor
);
309 sessionInfo
.setSnapshotInfo(snapshot
);
316 public ISnapshotInfo
getSnapshotInfo(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
317 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_SNAPSHOT
, LTTngControlServiceConstants
.COMMAND_LIST_SNAPSHOT_OUTPUT
, LTTngControlServiceConstants
.OPTION_SESSION
, sessionName
);
318 ICommandResult result
= executeCommand(command
, monitor
);
323 // [1] snapshot-1: /home/user/lttng-traces/my-20130909-114431
325 // [3] snapshot-3: net4://172.0.0.1/
326 ISnapshotInfo snapshotInfo
= new SnapshotInfo(""); //$NON-NLS-1$
328 while (index
< result
.getOutput().size()) {
329 String line
= result
.getOutput().get(index
);
330 Matcher matcher
= LTTngControlServiceConstants
.LIST_SNAPSHOT_OUTPUT_PATTERN
.matcher(line
);
331 if (matcher
.matches()) {
332 snapshotInfo
.setId(Integer
.valueOf(matcher
.group(1)));
333 snapshotInfo
.setName(matcher
.group(2));
334 snapshotInfo
.setSnapshotPath(matcher
.group(3));
336 Matcher matcher2
= LTTngControlServiceConstants
.SNAPSHOT_NETWORK_PATH_PATTERN
.matcher(snapshotInfo
.getSnapshotPath());
337 if (matcher2
.matches()) {
338 snapshotInfo
.setStreamedSnapshot(true);
351 public List
<IBaseEventInfo
> getKernelProvider(IProgressMonitor monitor
) throws ExecutionException
{
352 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST
, LTTngControlServiceConstants
.OPTION_KERNEL
);
353 ICommandResult result
= executeCommand(command
, monitor
, false);
355 List
<IBaseEventInfo
> events
= new ArrayList
<>();
357 // Ignore the following 2 cases:
358 // Spawning a session daemon
359 // Error: Unable to list kernel events
361 // Error: Unable to list kernel events
363 if (ignoredPattern(result
.getErrorOutput(), LTTngControlServiceConstants
.LIST_KERNEL_NO_KERNEL_PROVIDER_PATTERN
)) {
367 if (isError(result
)) {
368 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + result
.toString()); //$NON-NLS-1$ //$NON-NLS-2$
373 // sched_kthread_stop (type: tracepoint)
374 getProviderEventInfo(result
.getOutput(), 0, events
);
379 public List
<IUstProviderInfo
> getUstProvider() throws ExecutionException
{
380 return getUstProvider(new NullProgressMonitor());
384 public List
<IUstProviderInfo
> getUstProvider(IProgressMonitor monitor
) throws ExecutionException
{
385 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST
, LTTngControlServiceConstants
.OPTION_UST
);
387 if (isVersionSupported("2.1.0")) { //$NON-NLS-1$
388 command
.add(LTTngControlServiceConstants
.OPTION_FIELDS
);
391 ICommandResult result
= executeCommand(command
, monitor
, false);
392 List
<IUstProviderInfo
> allProviders
= new ArrayList
<>();
394 // Workaround for versions 2.0.x which causes a segmentation fault for
396 // if LTTng Tools is compiled without UST support.
397 if (!isVersionSupported("2.1.0") && (result
.getResult() != 0)) { //$NON-NLS-1$
401 // Ignore the following 2 cases:
402 // Spawning a session daemon
403 // Error: Unable to list UST events: Listing UST events failed
405 // Error: Unable to list UST events: Listing UST events failed
407 if (ignoredPattern(result
.getErrorOutput(), LTTngControlServiceConstants
.LIST_UST_NO_UST_PROVIDER_PATTERN
)) {
411 if (isError(result
)) {
412 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + result
.toString()); //$NON-NLS-1$ //$NON-NLS-2$
415 // Note that field print-outs exists for version >= 2.1.0
421 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
422 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
424 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
425 // field: doublefield (float)
426 // field: floatfield (float)
427 // field: stringfield (string)
430 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
431 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
433 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
434 // field: doublefield (float)
435 // field: floatfield (float)
436 // field: stringfield (string)
438 IUstProviderInfo provider
= null;
441 while (index
< result
.getOutput().size()) {
442 String line
= result
.getOutput().get(index
);
443 Matcher matcher
= LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
);
444 if (matcher
.matches()) {
445 provider
= new UstProviderInfo(matcher
.group(2).trim());
446 provider
.setPid(Integer
.valueOf(matcher
.group(1).trim()));
447 List
<IBaseEventInfo
> events
= new ArrayList
<>();
448 index
= getProviderEventInfo(result
.getOutput(), ++index
, events
);
449 provider
.setEvents(events
);
450 allProviders
.add(provider
);
459 public ISessionInfo
createSession(ISessionInfo sessionInfo
, IProgressMonitor monitor
) throws ExecutionException
{
460 if (sessionInfo
.isStreamedTrace()) {
461 return createStreamedSession(sessionInfo
, monitor
);
464 ICommandInput command
= prepareSessionCreationCommand(sessionInfo
);
466 ICommandResult result
= executeCommand(command
, monitor
);
468 // Session myssession2 created.
469 // Traces will be written in
470 // /home/user/lttng-traces/myssession2-20120209-095418
471 List
<String
> output
= result
.getOutput();
473 // Get and session name and path
477 for (String line
: output
) {
478 Matcher nameMatcher
= LTTngControlServiceConstants
.CREATE_SESSION_NAME_PATTERN
.matcher(line
);
479 Matcher pathMatcher
= LTTngControlServiceConstants
.CREATE_SESSION_PATH_PATTERN
.matcher(line
);
480 if (nameMatcher
.matches()) {
481 name
= String
.valueOf(nameMatcher
.group(1).trim());
482 } else if (pathMatcher
.matches()) {
483 path
= String
.valueOf(pathMatcher
.group(1).trim());
487 // Verify session name
488 if ((name
== null) || (!"".equals(sessionInfo
.getName()) && !name
.equals(sessionInfo
.getName()))) { //$NON-NLS-1$
489 // Unexpected name returned
490 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
491 Messages
.TraceControl_UnexpectedNameError
+ ": " + name
); //$NON-NLS-1$
494 sessionInfo
.setName(name
);
495 // Verify session path
496 if (!sessionInfo
.isSnapshotSession() &&
497 ((path
== null) || ((sessionInfo
.getSessionPath() != null) && (!path
.contains(sessionInfo
.getSessionPath()))))) {
499 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
500 Messages
.TraceControl_UnexpectedPathError
+ ": " + name
); //$NON-NLS-1$
503 if (sessionInfo
.isSnapshotSession()) {
504 // Make it a snapshot session - content of snapshot info need to
505 // set afterwards using getSession() or getSnapshotInfo()
506 sessionInfo
.setSnapshotInfo(new SnapshotInfo("")); //$NON-NLS-1$
508 sessionInfo
.setSessionPath(path
);
516 * Basic generation of command for session creation
519 * the session to create
520 * @return the basic command for command creation
522 protected @NonNull ICommandInput
prepareSessionCreationCommand(ISessionInfo sessionInfo
) {
523 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_CREATE_SESSION
);
524 if (!sessionInfo
.getName().isEmpty()) {
525 command
.add(sessionInfo
.getName());
528 String newPath
= sessionInfo
.getSessionPath();
529 if (newPath
!= null && !"".equals(newPath
)) { //$NON-NLS-1$
530 command
.add(LTTngControlServiceConstants
.OPTION_OUTPUT_PATH
);
531 command
.add(newPath
);
534 if (sessionInfo
.isSnapshotSession()) {
535 command
.add(LTTngControlServiceConstants
.OPTION_SNAPSHOT
);
540 private @NonNull ISessionInfo
createStreamedSession(ISessionInfo sessionInfo
, IProgressMonitor monitor
) throws ExecutionException
{
542 ICommandInput command
= prepareStreamedSessionCreationCommand(sessionInfo
);
544 ICommandResult result
= executeCommand(command
, monitor
);
547 List
<String
> output
= result
.getOutput();
549 // Get and session name and path
553 for (String line
: output
) {
554 Matcher nameMatcher
= LTTngControlServiceConstants
.CREATE_SESSION_NAME_PATTERN
.matcher(line
);
555 Matcher pathMatcher
= LTTngControlServiceConstants
.CREATE_SESSION_PATH_PATTERN
.matcher(line
);
557 if (nameMatcher
.matches()) {
558 name
= String
.valueOf(nameMatcher
.group(1).trim());
559 } else if (pathMatcher
.matches() && (sessionInfo
.getNetworkUrl() != null)) {
560 path
= String
.valueOf(pathMatcher
.group(1).trim());
564 // Verify session name
565 if ((name
== null) || (!"".equals(sessionInfo
.getName()) && !name
.equals(sessionInfo
.getName()))) { //$NON-NLS-1$
566 // Unexpected name returned
567 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
568 Messages
.TraceControl_UnexpectedNameError
+ ": " + name
); //$NON-NLS-1$
571 sessionInfo
.setName(name
);
573 sessionInfo
.setStreamedTrace(true);
575 // Verify session path
576 if (sessionInfo
.getNetworkUrl() != null) {
577 if (!sessionInfo
.isSnapshotSession() && (path
== null)) {
579 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
580 Messages
.TraceControl_UnexpectedPathError
+ ": " + name
); //$NON-NLS-1$
583 if (sessionInfo
.isSnapshotSession()) {
584 sessionInfo
.setStreamedTrace(false);
586 sessionInfo
.setSessionPath(path
);
587 // Check file protocol
588 Matcher matcher
= LTTngControlServiceConstants
.TRACE_FILE_PROTOCOL_PATTERN
.matcher(path
);
589 if (matcher
.matches()) {
590 sessionInfo
.setStreamedTrace(false);
595 // When using controlUrl and dataUrl the full session path is not known
596 // yet and will be set later on when listing the session
602 * Basic generation of command for streamed session creation
605 * the session to create
606 * @return the basic command for command creation
608 protected @NonNull ICommandInput
prepareStreamedSessionCreationCommand(ISessionInfo sessionInfo
) {
609 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_CREATE_SESSION
);
610 if (!sessionInfo
.getName().isEmpty()) {
611 command
.add(sessionInfo
.getName());
614 if (sessionInfo
.isSnapshotSession()) {
615 command
.add(LTTngControlServiceConstants
.OPTION_SNAPSHOT
);
616 } else if (sessionInfo
.isLive()) {
617 command
.add(LTTngControlServiceConstants
.OPTION_LIVE
);
618 if (sessionInfo
.getLiveDelay() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
619 command
.add(String
.valueOf(sessionInfo
.getLiveDelay()));
623 if (sessionInfo
.getNetworkUrl() != null) {
624 command
.add(LTTngControlServiceConstants
.OPTION_NETWORK_URL
);
625 command
.add(sessionInfo
.getNetworkUrl());
627 command
.add(LTTngControlServiceConstants
.OPTION_CONTROL_URL
);
628 command
.add(sessionInfo
.getControlUrl());
630 command
.add(LTTngControlServiceConstants
.OPTION_DATA_URL
);
631 command
.add(sessionInfo
.getDataUrl());
637 public void destroySession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
639 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_DESTROY_SESSION
, sessionName
);
641 ICommandResult result
= executeCommand(command
, monitor
, false);
642 boolean isError
= isError(result
);
643 if (isError
&& !ignoredPattern(result
.getErrorOutput(), LTTngControlServiceConstants
.SESSION_NOT_FOUND_ERROR_PATTERN
)) {
644 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + result
.toString()); //$NON-NLS-1$ //$NON-NLS-2$
647 // Session <sessionName> destroyed
651 public void startSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
653 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_START_SESSION
, sessionName
);
655 executeCommand(command
, monitor
);
657 // Session <sessionName> started
661 public void stopSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
662 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_STOP_SESSION
, sessionName
);
664 executeCommand(command
, monitor
);
666 // Session <sessionName> stopped
671 public void enableChannels(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IChannelInfo info
, IProgressMonitor monitor
) throws ExecutionException
{
673 // no channels to enable
674 if (channelNames
.isEmpty()) {
678 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_CHANNEL
);
680 command
.add(toCsv(channelNames
));
683 command
.add(LTTngControlServiceConstants
.OPTION_KERNEL
);
685 command
.add(LTTngControlServiceConstants
.OPTION_UST
);
688 command
.add(LTTngControlServiceConstants
.OPTION_SESSION
);
689 command
.add(sessionName
);
692 // --discard Discard event when buffers are full (default)
694 // --overwrite Flight recorder mode
695 if (info
.isOverwriteMode()) {
696 command
.add(LTTngControlServiceConstants
.OPTION_OVERWRITE
);
698 // --subbuf-size SIZE Subbuffer size in bytes
699 // (default: 4096, kernel default: 262144)
700 if (info
.getSubBufferSize() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
701 command
.add(LTTngControlServiceConstants
.OPTION_SUB_BUFFER_SIZE
);
702 command
.add(String
.valueOf(info
.getSubBufferSize()));
705 // --num-subbuf NUM Number of subbufers
706 if (info
.getNumberOfSubBuffers() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
707 command
.add(LTTngControlServiceConstants
.OPTION_NUM_SUB_BUFFERS
);
708 command
.add(String
.valueOf(info
.getNumberOfSubBuffers()));
711 // --switch-timer USEC Switch timer interval in usec
712 if (info
.getSwitchTimer() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
713 command
.add(LTTngControlServiceConstants
.OPTION_SWITCH_TIMER
);
714 command
.add(String
.valueOf(info
.getSwitchTimer()));
717 // --read-timer USEC Read timer interval in usec
718 if (info
.getReadTimer() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
719 command
.add(LTTngControlServiceConstants
.OPTION_READ_TIMER
);
720 command
.add(String
.valueOf(info
.getReadTimer()));
723 if (isVersionSupported("2.2.0")) { //$NON-NLS-1$
724 // --buffers-uid Every application sharing the same UID use the
725 // same buffers --buffers-pid Buffers are allocated per PID
727 if (info
.getBufferType() == BufferType
.BUFFER_PER_PID
) {
728 command
.add(LTTngControlServiceConstants
.OPTION_PER_PID_BUFFERS
);
730 } else if (info
.getBufferType() == BufferType
.BUFFER_PER_UID
) {
731 command
.add(LTTngControlServiceConstants
.OPTION_PER_UID_BUFFERS
);
735 // -C SIZE Maximum size of trace files in bytes
736 if (info
.getMaxSizeTraceFiles() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
737 command
.add(LTTngControlServiceConstants
.OPTION_MAX_SIZE_TRACE_FILES
);
738 command
.add(String
.valueOf(info
.getMaxSizeTraceFiles()));
741 // -W NUM Maximum number of trace files
742 if (info
.getMaxNumberTraceFiles() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
743 command
.add(LTTngControlServiceConstants
.OPTION_MAX_TRACE_FILES
);
744 command
.add(String
.valueOf(info
.getMaxNumberTraceFiles()));
749 executeCommand(command
, monitor
);
754 public void disableChannels(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
756 // no channels to enable
757 if (channelNames
.isEmpty()) {
761 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_DISABLE_CHANNEL
);
763 command
.add(toCsv(channelNames
));
766 command
.add(LTTngControlServiceConstants
.OPTION_KERNEL
);
768 command
.add(LTTngControlServiceConstants
.OPTION_UST
);
771 command
.add(LTTngControlServiceConstants
.OPTION_SESSION
);
772 command
.add(sessionName
);
774 executeCommand(command
, monitor
);
778 public void enableEvents(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, String filterExpression
, List
<String
> excludedEvents
, IProgressMonitor monitor
) throws ExecutionException
{
780 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
781 boolean isAllEvents
= ALL_EVENTS
.equals(eventNames
);
783 if (isAllEvents
|| (eventNames
== null) || (eventNames
.isEmpty())) {
784 command
.add(LTTngControlServiceConstants
.OPTION_ALL
);
786 command
.add(toCsv(eventNames
));
790 command
.add(LTTngControlServiceConstants
.OPTION_KERNEL
);
792 command
.add(LTTngControlServiceConstants
.OPTION_UST
);
795 command
.add(LTTngControlServiceConstants
.OPTION_SESSION
);
796 command
.add(sessionName
);
798 if (channelName
!= null) {
799 command
.add(LTTngControlServiceConstants
.OPTION_CHANNEL
);
800 command
.add(channelName
);
804 command
.add(LTTngControlServiceConstants
.OPTION_TRACEPOINT
);
807 if (filterExpression
!= null) {
808 command
.add(LTTngControlServiceConstants
.OPTION_FILTER
);
809 command
.add(filterExpression
);
812 if (excludedEvents
!= null && !excludedEvents
.isEmpty()) {
813 command
.add(LTTngControlServiceConstants
.OPTION_EXCLUDE
);
814 command
.add(toCsv(excludedEvents
));
817 executeCommand(command
, monitor
);
821 public void enableSyscalls(String sessionName
, String channelName
, IProgressMonitor monitor
) throws ExecutionException
{
823 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
825 command
.add(LTTngControlServiceConstants
.OPTION_ALL
);
826 command
.add(LTTngControlServiceConstants
.OPTION_KERNEL
);
828 command
.add(LTTngControlServiceConstants
.OPTION_SESSION
);
829 command
.add(sessionName
);
831 if (channelName
!= null) {
832 command
.add(LTTngControlServiceConstants
.OPTION_CHANNEL
);
833 command
.add(channelName
);
836 command
.add(LTTngControlServiceConstants
.OPTION_SYSCALL
);
838 executeCommand(command
, monitor
);
842 public void enableProbe(String sessionName
, String channelName
, String eventName
, boolean isFunction
, String probe
, IProgressMonitor monitor
) throws ExecutionException
{
843 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
845 command
.add(eventName
);
846 command
.add(LTTngControlServiceConstants
.OPTION_KERNEL
);
848 command
.add(LTTngControlServiceConstants
.OPTION_SESSION
);
849 command
.add(sessionName
);
851 if (channelName
!= null) {
852 command
.add(LTTngControlServiceConstants
.OPTION_CHANNEL
);
853 command
.add(channelName
);
856 command
.add(LTTngControlServiceConstants
.OPTION_FUNCTION_PROBE
);
858 command
.add(LTTngControlServiceConstants
.OPTION_PROBE
);
863 executeCommand(command
, monitor
);
867 public void enableLogLevel(String sessionName
, String channelName
, String eventName
, LogLevelType logLevelType
, TraceLogLevel level
, String filterExpression
, IProgressMonitor monitor
) throws ExecutionException
{
868 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
870 command
.add(eventName
);
871 command
.add(LTTngControlServiceConstants
.OPTION_UST
);
873 command
.add(LTTngControlServiceConstants
.OPTION_SESSION
);
874 command
.add(sessionName
);
876 if (channelName
!= null) {
877 command
.add(LTTngControlServiceConstants
.OPTION_CHANNEL
);
878 command
.add(channelName
);
881 if (logLevelType
== LogLevelType
.LOGLEVEL
) {
882 command
.add(LTTngControlServiceConstants
.OPTION_LOGLEVEL
);
883 } else if (logLevelType
== LogLevelType
.LOGLEVEL_ONLY
) {
884 command
.add(LTTngControlServiceConstants
.OPTION_LOGLEVEL_ONLY
);
889 command
.add(level
.getInName());
891 executeCommand(command
, monitor
);
895 public void disableEvent(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
896 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_DISABLE_EVENT
);
898 if (eventNames
== null) {
899 command
.add(LTTngControlServiceConstants
.OPTION_ALL
);
901 // no events to disable
902 if (eventNames
.isEmpty()) {
906 StringBuffer eventNameParameter
= new StringBuffer();
907 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
908 String event
= iterator
.next();
909 eventNameParameter
.append(event
);
910 if (iterator
.hasNext()) {
911 eventNameParameter
.append(',');
914 command
.add(eventNameParameter
.toString());
918 command
.add(LTTngControlServiceConstants
.OPTION_KERNEL
);
920 command
.add(LTTngControlServiceConstants
.OPTION_UST
);
923 command
.add(LTTngControlServiceConstants
.OPTION_SESSION
);
924 command
.add(sessionName
);
926 if (channelName
!= null) {
927 command
.add(LTTngControlServiceConstants
.OPTION_CHANNEL
);
928 command
.add(channelName
);
931 executeCommand(command
, monitor
);
935 public List
<String
> getContextList(IProgressMonitor monitor
) throws ExecutionException
{
937 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_ADD_CONTEXT
, LTTngControlServiceConstants
.OPTION_HELP
);
939 ICommandResult result
= executeCommand(command
, monitor
);
941 List
<String
> output
= result
.getOutput();
943 List
<String
> contexts
= new ArrayList
<>(0);
946 boolean inList
= false;
947 while (index
< output
.size()) {
948 String line
= output
.get(index
);
950 Matcher startMatcher
= LTTngControlServiceConstants
.ADD_CONTEXT_HELP_CONTEXTS_INTRO
.matcher(line
);
951 Matcher endMatcher
= LTTngControlServiceConstants
.ADD_CONTEXT_HELP_CONTEXTS_END_LINE
.matcher(line
);
953 if (startMatcher
.matches()) {
955 } else if (endMatcher
.matches()) {
958 String
[] tmp
= line
.split(","); //$NON-NLS-1$
959 for (int i
= 0; i
< tmp
.length
; i
++) {
960 contexts
.add(tmp
[i
].trim());
969 public void addContexts(String sessionName
, String channelName
, String eventName
, boolean isKernel
, List
<String
> contextNames
, IProgressMonitor monitor
) throws ExecutionException
{
970 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_ADD_CONTEXT
);
972 command
.add(LTTngControlServiceConstants
.OPTION_SESSION
);
973 command
.add(sessionName
);
975 if (channelName
!= null) {
976 command
.add(LTTngControlServiceConstants
.OPTION_CHANNEL
);
977 command
.add(channelName
);
980 if (eventName
!= null) {
981 command
.add(LTTngControlServiceConstants
.OPTION_EVENT
);
982 command
.add(eventName
);
986 command
.add(LTTngControlServiceConstants
.OPTION_KERNEL
);
988 command
.add(LTTngControlServiceConstants
.OPTION_UST
);
991 for (Iterator
<String
> iterator
= contextNames
.iterator(); iterator
.hasNext();) {
992 String context
= iterator
.next();
993 command
.add(LTTngControlServiceConstants
.OPTION_CONTEXT_TYPE
);
994 command
.add(context
);
997 executeCommand(command
, monitor
);
1002 public void recordSnapshot(String sessionName
, IProgressMonitor monitor
)
1003 throws ExecutionException
{
1004 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_SNAPSHOT
, LTTngControlServiceConstants
.COMMAND_RECORD_SNAPSHOT
);
1006 String newSessionName
= sessionName
;
1007 command
.add(LTTngControlServiceConstants
.OPTION_SESSION
);
1008 command
.add(newSessionName
);
1010 executeCommand(command
, monitor
);
1014 public void loadSession(String inputPath
, boolean isForce
, IProgressMonitor monitor
)
1015 throws ExecutionException
{
1016 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_LOAD_SESSION
);
1018 if (inputPath
!= null) {
1019 command
.add(LTTngControlServiceConstants
.OPTION_INPUT_PATH
);
1020 command
.add(inputPath
);
1024 command
.add(LTTngControlServiceConstants
.OPTION_FORCE
);
1026 executeCommand(command
, monitor
);
1030 public void saveSession(String session
, String outputPath
, boolean isForce
, IProgressMonitor monitor
) throws ExecutionException
{
1031 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_SAVE_SESSION
);
1033 if (outputPath
!= null) {
1034 command
.add(LTTngControlServiceConstants
.OPTION_OUTPUT_PATH
);
1035 command
.add(outputPath
);
1039 command
.add(LTTngControlServiceConstants
.OPTION_FORCE
);
1042 if (session
!= null) {
1043 command
.add(session
);
1045 executeCommand(command
, monitor
);
1049 public void runCommands(IProgressMonitor monitor
, List
<String
> commandLines
) throws ExecutionException
{
1050 for (String commandLine
: commandLines
) {
1051 if (monitor
.isCanceled()) {
1055 if (commandLine
.isEmpty() || commandLine
.startsWith("#")) { //$NON-NLS-1$
1058 String
[] args
= commandLine
.split("\\s+"); //$NON-NLS-1$
1059 ICommandInput command
= fCommandShell
.createCommand();
1060 command
.addAll(Arrays
.asList(args
));
1061 ICommandResult result
= executeCommand(command
, monitor
);
1063 if (isError(result
)) {
1064 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + result
.toString()); //$NON-NLS-1$ //$NON-NLS-2$
1069 // ------------------------------------------------------------------------
1071 // ------------------------------------------------------------------------
1073 private static void setFilterExpression(IEventInfo eventInfo
, String filter
) {
1074 // remove '[' and ']'
1075 String temp
= filter
.substring(1, filter
.length() - 1);
1076 if (temp
.equals(LTTngControlServiceConstants
.HAS_EXCLUSIONS
)) {
1077 eventInfo
.setExcludedEvents(temp
);
1079 eventInfo
.setFilterExpression(temp
);
1084 * Checks if command result is an error result.
1087 * - the command result to check
1088 * @return true if error else false
1090 protected boolean isError(ICommandResult result
) {
1091 // Check return code and length of returned strings
1093 if ((result
.getResult()) != 0) {
1097 // Look for error pattern
1098 for (String line
: result
.getErrorOutput()) {
1099 Matcher matcher
= LTTngControlServiceConstants
.ERROR_PATTERN
.matcher(line
);
1100 if (matcher
.matches()) {
1109 * Creates a comma separated string from list of names
1112 * List of name to convert
1113 * @return comma separated string
1115 protected String
toCsv(List
<String
> names
) {
1116 StringBuilder csvString
= new StringBuilder();
1117 for (Iterator
<String
> iterator
= names
.iterator(); iterator
.hasNext();) {
1118 String name
= iterator
.next();
1119 csvString
.append(name
);
1120 if (iterator
.hasNext()) {
1121 csvString
.append(',');
1124 return csvString
.toString();
1128 * Parses the domain information.
1131 * a command output list
1132 * @param currentIndex
1133 * current index in command output list
1135 * list for returning channel information
1137 * The domain information
1138 * @return the new current index in command output list
1140 protected int parseDomain(List
<String
> output
, int currentIndex
, List
<IChannelInfo
> channels
, IDomainInfo domainInfo
) {
1141 int index
= currentIndex
;
1143 // if kernel set the buffer type to shared
1144 if (domainInfo
.isKernel()) {
1145 domainInfo
.setBufferType(BufferType
.BUFFER_SHARED
);
1150 // - channnel1: [enabled]
1153 // overwrite mode: 0
1154 // subbufers size: 262144
1155 // number of subbufers: 4
1156 // switch timer interval: 0
1157 // read timer interval: 200
1160 while (index
< output
.size()) {
1161 String line
= output
.get(index
);
1163 if (isVersionSupported("2.2.0")) { //$NON-NLS-1$
1164 Matcher bufferTypeMatcher
= LTTngControlServiceConstants
.BUFFER_TYPE_PATTERN
.matcher(line
);
1165 if (bufferTypeMatcher
.matches()) {
1166 String bufferTypeString
= getAttributeValue(line
);
1167 if (BufferType
.BUFFER_PER_PID
.getInName().equals(bufferTypeString
)) {
1168 domainInfo
.setBufferType(BufferType
.BUFFER_PER_PID
);
1169 } else if (BufferType
.BUFFER_PER_UID
.getInName().equals(bufferTypeString
)) {
1170 domainInfo
.setBufferType(BufferType
.BUFFER_PER_UID
);
1172 domainInfo
.setBufferType(BufferType
.BUFFER_TYPE_UNKNOWN
);
1176 domainInfo
.setBufferType(BufferType
.BUFFER_TYPE_UNKNOWN
);
1178 Matcher outerMatcher
= LTTngControlServiceConstants
.CHANNELS_SECTION_PATTERN
.matcher(line
);
1179 Matcher noKernelChannelMatcher
= LTTngControlServiceConstants
.DOMAIN_NO_KERNEL_CHANNEL_PATTERN
.matcher(line
);
1180 Matcher noUstChannelMatcher
= LTTngControlServiceConstants
.DOMAIN_NO_UST_CHANNEL_PATTERN
.matcher(line
);
1181 if (outerMatcher
.matches()) {
1182 IChannelInfo channelInfo
= null;
1183 while (index
< output
.size()) {
1184 String subLine
= output
.get(index
);
1186 Matcher innerMatcher
= LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(subLine
);
1187 if (innerMatcher
.matches()) {
1188 channelInfo
= new ChannelInfo(""); //$NON-NLS-1$
1190 channelInfo
.setName(innerMatcher
.group(1));
1192 // get channel enablement
1193 channelInfo
.setState(innerMatcher
.group(2));
1196 channelInfo
.setBufferType(domainInfo
.getBufferType());
1199 channels
.add(channelInfo
);
1201 } else if (LTTngControlServiceConstants
.OVERWRITE_MODE_ATTRIBUTE
.matcher(subLine
).matches()) {
1202 String value
= getAttributeValue(subLine
);
1203 if (channelInfo
!= null) {
1204 channelInfo
.setOverwriteMode(!LTTngControlServiceConstants
.OVERWRITE_MODE_ATTRIBUTE_FALSE
.equals(value
));
1206 } else if (LTTngControlServiceConstants
.SUBBUFFER_SIZE_ATTRIBUTE
.matcher(subLine
).matches()) {
1207 if (channelInfo
!= null) {
1208 channelInfo
.setSubBufferSize(Long
.valueOf(getAttributeValue(subLine
)));
1211 } else if (LTTngControlServiceConstants
.NUM_SUBBUFFERS_ATTRIBUTE
.matcher(subLine
).matches()) {
1212 if (channelInfo
!= null) {
1213 channelInfo
.setNumberOfSubBuffers(Integer
.valueOf(getAttributeValue(subLine
)));
1216 } else if (LTTngControlServiceConstants
.SWITCH_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
1217 if (channelInfo
!= null) {
1218 channelInfo
.setSwitchTimer(Long
.valueOf(getAttributeValue(subLine
)));
1221 } else if (LTTngControlServiceConstants
.READ_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
1222 if (channelInfo
!= null) {
1223 channelInfo
.setReadTimer(Long
.valueOf(getAttributeValue(subLine
)));
1226 } else if (LTTngControlServiceConstants
.OUTPUT_ATTRIBUTE
.matcher(subLine
).matches()) {
1227 if (channelInfo
!= null) {
1228 channelInfo
.setOutputType(getAttributeValue(subLine
));
1231 } else if (LTTngControlServiceConstants
.TRACE_FILE_COUNT_ATTRIBUTE
.matcher(subLine
).matches()) {
1232 if (channelInfo
!= null) {
1233 channelInfo
.setMaxNumberTraceFiles(Integer
.valueOf(getAttributeValue(subLine
)));
1236 } else if (LTTngControlServiceConstants
.TRACE_FILE_SIZE_ATTRIBUTE
.matcher(subLine
).matches()) {
1237 if (channelInfo
!= null) {
1238 channelInfo
.setMaxSizeTraceFiles(Long
.valueOf(getAttributeValue(subLine
)));
1240 } else if (LTTngControlServiceConstants
.EVENT_SECTION_PATTERN
.matcher(subLine
).matches()) {
1241 List
<IEventInfo
> events
= new ArrayList
<>();
1242 index
= parseEvents(output
, index
, events
);
1243 if (channelInfo
!= null) {
1244 channelInfo
.setEvents(events
);
1246 // we want to stay at the current index to be able to
1249 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(subLine
).matches()) {
1252 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(subLine
).matches()) {
1257 } else if (noKernelChannelMatcher
.matches() || noUstChannelMatcher
.matches()) {
1258 // domain indicates that no channels were found -> return
1268 * Parses the event information within a domain.
1271 * a command output list
1272 * @param currentIndex
1273 * current index in command output list
1275 * list for returning event information
1276 * @return the new current index in command output list
1278 protected int parseEvents(List
<String
> output
, int currentIndex
, List
<IEventInfo
> events
) {
1279 int index
= currentIndex
;
1281 while (index
< output
.size()) {
1282 String line
= output
.get(index
);
1283 if (LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(line
).matches()) {
1286 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(line
).matches()) {
1289 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
).matches()) {
1294 Matcher matcher
= LTTngControlServiceConstants
.EVENT_PATTERN
.matcher(line
);
1295 Matcher matcher2
= LTTngControlServiceConstants
.WILDCARD_EVENT_PATTERN
.matcher(line
);
1297 if (matcher
.matches()) {
1298 IEventInfo eventInfo
= new EventInfo(matcher
.group(1).trim());
1299 eventInfo
.setLogLevelType(matcher
.group(2).trim());
1300 eventInfo
.setLogLevel(matcher
.group(3).trim());
1301 eventInfo
.setEventType(matcher
.group(4).trim());
1302 eventInfo
.setState(matcher
.group(5));
1303 String filter
= matcher
.group(6);
1304 if (filter
!= null) {
1305 setFilterExpression(eventInfo
, filter
);
1307 events
.add(eventInfo
);
1309 } else if (matcher2
.matches()) {
1310 IEventInfo eventInfo
= new EventInfo(matcher2
.group(1).trim());
1311 eventInfo
.setLogLevel(TraceLogLevel
.LEVEL_UNKNOWN
);
1312 eventInfo
.setEventType(matcher2
.group(2).trim());
1313 eventInfo
.setState(matcher2
.group(3));
1314 String filter
= matcher2
.group(4);
1315 if (filter
!= null) {
1316 setFilterExpression(eventInfo
, filter
);
1319 if ((eventInfo
.getEventType() == TraceEventType
.PROBE
) ||
1320 (eventInfo
.getEventType() == TraceEventType
.FUNCTION
)) {
1321 IProbeEventInfo probeEvent
= new ProbeEventInfo(eventInfo
.getName());
1322 probeEvent
.setLogLevel(eventInfo
.getLogLevel());
1323 probeEvent
.setEventType(eventInfo
.getEventType());
1324 probeEvent
.setState(eventInfo
.getState());
1326 // Overwrite eventinfo
1327 eventInfo
= probeEvent
;
1329 // myevent2 (type: probe) [enabled]
1331 // myevent0 (type: function) [enabled]
1333 // symbol: init_post
1335 while (index
< output
.size()) {
1336 String probeLine
= output
.get(index
);
1338 Matcher addrMatcher
= LTTngControlServiceConstants
.PROBE_ADDRESS_PATTERN
.matcher(probeLine
);
1339 Matcher offsetMatcher
= LTTngControlServiceConstants
.PROBE_OFFSET_PATTERN
.matcher(probeLine
);
1340 Matcher symbolMatcher
= LTTngControlServiceConstants
.PROBE_SYMBOL_PATTERN
.matcher(probeLine
);
1341 if (addrMatcher
.matches()) {
1342 String addr
= addrMatcher
.group(2).trim();
1343 probeEvent
.setAddress(addr
);
1344 } else if (offsetMatcher
.matches()) {
1345 String offset
= offsetMatcher
.group(2).trim();
1346 probeEvent
.setOffset(offset
);
1347 } else if (symbolMatcher
.matches()) {
1348 String symbol
= symbolMatcher
.group(2).trim();
1349 probeEvent
.setSymbol(symbol
);
1350 } else if ((LTTngControlServiceConstants
.EVENT_PATTERN
.matcher(probeLine
).matches()) || (LTTngControlServiceConstants
.WILDCARD_EVENT_PATTERN
.matcher(probeLine
).matches())) {
1352 } else if (LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(probeLine
).matches()) {
1354 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(probeLine
).matches()) {
1357 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(probeLine
).matches()) {
1363 events
.add(eventInfo
);
1365 events
.add(eventInfo
);
1378 * Parses a line with attributes: <attribute Name>: <attribute value>
1381 * - attribute line to parse
1382 * @return the attribute value as string
1384 protected String
getAttributeValue(String line
) {
1385 String
[] temp
= line
.split("\\: "); //$NON-NLS-1$
1390 * Parses the event information within a provider.
1393 * a command output list
1394 * @param currentIndex
1395 * current index in command output list
1397 * list for returning event information
1398 * @return the new current index in command output list
1400 protected int getProviderEventInfo(List
<String
> output
, int currentIndex
, List
<IBaseEventInfo
> events
) {
1401 int index
= currentIndex
;
1402 IBaseEventInfo eventInfo
= null;
1403 while (index
< output
.size()) {
1404 String line
= output
.get(index
);
1405 Matcher matcher
= LTTngControlServiceConstants
.PROVIDER_EVENT_PATTERN
.matcher(line
);
1406 if (matcher
.matches()) {
1407 // sched_kthread_stop (loglevel: TRACE_EMERG0) (type:
1409 eventInfo
= new BaseEventInfo(matcher
.group(1).trim());
1410 eventInfo
.setLogLevel(matcher
.group(2).trim());
1411 eventInfo
.setEventType(matcher
.group(3).trim());
1412 events
.add(eventInfo
);
1414 } else if (LTTngControlServiceConstants
.EVENT_FIELD_PATTERN
.matcher(line
).matches()) {
1415 if (eventInfo
!= null) {
1416 List
<IFieldInfo
> fields
= new ArrayList
<>();
1417 index
= getFieldInfo(output
, index
, fields
);
1418 eventInfo
.setFields(fields
);
1422 } else if (LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
).matches()) {
1432 * Parse a field's information.
1435 * A command output list
1436 * @param currentIndex
1437 * The current index in the command output list
1439 * List for returning the field information
1440 * @return The new current index in the command output list
1442 protected int getFieldInfo(List
<String
> output
, int currentIndex
, List
<IFieldInfo
> fields
) {
1443 int index
= currentIndex
;
1444 IFieldInfo fieldInfo
= null;
1445 while (index
< output
.size()) {
1446 String line
= output
.get(index
);
1447 Matcher matcher
= LTTngControlServiceConstants
.EVENT_FIELD_PATTERN
.matcher(line
);
1448 if (matcher
.matches()) {
1449 // field: content (string)
1450 fieldInfo
= new FieldInfo(matcher
.group(2).trim());
1451 fieldInfo
.setFieldType(matcher
.group(3).trim());
1452 fields
.add(fieldInfo
);
1453 } else if (LTTngControlServiceConstants
.PROVIDER_EVENT_PATTERN
.matcher(line
).matches()) {
1455 } else if (LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
).matches()) {
1464 * Creates a command input instance
1467 * array of string that makes up a command line
1468 * @return {@link ICommandInput} instance
1470 protected @NonNull ICommandInput
createCommand(String
... segments
) {
1471 ICommandInput command
= fCommandShell
.createCommand();
1472 command
.add(LTTngControlServiceConstants
.CONTROL_COMMAND
);
1473 List
<@NonNull String
> groupOption
= getTracingGroupOption();
1474 if (!groupOption
.isEmpty()) {
1475 command
.addAll(groupOption
);
1477 String verboseOption
= getVerboseOption();
1478 if (!verboseOption
.isEmpty()) {
1479 command
.add(verboseOption
);
1481 for (String string
: segments
) {
1482 command
.add(checkNotNull(string
));
1488 * @return the tracing group option if configured in the preferences
1490 protected @NonNull List
<@NonNull String
> getTracingGroupOption() {
1491 List
<@NonNull String
> groupOption
= new ArrayList
<>();
1492 if (!ControlPreferences
.getInstance().isDefaultTracingGroup() && !ControlPreferences
.getInstance().getTracingGroup().equals("")) { //$NON-NLS-1$
1493 groupOption
.add(LTTngControlServiceConstants
.OPTION_TRACING_GROUP
);
1494 groupOption
.add(ControlPreferences
.getInstance().getTracingGroup());
1500 * @return the verbose option as configured in the preferences
1502 protected String
getVerboseOption() {
1503 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1504 String level
= ControlPreferences
.getInstance().getVerboseLevel();
1505 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_VERBOSE
.equals(level
)) {
1506 return LTTngControlServiceConstants
.OPTION_VERBOSE
;
1508 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_V_VERBOSE
.equals(level
)) {
1509 return LTTngControlServiceConstants
.OPTION_VERY_VERBOSE
;
1511 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_V_V_VERBOSE
.equals(level
)) {
1512 return LTTngControlServiceConstants
.OPTION_VERY_VERY_VERBOSE
;
1515 return ""; //$NON-NLS-1$
1519 * Method that logs the command and command result if logging is enabled as
1520 * well as forwards the command execution to the shell.
1523 * - the command to execute
1525 * - a progress monitor
1526 * @return the command result
1527 * @throws ExecutionException
1528 * If the command fails
1530 protected ICommandResult
executeCommand(@NonNull ICommandInput command
,
1531 @Nullable IProgressMonitor monitor
) throws ExecutionException
{
1532 return executeCommand(command
, monitor
, true);
1536 * Method that logs the command and command result if logging is enabled as
1537 * well as forwards the command execution to the shell.
1540 * - the command to execute
1542 * - a progress monitor
1543 * @param checkForError
1544 * - true to verify command result, else false
1545 * @return the command result
1546 * @throws ExecutionException
1547 * in case of error result
1549 protected ICommandResult
executeCommand(@NonNull ICommandInput command
,
1550 @Nullable IProgressMonitor monitor
, boolean checkForError
)
1551 throws ExecutionException
{
1552 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1553 ControlCommandLogger
.log(command
.toString());
1556 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
1558 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1559 ControlCommandLogger
.log(result
.toString());
1562 if (checkForError
&& isError(result
)) {
1563 throw new ExecutionException(Messages
.TraceControl_CommandError
1564 + " " + command
.toString() + "\n" + result
.toString()); //$NON-NLS-1$ //$NON-NLS-2$