1 /**********************************************************************
2 * Copyright (c) 2012, 2015 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
{
72 // ------------------------------------------------------------------------
74 // ------------------------------------------------------------------------
76 * The command shell implementation
78 private final @NonNull ICommandShell fCommandShell
;
83 private @NonNull LttngVersion fVersion
= LttngVersion
.NULL_VERSION
;
85 // ------------------------------------------------------------------------
87 // ------------------------------------------------------------------------
93 * - the command shell implementation to use
95 public LTTngControlService(@NonNull ICommandShell shell
) {
96 fCommandShell
= shell
;
99 // ------------------------------------------------------------------------
101 // ------------------------------------------------------------------------
104 public String
getVersionString() {
105 return nullToEmptyString(fVersion
.toString());
109 public LttngVersion
getVersion() {
114 * Sets the version of the LTTng 2.0 control service.
119 public void setVersion(@Nullable String version
) {
120 if (version
!= null) {
121 fVersion
= new LttngVersion(version
);
126 * Sets the version of the LTTng 2.x control service.
131 public void setVersion(LttngVersion version
) {
132 if (version
!= null) {
138 public boolean isVersionSupported(String version
) {
139 LttngVersion tmp
= new LttngVersion(version
);
140 return (fVersion
.compareTo(tmp
) >= 0) ?
true : false;
144 * Returns the command shell implementation.
146 * @return the command shell implementation
148 protected ICommandShell
getCommandShell() {
149 return fCommandShell
;
152 // ------------------------------------------------------------------------
154 // ------------------------------------------------------------------------
157 public List
<String
> getSessionNames(IProgressMonitor monitor
) throws ExecutionException
{
158 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST
);
160 ICommandResult result
= executeCommand(command
, monitor
);
163 // Available tracing sessions:
164 // 1) mysession1 (/home/user/lttng-traces/mysession1-20120123-083928)
166 // 2) mysession (/home/user/lttng-traces/mysession-20120123-083318)
169 // Use lttng list <session_name> for more details
171 ArrayList
<String
> retArray
= new ArrayList
<>();
172 for (String line
: result
.getOutput()) {
173 Matcher matcher
= LTTngControlServiceConstants
.SESSION_PATTERN
.matcher(line
);
174 if (matcher
.matches()) {
175 retArray
.add(matcher
.group(2).trim());
182 * Check if there is a pattern to be ignored into a sequence of string
185 * an input list of Strings
187 * the pattern to search for
188 * @return if the pattern exist in the array of string
190 protected boolean ignoredPattern(List
<String
> input
, Pattern pattern
) {
191 for (String line
: input
) {
192 Matcher matcher
= pattern
.matcher(line
);
193 if (matcher
.matches()) {
201 public ISessionInfo
getSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
202 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST
, sessionName
);
203 ICommandResult result
= executeCommand(command
, monitor
);
208 // Tracing session mysession2: [inactive]
209 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
210 ISessionInfo sessionInfo
= new SessionInfo(sessionName
);
212 while (index
< result
.getOutput().size()) {
213 // Tracing session mysession2: [inactive]
214 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
216 // === Domain: Kernel ===
218 String line
= result
.getOutput().get(index
);
219 Matcher matcher
= LTTngControlServiceConstants
.TRACE_SESSION_PATTERN
.matcher(line
);
220 if (matcher
.matches()) {
221 sessionInfo
.setSessionState(matcher
.group(2));
226 matcher
= LTTngControlServiceConstants
.TRACE_SNAPSHOT_SESSION_PATTERN
.matcher(line
);
227 if (matcher
.matches()) {
228 sessionInfo
.setSessionState(matcher
.group(2));
229 // real name will be set later
230 ISnapshotInfo snapshotInfo
= new SnapshotInfo(""); //$NON-NLS-1$
231 sessionInfo
.setSnapshotInfo(snapshotInfo
);
236 if (!sessionInfo
.isSnapshotSession()) {
237 matcher
= LTTngControlServiceConstants
.TRACE_NETWORK_PATH_PATTERN
.matcher(line
);
238 if (matcher
.matches()) {
239 sessionInfo
.setStreamedTrace(true);
242 matcher
= LTTngControlServiceConstants
.TRACE_SESSION_PATH_PATTERN
.matcher(line
);
243 if (matcher
.matches()) {
244 sessionInfo
.setSessionPath(matcher
.group(1).trim());
250 matcher
= LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(line
);
251 if (matcher
.matches()) {
253 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_KernelDomainDisplayName
);
256 domainInfo
.setIsKernel(true);
259 ArrayList
<IChannelInfo
> channels
= new ArrayList
<>();
260 index
= parseDomain(result
.getOutput(), index
, channels
, domainInfo
);
262 if (channels
.size() > 0) {
264 sessionInfo
.addDomain(domainInfo
);
267 domainInfo
.setChannels(channels
);
272 matcher
= LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
);
273 if (matcher
.matches()) {
274 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_UstGlobalDomainDisplayName
);
277 domainInfo
.setIsKernel(false);
280 ArrayList
<IChannelInfo
> channels
= new ArrayList
<>();
281 index
= parseDomain(result
.getOutput(), index
, channels
, domainInfo
);
283 if (channels
.size() > 0) {
285 sessionInfo
.addDomain(domainInfo
);
288 domainInfo
.setChannels(channels
);
292 matcher
= LTTngControlServiceConstants
.LIST_LIVE_TIMER_INTERVAL_PATTERN
.matcher(line
);
293 if (matcher
.matches()) {
294 long liveDelay
= Long
.parseLong(matcher
.group(1));
295 if ((liveDelay
> 0) && (liveDelay
<= LTTngControlServiceConstants
.MAX_LIVE_TIMER_INTERVAL
)) {
296 sessionInfo
.setLive(true);
297 sessionInfo
.setLiveUrl(SessionInfo
.DEFAULT_LIVE_NETWORK_URL
);
298 sessionInfo
.setLivePort(SessionInfo
.DEFAULT_LIVE_PORT
);
299 sessionInfo
.setLiveDelay(liveDelay
);
308 if (sessionInfo
.isSnapshotSession()) {
309 ISnapshotInfo snapshot
= getSnapshotInfo(sessionName
, monitor
);
310 sessionInfo
.setSnapshotInfo(snapshot
);
317 public ISnapshotInfo
getSnapshotInfo(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
318 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_SNAPSHOT
, LTTngControlServiceConstants
.COMMAND_LIST_SNAPSHOT_OUTPUT
, LTTngControlServiceConstants
.OPTION_SESSION
, sessionName
);
319 ICommandResult result
= executeCommand(command
, monitor
);
324 // [1] snapshot-1: /home/user/lttng-traces/my-20130909-114431
326 // [3] snapshot-3: net4://172.0.0.1/
327 ISnapshotInfo snapshotInfo
= new SnapshotInfo(""); //$NON-NLS-1$
329 while (index
< result
.getOutput().size()) {
330 String line
= result
.getOutput().get(index
);
331 Matcher matcher
= LTTngControlServiceConstants
.LIST_SNAPSHOT_OUTPUT_PATTERN
.matcher(line
);
332 if (matcher
.matches()) {
333 snapshotInfo
.setId(Integer
.valueOf(matcher
.group(1)));
334 snapshotInfo
.setName(matcher
.group(2));
335 snapshotInfo
.setSnapshotPath(matcher
.group(3));
337 Matcher matcher2
= LTTngControlServiceConstants
.SNAPSHOT_NETWORK_PATH_PATTERN
.matcher(snapshotInfo
.getSnapshotPath());
338 if (matcher2
.matches()) {
339 snapshotInfo
.setStreamedSnapshot(true);
352 public List
<IBaseEventInfo
> getKernelProvider(IProgressMonitor monitor
) throws ExecutionException
{
353 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST
, LTTngControlServiceConstants
.OPTION_KERNEL
);
354 ICommandResult result
= executeCommand(command
, monitor
, false);
356 List
<IBaseEventInfo
> events
= new ArrayList
<>();
358 // Ignore the following 2 cases:
359 // Spawning a session daemon
360 // Error: Unable to list kernel events
362 // Error: Unable to list kernel events
364 if (ignoredPattern(result
.getErrorOutput(), LTTngControlServiceConstants
.LIST_KERNEL_NO_KERNEL_PROVIDER_PATTERN
)) {
368 if (isError(result
)) {
369 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + result
.toString()); //$NON-NLS-1$ //$NON-NLS-2$
374 // sched_kthread_stop (type: tracepoint)
375 getProviderEventInfo(result
.getOutput(), 0, events
);
380 public List
<IUstProviderInfo
> getUstProvider() throws ExecutionException
{
381 return getUstProvider(new NullProgressMonitor());
385 public List
<IUstProviderInfo
> getUstProvider(IProgressMonitor monitor
) throws ExecutionException
{
386 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST
, LTTngControlServiceConstants
.OPTION_UST
);
388 if (isVersionSupported("2.1.0")) { //$NON-NLS-1$
389 command
.add(LTTngControlServiceConstants
.OPTION_FIELDS
);
392 ICommandResult result
= executeCommand(command
, monitor
, false);
393 List
<IUstProviderInfo
> allProviders
= new ArrayList
<>();
395 // Workaround for versions 2.0.x which causes a segmentation fault for
397 // if LTTng Tools is compiled without UST support.
398 if (!isVersionSupported("2.1.0") && (result
.getResult() != 0)) { //$NON-NLS-1$
402 // Ignore the following 2 cases:
403 // Spawning a session daemon
404 // Error: Unable to list UST events: Listing UST events failed
406 // Error: Unable to list UST events: Listing UST events failed
408 if (ignoredPattern(result
.getErrorOutput(), LTTngControlServiceConstants
.LIST_UST_NO_UST_PROVIDER_PATTERN
)) {
412 if (isError(result
)) {
413 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + result
.toString()); //$NON-NLS-1$ //$NON-NLS-2$
416 // Note that field print-outs exists for version >= 2.1.0
422 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
423 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
425 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
426 // field: doublefield (float)
427 // field: floatfield (float)
428 // field: stringfield (string)
431 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
432 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
434 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
435 // field: doublefield (float)
436 // field: floatfield (float)
437 // field: stringfield (string)
439 IUstProviderInfo provider
= null;
442 while (index
< result
.getOutput().size()) {
443 String line
= result
.getOutput().get(index
);
444 Matcher matcher
= LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
);
445 if (matcher
.matches()) {
446 provider
= new UstProviderInfo(matcher
.group(2).trim());
447 provider
.setPid(Integer
.valueOf(matcher
.group(1).trim()));
448 List
<IBaseEventInfo
> events
= new ArrayList
<>();
449 index
= getProviderEventInfo(result
.getOutput(), ++index
, events
);
450 provider
.setEvents(events
);
451 allProviders
.add(provider
);
460 public ISessionInfo
createSession(ISessionInfo sessionInfo
, IProgressMonitor monitor
) throws ExecutionException
{
461 if (sessionInfo
.isStreamedTrace()) {
462 return createStreamedSession(sessionInfo
, monitor
);
465 ICommandInput command
= prepareSessionCreationCommand(sessionInfo
);
467 ICommandResult result
= executeCommand(command
, monitor
);
469 // Session myssession2 created.
470 // Traces will be written in
471 // /home/user/lttng-traces/myssession2-20120209-095418
472 List
<String
> output
= result
.getOutput();
474 // Get and session name and path
478 for (String line
: output
) {
479 Matcher nameMatcher
= LTTngControlServiceConstants
.CREATE_SESSION_NAME_PATTERN
.matcher(line
);
480 Matcher pathMatcher
= LTTngControlServiceConstants
.CREATE_SESSION_PATH_PATTERN
.matcher(line
);
481 if (nameMatcher
.matches()) {
482 name
= String
.valueOf(nameMatcher
.group(1).trim());
483 } else if (pathMatcher
.matches()) {
484 path
= String
.valueOf(pathMatcher
.group(1).trim());
488 // Verify session name
489 if ((name
== null) || (!"".equals(sessionInfo
.getName()) && !name
.equals(sessionInfo
.getName()))) { //$NON-NLS-1$
490 // Unexpected name returned
491 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
492 Messages
.TraceControl_UnexpectedNameError
+ ": " + name
); //$NON-NLS-1$
495 sessionInfo
.setName(name
);
496 // Verify session path
497 if (!sessionInfo
.isSnapshotSession() &&
498 ((path
== null) || ((sessionInfo
.getSessionPath() != null) && (!path
.contains(sessionInfo
.getSessionPath()))))) {
500 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
501 Messages
.TraceControl_UnexpectedPathError
+ ": " + name
); //$NON-NLS-1$
504 if (sessionInfo
.isSnapshotSession()) {
505 // Make it a snapshot session - content of snapshot info need to
506 // set afterwards using getSession() or getSnapshotInfo()
507 sessionInfo
.setSnapshotInfo(new SnapshotInfo("")); //$NON-NLS-1$
509 sessionInfo
.setSessionPath(path
);
517 * Basic generation of command for session creation
520 * the session to create
521 * @return the basic command for command creation
523 protected @NonNull ICommandInput
prepareSessionCreationCommand(ISessionInfo sessionInfo
) {
524 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_CREATE_SESSION
);
525 if (!sessionInfo
.getName().isEmpty()) {
526 command
.add(sessionInfo
.getName());
529 String newPath
= sessionInfo
.getSessionPath();
530 if (newPath
!= null && !"".equals(newPath
)) { //$NON-NLS-1$
531 command
.add(LTTngControlServiceConstants
.OPTION_OUTPUT_PATH
);
532 command
.add(newPath
);
535 if (sessionInfo
.isSnapshotSession()) {
536 command
.add(LTTngControlServiceConstants
.OPTION_SNAPSHOT
);
541 private @NonNull ISessionInfo
createStreamedSession(ISessionInfo sessionInfo
, IProgressMonitor monitor
) throws ExecutionException
{
543 ICommandInput command
= prepareStreamedSessionCreationCommand(sessionInfo
);
545 ICommandResult result
= executeCommand(command
, monitor
);
548 List
<String
> output
= result
.getOutput();
550 // Get and session name and path
554 for (String line
: output
) {
555 Matcher nameMatcher
= LTTngControlServiceConstants
.CREATE_SESSION_NAME_PATTERN
.matcher(line
);
556 Matcher pathMatcher
= LTTngControlServiceConstants
.CREATE_SESSION_PATH_PATTERN
.matcher(line
);
558 if (nameMatcher
.matches()) {
559 name
= String
.valueOf(nameMatcher
.group(1).trim());
560 } else if (pathMatcher
.matches() && (sessionInfo
.getNetworkUrl() != null)) {
561 path
= String
.valueOf(pathMatcher
.group(1).trim());
565 // Verify session name
566 if ((name
== null) || (!"".equals(sessionInfo
.getName()) && !name
.equals(sessionInfo
.getName()))) { //$NON-NLS-1$
567 // Unexpected name returned
568 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
569 Messages
.TraceControl_UnexpectedNameError
+ ": " + name
); //$NON-NLS-1$
572 sessionInfo
.setName(name
);
574 sessionInfo
.setStreamedTrace(true);
576 // Verify session path
577 if (sessionInfo
.getNetworkUrl() != null) {
578 if (!sessionInfo
.isSnapshotSession() && (path
== null)) {
580 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
581 Messages
.TraceControl_UnexpectedPathError
+ ": " + name
); //$NON-NLS-1$
584 if (sessionInfo
.isSnapshotSession()) {
585 sessionInfo
.setStreamedTrace(false);
587 sessionInfo
.setSessionPath(path
);
588 // Check file protocol
589 Matcher matcher
= LTTngControlServiceConstants
.TRACE_FILE_PROTOCOL_PATTERN
.matcher(path
);
590 if (matcher
.matches()) {
591 sessionInfo
.setStreamedTrace(false);
596 // When using controlUrl and dataUrl the full session path is not known
597 // yet and will be set later on when listing the session
603 * Basic generation of command for streamed session creation
606 * the session to create
607 * @return the basic command for command creation
609 protected @NonNull ICommandInput
prepareStreamedSessionCreationCommand(ISessionInfo sessionInfo
) {
610 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_CREATE_SESSION
);
611 if (!sessionInfo
.getName().isEmpty()) {
612 command
.add(sessionInfo
.getName());
615 if (sessionInfo
.isSnapshotSession()) {
616 command
.add(LTTngControlServiceConstants
.OPTION_SNAPSHOT
);
617 } else if (sessionInfo
.isLive()) {
618 command
.add(LTTngControlServiceConstants
.OPTION_LIVE
);
619 if (sessionInfo
.getLiveDelay() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
620 command
.add(String
.valueOf(sessionInfo
.getLiveDelay()));
624 if (sessionInfo
.getNetworkUrl() != null) {
625 command
.add(LTTngControlServiceConstants
.OPTION_NETWORK_URL
);
626 command
.add(sessionInfo
.getNetworkUrl());
628 command
.add(LTTngControlServiceConstants
.OPTION_CONTROL_URL
);
629 command
.add(sessionInfo
.getControlUrl());
631 command
.add(LTTngControlServiceConstants
.OPTION_DATA_URL
);
632 command
.add(sessionInfo
.getDataUrl());
638 public void destroySession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
640 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_DESTROY_SESSION
, sessionName
);
642 ICommandResult result
= executeCommand(command
, monitor
, false);
643 boolean isError
= isError(result
);
644 if (isError
&& !ignoredPattern(result
.getErrorOutput(), LTTngControlServiceConstants
.SESSION_NOT_FOUND_ERROR_PATTERN
)) {
645 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + result
.toString()); //$NON-NLS-1$ //$NON-NLS-2$
648 // Session <sessionName> destroyed
652 public void startSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
654 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_START_SESSION
, sessionName
);
656 executeCommand(command
, monitor
);
658 // Session <sessionName> started
662 public void stopSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
663 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_STOP_SESSION
, sessionName
);
665 executeCommand(command
, monitor
);
667 // Session <sessionName> stopped
672 public void enableChannels(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IChannelInfo info
, IProgressMonitor monitor
) throws ExecutionException
{
674 // no channels to enable
675 if (channelNames
.isEmpty()) {
679 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_CHANNEL
);
681 command
.add(toCsv(channelNames
));
684 command
.add(LTTngControlServiceConstants
.OPTION_KERNEL
);
686 command
.add(LTTngControlServiceConstants
.OPTION_UST
);
689 command
.add(LTTngControlServiceConstants
.OPTION_SESSION
);
690 command
.add(sessionName
);
693 // --discard Discard event when buffers are full (default)
695 // --overwrite Flight recorder mode
696 if (info
.isOverwriteMode()) {
697 command
.add(LTTngControlServiceConstants
.OPTION_OVERWRITE
);
699 // --subbuf-size SIZE Subbuffer size in bytes
700 // (default: 4096, kernel default: 262144)
701 if (info
.getSubBufferSize() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
702 command
.add(LTTngControlServiceConstants
.OPTION_SUB_BUFFER_SIZE
);
703 command
.add(String
.valueOf(info
.getSubBufferSize()));
706 // --num-subbuf NUM Number of subbufers
707 if (info
.getNumberOfSubBuffers() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
708 command
.add(LTTngControlServiceConstants
.OPTION_NUM_SUB_BUFFERS
);
709 command
.add(String
.valueOf(info
.getNumberOfSubBuffers()));
712 // --switch-timer USEC Switch timer interval in usec
713 if (info
.getSwitchTimer() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
714 command
.add(LTTngControlServiceConstants
.OPTION_SWITCH_TIMER
);
715 command
.add(String
.valueOf(info
.getSwitchTimer()));
718 // --read-timer USEC Read timer interval in usec
719 if (info
.getReadTimer() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
720 command
.add(LTTngControlServiceConstants
.OPTION_READ_TIMER
);
721 command
.add(String
.valueOf(info
.getReadTimer()));
724 if (isVersionSupported("2.2.0")) { //$NON-NLS-1$
725 // --buffers-uid Every application sharing the same UID use the
726 // same buffers --buffers-pid Buffers are allocated per PID
728 if (info
.getBufferType() == BufferType
.BUFFER_PER_PID
) {
729 command
.add(LTTngControlServiceConstants
.OPTION_PER_PID_BUFFERS
);
731 } else if (info
.getBufferType() == BufferType
.BUFFER_PER_UID
) {
732 command
.add(LTTngControlServiceConstants
.OPTION_PER_UID_BUFFERS
);
736 // -C SIZE Maximum size of trace files in bytes
737 if (info
.getMaxSizeTraceFiles() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
738 command
.add(LTTngControlServiceConstants
.OPTION_MAX_SIZE_TRACE_FILES
);
739 command
.add(String
.valueOf(info
.getMaxSizeTraceFiles()));
742 // -W NUM Maximum number of trace files
743 if (info
.getMaxNumberTraceFiles() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
744 command
.add(LTTngControlServiceConstants
.OPTION_MAX_TRACE_FILES
);
745 command
.add(String
.valueOf(info
.getMaxNumberTraceFiles()));
750 executeCommand(command
, monitor
);
755 public void disableChannels(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
757 // no channels to enable
758 if (channelNames
.isEmpty()) {
762 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_DISABLE_CHANNEL
);
764 command
.add(toCsv(channelNames
));
767 command
.add(LTTngControlServiceConstants
.OPTION_KERNEL
);
769 command
.add(LTTngControlServiceConstants
.OPTION_UST
);
772 command
.add(LTTngControlServiceConstants
.OPTION_SESSION
);
773 command
.add(sessionName
);
775 executeCommand(command
, monitor
);
779 public void enableEvents(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, String filterExpression
, IProgressMonitor monitor
) throws ExecutionException
{
781 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
783 if (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
);
803 command
.add(LTTngControlServiceConstants
.OPTION_TRACEPOINT
);
805 if (filterExpression
!= null) {
806 command
.add(LTTngControlServiceConstants
.OPTION_FILTER
);
807 command
.add(filterExpression
);
810 executeCommand(command
, monitor
);
815 public void enableSyscalls(String sessionName
, String channelName
, IProgressMonitor monitor
) throws ExecutionException
{
817 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
819 command
.add(LTTngControlServiceConstants
.OPTION_ALL
);
820 command
.add(LTTngControlServiceConstants
.OPTION_KERNEL
);
823 command
.add(LTTngControlServiceConstants
.OPTION_SESSION
);
824 command
.add(sessionName
);
826 if (channelName
!= null) {
827 command
.add(LTTngControlServiceConstants
.OPTION_CHANNEL
);
828 command
.add(channelName
);
831 command
.add(LTTngControlServiceConstants
.OPTION_SYSCALL
);
833 executeCommand(command
, monitor
);
837 public void enableProbe(String sessionName
, String channelName
, String eventName
, boolean isFunction
, String probe
, IProgressMonitor monitor
) throws ExecutionException
{
838 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
840 command
.add(eventName
);
841 command
.add(LTTngControlServiceConstants
.OPTION_KERNEL
);
843 command
.add(LTTngControlServiceConstants
.OPTION_SESSION
);
844 command
.add(sessionName
);
846 if (channelName
!= null) {
847 command
.add(LTTngControlServiceConstants
.OPTION_CHANNEL
);
848 command
.add(channelName
);
851 command
.add(LTTngControlServiceConstants
.OPTION_FUNCTION_PROBE
);
853 command
.add(LTTngControlServiceConstants
.OPTION_PROBE
);
858 executeCommand(command
, monitor
);
862 public void enableLogLevel(String sessionName
, String channelName
, String eventName
, LogLevelType logLevelType
, TraceLogLevel level
, String filterExpression
, IProgressMonitor monitor
) throws ExecutionException
{
863 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
865 command
.add(eventName
);
866 command
.add(LTTngControlServiceConstants
.OPTION_UST
);
868 command
.add(LTTngControlServiceConstants
.OPTION_SESSION
);
869 command
.add(sessionName
);
871 if (channelName
!= null) {
872 command
.add(LTTngControlServiceConstants
.OPTION_CHANNEL
);
873 command
.add(channelName
);
876 if (logLevelType
== LogLevelType
.LOGLEVEL
) {
877 command
.add(LTTngControlServiceConstants
.OPTION_LOGLEVEL
);
878 } else if (logLevelType
== LogLevelType
.LOGLEVEL_ONLY
) {
879 command
.add(LTTngControlServiceConstants
.OPTION_LOGLEVEL_ONLY
);
884 command
.add(level
.getInName());
886 executeCommand(command
, monitor
);
890 public void disableEvent(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
891 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_DISABLE_EVENT
);
893 if (eventNames
== null) {
894 command
.add(LTTngControlServiceConstants
.OPTION_ALL
);
896 // no events to disable
897 if (eventNames
.isEmpty()) {
901 StringBuffer eventNameParameter
= new StringBuffer();
902 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
903 String event
= iterator
.next();
904 eventNameParameter
.append(event
);
905 if (iterator
.hasNext()) {
906 eventNameParameter
.append(',');
909 command
.add(eventNameParameter
.toString());
913 command
.add(LTTngControlServiceConstants
.OPTION_KERNEL
);
915 command
.add(LTTngControlServiceConstants
.OPTION_UST
);
918 command
.add(LTTngControlServiceConstants
.OPTION_SESSION
);
919 command
.add(sessionName
);
921 if (channelName
!= null) {
922 command
.add(LTTngControlServiceConstants
.OPTION_CHANNEL
);
923 command
.add(channelName
);
926 executeCommand(command
, monitor
);
930 public List
<String
> getContextList(IProgressMonitor monitor
) throws ExecutionException
{
932 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_ADD_CONTEXT
, LTTngControlServiceConstants
.OPTION_HELP
);
934 ICommandResult result
= executeCommand(command
, monitor
);
936 List
<String
> output
= result
.getOutput();
938 List
<String
> contexts
= new ArrayList
<>(0);
941 boolean inList
= false;
942 while (index
< output
.size()) {
943 String line
= output
.get(index
);
945 Matcher startMatcher
= LTTngControlServiceConstants
.ADD_CONTEXT_HELP_CONTEXTS_INTRO
.matcher(line
);
946 Matcher endMatcher
= LTTngControlServiceConstants
.ADD_CONTEXT_HELP_CONTEXTS_END_LINE
.matcher(line
);
948 if (startMatcher
.matches()) {
950 } else if (endMatcher
.matches()) {
952 } else if (inList
== true) {
953 String
[] tmp
= line
.split(","); //$NON-NLS-1$
954 for (int i
= 0; i
< tmp
.length
; i
++) {
955 contexts
.add(tmp
[i
].trim());
964 public void addContexts(String sessionName
, String channelName
, String eventName
, boolean isKernel
, List
<String
> contextNames
, IProgressMonitor monitor
) throws ExecutionException
{
965 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_ADD_CONTEXT
);
967 command
.add(LTTngControlServiceConstants
.OPTION_SESSION
);
968 command
.add(sessionName
);
970 if (channelName
!= null) {
971 command
.add(LTTngControlServiceConstants
.OPTION_CHANNEL
);
972 command
.add(channelName
);
975 if (eventName
!= null) {
976 command
.add(LTTngControlServiceConstants
.OPTION_EVENT
);
977 command
.add(eventName
);
981 command
.add(LTTngControlServiceConstants
.OPTION_KERNEL
);
983 command
.add(LTTngControlServiceConstants
.OPTION_UST
);
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 calibrate(boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
998 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_CALIBRATE
);
1001 command
.add(LTTngControlServiceConstants
.OPTION_KERNEL
);
1003 command
.add(LTTngControlServiceConstants
.OPTION_UST
);
1006 command
.add(LTTngControlServiceConstants
.OPTION_FUNCTION_PROBE
);
1008 executeCommand(command
, monitor
);
1012 public void recordSnapshot(String sessionName
, IProgressMonitor monitor
)
1013 throws ExecutionException
{
1014 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_SNAPSHOT
, LTTngControlServiceConstants
.COMMAND_RECORD_SNAPSHOT
);
1016 String newSessionName
= sessionName
;
1017 command
.add(LTTngControlServiceConstants
.OPTION_SESSION
);
1018 command
.add(newSessionName
);
1020 executeCommand(command
, monitor
);
1024 public void loadSession(String inputPath
, boolean isForce
, IProgressMonitor monitor
)
1025 throws ExecutionException
{
1026 ICommandInput command
= createCommand(LTTngControlServiceConstants
.COMMAND_LOAD_SESSION
);
1028 if (inputPath
!= null) {
1029 command
.add(LTTngControlServiceConstants
.OPTION_INPUT_PATH
);
1030 command
.add(inputPath
);
1034 command
.add(LTTngControlServiceConstants
.OPTION_FORCE
);
1036 executeCommand(command
, monitor
);
1040 public void runCommands(IProgressMonitor monitor
, List
<String
> commandLines
) throws ExecutionException
{
1041 for (String commandLine
: commandLines
) {
1042 if (monitor
.isCanceled()) {
1046 if (commandLine
.isEmpty() || commandLine
.startsWith("#")) { //$NON-NLS-1$
1049 String
[] args
= commandLine
.split("\\s+"); //$NON-NLS-1$
1050 ICommandInput command
= fCommandShell
.createCommand();
1051 command
.addAll(checkNotNull(Arrays
.asList(args
)));
1052 ICommandResult result
= executeCommand(command
, monitor
);
1054 if (isError(result
)) {
1055 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + result
.toString()); //$NON-NLS-1$ //$NON-NLS-2$
1060 // ------------------------------------------------------------------------
1062 // ------------------------------------------------------------------------
1065 * Checks if command result is an error result.
1068 * - the command result to check
1069 * @return true if error else false
1071 protected boolean isError(ICommandResult result
) {
1072 // Check return code and length of returned strings
1074 if ((result
.getResult()) != 0) {
1078 // Look for error pattern
1079 for (String line
: result
.getErrorOutput()) {
1080 Matcher matcher
= LTTngControlServiceConstants
.ERROR_PATTERN
.matcher(line
);
1081 if (matcher
.matches()) {
1090 * Creates a comma separated string from list of names
1092 * List of name to convert
1093 * @return comma separated string
1095 protected String
toCsv(List
<String
> names
) {
1096 StringBuilder csvString
= new StringBuilder();
1097 for (Iterator
<String
> iterator
= names
.iterator(); iterator
.hasNext();) {
1098 String name
= iterator
.next();
1099 csvString
.append(name
);
1100 if (iterator
.hasNext()) {
1101 csvString
.append(',');
1104 return csvString
.toString();
1108 * Parses the domain information.
1111 * a command output list
1112 * @param currentIndex
1113 * current index in command output list
1115 * list for returning channel information
1117 * The domain information
1118 * @return the new current index in command output list
1120 protected int parseDomain(List
<String
> output
, int currentIndex
, List
<IChannelInfo
> channels
, IDomainInfo domainInfo
) {
1121 int index
= currentIndex
;
1123 // if kernel set the buffer type to shared
1124 if (domainInfo
.isKernel()) {
1125 domainInfo
.setBufferType(BufferType
.BUFFER_SHARED
);
1130 // - channnel1: [enabled]
1133 // overwrite mode: 0
1134 // subbufers size: 262144
1135 // number of subbufers: 4
1136 // switch timer interval: 0
1137 // read timer interval: 200
1140 while (index
< output
.size()) {
1141 String line
= output
.get(index
);
1143 if (isVersionSupported("2.2.0")) { //$NON-NLS-1$
1144 Matcher bufferTypeMatcher
= LTTngControlServiceConstants
.BUFFER_TYPE_PATTERN
.matcher(line
);
1145 if (bufferTypeMatcher
.matches()) {
1146 String bufferTypeString
= getAttributeValue(line
);
1147 if (BufferType
.BUFFER_PER_PID
.getInName().equals(bufferTypeString
)) {
1148 domainInfo
.setBufferType(BufferType
.BUFFER_PER_PID
);
1149 } else if (BufferType
.BUFFER_PER_UID
.getInName().equals(bufferTypeString
)) {
1150 domainInfo
.setBufferType(BufferType
.BUFFER_PER_UID
);
1152 domainInfo
.setBufferType(BufferType
.BUFFER_TYPE_UNKNOWN
);
1156 domainInfo
.setBufferType(BufferType
.BUFFER_TYPE_UNKNOWN
);
1158 Matcher outerMatcher
= LTTngControlServiceConstants
.CHANNELS_SECTION_PATTERN
.matcher(line
);
1159 Matcher noKernelChannelMatcher
= LTTngControlServiceConstants
.DOMAIN_NO_KERNEL_CHANNEL_PATTERN
.matcher(line
);
1160 Matcher noUstChannelMatcher
= LTTngControlServiceConstants
.DOMAIN_NO_UST_CHANNEL_PATTERN
.matcher(line
);
1161 if (outerMatcher
.matches()) {
1162 IChannelInfo channelInfo
= null;
1163 while (index
< output
.size()) {
1164 String subLine
= output
.get(index
);
1166 Matcher innerMatcher
= LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(subLine
);
1167 if (innerMatcher
.matches()) {
1168 channelInfo
= new ChannelInfo(""); //$NON-NLS-1$
1170 channelInfo
.setName(innerMatcher
.group(1));
1172 // get channel enablement
1173 channelInfo
.setState(innerMatcher
.group(2));
1176 channelInfo
.setBufferType(domainInfo
.getBufferType());
1179 channels
.add(channelInfo
);
1181 } else if (LTTngControlServiceConstants
.OVERWRITE_MODE_ATTRIBUTE
.matcher(subLine
).matches()) {
1182 String value
= getAttributeValue(subLine
);
1183 if (channelInfo
!= null) {
1184 channelInfo
.setOverwriteMode(!LTTngControlServiceConstants
.OVERWRITE_MODE_ATTRIBUTE_FALSE
.equals(value
));
1186 } else if (LTTngControlServiceConstants
.SUBBUFFER_SIZE_ATTRIBUTE
.matcher(subLine
).matches()) {
1187 if (channelInfo
!= null) {
1188 channelInfo
.setSubBufferSize(Long
.valueOf(getAttributeValue(subLine
)));
1191 } else if (LTTngControlServiceConstants
.NUM_SUBBUFFERS_ATTRIBUTE
.matcher(subLine
).matches()) {
1192 if (channelInfo
!= null) {
1193 channelInfo
.setNumberOfSubBuffers(Integer
.valueOf(getAttributeValue(subLine
)));
1196 } else if (LTTngControlServiceConstants
.SWITCH_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
1197 if (channelInfo
!= null) {
1198 channelInfo
.setSwitchTimer(Long
.valueOf(getAttributeValue(subLine
)));
1201 } else if (LTTngControlServiceConstants
.READ_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
1202 if (channelInfo
!= null) {
1203 channelInfo
.setReadTimer(Long
.valueOf(getAttributeValue(subLine
)));
1206 } else if (LTTngControlServiceConstants
.OUTPUT_ATTRIBUTE
.matcher(subLine
).matches()) {
1207 if (channelInfo
!= null) {
1208 channelInfo
.setOutputType(getAttributeValue(subLine
));
1211 } else if (LTTngControlServiceConstants
.TRACE_FILE_COUNT_ATTRIBUTE
.matcher(subLine
).matches()) {
1212 if (channelInfo
!= null) {
1213 channelInfo
.setMaxNumberTraceFiles(Integer
.valueOf(getAttributeValue(subLine
)));
1216 } else if (LTTngControlServiceConstants
.TRACE_FILE_SIZE_ATTRIBUTE
.matcher(subLine
).matches()) {
1217 if (channelInfo
!= null) {
1218 channelInfo
.setMaxSizeTraceFiles(Long
.valueOf(getAttributeValue(subLine
)));
1220 } else if (LTTngControlServiceConstants
.EVENT_SECTION_PATTERN
.matcher(subLine
).matches()) {
1221 List
<IEventInfo
> events
= new ArrayList
<>();
1222 index
= parseEvents(output
, index
, events
);
1223 if (channelInfo
!= null) {
1224 channelInfo
.setEvents(events
);
1226 // we want to stay at the current index to be able to
1229 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(subLine
).matches()) {
1232 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(subLine
).matches()) {
1237 } else if (noKernelChannelMatcher
.matches() || noUstChannelMatcher
.matches()) {
1238 // domain indicates that no channels were found -> return
1248 * Parses the event information within a domain.
1251 * a command output list
1252 * @param currentIndex
1253 * current index in command output list
1255 * list for returning event information
1256 * @return the new current index in command output list
1258 protected int parseEvents(List
<String
> output
, int currentIndex
, List
<IEventInfo
> events
) {
1259 int index
= currentIndex
;
1261 while (index
< output
.size()) {
1262 String line
= output
.get(index
);
1263 if (LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(line
).matches()) {
1266 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(line
).matches()) {
1269 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
).matches()) {
1274 Matcher matcher
= LTTngControlServiceConstants
.EVENT_PATTERN
.matcher(line
);
1275 Matcher matcher2
= LTTngControlServiceConstants
.WILDCARD_EVENT_PATTERN
.matcher(line
);
1277 if (matcher
.matches()) {
1278 IEventInfo eventInfo
= new EventInfo(matcher
.group(1).trim());
1279 eventInfo
.setLogLevelType(matcher
.group(2).trim());
1280 eventInfo
.setLogLevel(matcher
.group(3).trim());
1281 eventInfo
.setEventType(matcher
.group(4).trim());
1282 eventInfo
.setState(matcher
.group(5));
1283 String filter
= matcher
.group(6);
1284 if (filter
!= null) {
1285 // remove '[' and ']'
1286 filter
= filter
.substring(1, filter
.length() - 1);
1287 eventInfo
.setFilterExpression(filter
);
1289 events
.add(eventInfo
);
1291 } else if (matcher2
.matches()) {
1292 IEventInfo eventInfo
= new EventInfo(matcher2
.group(1).trim());
1293 eventInfo
.setLogLevel(TraceLogLevel
.LEVEL_UNKNOWN
);
1294 eventInfo
.setEventType(matcher2
.group(2).trim());
1295 eventInfo
.setState(matcher2
.group(3));
1296 String filter
= matcher2
.group(4);
1297 if (filter
!= null) {
1298 // remove '[' and ']'
1299 filter
= filter
.substring(1, filter
.length() - 1);
1300 eventInfo
.setFilterExpression(filter
);
1303 if ((eventInfo
.getEventType() == TraceEventType
.PROBE
) ||
1304 (eventInfo
.getEventType() == TraceEventType
.FUNCTION
)) {
1305 IProbeEventInfo probeEvent
= new ProbeEventInfo(eventInfo
.getName());
1306 probeEvent
.setLogLevel(eventInfo
.getLogLevel());
1307 probeEvent
.setEventType(eventInfo
.getEventType());
1308 probeEvent
.setState(eventInfo
.getState());
1310 // Overwrite eventinfo
1311 eventInfo
= probeEvent
;
1313 // myevent2 (type: probe) [enabled]
1315 // myevent0 (type: function) [enabled]
1317 // symbol: init_post
1319 while (index
< output
.size()) {
1320 String probeLine
= output
.get(index
);
1322 Matcher addrMatcher
= LTTngControlServiceConstants
.PROBE_ADDRESS_PATTERN
.matcher(probeLine
);
1323 Matcher offsetMatcher
= LTTngControlServiceConstants
.PROBE_OFFSET_PATTERN
.matcher(probeLine
);
1324 Matcher symbolMatcher
= LTTngControlServiceConstants
.PROBE_SYMBOL_PATTERN
.matcher(probeLine
);
1325 if (addrMatcher
.matches()) {
1326 String addr
= addrMatcher
.group(2).trim();
1327 probeEvent
.setAddress(addr
);
1328 } else if (offsetMatcher
.matches()) {
1329 String offset
= offsetMatcher
.group(2).trim();
1330 probeEvent
.setOffset(offset
);
1331 } else if (symbolMatcher
.matches()) {
1332 String symbol
= symbolMatcher
.group(2).trim();
1333 probeEvent
.setSymbol(symbol
);
1334 } else if ((LTTngControlServiceConstants
.EVENT_PATTERN
.matcher(probeLine
).matches()) || (LTTngControlServiceConstants
.WILDCARD_EVENT_PATTERN
.matcher(probeLine
).matches())) {
1336 } else if (LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(probeLine
).matches()) {
1338 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(probeLine
).matches()) {
1341 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(probeLine
).matches()) {
1347 events
.add(eventInfo
);
1349 events
.add(eventInfo
);
1362 * Parses a line with attributes: <attribute Name>: <attribute value>
1365 * - attribute line to parse
1366 * @return the attribute value as string
1368 protected String
getAttributeValue(String line
) {
1369 String
[] temp
= line
.split("\\: "); //$NON-NLS-1$
1374 * Parses the event information within a provider.
1377 * a command output list
1378 * @param currentIndex
1379 * current index in command output list
1381 * list for returning event information
1382 * @return the new current index in command output list
1384 protected int getProviderEventInfo(List
<String
> output
, int currentIndex
, List
<IBaseEventInfo
> events
) {
1385 int index
= currentIndex
;
1386 IBaseEventInfo eventInfo
= null;
1387 while (index
< output
.size()) {
1388 String line
= output
.get(index
);
1389 Matcher matcher
= LTTngControlServiceConstants
.PROVIDER_EVENT_PATTERN
.matcher(line
);
1390 if (matcher
.matches()) {
1391 // sched_kthread_stop (loglevel: TRACE_EMERG0) (type:
1393 eventInfo
= new BaseEventInfo(matcher
.group(1).trim());
1394 eventInfo
.setLogLevel(matcher
.group(2).trim());
1395 eventInfo
.setEventType(matcher
.group(3).trim());
1396 events
.add(eventInfo
);
1398 } else if (LTTngControlServiceConstants
.EVENT_FIELD_PATTERN
.matcher(line
).matches()) {
1399 if (eventInfo
!= null) {
1400 List
<IFieldInfo
> fields
= new ArrayList
<>();
1401 index
= getFieldInfo(output
, index
, fields
);
1402 eventInfo
.setFields(fields
);
1407 else if (LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
).matches()) {
1417 * Parse a field's information.
1420 * A command output list
1421 * @param currentIndex
1422 * The current index in the command output list
1424 * List for returning the field information
1425 * @return The new current index in the command output list
1427 protected int getFieldInfo(List
<String
> output
, int currentIndex
, List
<IFieldInfo
> fields
) {
1428 int index
= currentIndex
;
1429 IFieldInfo fieldInfo
= null;
1430 while (index
< output
.size()) {
1431 String line
= output
.get(index
);
1432 Matcher matcher
= LTTngControlServiceConstants
.EVENT_FIELD_PATTERN
.matcher(line
);
1433 if (matcher
.matches()) {
1434 // field: content (string)
1435 fieldInfo
= new FieldInfo(matcher
.group(2).trim());
1436 fieldInfo
.setFieldType(matcher
.group(3).trim());
1437 fields
.add(fieldInfo
);
1438 } else if (LTTngControlServiceConstants
.PROVIDER_EVENT_PATTERN
.matcher(line
).matches()) {
1440 } else if (LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
).matches()) {
1449 * Creates a command input instance
1452 * array of string that makes up a command line
1453 * @return {@link ICommandInput} instance
1455 protected @NonNull ICommandInput
createCommand(String
... segments
) {
1456 ICommandInput command
= fCommandShell
.createCommand();
1457 command
.add(LTTngControlServiceConstants
.CONTROL_COMMAND
);
1458 List
<String
> groupOption
= getTracingGroupOption();
1459 if (!groupOption
.isEmpty()) {
1460 command
.addAll(groupOption
);
1462 String verboseOption
= getVerboseOption();
1463 if (!verboseOption
.isEmpty()) {
1464 command
.add(verboseOption
);
1466 for (String string
: segments
) {
1467 command
.add(checkNotNull(string
));
1473 * @return the tracing group option if configured in the preferences
1475 protected @NonNull List
<String
> getTracingGroupOption() {
1476 List
<String
> groupOption
= new ArrayList
<>();
1477 if (!ControlPreferences
.getInstance().isDefaultTracingGroup() && !ControlPreferences
.getInstance().getTracingGroup().equals("")) { //$NON-NLS-1$
1478 groupOption
.add(LTTngControlServiceConstants
.OPTION_TRACING_GROUP
);
1479 groupOption
.add(ControlPreferences
.getInstance().getTracingGroup());
1485 * @return the verbose option as configured in the preferences
1487 protected String
getVerboseOption() {
1488 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1489 String level
= ControlPreferences
.getInstance().getVerboseLevel();
1490 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_VERBOSE
.equals(level
)) {
1491 return LTTngControlServiceConstants
.OPTION_VERBOSE
;
1493 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_V_VERBOSE
.equals(level
)) {
1494 return LTTngControlServiceConstants
.OPTION_VERY_VERBOSE
;
1496 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_V_V_VERBOSE
.equals(level
)) {
1497 return LTTngControlServiceConstants
.OPTION_VERY_VERY_VERBOSE
;
1500 return ""; //$NON-NLS-1$
1504 * Method that logs the command and command result if logging is enabled as
1505 * well as forwards the command execution to the shell.
1508 * - the command to execute
1510 * - a progress monitor
1511 * @return the command result
1512 * @throws ExecutionException
1513 * If the command fails
1515 protected ICommandResult
executeCommand(@NonNull ICommandInput command
,
1516 @Nullable IProgressMonitor monitor
) throws ExecutionException
{
1517 return executeCommand(command
, monitor
, true);
1521 * Method that logs the command and command result if logging is enabled as
1522 * well as forwards the command execution to the shell.
1525 * - the command to execute
1527 * - a progress monitor
1528 * @param checkForError
1529 * - true to verify command result, else false
1530 * @return the command result
1531 * @throws ExecutionException
1532 * in case of error result
1534 protected ICommandResult
executeCommand(@NonNull ICommandInput command
,
1535 @Nullable IProgressMonitor monitor
, boolean checkForError
)
1536 throws ExecutionException
{
1537 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1538 ControlCommandLogger
.log(command
.toString());
1541 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
1543 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1544 ControlCommandLogger
.log(result
.toString());
1547 if (checkForError
&& isError(result
)) {
1548 throw new ExecutionException(Messages
.TraceControl_CommandError
1549 + " " + command
.toString() + "\n" + result
.toString()); //$NON-NLS-1$ //$NON-NLS-2$