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 java
.util
.ArrayList
;
19 import java
.util
.Arrays
;
20 import java
.util
.Iterator
;
21 import java
.util
.List
;
22 import java
.util
.regex
.Matcher
;
23 import java
.util
.regex
.Pattern
;
25 import org
.eclipse
.core
.commands
.ExecutionException
;
26 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
27 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
28 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.IBaseEventInfo
;
29 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.IChannelInfo
;
30 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.IDomainInfo
;
31 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.IEventInfo
;
32 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.IFieldInfo
;
33 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.IProbeEventInfo
;
34 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.ISessionInfo
;
35 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.ISnapshotInfo
;
36 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.IUstProviderInfo
;
37 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.LogLevelType
;
38 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TraceEventType
;
39 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TraceLogLevel
;
40 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.BaseEventInfo
;
41 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.BufferType
;
42 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.ChannelInfo
;
43 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.DomainInfo
;
44 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.EventInfo
;
45 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.FieldInfo
;
46 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.ProbeEventInfo
;
47 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.SessionInfo
;
48 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.SnapshotInfo
;
49 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.UstProviderInfo
;
50 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.logging
.ControlCommandLogger
;
51 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.messages
.Messages
;
52 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.preferences
.ControlPreferences
;
53 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.remote
.ICommandResult
;
54 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.remote
.ICommandShell
;
58 * Service for sending LTTng trace control commands to remote host.
61 * @author Bernd Hufmann
63 public class LTTngControlService
implements ILttngControlService
{
65 // ------------------------------------------------------------------------
67 // ------------------------------------------------------------------------
69 * The command shell implementation
71 private final ICommandShell fCommandShell
;
76 private LttngVersion fVersion
= null;
78 // ------------------------------------------------------------------------
80 // ------------------------------------------------------------------------
86 * - the command shell implementation to use
88 public LTTngControlService(ICommandShell shell
) {
89 fCommandShell
= shell
;
92 // ------------------------------------------------------------------------
94 // ------------------------------------------------------------------------
97 public String
getVersionString() {
98 if (fVersion
== null) {
99 return "Unknown"; //$NON-NLS-1$
101 return fVersion
.toString();
105 public LttngVersion
getVersion() {
110 * Sets the version of the LTTng 2.0 control service.
115 public void setVersion(String version
) {
116 fVersion
= new LttngVersion(version
);
120 * Sets the version of the LTTng 2.x control service.
125 public void setVersion(LttngVersion version
) {
130 public boolean isVersionSupported(String version
) {
131 LttngVersion tmp
= new LttngVersion(version
);
132 return (fVersion
!= null && fVersion
.compareTo(tmp
) >= 0) ?
true : false;
136 * Returns the command shell implementation.
138 * @return the command shell implementation
140 protected ICommandShell
getCommandShell() {
141 return fCommandShell
;
144 // ------------------------------------------------------------------------
146 // ------------------------------------------------------------------------
149 public String
[] getSessionNames(IProgressMonitor monitor
) throws ExecutionException
{
150 List
<String
> command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST
);
152 ICommandResult result
= executeCommand(command
, monitor
);
155 // Available tracing sessions:
156 // 1) mysession1 (/home/user/lttng-traces/mysession1-20120123-083928)
158 // 2) mysession (/home/user/lttng-traces/mysession-20120123-083318)
161 // Use lttng list <session_name> for more details
163 ArrayList
<String
> retArray
= new ArrayList
<>();
165 while (index
< result
.getOutput().length
) {
166 String line
= result
.getOutput()[index
];
167 Matcher matcher
= LTTngControlServiceConstants
.SESSION_PATTERN
.matcher(line
);
168 if (matcher
.matches()) {
169 retArray
.add(matcher
.group(2).trim());
173 return retArray
.toArray(new String
[retArray
.size()]);
177 * Check if there is a pattern to be ignored into a sequence of string
180 * an arrays of string
182 * the pattern to search for
183 * @return if the pattern exist into the array of string
185 protected boolean ignoredPattern(String
[] input
, Pattern pattern
) {
186 for (String line
: input
) {
187 Matcher matcher
= pattern
.matcher(line
);
188 if (matcher
.matches()) {
196 public ISessionInfo
getSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
197 List
<String
> command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST
, sessionName
);
198 ICommandResult result
= executeCommand(command
, monitor
);
203 // Tracing session mysession2: [inactive]
204 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
205 ISessionInfo sessionInfo
= new SessionInfo(sessionName
);
207 while (index
< result
.getOutput().length
) {
208 // Tracing session mysession2: [inactive]
209 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
211 // === Domain: Kernel ===
213 String line
= result
.getOutput()[index
];
214 Matcher matcher
= LTTngControlServiceConstants
.TRACE_SESSION_PATTERN
.matcher(line
);
215 if (matcher
.matches()) {
216 sessionInfo
.setSessionState(matcher
.group(2));
221 matcher
= LTTngControlServiceConstants
.TRACE_SNAPSHOT_SESSION_PATTERN
.matcher(line
);
222 if (matcher
.matches()) {
223 sessionInfo
.setSessionState(matcher
.group(2));
224 // real name will be set later
225 ISnapshotInfo snapshotInfo
= new SnapshotInfo(""); //$NON-NLS-1$
226 sessionInfo
.setSnapshotInfo(snapshotInfo
);
231 if (!sessionInfo
.isSnapshotSession()) {
232 matcher
= LTTngControlServiceConstants
.TRACE_NETWORK_PATH_PATTERN
.matcher(line
);
233 if (matcher
.matches()) {
234 sessionInfo
.setStreamedTrace(true);
237 matcher
= LTTngControlServiceConstants
.TRACE_SESSION_PATH_PATTERN
.matcher(line
);
238 if (matcher
.matches()) {
239 sessionInfo
.setSessionPath(matcher
.group(1).trim());
245 matcher
= LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(line
);
246 if (matcher
.matches()) {
248 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_KernelDomainDisplayName
);
251 domainInfo
.setIsKernel(true);
254 ArrayList
<IChannelInfo
> channels
= new ArrayList
<>();
255 index
= parseDomain(result
.getOutput(), index
, channels
, domainInfo
);
257 if (channels
.size() > 0) {
259 sessionInfo
.addDomain(domainInfo
);
262 domainInfo
.setChannels(channels
);
267 matcher
= LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
);
268 if (matcher
.matches()) {
269 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_UstGlobalDomainDisplayName
);
272 domainInfo
.setIsKernel(false);
275 ArrayList
<IChannelInfo
> channels
= new ArrayList
<>();
276 index
= parseDomain(result
.getOutput(), index
, channels
, domainInfo
);
278 if (channels
.size() > 0) {
280 sessionInfo
.addDomain(domainInfo
);
283 domainInfo
.setChannels(channels
);
287 matcher
= LTTngControlServiceConstants
.LIST_LIVE_TIMER_INTERVAL_PATTERN
.matcher(line
);
288 if (matcher
.matches()) {
289 long liveDelay
= Long
.parseLong(matcher
.group(1));
291 sessionInfo
.setLive(true);
292 sessionInfo
.setLiveUrl(SessionInfo
.DEFAULT_LIVE_NETWORK_URL
);
293 sessionInfo
.setLivePort(SessionInfo
.DEFAULT_LIVE_PORT
);
294 sessionInfo
.setLiveDelay(liveDelay
);
303 if (sessionInfo
.isSnapshotSession()) {
304 ISnapshotInfo snapshot
= getSnapshotInfo(sessionName
, monitor
);
305 sessionInfo
.setSnapshotInfo(snapshot
);
312 public ISnapshotInfo
getSnapshotInfo(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
313 List
<String
> command
= createCommand(LTTngControlServiceConstants
.COMMAND_SNAPSHOT
, LTTngControlServiceConstants
.COMMAND_LIST_SNAPSHOT_OUTPUT
, LTTngControlServiceConstants
.OPTION_SESSION
, sessionName
);
314 ICommandResult result
= executeCommand(command
, monitor
);
319 // [1] snapshot-1: /home/user/lttng-traces/my-20130909-114431
321 // [3] snapshot-3: net4://172.0.0.1/
322 ISnapshotInfo snapshotInfo
= new SnapshotInfo(""); //$NON-NLS-1$
324 while (index
< result
.getOutput().length
) {
325 String line
= result
.getOutput()[index
];
326 Matcher matcher
= LTTngControlServiceConstants
.LIST_SNAPSHOT_OUTPUT_PATTERN
.matcher(line
);
327 if (matcher
.matches()) {
328 snapshotInfo
.setId(Integer
.valueOf(matcher
.group(1)));
329 snapshotInfo
.setName(matcher
.group(2));
330 snapshotInfo
.setSnapshotPath(matcher
.group(3));
332 Matcher matcher2
= LTTngControlServiceConstants
.SNAPSHOT_NETWORK_PATH_PATTERN
.matcher(snapshotInfo
.getSnapshotPath());
333 if (matcher2
.matches()) {
334 snapshotInfo
.setStreamedSnapshot(true);
347 public List
<IBaseEventInfo
> getKernelProvider(IProgressMonitor monitor
) throws ExecutionException
{
348 List
<String
> command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST
, LTTngControlServiceConstants
.OPTION_KERNEL
);
349 ICommandResult result
= executeCommand(command
, monitor
, false);
351 List
<IBaseEventInfo
> events
= new ArrayList
<>();
353 if (result
.getErrorOutput() != null) {
354 // Ignore the following 2 cases:
355 // Spawning a session daemon
356 // Error: Unable to list kernel events
358 // Error: Unable to list kernel events
360 if (ignoredPattern(result
.getErrorOutput(), LTTngControlServiceConstants
.LIST_KERNEL_NO_KERNEL_PROVIDER_PATTERN
)) {
365 if (isError(result
)) {
366 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + toCommandString(command
) + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$
371 // sched_kthread_stop (type: tracepoint)
372 getProviderEventInfo(result
.getOutput(), 0, events
);
377 public List
<IUstProviderInfo
> getUstProvider() throws ExecutionException
{
378 return getUstProvider(new NullProgressMonitor());
382 public List
<IUstProviderInfo
> getUstProvider(IProgressMonitor monitor
) throws ExecutionException
{
383 List
<String
> command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST
, LTTngControlServiceConstants
.OPTION_UST
);
385 if (isVersionSupported("2.1.0")) { //$NON-NLS-1$
386 command
.add(LTTngControlServiceConstants
.OPTION_FIELDS
);
389 ICommandResult result
= executeCommand(command
, monitor
, false);
390 List
<IUstProviderInfo
> allProviders
= new ArrayList
<>();
392 // Workaround for versions 2.0.x which causes a segmentation fault for
394 // if LTTng Tools is compiled without UST support.
395 if (!isVersionSupported("2.1.0") && (result
.getResult() != 0)) { //$NON-NLS-1$
399 if (result
.getErrorOutput() != null) {
400 // Ignore the following 2 cases:
401 // Spawning a session daemon
402 // Error: Unable to list UST events: Listing UST events failed
404 // Error: Unable to list UST events: Listing UST events failed
406 if (ignoredPattern(result
.getErrorOutput(), LTTngControlServiceConstants
.LIST_UST_NO_UST_PROVIDER_PATTERN
)) {
411 if (isError(result
)) {
412 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + toCommandString(command
) + "\n" + formatOutput(result
)); //$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().length
) {
442 String line
= result
.getOutput()[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 List
<String
> 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 String
[] output
= result
.getOutput();
473 // Get and session name and path
478 while (index
< output
.length
) {
479 String line
= output
[index
];
480 Matcher nameMatcher
= LTTngControlServiceConstants
.CREATE_SESSION_NAME_PATTERN
.matcher(line
);
481 Matcher pathMatcher
= LTTngControlServiceConstants
.CREATE_SESSION_PATH_PATTERN
.matcher(line
);
482 if (nameMatcher
.matches()) {
483 name
= String
.valueOf(nameMatcher
.group(1).trim());
484 } else if (pathMatcher
.matches()) {
485 path
= String
.valueOf(pathMatcher
.group(1).trim());
490 // Verify session name
491 if ((name
== null) || (!"".equals(sessionInfo
.getName()) && !name
.equals(sessionInfo
.getName()))) { //$NON-NLS-1$
492 // Unexpected name returned
493 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + toCommandString(command
) + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
494 Messages
.TraceControl_UnexpectedNameError
+ ": " + name
); //$NON-NLS-1$
497 sessionInfo
.setName(name
);
498 // Verify session path
499 if (!sessionInfo
.isSnapshotSession() &&
500 ((path
== null) || ((sessionInfo
.getSessionPath() != null) && (!path
.contains(sessionInfo
.getSessionPath()))))) {
502 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + toCommandString(command
) + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
503 Messages
.TraceControl_UnexpectedPathError
+ ": " + name
); //$NON-NLS-1$
506 if (sessionInfo
.isSnapshotSession()) {
507 // Make it a snapshot session - content of snapshot info need to
508 // set afterwards using getSession() or getSnapshotInfo()
509 sessionInfo
.setSnapshotInfo(new SnapshotInfo("")); //$NON-NLS-1$
511 sessionInfo
.setSessionPath(path
);
519 * Basic generation of command for session creation
522 * the session to create
523 * @return the basic command for command creation
525 protected List
<String
> prepareSessionCreationCommand(ISessionInfo sessionInfo
) {
526 List
<String
> command
= createCommand(LTTngControlServiceConstants
.COMMAND_CREATE_SESSION
);
527 if (!sessionInfo
.getName().isEmpty()) {
528 command
.add(sessionInfo
.getName());
531 String newPath
= sessionInfo
.getSessionPath();
532 if (newPath
!= null && !"".equals(newPath
)) { //$NON-NLS-1$
533 command
.add(LTTngControlServiceConstants
.OPTION_OUTPUT_PATH
);
534 command
.add(newPath
);
537 if (sessionInfo
.isSnapshotSession()) {
538 command
.add(LTTngControlServiceConstants
.OPTION_SNAPSHOT
);
543 private ISessionInfo
createStreamedSession(ISessionInfo sessionInfo
, IProgressMonitor monitor
) throws ExecutionException
{
545 List
<String
> command
= prepareStreamedSessionCreationCommand(sessionInfo
);
547 ICommandResult result
= executeCommand(command
, monitor
);
550 String
[] output
= result
.getOutput();
552 // Get and session name and path
557 while (index
< output
.length
) {
558 String line
= output
[index
];
559 Matcher nameMatcher
= LTTngControlServiceConstants
.CREATE_SESSION_NAME_PATTERN
.matcher(line
);
560 Matcher pathMatcher
= LTTngControlServiceConstants
.CREATE_SESSION_PATH_PATTERN
.matcher(line
);
562 if (nameMatcher
.matches()) {
563 name
= String
.valueOf(nameMatcher
.group(1).trim());
564 } else if (pathMatcher
.matches() && (sessionInfo
.getNetworkUrl() != null)) {
565 path
= String
.valueOf(pathMatcher
.group(1).trim());
570 // Verify session name
571 if ((name
== null) || (!"".equals(sessionInfo
.getName()) && !name
.equals(sessionInfo
.getName()))) { //$NON-NLS-1$
572 // Unexpected name returned
573 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + toCommandString(command
) + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
574 Messages
.TraceControl_UnexpectedNameError
+ ": " + name
); //$NON-NLS-1$
577 sessionInfo
.setName(name
);
579 sessionInfo
.setStreamedTrace(true);
581 // Verify session path
582 if (sessionInfo
.getNetworkUrl() != null) {
583 if (!sessionInfo
.isSnapshotSession() && (path
== null)) {
585 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + toCommandString(command
) + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
586 Messages
.TraceControl_UnexpectedPathError
+ ": " + name
); //$NON-NLS-1$
589 if (sessionInfo
.isSnapshotSession()) {
590 sessionInfo
.setStreamedTrace(false);
592 sessionInfo
.setSessionPath(path
);
593 // Check file protocol
594 Matcher matcher
= LTTngControlServiceConstants
.TRACE_FILE_PROTOCOL_PATTERN
.matcher(path
);
595 if (matcher
.matches()) {
596 sessionInfo
.setStreamedTrace(false);
601 // When using controlUrl and dataUrl the full session path is not known
602 // yet and will be set later on when listing the session
608 * Basic generation of command for streamed session creation
611 * the session to create
612 * @return the basic command for command creation
614 protected List
<String
> prepareStreamedSessionCreationCommand(ISessionInfo sessionInfo
) {
615 List
<String
> command
= createCommand(LTTngControlServiceConstants
.COMMAND_CREATE_SESSION
);
616 if (!sessionInfo
.getName().isEmpty()) {
617 command
.add(sessionInfo
.getName());
620 if (sessionInfo
.isSnapshotSession()) {
621 command
.add(LTTngControlServiceConstants
.OPTION_SNAPSHOT
);
622 } else if (sessionInfo
.isLive()) {
623 command
.add(LTTngControlServiceConstants
.OPTION_LIVE
);
624 if (sessionInfo
.getLiveDelay() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
625 command
.add(String
.valueOf(sessionInfo
.getLiveDelay()));
629 if (sessionInfo
.getNetworkUrl() != null) {
630 command
.add(LTTngControlServiceConstants
.OPTION_NETWORK_URL
);
631 command
.add(sessionInfo
.getNetworkUrl());
633 command
.add(LTTngControlServiceConstants
.OPTION_CONTROL_URL
);
634 command
.add(sessionInfo
.getControlUrl());
636 command
.add(LTTngControlServiceConstants
.OPTION_DATA_URL
);
637 command
.add(sessionInfo
.getDataUrl());
643 public void destroySession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
645 List
<String
> command
= createCommand(LTTngControlServiceConstants
.COMMAND_DESTROY_SESSION
, sessionName
);
647 ICommandResult result
= executeCommand(command
, monitor
, false);
648 String
[] errorOutput
= result
.getErrorOutput();
650 boolean isError
= isError(result
);
651 if (isError
&& (errorOutput
!= null)) {
652 if (ignoredPattern(result
.getErrorOutput(), LTTngControlServiceConstants
.SESSION_NOT_FOUND_ERROR_PATTERN
)) {
659 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + toCommandString(command
) + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$
662 // Session <sessionName> destroyed
666 public void startSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
668 List
<String
> command
= createCommand(LTTngControlServiceConstants
.COMMAND_START_SESSION
, sessionName
);
670 executeCommand(command
, monitor
);
672 // Session <sessionName> started
676 public void stopSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
677 List
<String
> command
= createCommand(LTTngControlServiceConstants
.COMMAND_STOP_SESSION
, sessionName
);
679 executeCommand(command
, monitor
);
681 // Session <sessionName> stopped
686 public void enableChannels(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IChannelInfo info
, IProgressMonitor monitor
) throws ExecutionException
{
688 // no channels to enable
689 if (channelNames
.isEmpty()) {
693 List
<String
> command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_CHANNEL
);
695 command
.add(toCsv(channelNames
));
698 command
.add(LTTngControlServiceConstants
.OPTION_KERNEL
);
700 command
.add(LTTngControlServiceConstants
.OPTION_UST
);
703 command
.add(LTTngControlServiceConstants
.OPTION_SESSION
);
704 command
.add(sessionName
);
707 // --discard Discard event when buffers are full (default)
709 // --overwrite Flight recorder mode
710 if (info
.isOverwriteMode()) {
711 command
.add(LTTngControlServiceConstants
.OPTION_OVERWRITE
);
713 // --subbuf-size SIZE Subbuffer size in bytes
714 // (default: 4096, kernel default: 262144)
715 if (info
.getSubBufferSize() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
716 command
.add(LTTngControlServiceConstants
.OPTION_SUB_BUFFER_SIZE
);
717 command
.add(String
.valueOf(info
.getSubBufferSize()));
720 // --num-subbuf NUM Number of subbufers
721 if (info
.getNumberOfSubBuffers() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
722 command
.add(LTTngControlServiceConstants
.OPTION_NUM_SUB_BUFFERS
);
723 command
.add(String
.valueOf(info
.getNumberOfSubBuffers()));
726 // --switch-timer USEC Switch timer interval in usec
727 if (info
.getSwitchTimer() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
728 command
.add(LTTngControlServiceConstants
.OPTION_SWITCH_TIMER
);
729 command
.add(String
.valueOf(info
.getSwitchTimer()));
732 // --read-timer USEC Read timer interval in usec
733 if (info
.getReadTimer() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
734 command
.add(LTTngControlServiceConstants
.OPTION_READ_TIMER
);
735 command
.add(String
.valueOf(info
.getReadTimer()));
738 if (isVersionSupported("2.2.0")) { //$NON-NLS-1$
739 // --buffers-uid Every application sharing the same UID use the
740 // same buffers --buffers-pid Buffers are allocated per PID
742 if (info
.getBufferType() == BufferType
.BUFFER_PER_PID
) {
743 command
.add(LTTngControlServiceConstants
.OPTION_PER_PID_BUFFERS
);
745 } else if (info
.getBufferType() == BufferType
.BUFFER_PER_UID
) {
746 command
.add(LTTngControlServiceConstants
.OPTION_PER_UID_BUFFERS
);
750 // -C SIZE Maximum size of trace files in bytes
751 if (info
.getMaxSizeTraceFiles() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
752 command
.add(LTTngControlServiceConstants
.OPTION_MAX_SIZE_TRACE_FILES
);
753 command
.add(String
.valueOf(info
.getMaxSizeTraceFiles()));
756 // -W NUM Maximum number of trace files
757 if (info
.getMaxNumberTraceFiles() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
758 command
.add(LTTngControlServiceConstants
.OPTION_MAX_TRACE_FILES
);
759 command
.add(String
.valueOf(info
.getMaxNumberTraceFiles()));
764 executeCommand(command
, monitor
);
769 public void disableChannels(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
771 // no channels to enable
772 if (channelNames
.isEmpty()) {
776 List
<String
> command
= createCommand(LTTngControlServiceConstants
.COMMAND_DISABLE_CHANNEL
);
778 command
.add(toCsv(channelNames
));
781 command
.add(LTTngControlServiceConstants
.OPTION_KERNEL
);
783 command
.add(LTTngControlServiceConstants
.OPTION_UST
);
786 command
.add(LTTngControlServiceConstants
.OPTION_SESSION
);
787 command
.add(sessionName
);
789 executeCommand(command
, monitor
);
793 public void enableEvents(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, String filterExpression
, IProgressMonitor monitor
) throws ExecutionException
{
795 List
<String
> command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
797 if (eventNames
== null || eventNames
.isEmpty()) {
798 command
.add(LTTngControlServiceConstants
.OPTION_ALL
);
800 command
.add(toCsv(eventNames
));
804 command
.add(LTTngControlServiceConstants
.OPTION_KERNEL
);
806 command
.add(LTTngControlServiceConstants
.OPTION_UST
);
809 command
.add(LTTngControlServiceConstants
.OPTION_SESSION
);
810 command
.add(sessionName
);
812 if (channelName
!= null) {
813 command
.add(LTTngControlServiceConstants
.OPTION_CHANNEL
);
814 command
.add(channelName
);
817 command
.add(LTTngControlServiceConstants
.OPTION_TRACEPOINT
);
819 if (filterExpression
!= null) {
820 command
.add(LTTngControlServiceConstants
.OPTION_FILTER
);
821 command
.add(filterExpression
);
824 executeCommand(command
, monitor
);
829 public void enableSyscalls(String sessionName
, String channelName
, IProgressMonitor monitor
) throws ExecutionException
{
831 List
<String
> command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
833 command
.add(LTTngControlServiceConstants
.OPTION_ALL
);
834 command
.add(LTTngControlServiceConstants
.OPTION_KERNEL
);
837 command
.add(LTTngControlServiceConstants
.OPTION_SESSION
);
838 command
.add(sessionName
);
840 if (channelName
!= null) {
841 command
.add(LTTngControlServiceConstants
.OPTION_CHANNEL
);
842 command
.add(channelName
);
845 command
.add(LTTngControlServiceConstants
.OPTION_SYSCALL
);
847 executeCommand(command
, monitor
);
851 public void enableProbe(String sessionName
, String channelName
, String eventName
, boolean isFunction
, String probe
, IProgressMonitor monitor
) throws ExecutionException
{
852 List
<String
> command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
854 command
.add(eventName
);
855 command
.add(LTTngControlServiceConstants
.OPTION_KERNEL
);
857 command
.add(LTTngControlServiceConstants
.OPTION_SESSION
);
858 command
.add(sessionName
);
860 if (channelName
!= null) {
861 command
.add(LTTngControlServiceConstants
.OPTION_CHANNEL
);
862 command
.add(channelName
);
865 command
.add(LTTngControlServiceConstants
.OPTION_FUNCTION_PROBE
);
867 command
.add(LTTngControlServiceConstants
.OPTION_PROBE
);
872 executeCommand(command
, monitor
);
876 public void enableLogLevel(String sessionName
, String channelName
, String eventName
, LogLevelType logLevelType
, TraceLogLevel level
, String filterExpression
, IProgressMonitor monitor
) throws ExecutionException
{
877 List
<String
> command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
879 command
.add(eventName
);
880 command
.add(LTTngControlServiceConstants
.OPTION_UST
);
882 command
.add(LTTngControlServiceConstants
.OPTION_SESSION
);
883 command
.add(sessionName
);
885 if (channelName
!= null) {
886 command
.add(LTTngControlServiceConstants
.OPTION_CHANNEL
);
887 command
.add(channelName
);
890 if (logLevelType
== LogLevelType
.LOGLEVEL
) {
891 command
.add(LTTngControlServiceConstants
.OPTION_LOGLEVEL
);
892 } else if (logLevelType
== LogLevelType
.LOGLEVEL_ONLY
) {
893 command
.add(LTTngControlServiceConstants
.OPTION_LOGLEVEL_ONLY
);
898 command
.add(level
.getInName());
900 executeCommand(command
, monitor
);
904 public void disableEvent(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
905 List
<String
> command
= createCommand(LTTngControlServiceConstants
.COMMAND_DISABLE_EVENT
);
907 if (eventNames
== null) {
908 command
.add(LTTngControlServiceConstants
.OPTION_ALL
);
910 // no events to disable
911 if (eventNames
.isEmpty()) {
915 StringBuffer eventNameParameter
= new StringBuffer();
916 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
917 String event
= iterator
.next();
918 eventNameParameter
.append(event
);
919 if (iterator
.hasNext()) {
920 eventNameParameter
.append(',');
923 command
.add(eventNameParameter
.toString());
927 command
.add(LTTngControlServiceConstants
.OPTION_KERNEL
);
929 command
.add(LTTngControlServiceConstants
.OPTION_UST
);
932 command
.add(LTTngControlServiceConstants
.OPTION_SESSION
);
933 command
.add(sessionName
);
935 if (channelName
!= null) {
936 command
.add(LTTngControlServiceConstants
.OPTION_CHANNEL
);
937 command
.add(channelName
);
940 executeCommand(command
, monitor
);
944 public List
<String
> getContextList(IProgressMonitor monitor
) throws ExecutionException
{
946 List
<String
> command
= createCommand(LTTngControlServiceConstants
.COMMAND_ADD_CONTEXT
, LTTngControlServiceConstants
.OPTION_HELP
);
948 ICommandResult result
= executeCommand(command
, monitor
);
950 String
[] output
= result
.getOutput();
952 List
<String
> contexts
= new ArrayList
<>(0);
955 boolean inList
= false;
956 while (index
< output
.length
) {
957 String line
= result
.getOutput()[index
];
959 Matcher startMatcher
= LTTngControlServiceConstants
.ADD_CONTEXT_HELP_CONTEXTS_INTRO
.matcher(line
);
960 Matcher endMatcher
= LTTngControlServiceConstants
.ADD_CONTEXT_HELP_CONTEXTS_END_LINE
.matcher(line
);
962 if (startMatcher
.matches()) {
964 } else if (endMatcher
.matches()) {
966 } else if (inList
== true) {
967 String
[] tmp
= line
.split(","); //$NON-NLS-1$
968 for (int i
= 0; i
< tmp
.length
; i
++) {
969 contexts
.add(tmp
[i
].trim());
978 public void addContexts(String sessionName
, String channelName
, String eventName
, boolean isKernel
, List
<String
> contextNames
, IProgressMonitor monitor
) throws ExecutionException
{
979 List
<String
> command
= createCommand(LTTngControlServiceConstants
.COMMAND_ADD_CONTEXT
);
981 command
.add(LTTngControlServiceConstants
.OPTION_SESSION
);
982 command
.add(sessionName
);
984 if (channelName
!= null) {
985 command
.add(LTTngControlServiceConstants
.OPTION_CHANNEL
);
986 command
.add(channelName
);
989 if (eventName
!= null) {
990 command
.add(LTTngControlServiceConstants
.OPTION_EVENT
);
991 command
.add(eventName
);
995 command
.add(LTTngControlServiceConstants
.OPTION_KERNEL
);
997 command
.add(LTTngControlServiceConstants
.OPTION_UST
);
1000 for (Iterator
<String
> iterator
= contextNames
.iterator(); iterator
.hasNext();) {
1001 String context
= iterator
.next();
1002 command
.add(LTTngControlServiceConstants
.OPTION_CONTEXT_TYPE
);
1003 command
.add(context
);
1006 executeCommand(command
, monitor
);
1011 public void calibrate(boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
1012 List
<String
> command
= createCommand(LTTngControlServiceConstants
.COMMAND_CALIBRATE
);
1015 command
.add(LTTngControlServiceConstants
.OPTION_KERNEL
);
1017 command
.add(LTTngControlServiceConstants
.OPTION_UST
);
1020 command
.add(LTTngControlServiceConstants
.OPTION_FUNCTION_PROBE
);
1022 executeCommand(command
, monitor
);
1026 public void recordSnapshot(String sessionName
, IProgressMonitor monitor
)
1027 throws ExecutionException
{
1028 List
<String
> command
= createCommand(LTTngControlServiceConstants
.COMMAND_SNAPSHOT
, LTTngControlServiceConstants
.COMMAND_RECORD_SNAPSHOT
);
1030 String newSessionName
= sessionName
;
1031 command
.add(LTTngControlServiceConstants
.OPTION_SESSION
);
1032 command
.add(newSessionName
);
1034 executeCommand(command
, monitor
);
1038 public void runCommands(IProgressMonitor monitor
, List
<String
> commandLines
) throws ExecutionException
{
1039 for (String commandLine
: commandLines
) {
1040 if (monitor
.isCanceled()) {
1044 if (commandLine
.isEmpty() || commandLine
.startsWith("#")) { //$NON-NLS-1$
1047 String
[] args
= commandLine
.split("\\s+"); //$NON-NLS-1$
1048 List
<String
> command
= Arrays
.asList(args
);
1049 ICommandResult result
= executeCommand(command
, monitor
);
1051 if (isError(result
)) {
1052 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + toCommandString(command
) + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$
1057 // ------------------------------------------------------------------------
1059 // ------------------------------------------------------------------------
1062 * Checks if command result is an error result.
1065 * - the command result to check
1066 * @return true if error else false
1068 protected boolean isError(ICommandResult result
) {
1069 // Check return code and length of returned strings
1071 if ((result
.getResult()) != 0) {
1075 // Look for error pattern
1077 while (index
< result
.getErrorOutput().length
) {
1078 String line
= result
.getErrorOutput()[index
];
1079 Matcher matcher
= LTTngControlServiceConstants
.ERROR_PATTERN
.matcher(line
);
1080 if (matcher
.matches()) {
1090 * Formats the output string as single string.
1094 * @return - the formatted output
1096 public static String
formatOutput(ICommandResult result
) {
1097 if ((result
== null) || ((result
.getOutput() == null || result
.getOutput().length
== 0) && (result
.getErrorOutput() == null || result
.getErrorOutput().length
== 0))) {
1098 return ""; //$NON-NLS-1$
1100 String
[] output
= result
.getOutput();
1101 String
[] errorOutput
= result
.getErrorOutput();
1102 StringBuffer ret
= new StringBuffer();
1103 ret
.append("Error Ouptut:\n"); //$NON-NLS-1$
1104 for (int i
= 0; i
< errorOutput
.length
; i
++) {
1105 ret
.append(errorOutput
[i
]).append("\n"); //$NON-NLS-1$
1107 ret
.append("Return Value: "); //$NON-NLS-1$
1108 ret
.append(result
.getResult());
1109 ret
.append("\n"); //$NON-NLS-1$
1110 for (int i
= 0; i
< output
.length
; i
++) {
1111 ret
.append(output
[i
]).append("\n"); //$NON-NLS-1$
1113 return ret
.toString();
1117 * Creates a single command string from a command line list.
1120 * @return single command string
1122 public static String
toCommandString(List
<String
> command
) {
1123 StringBuilder builder
= new StringBuilder();
1124 for (String segment
: command
) {
1125 builder
.append(segment
).append(' ');
1127 return builder
.toString().trim();
1131 * Creates a comma separated string from list of names
1133 * List of name to convert
1134 * @return comma separated string
1136 protected String
toCsv(List
<String
> names
) {
1137 StringBuilder csvString
= new StringBuilder();
1138 for (Iterator
<String
> iterator
= names
.iterator(); iterator
.hasNext();) {
1139 String name
= iterator
.next();
1140 csvString
.append(name
);
1141 if (iterator
.hasNext()) {
1142 csvString
.append(',');
1145 return csvString
.toString();
1149 * Parses the domain information.
1152 * - a command output array
1153 * @param currentIndex
1154 * - current index in command output array
1156 * - list for returning channel information
1158 * - The domain information
1159 * @return the new current index in command output array
1161 protected int parseDomain(String
[] output
, int currentIndex
, List
<IChannelInfo
> channels
, IDomainInfo domainInfo
) {
1162 int index
= currentIndex
;
1164 // if kernel set the buffer type to shared
1165 if (domainInfo
.isKernel()) {
1166 domainInfo
.setBufferType(BufferType
.BUFFER_SHARED
);
1171 // - channnel1: [enabled]
1174 // overwrite mode: 0
1175 // subbufers size: 262144
1176 // number of subbufers: 4
1177 // switch timer interval: 0
1178 // read timer interval: 200
1181 while (index
< output
.length
) {
1182 String line
= output
[index
];
1184 if (isVersionSupported("2.2.0")) { //$NON-NLS-1$
1185 Matcher bufferTypeMatcher
= LTTngControlServiceConstants
.BUFFER_TYPE_PATTERN
.matcher(line
);
1186 if (bufferTypeMatcher
.matches()) {
1187 String bufferTypeString
= getAttributeValue(line
);
1188 if (BufferType
.BUFFER_PER_PID
.getInName().equals(bufferTypeString
)) {
1189 domainInfo
.setBufferType(BufferType
.BUFFER_PER_PID
);
1190 } else if (BufferType
.BUFFER_PER_UID
.getInName().equals(bufferTypeString
)) {
1191 domainInfo
.setBufferType(BufferType
.BUFFER_PER_UID
);
1193 domainInfo
.setBufferType(BufferType
.BUFFER_TYPE_UNKNOWN
);
1197 domainInfo
.setBufferType(BufferType
.BUFFER_TYPE_UNKNOWN
);
1199 Matcher outerMatcher
= LTTngControlServiceConstants
.CHANNELS_SECTION_PATTERN
.matcher(line
);
1200 Matcher noKernelChannelMatcher
= LTTngControlServiceConstants
.DOMAIN_NO_KERNEL_CHANNEL_PATTERN
.matcher(line
);
1201 Matcher noUstChannelMatcher
= LTTngControlServiceConstants
.DOMAIN_NO_UST_CHANNEL_PATTERN
.matcher(line
);
1202 if (outerMatcher
.matches()) {
1203 IChannelInfo channelInfo
= null;
1204 while (index
< output
.length
) {
1205 String subLine
= output
[index
];
1207 Matcher innerMatcher
= LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(subLine
);
1208 if (innerMatcher
.matches()) {
1209 channelInfo
= new ChannelInfo(""); //$NON-NLS-1$
1211 channelInfo
.setName(innerMatcher
.group(1));
1213 // get channel enablement
1214 channelInfo
.setState(innerMatcher
.group(2));
1217 channelInfo
.setBufferType(domainInfo
.getBufferType());
1220 channels
.add(channelInfo
);
1222 } else if (LTTngControlServiceConstants
.OVERWRITE_MODE_ATTRIBUTE
.matcher(subLine
).matches()) {
1223 String value
= getAttributeValue(subLine
);
1224 if (channelInfo
!= null) {
1225 channelInfo
.setOverwriteMode(!LTTngControlServiceConstants
.OVERWRITE_MODE_ATTRIBUTE_FALSE
.equals(value
));
1227 } else if (LTTngControlServiceConstants
.SUBBUFFER_SIZE_ATTRIBUTE
.matcher(subLine
).matches()) {
1228 if (channelInfo
!= null) {
1229 channelInfo
.setSubBufferSize(Long
.valueOf(getAttributeValue(subLine
)));
1232 } else if (LTTngControlServiceConstants
.NUM_SUBBUFFERS_ATTRIBUTE
.matcher(subLine
).matches()) {
1233 if (channelInfo
!= null) {
1234 channelInfo
.setNumberOfSubBuffers(Integer
.valueOf(getAttributeValue(subLine
)));
1237 } else if (LTTngControlServiceConstants
.SWITCH_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
1238 if (channelInfo
!= null) {
1239 channelInfo
.setSwitchTimer(Long
.valueOf(getAttributeValue(subLine
)));
1242 } else if (LTTngControlServiceConstants
.READ_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
1243 if (channelInfo
!= null) {
1244 channelInfo
.setReadTimer(Long
.valueOf(getAttributeValue(subLine
)));
1247 } else if (LTTngControlServiceConstants
.OUTPUT_ATTRIBUTE
.matcher(subLine
).matches()) {
1248 if (channelInfo
!= null) {
1249 channelInfo
.setOutputType(getAttributeValue(subLine
));
1252 } else if (LTTngControlServiceConstants
.EVENT_SECTION_PATTERN
.matcher(subLine
).matches()) {
1253 List
<IEventInfo
> events
= new ArrayList
<>();
1254 index
= parseEvents(output
, index
, events
);
1255 if (channelInfo
!= null) {
1256 channelInfo
.setEvents(events
);
1258 // we want to stay at the current index to be able to
1261 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(subLine
).matches()) {
1264 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(subLine
).matches()) {
1269 } else if (noKernelChannelMatcher
.matches() || noUstChannelMatcher
.matches()) {
1270 // domain indicates that no channels were found -> return
1280 * Parses the event information within a domain.
1283 * - a command output array
1284 * @param currentIndex
1285 * - current index in command output array
1287 * - list for returning event information
1288 * @return the new current index in command output array
1290 protected int parseEvents(String
[] output
, int currentIndex
, List
<IEventInfo
> events
) {
1291 int index
= currentIndex
;
1293 while (index
< output
.length
) {
1294 String line
= output
[index
];
1295 if (LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(line
).matches()) {
1298 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(line
).matches()) {
1301 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
).matches()) {
1306 Matcher matcher
= LTTngControlServiceConstants
.EVENT_PATTERN
.matcher(line
);
1307 Matcher matcher2
= LTTngControlServiceConstants
.WILDCARD_EVENT_PATTERN
.matcher(line
);
1309 if (matcher
.matches()) {
1310 IEventInfo eventInfo
= new EventInfo(matcher
.group(1).trim());
1311 eventInfo
.setLogLevelType(matcher
.group(2).trim());
1312 eventInfo
.setLogLevel(matcher
.group(3).trim());
1313 eventInfo
.setEventType(matcher
.group(4).trim());
1314 eventInfo
.setState(matcher
.group(5));
1315 String filter
= matcher
.group(6);
1316 if (filter
!= null) {
1317 // remove '[' and ']'
1318 filter
= filter
.substring(1, filter
.length() - 1);
1319 eventInfo
.setFilterExpression(filter
);
1321 events
.add(eventInfo
);
1323 } else if (matcher2
.matches()) {
1324 IEventInfo eventInfo
= new EventInfo(matcher2
.group(1).trim());
1325 eventInfo
.setLogLevel(TraceLogLevel
.LEVEL_UNKNOWN
);
1326 eventInfo
.setEventType(matcher2
.group(2).trim());
1327 eventInfo
.setState(matcher2
.group(3));
1328 String filter
= matcher2
.group(4);
1329 if (filter
!= null) {
1330 // remove '[' and ']'
1331 filter
= filter
.substring(1, filter
.length() - 1);
1332 eventInfo
.setFilterExpression(filter
);
1335 if ((eventInfo
.getEventType() == TraceEventType
.PROBE
) ||
1336 (eventInfo
.getEventType() == TraceEventType
.FUNCTION
)) {
1337 IProbeEventInfo probeEvent
= new ProbeEventInfo(eventInfo
.getName());
1338 probeEvent
.setLogLevel(eventInfo
.getLogLevel());
1339 probeEvent
.setEventType(eventInfo
.getEventType());
1340 probeEvent
.setState(eventInfo
.getState());
1342 // Overwrite eventinfo
1343 eventInfo
= probeEvent
;
1345 // myevent2 (type: probe) [enabled]
1347 // myevent0 (type: function) [enabled]
1349 // symbol: init_post
1351 while (index
< output
.length
) {
1352 String probeLine
= output
[index
];
1354 Matcher addrMatcher
= LTTngControlServiceConstants
.PROBE_ADDRESS_PATTERN
.matcher(probeLine
);
1355 Matcher offsetMatcher
= LTTngControlServiceConstants
.PROBE_OFFSET_PATTERN
.matcher(probeLine
);
1356 Matcher symbolMatcher
= LTTngControlServiceConstants
.PROBE_SYMBOL_PATTERN
.matcher(probeLine
);
1357 if (addrMatcher
.matches()) {
1358 String addr
= addrMatcher
.group(2).trim();
1359 probeEvent
.setAddress(addr
);
1360 } else if (offsetMatcher
.matches()) {
1361 String offset
= offsetMatcher
.group(2).trim();
1362 probeEvent
.setOffset(offset
);
1363 } else if (symbolMatcher
.matches()) {
1364 String symbol
= symbolMatcher
.group(2).trim();
1365 probeEvent
.setSymbol(symbol
);
1366 } else if ((LTTngControlServiceConstants
.EVENT_PATTERN
.matcher(probeLine
).matches()) || (LTTngControlServiceConstants
.WILDCARD_EVENT_PATTERN
.matcher(probeLine
).matches())) {
1368 } else if (LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(probeLine
).matches()) {
1370 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(probeLine
).matches()) {
1373 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(probeLine
).matches()) {
1379 events
.add(eventInfo
);
1381 events
.add(eventInfo
);
1394 * Parses a line with attributes: <attribute Name>: <attribute value>
1397 * - attribute line to parse
1398 * @return the attribute value as string
1400 protected String
getAttributeValue(String line
) {
1401 String
[] temp
= line
.split("\\: "); //$NON-NLS-1$
1406 * Parses the event information within a provider.
1409 * - a command output array
1410 * @param currentIndex
1411 * - current index in command output array
1413 * - list for returning event information
1414 * @return the new current index in command output array
1416 protected int getProviderEventInfo(String
[] output
, int currentIndex
, List
<IBaseEventInfo
> events
) {
1417 int index
= currentIndex
;
1418 IBaseEventInfo eventInfo
= null;
1419 while (index
< output
.length
) {
1420 String line
= output
[index
];
1421 Matcher matcher
= LTTngControlServiceConstants
.PROVIDER_EVENT_PATTERN
.matcher(line
);
1422 if (matcher
.matches()) {
1423 // sched_kthread_stop (loglevel: TRACE_EMERG0) (type:
1425 eventInfo
= new BaseEventInfo(matcher
.group(1).trim());
1426 eventInfo
.setLogLevel(matcher
.group(2).trim());
1427 eventInfo
.setEventType(matcher
.group(3).trim());
1428 events
.add(eventInfo
);
1430 } else if (LTTngControlServiceConstants
.EVENT_FIELD_PATTERN
.matcher(line
).matches()) {
1431 if (eventInfo
!= null) {
1432 List
<IFieldInfo
> fields
= new ArrayList
<>();
1433 index
= getFieldInfo(output
, index
, fields
);
1434 eventInfo
.setFields(fields
);
1439 else if (LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
).matches()) {
1449 * Parse a field's information.
1452 * A command output array
1453 * @param currentIndex
1454 * The current index in the command output array
1456 * List for returning the field information
1457 * @return The new current index in the command output array
1459 protected int getFieldInfo(String
[] output
, int currentIndex
, List
<IFieldInfo
> fields
) {
1460 int index
= currentIndex
;
1461 IFieldInfo fieldInfo
= null;
1462 while (index
< output
.length
) {
1463 String line
= output
[index
];
1464 Matcher matcher
= LTTngControlServiceConstants
.EVENT_FIELD_PATTERN
.matcher(line
);
1465 if (matcher
.matches()) {
1466 // field: content (string)
1467 fieldInfo
= new FieldInfo(matcher
.group(2).trim());
1468 fieldInfo
.setFieldType(matcher
.group(3).trim());
1469 fields
.add(fieldInfo
);
1470 } else if (LTTngControlServiceConstants
.PROVIDER_EVENT_PATTERN
.matcher(line
).matches()) {
1472 } else if (LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
).matches()) {
1482 * array of string that makes up a command line
1483 * @return string buffer with created command line
1485 protected List
<String
> createCommand(String
... strings
) {
1486 List
<String
> command
= new ArrayList
<>();
1487 command
.add(LTTngControlServiceConstants
.CONTROL_COMMAND
);
1488 String groupOption
= getTracingGroupOption();
1489 if (!groupOption
.isEmpty()) {
1490 command
.add(groupOption
);
1492 String verboseOption
= getVerboseOption();
1493 if (!verboseOption
.isEmpty()) {
1494 command
.add(verboseOption
);
1496 for (String string
: strings
) {
1497 command
.add(string
);
1503 * @return the tracing group option if configured in the preferences
1505 protected String
getTracingGroupOption() {
1506 if (!ControlPreferences
.getInstance().isDefaultTracingGroup() && !ControlPreferences
.getInstance().getTracingGroup().equals("")) { //$NON-NLS-1$
1507 return LTTngControlServiceConstants
.OPTION_TRACING_GROUP
+ ControlPreferences
.getInstance().getTracingGroup();
1509 return ""; //$NON-NLS-1$
1513 * @return the verbose option as configured in the preferences
1515 protected String
getVerboseOption() {
1516 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1517 String level
= ControlPreferences
.getInstance().getVerboseLevel();
1518 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_VERBOSE
.equals(level
)) {
1519 return LTTngControlServiceConstants
.OPTION_VERBOSE
;
1521 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_V_VERBOSE
.equals(level
)) {
1522 return LTTngControlServiceConstants
.OPTION_VERY_VERBOSE
;
1524 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_V_V_VERBOSE
.equals(level
)) {
1525 return LTTngControlServiceConstants
.OPTION_VERY_VERY_VERBOSE
;
1528 return ""; //$NON-NLS-1$
1532 * Method that logs the command and command result if logging is enabled as
1533 * well as forwards the command execution to the shell.
1536 * - the command to execute
1538 * - a progress monitor
1539 * @return the command result
1540 * @throws ExecutionException
1541 * If the command fails
1543 protected ICommandResult
executeCommand(List
<String
> command
,
1544 IProgressMonitor monitor
) throws ExecutionException
{
1545 return executeCommand(command
, monitor
, true);
1549 * Method that logs the command and command result if logging is enabled as
1550 * well as forwards the command execution to the shell.
1553 * - the command to execute
1555 * - a progress monitor
1556 * @param checkForError
1557 * - true to verify command result, else false
1558 * @return the command result
1559 * @throws ExecutionException
1560 * in case of error result
1562 protected ICommandResult
executeCommand(List
<String
> command
,
1563 IProgressMonitor monitor
, boolean checkForError
)
1564 throws ExecutionException
{
1565 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1566 ControlCommandLogger
.log(toCommandString(command
));
1569 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
1571 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1572 ControlCommandLogger
.log(formatOutput(result
));
1575 if (checkForError
&& isError(result
)) {
1576 throw new ExecutionException(Messages
.TraceControl_CommandError
1577 + " " + toCommandString(command
) + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$