1 /**********************************************************************
2 * Copyright (c) 2012, 2014 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Bernd Hufmann - Initial API and implementation
11 * Bernd Hufmann - Updated for support of LTTng Tools 2.1
12 * Simon Delisle - Updated for support of LTTng Tools 2.2
13 * Marc-Andre Laperle - Support for creating a live session
14 * 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
.Iterator
;
20 import java
.util
.List
;
21 import java
.util
.regex
.Matcher
;
22 import java
.util
.regex
.Pattern
;
24 import org
.eclipse
.core
.commands
.ExecutionException
;
25 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
26 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
27 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.IBaseEventInfo
;
28 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.IChannelInfo
;
29 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.IDomainInfo
;
30 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.IEventInfo
;
31 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.IFieldInfo
;
32 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.IProbeEventInfo
;
33 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.ISessionInfo
;
34 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.ISnapshotInfo
;
35 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.IUstProviderInfo
;
36 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.LogLevelType
;
37 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TraceEventType
;
38 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TraceLogLevel
;
39 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.BaseEventInfo
;
40 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.BufferType
;
41 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.ChannelInfo
;
42 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.DomainInfo
;
43 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.EventInfo
;
44 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.FieldInfo
;
45 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.ProbeEventInfo
;
46 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.SessionInfo
;
47 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.SnapshotInfo
;
48 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.UstProviderInfo
;
49 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.logging
.ControlCommandLogger
;
50 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.messages
.Messages
;
51 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.preferences
.ControlPreferences
;
52 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.remote
.ICommandResult
;
53 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.remote
.ICommandShell
;
57 * Service for sending LTTng trace control commands to remote host.
60 * @author Bernd Hufmann
62 public class LTTngControlService
implements ILttngControlService
{
64 // ------------------------------------------------------------------------
66 // ------------------------------------------------------------------------
68 * The command shell implementation
70 private final ICommandShell fCommandShell
;
75 private LttngVersion fVersion
= null;
77 // ------------------------------------------------------------------------
79 // ------------------------------------------------------------------------
85 * - the command shell implementation to use
87 public LTTngControlService(ICommandShell shell
) {
88 fCommandShell
= shell
;
91 // ------------------------------------------------------------------------
93 // ------------------------------------------------------------------------
96 public String
getVersionString() {
97 if (fVersion
== null) {
98 return "Unknown"; //$NON-NLS-1$
100 return fVersion
.toString();
104 public LttngVersion
getVersion() {
109 * Sets the version of the LTTng 2.0 control service.
114 public void setVersion(String version
) {
115 fVersion
= new LttngVersion(version
);
119 * Sets the version of the LTTng 2.x control service.
124 public void setVersion(LttngVersion version
) {
129 public boolean isVersionSupported(String version
) {
130 LttngVersion tmp
= new LttngVersion(version
);
131 return (fVersion
!= null && fVersion
.compareTo(tmp
) >= 0) ?
true : false;
135 * Returns the command shell implementation.
137 * @return the command shell implementation
139 protected ICommandShell
getCommandShell() {
140 return fCommandShell
;
143 // ------------------------------------------------------------------------
145 // ------------------------------------------------------------------------
148 public String
[] getSessionNames(IProgressMonitor monitor
) throws ExecutionException
{
149 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST
);
151 ICommandResult result
= executeCommand(command
.toString(), monitor
);
154 // Available tracing sessions:
155 // 1) mysession1 (/home/user/lttng-traces/mysession1-20120123-083928)
157 // 2) mysession (/home/user/lttng-traces/mysession-20120123-083318)
160 // Use lttng list <session_name> for more details
162 ArrayList
<String
> retArray
= new ArrayList
<>();
164 while (index
< result
.getOutput().length
) {
165 String line
= result
.getOutput()[index
];
166 Matcher matcher
= LTTngControlServiceConstants
.SESSION_PATTERN
.matcher(line
);
167 if (matcher
.matches()) {
168 retArray
.add(matcher
.group(2).trim());
172 return retArray
.toArray(new String
[retArray
.size()]);
176 * Check if there is a pattern to be ignored into a sequence of string
179 * an arrays of string
181 * the pattern to search for
182 * @return if the pattern exist into the array of string
184 protected boolean ignoredPattern(String
[] input
, Pattern pattern
) {
185 for (String line
: input
) {
186 Matcher matcher
= pattern
.matcher(line
);
187 if (matcher
.matches()) {
195 public ISessionInfo
getSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
196 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST
, sessionName
);
197 ICommandResult result
= executeCommand(command
.toString(), monitor
);
202 // Tracing session mysession2: [inactive]
203 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
204 ISessionInfo sessionInfo
= new SessionInfo(sessionName
);
206 while (index
< result
.getOutput().length
) {
207 // Tracing session mysession2: [inactive]
208 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
210 // === Domain: Kernel ===
212 String line
= result
.getOutput()[index
];
213 Matcher matcher
= LTTngControlServiceConstants
.TRACE_SESSION_PATTERN
.matcher(line
);
214 if (matcher
.matches()) {
215 sessionInfo
.setSessionState(matcher
.group(2));
220 matcher
= LTTngControlServiceConstants
.TRACE_SNAPSHOT_SESSION_PATTERN
.matcher(line
);
221 if (matcher
.matches()) {
222 sessionInfo
.setSessionState(matcher
.group(2));
223 // real name will be set later
224 ISnapshotInfo snapshotInfo
= new SnapshotInfo(""); //$NON-NLS-1$
225 sessionInfo
.setSnapshotInfo(snapshotInfo
);
230 if (!sessionInfo
.isSnapshotSession()) {
231 matcher
= LTTngControlServiceConstants
.TRACE_NETWORK_PATH_PATTERN
.matcher(line
);
232 if (matcher
.matches()) {
233 sessionInfo
.setStreamedTrace(true);
236 matcher
= LTTngControlServiceConstants
.TRACE_SESSION_PATH_PATTERN
.matcher(line
);
237 if (matcher
.matches()) {
238 sessionInfo
.setSessionPath(matcher
.group(1).trim());
244 matcher
= LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(line
);
245 if (matcher
.matches()) {
247 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_KernelDomainDisplayName
);
250 domainInfo
.setIsKernel(true);
253 ArrayList
<IChannelInfo
> channels
= new ArrayList
<>();
254 index
= parseDomain(result
.getOutput(), index
, channels
, domainInfo
);
256 if (channels
.size() > 0) {
258 sessionInfo
.addDomain(domainInfo
);
261 domainInfo
.setChannels(channels
);
266 matcher
= LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
);
267 if (matcher
.matches()) {
268 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_UstGlobalDomainDisplayName
);
271 domainInfo
.setIsKernel(false);
274 ArrayList
<IChannelInfo
> channels
= new ArrayList
<>();
275 index
= parseDomain(result
.getOutput(), index
, channels
, domainInfo
);
277 if (channels
.size() > 0) {
279 sessionInfo
.addDomain(domainInfo
);
282 domainInfo
.setChannels(channels
);
286 matcher
= LTTngControlServiceConstants
.LIST_LIVE_TIMER_INTERVAL_PATTERN
.matcher(line
);
287 if (matcher
.matches()) {
288 int liveDelay
= Integer
.parseInt(matcher
.group(1));
290 sessionInfo
.setLive(true);
291 sessionInfo
.setLiveUrl(SessionInfo
.DEFAULT_LIVE_NETWORK_URL
);
292 sessionInfo
.setLivePort(SessionInfo
.DEFAULT_LIVE_PORT
);
293 sessionInfo
.setLiveDelay(liveDelay
);
302 if (sessionInfo
.isSnapshotSession()) {
303 ISnapshotInfo snapshot
= getSnapshotInfo(sessionName
, monitor
);
304 sessionInfo
.setSnapshotInfo(snapshot
);
311 public ISnapshotInfo
getSnapshotInfo(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
312 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST_SNAPSHOT_OUTPUT
, LTTngControlServiceConstants
.OPTION_SESSION
, sessionName
);
313 ICommandResult result
= executeCommand(command
.toString(), monitor
);
318 // [1] snapshot-1: /home/user/lttng-traces/my-20130909-114431
320 // [3] snapshot-3: net4://172.0.0.1/
321 ISnapshotInfo snapshotInfo
= new SnapshotInfo(""); //$NON-NLS-1$
323 while (index
< result
.getOutput().length
) {
324 String line
= result
.getOutput()[index
];
325 Matcher matcher
= LTTngControlServiceConstants
.LIST_SNAPSHOT_OUTPUT_PATTERN
.matcher(line
);
326 if (matcher
.matches()) {
327 snapshotInfo
.setId(Integer
.valueOf(matcher
.group(1)));
328 snapshotInfo
.setName(matcher
.group(2));
329 snapshotInfo
.setSnapshotPath(matcher
.group(3));
331 Matcher matcher2
= LTTngControlServiceConstants
.SNAPSHOT_NETWORK_PATH_PATTERN
.matcher(snapshotInfo
.getSnapshotPath());
332 if (matcher2
.matches()) {
333 snapshotInfo
.setStreamedSnapshot(true);
346 public List
<IBaseEventInfo
> getKernelProvider(IProgressMonitor monitor
) throws ExecutionException
{
347 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST_KERNEL
);
348 ICommandResult result
= executeCommand(command
.toString(), monitor
, false);
350 List
<IBaseEventInfo
> events
= new ArrayList
<>();
352 if (result
.getErrorOutput() != null) {
353 // Ignore the following 2 cases:
354 // Spawning a session daemon
355 // Error: Unable to list kernel events
357 // Error: Unable to list kernel events
359 if (ignoredPattern(result
.getErrorOutput(), LTTngControlServiceConstants
.LIST_KERNEL_NO_KERNEL_PROVIDER_PATTERN
)) {
364 if (isError(result
)) {
365 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$
370 // sched_kthread_stop (type: tracepoint)
371 getProviderEventInfo(result
.getOutput(), 0, events
);
376 public List
<IUstProviderInfo
> getUstProvider() throws ExecutionException
{
377 return getUstProvider(new NullProgressMonitor());
381 public List
<IUstProviderInfo
> getUstProvider(IProgressMonitor monitor
) throws ExecutionException
{
382 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST_UST
);
384 if (isVersionSupported("2.1.0")) { //$NON-NLS-1$
385 command
.append(LTTngControlServiceConstants
.OPTION_FIELDS
);
388 ICommandResult result
= executeCommand(command
.toString(), monitor
, false);
389 List
<IUstProviderInfo
> allProviders
= new ArrayList
<>();
391 // Workaround for versions 2.0.x which causes a segmentation fault for
393 // if LTTng Tools is compiled without UST support.
394 if (!isVersionSupported("2.1.0") && (result
.getResult() != 0)) { //$NON-NLS-1$
398 if (result
.getErrorOutput() != null) {
399 // Ignore the following 2 cases:
400 // Spawning a session daemon
401 // Error: Unable to list UST events: Listing UST events failed
403 // Error: Unable to list UST events: Listing UST events failed
405 if (ignoredPattern(result
.getErrorOutput(), LTTngControlServiceConstants
.LIST_UST_NO_UST_PROVIDER_PATTERN
)) {
410 if (isError(result
)) {
411 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$
414 // Note that field print-outs exists for version >= 2.1.0
420 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
421 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
423 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
424 // field: doublefield (float)
425 // field: floatfield (float)
426 // field: stringfield (string)
429 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
430 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
432 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
433 // field: doublefield (float)
434 // field: floatfield (float)
435 // field: stringfield (string)
437 IUstProviderInfo provider
= null;
440 while (index
< result
.getOutput().length
) {
441 String line
= result
.getOutput()[index
];
442 Matcher matcher
= LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
);
443 if (matcher
.matches()) {
444 provider
= new UstProviderInfo(matcher
.group(2).trim());
445 provider
.setPid(Integer
.valueOf(matcher
.group(1).trim()));
446 List
<IBaseEventInfo
> events
= new ArrayList
<>();
447 index
= getProviderEventInfo(result
.getOutput(), ++index
, events
);
448 provider
.setEvents(events
);
449 allProviders
.add(provider
);
458 public ISessionInfo
createSession(ISessionInfo sessionInfo
, IProgressMonitor monitor
) throws ExecutionException
{
459 if (sessionInfo
.isStreamedTrace()) {
460 return createStreamedSession(sessionInfo
, monitor
);
463 StringBuffer command
= prepareSessionCreationCommand(sessionInfo
);
465 ICommandResult result
= executeCommand(command
.toString(), monitor
);
467 // Session myssession2 created.
468 // Traces will be written in
469 // /home/user/lttng-traces/myssession2-20120209-095418
470 String
[] output
= result
.getOutput();
472 // Get and session name and path
477 while (index
< output
.length
) {
478 String line
= output
[index
];
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());
489 // Verify session name
490 if ((name
== null) || (!"".equals(sessionInfo
.getName()) && !name
.equals(sessionInfo
.getName()))) { //$NON-NLS-1$
491 // Unexpected name returned
492 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
493 Messages
.TraceControl_UnexpectedNameError
+ ": " + name
); //$NON-NLS-1$
496 sessionInfo
.setName(name
);
497 // Verify session path
498 if (!sessionInfo
.isSnapshotSession() &&
499 ((path
== null) || ((sessionInfo
.getSessionPath() != null) && (!path
.contains(sessionInfo
.getSessionPath()))))) {
501 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
502 Messages
.TraceControl_UnexpectedPathError
+ ": " + name
); //$NON-NLS-1$
505 if (sessionInfo
.isSnapshotSession()) {
506 // Make it a snapshot session - content of snapshot info need to
507 // set afterwards using getSession() or getSnapshotInfo()
508 sessionInfo
.setSnapshotInfo(new SnapshotInfo("")); //$NON-NLS-1$
510 sessionInfo
.setSessionPath(path
);
518 * Basic generation of command for session creation
521 * the session to create
522 * @return the basic command for command creation
524 protected StringBuffer
prepareSessionCreationCommand(ISessionInfo sessionInfo
) {
525 String newName
= formatParameter(sessionInfo
.getName());
526 String newPath
= formatParameter(sessionInfo
.getSessionPath());
528 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_CREATE_SESSION
, newName
);
530 if (newPath
!= null && !"".equals(newPath
)) { //$NON-NLS-1$
531 command
.append(LTTngControlServiceConstants
.OPTION_OUTPUT_PATH
);
532 command
.append(newPath
);
535 if (sessionInfo
.isSnapshotSession()) {
536 command
.append(LTTngControlServiceConstants
.OPTION_SNAPSHOT
);
541 private ISessionInfo
createStreamedSession(ISessionInfo sessionInfo
, IProgressMonitor monitor
) throws ExecutionException
{
543 StringBuffer command
= prepareStreamedSessionCreationCommand(sessionInfo
);
545 ICommandResult result
= executeCommand(command
.toString(), monitor
);
548 String
[] output
= result
.getOutput();
550 // Get and session name and path
555 while (index
< output
.length
) {
556 String line
= output
[index
];
557 Matcher nameMatcher
= LTTngControlServiceConstants
.CREATE_SESSION_NAME_PATTERN
.matcher(line
);
558 Matcher pathMatcher
= LTTngControlServiceConstants
.CREATE_SESSION_PATH_PATTERN
.matcher(line
);
560 if (nameMatcher
.matches()) {
561 name
= String
.valueOf(nameMatcher
.group(1).trim());
562 } else if (pathMatcher
.matches() && (sessionInfo
.getNetworkUrl() != null)) {
563 path
= String
.valueOf(pathMatcher
.group(1).trim());
568 // Verify session name
569 if ((name
== null) || (!"".equals(sessionInfo
.getName()) && !name
.equals(sessionInfo
.getName()))) { //$NON-NLS-1$
570 // Unexpected name returned
571 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
572 Messages
.TraceControl_UnexpectedNameError
+ ": " + name
); //$NON-NLS-1$
575 sessionInfo
.setName(name
);
577 sessionInfo
.setStreamedTrace(true);
579 // Verify session path
580 if (sessionInfo
.getNetworkUrl() != null) {
581 if (!sessionInfo
.isSnapshotSession() && (path
== null)) {
583 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
584 Messages
.TraceControl_UnexpectedPathError
+ ": " + name
); //$NON-NLS-1$
587 if (sessionInfo
.isSnapshotSession()) {
588 sessionInfo
.setStreamedTrace(false);
590 sessionInfo
.setSessionPath(path
);
591 // Check file protocol
592 Matcher matcher
= LTTngControlServiceConstants
.TRACE_FILE_PROTOCOL_PATTERN
.matcher(path
);
593 if (matcher
.matches()) {
594 sessionInfo
.setStreamedTrace(false);
599 // When using controlUrl and dataUrl the full session path is not known
600 // yet and will be set later on when listing the session
606 * Basic generation of command for streamed session creation
609 * the session to create
610 * @return the basic command for command creation
612 protected StringBuffer
prepareStreamedSessionCreationCommand(ISessionInfo sessionInfo
) {
613 String newName
= formatParameter(sessionInfo
.getName());
614 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_CREATE_SESSION
, newName
);
616 if (sessionInfo
.isSnapshotSession()) {
617 command
.append(LTTngControlServiceConstants
.OPTION_SNAPSHOT
);
618 } else if (sessionInfo
.isLive()) {
619 command
.append(LTTngControlServiceConstants
.OPTION_LIVE
);
620 if (sessionInfo
.getLiveDelay() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
621 command
.append(sessionInfo
.getLiveDelay());
625 if (sessionInfo
.getNetworkUrl() != null) {
626 command
.append(LTTngControlServiceConstants
.OPTION_NETWORK_URL
);
627 command
.append(sessionInfo
.getNetworkUrl());
629 command
.append(LTTngControlServiceConstants
.OPTION_CONTROL_URL
);
630 command
.append(sessionInfo
.getControlUrl());
632 command
.append(LTTngControlServiceConstants
.OPTION_DATA_URL
);
633 command
.append(sessionInfo
.getDataUrl());
639 public void destroySession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
640 String newName
= formatParameter(sessionName
);
642 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_DESTROY_SESSION
, newName
);
644 ICommandResult result
= executeCommand(command
.toString(), monitor
, false);
645 String
[] errorOutput
= result
.getErrorOutput();
647 boolean isError
= isError(result
);
648 if (isError
&& (errorOutput
!= null)) {
649 if (ignoredPattern(result
.getErrorOutput(), LTTngControlServiceConstants
.SESSION_NOT_FOUND_ERROR_PATTERN
)) {
656 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$
659 // Session <sessionName> destroyed
663 public void startSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
665 String newSessionName
= formatParameter(sessionName
);
667 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_START_SESSION
, newSessionName
);
669 executeCommand(command
.toString(), monitor
);
671 // Session <sessionName> started
675 public void stopSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
676 String newSessionName
= formatParameter(sessionName
);
677 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_STOP_SESSION
, newSessionName
);
679 executeCommand(command
.toString(), 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 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_CHANNEL
);
695 for (Iterator
<String
> iterator
= channelNames
.iterator(); iterator
.hasNext();) {
696 String channel
= iterator
.next();
697 command
.append(channel
);
698 if (iterator
.hasNext()) {
704 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
706 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
709 String newSessionName
= formatParameter(sessionName
);
710 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
711 command
.append(newSessionName
);
714 // --discard Discard event when buffers are full (default)
716 // --overwrite Flight recorder mode
717 if (info
.isOverwriteMode()) {
718 command
.append(LTTngControlServiceConstants
.OPTION_OVERWRITE
);
720 // --subbuf-size SIZE Subbuffer size in bytes
721 // (default: 4096, kernel default: 262144)
722 if (info
.getSubBufferSize() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
723 command
.append(LTTngControlServiceConstants
.OPTION_SUB_BUFFER_SIZE
);
724 command
.append(String
.valueOf(info
.getSubBufferSize()));
727 // --num-subbuf NUM Number of subbufers
728 if (info
.getNumberOfSubBuffers() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
729 command
.append(LTTngControlServiceConstants
.OPTION_NUM_SUB_BUFFERS
);
730 command
.append(String
.valueOf(info
.getNumberOfSubBuffers()));
733 // --switch-timer USEC Switch timer interval in usec
734 if (info
.getSwitchTimer() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
735 command
.append(LTTngControlServiceConstants
.OPTION_SWITCH_TIMER
);
736 command
.append(String
.valueOf(info
.getSwitchTimer()));
739 // --read-timer USEC Read timer interval in usec
740 if (info
.getReadTimer() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
741 command
.append(LTTngControlServiceConstants
.OPTION_READ_TIMER
);
742 command
.append(String
.valueOf(info
.getReadTimer()));
745 if (isVersionSupported("2.2.0")) { //$NON-NLS-1$
746 // --buffers-uid Every application sharing the same UID use the
747 // same buffers --buffers-pid Buffers are allocated per PID
749 if (info
.getBufferType() == BufferType
.BUFFER_PER_PID
) {
750 command
.append(LTTngControlServiceConstants
.OPTION_PER_PID_BUFFERS
);
752 } else if (info
.getBufferType() == BufferType
.BUFFER_PER_UID
) {
753 command
.append(LTTngControlServiceConstants
.OPTION_PER_UID_BUFFERS
);
757 // -C SIZE Maximum size of trace files in bytes
758 if (info
.getMaxSizeTraceFiles() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
759 command
.append(LTTngControlServiceConstants
.OPTION_MAX_SIZE_TRACE_FILES
);
760 command
.append(String
.valueOf(info
.getMaxSizeTraceFiles()));
763 // -W NUM Maximum number of trace files
764 if (info
.getMaxNumberTraceFiles() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
765 command
.append(LTTngControlServiceConstants
.OPTION_MAX_TRACE_FILES
);
766 command
.append(String
.valueOf(info
.getMaxNumberTraceFiles()));
771 executeCommand(command
.toString(), monitor
);
776 public void disableChannels(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
778 // no channels to enable
779 if (channelNames
.isEmpty()) {
783 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_DISABLE_CHANNEL
);
785 for (Iterator
<String
> iterator
= channelNames
.iterator(); iterator
.hasNext();) {
786 String channel
= iterator
.next();
787 command
.append(channel
);
788 if (iterator
.hasNext()) {
794 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
796 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
799 String newSessionName
= formatParameter(sessionName
);
800 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
801 command
.append(newSessionName
);
803 executeCommand(command
.toString(), monitor
);
807 public void enableEvents(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, String filterExpression
, IProgressMonitor monitor
) throws ExecutionException
{
809 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
811 if (eventNames
== null || eventNames
.isEmpty()) {
812 command
.append(LTTngControlServiceConstants
.OPTION_ALL
);
815 StringBuffer eventNameParameter
= new StringBuffer();
816 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
817 String event
= iterator
.next();
818 eventNameParameter
.append(event
);
819 if (iterator
.hasNext()) {
820 eventNameParameter
.append(',');
823 command
.append(formatParameter(eventNameParameter
.toString()));
827 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
829 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
832 String newSessionName
= formatParameter(sessionName
);
834 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
835 command
.append(newSessionName
);
837 if (channelName
!= null) {
838 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
839 command
.append(channelName
);
842 command
.append(LTTngControlServiceConstants
.OPTION_TRACEPOINT
);
844 if (filterExpression
!= null) {
845 command
.append(LTTngControlServiceConstants
.OPTION_FILTER
);
846 command
.append('\'');
847 command
.append(filterExpression
);
848 command
.append('\'');
851 executeCommand(command
.toString(), monitor
);
856 public void enableSyscalls(String sessionName
, String channelName
, IProgressMonitor monitor
) throws ExecutionException
{
858 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
860 command
.append(LTTngControlServiceConstants
.OPTION_ALL
);
861 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
863 String newSessionName
= formatParameter(sessionName
);
865 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
866 command
.append(newSessionName
);
868 if (channelName
!= null) {
869 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
870 command
.append(channelName
);
873 command
.append(LTTngControlServiceConstants
.OPTION_SYSCALL
);
875 executeCommand(command
.toString(), monitor
);
879 public void enableProbe(String sessionName
, String channelName
, String eventName
, boolean isFunction
, String probe
, IProgressMonitor monitor
) throws ExecutionException
{
880 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
882 command
.append(eventName
);
883 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
885 String newSessionName
= formatParameter(sessionName
);
886 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
887 command
.append(newSessionName
);
889 if (channelName
!= null) {
890 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
891 command
.append(channelName
);
894 command
.append(LTTngControlServiceConstants
.OPTION_FUNCTION_PROBE
);
896 command
.append(LTTngControlServiceConstants
.OPTION_PROBE
);
899 command
.append(probe
);
901 executeCommand(command
.toString(), monitor
);
905 public void enableLogLevel(String sessionName
, String channelName
, String eventName
, LogLevelType logLevelType
, TraceLogLevel level
, String filterExpression
, IProgressMonitor monitor
) throws ExecutionException
{
906 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
908 command
.append(eventName
);
909 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
911 String newSessionName
= formatParameter(sessionName
);
912 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
913 command
.append(newSessionName
);
915 if (channelName
!= null) {
916 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
917 command
.append(channelName
);
920 if (logLevelType
== LogLevelType
.LOGLEVEL
) {
921 command
.append(LTTngControlServiceConstants
.OPTION_LOGLEVEL
);
922 } else if (logLevelType
== LogLevelType
.LOGLEVEL_ONLY
) {
923 command
.append(LTTngControlServiceConstants
.OPTION_LOGLEVEL_ONLY
);
928 command
.append(level
.getInName());
930 executeCommand(command
.toString(), monitor
);
934 public void disableEvent(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
935 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_DISABLE_EVENT
);
937 if (eventNames
== null) {
938 command
.append(LTTngControlServiceConstants
.OPTION_ALL
);
940 // no events to disable
941 if (eventNames
.isEmpty()) {
945 StringBuffer eventNameParameter
= new StringBuffer();
946 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
947 String event
= iterator
.next();
948 eventNameParameter
.append(event
);
949 if (iterator
.hasNext()) {
950 eventNameParameter
.append(',');
953 command
.append(formatParameter(eventNameParameter
.toString()));
957 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
959 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
962 String newSessionName
= formatParameter(sessionName
);
963 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
964 command
.append(newSessionName
);
966 if (channelName
!= null) {
967 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
968 command
.append(channelName
);
971 executeCommand(command
.toString(), monitor
);
975 public List
<String
> getContextList(IProgressMonitor monitor
) throws ExecutionException
{
977 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ADD_CONTEXT
, LTTngControlServiceConstants
.OPTION_HELP
);
979 ICommandResult result
= executeCommand(command
.toString(), monitor
);
981 String
[] output
= result
.getOutput();
983 List
<String
> contexts
= new ArrayList
<>(0);
986 boolean inList
= false;
987 while (index
< output
.length
) {
988 String line
= result
.getOutput()[index
];
990 Matcher startMatcher
= LTTngControlServiceConstants
.ADD_CONTEXT_HELP_CONTEXTS_INTRO
.matcher(line
);
991 Matcher endMatcher
= LTTngControlServiceConstants
.ADD_CONTEXT_HELP_CONTEXTS_END_LINE
.matcher(line
);
993 if (startMatcher
.matches()) {
995 } else if (endMatcher
.matches()) {
997 } else if (inList
== true) {
998 String
[] tmp
= line
.split(","); //$NON-NLS-1$
999 for (int i
= 0; i
< tmp
.length
; i
++) {
1000 contexts
.add(tmp
[i
].trim());
1009 public void addContexts(String sessionName
, String channelName
, String eventName
, boolean isKernel
, List
<String
> contextNames
, IProgressMonitor monitor
) throws ExecutionException
{
1010 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ADD_CONTEXT
);
1012 String newSessionName
= formatParameter(sessionName
);
1013 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
1014 command
.append(newSessionName
);
1016 if (channelName
!= null) {
1017 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
1018 command
.append(channelName
);
1021 if (eventName
!= null) {
1022 command
.append(LTTngControlServiceConstants
.OPTION_EVENT
);
1023 command
.append(eventName
);
1027 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
1029 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
1032 for (Iterator
<String
> iterator
= contextNames
.iterator(); iterator
.hasNext();) {
1033 String context
= iterator
.next();
1034 command
.append(LTTngControlServiceConstants
.OPTION_CONTEXT_TYPE
);
1035 command
.append(context
);
1038 executeCommand(command
.toString(), monitor
);
1043 public void calibrate(boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
1044 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_CALIBRATE
);
1047 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
1049 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
1052 command
.append(LTTngControlServiceConstants
.OPTION_FUNCTION_PROBE
);
1054 executeCommand(command
.toString(), monitor
);
1058 public void recordSnapshot(String sessionName
, IProgressMonitor monitor
)
1059 throws ExecutionException
{
1060 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_RECORD_SNAPSHOT
);
1062 String newSessionName
= formatParameter(sessionName
);
1063 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
1064 command
.append(newSessionName
);
1066 executeCommand(command
.toString(), monitor
);
1070 public void runCommands(IProgressMonitor monitor
, List
<String
> commands
) throws ExecutionException
{
1071 for (String command
: commands
) {
1072 if (monitor
.isCanceled()) {
1076 if (command
.isEmpty() || command
.startsWith("#")) { //$NON-NLS-1$
1079 executeCommand(command
, monitor
);
1083 // ------------------------------------------------------------------------
1085 // ------------------------------------------------------------------------
1088 * Checks if command result is an error result.
1091 * - the command result to check
1092 * @return true if error else false
1094 protected boolean isError(ICommandResult result
) {
1095 // Check return code and length of returned strings
1097 if ((result
.getResult()) != 0) {
1101 // Look for error pattern
1103 while (index
< result
.getErrorOutput().length
) {
1104 String line
= result
.getErrorOutput()[index
];
1105 Matcher matcher
= LTTngControlServiceConstants
.ERROR_PATTERN
.matcher(line
);
1106 if (matcher
.matches()) {
1116 * Formats the output string as single string.
1120 * @return - the formatted output
1122 public static String
formatOutput(ICommandResult result
) {
1123 if ((result
== null) || ((result
.getOutput() == null || result
.getOutput().length
== 0) && (result
.getErrorOutput() == null || result
.getErrorOutput().length
== 0))) {
1124 return ""; //$NON-NLS-1$
1126 String
[] output
= result
.getOutput();
1127 String
[] errorOutput
= result
.getErrorOutput();
1128 StringBuffer ret
= new StringBuffer();
1129 ret
.append("Error Ouptut:\n"); //$NON-NLS-1$
1130 for (int i
= 0; i
< errorOutput
.length
; i
++) {
1131 ret
.append(errorOutput
[i
]).append("\n"); //$NON-NLS-1$
1133 ret
.append("Return Value: "); //$NON-NLS-1$
1134 ret
.append(result
.getResult());
1135 ret
.append("\n"); //$NON-NLS-1$
1136 for (int i
= 0; i
< output
.length
; i
++) {
1137 ret
.append(output
[i
]).append("\n"); //$NON-NLS-1$
1139 return ret
.toString();
1143 * Parses the domain information.
1146 * - a command output array
1147 * @param currentIndex
1148 * - current index in command output array
1150 * - list for returning channel information
1152 * - The domain information
1153 * @return the new current index in command output array
1155 protected int parseDomain(String
[] output
, int currentIndex
, List
<IChannelInfo
> channels
, IDomainInfo domainInfo
) {
1156 int index
= currentIndex
;
1158 // if kernel set the buffer type to shared
1159 if (domainInfo
.isKernel()) {
1160 domainInfo
.setBufferType(BufferType
.BUFFER_SHARED
);
1165 // - channnel1: [enabled]
1168 // overwrite mode: 0
1169 // subbufers size: 262144
1170 // number of subbufers: 4
1171 // switch timer interval: 0
1172 // read timer interval: 200
1175 while (index
< output
.length
) {
1176 String line
= output
[index
];
1178 if (isVersionSupported("2.2.0")) { //$NON-NLS-1$
1179 Matcher bufferTypeMatcher
= LTTngControlServiceConstants
.BUFFER_TYPE_PATTERN
.matcher(line
);
1180 if (bufferTypeMatcher
.matches()) {
1181 String bufferTypeString
= getAttributeValue(line
);
1182 if (BufferType
.BUFFER_PER_PID
.getInName().equals(bufferTypeString
)) {
1183 domainInfo
.setBufferType(BufferType
.BUFFER_PER_PID
);
1184 } else if (BufferType
.BUFFER_PER_UID
.getInName().equals(bufferTypeString
)) {
1185 domainInfo
.setBufferType(BufferType
.BUFFER_PER_UID
);
1187 domainInfo
.setBufferType(BufferType
.BUFFER_TYPE_UNKNOWN
);
1191 domainInfo
.setBufferType(BufferType
.BUFFER_TYPE_UNKNOWN
);
1193 Matcher outerMatcher
= LTTngControlServiceConstants
.CHANNELS_SECTION_PATTERN
.matcher(line
);
1194 Matcher noKernelChannelMatcher
= LTTngControlServiceConstants
.DOMAIN_NO_KERNEL_CHANNEL_PATTERN
.matcher(line
);
1195 Matcher noUstChannelMatcher
= LTTngControlServiceConstants
.DOMAIN_NO_UST_CHANNEL_PATTERN
.matcher(line
);
1196 if (outerMatcher
.matches()) {
1197 IChannelInfo channelInfo
= null;
1198 while (index
< output
.length
) {
1199 String subLine
= output
[index
];
1201 Matcher innerMatcher
= LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(subLine
);
1202 if (innerMatcher
.matches()) {
1203 channelInfo
= new ChannelInfo(""); //$NON-NLS-1$
1205 channelInfo
.setName(innerMatcher
.group(1));
1207 // get channel enablement
1208 channelInfo
.setState(innerMatcher
.group(2));
1211 channelInfo
.setBufferType(domainInfo
.getBufferType());
1214 channels
.add(channelInfo
);
1216 } else if (LTTngControlServiceConstants
.OVERWRITE_MODE_ATTRIBUTE
.matcher(subLine
).matches()) {
1217 String value
= getAttributeValue(subLine
);
1218 if (channelInfo
!= null) {
1219 channelInfo
.setOverwriteMode(!LTTngControlServiceConstants
.OVERWRITE_MODE_ATTRIBUTE_FALSE
.equals(value
));
1221 } else if (LTTngControlServiceConstants
.SUBBUFFER_SIZE_ATTRIBUTE
.matcher(subLine
).matches()) {
1222 if (channelInfo
!= null) {
1223 channelInfo
.setSubBufferSize(Long
.valueOf(getAttributeValue(subLine
)));
1226 } else if (LTTngControlServiceConstants
.NUM_SUBBUFFERS_ATTRIBUTE
.matcher(subLine
).matches()) {
1227 if (channelInfo
!= null) {
1228 channelInfo
.setNumberOfSubBuffers(Integer
.valueOf(getAttributeValue(subLine
)));
1231 } else if (LTTngControlServiceConstants
.SWITCH_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
1232 if (channelInfo
!= null) {
1233 channelInfo
.setSwitchTimer(Long
.valueOf(getAttributeValue(subLine
)));
1236 } else if (LTTngControlServiceConstants
.READ_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
1237 if (channelInfo
!= null) {
1238 channelInfo
.setReadTimer(Long
.valueOf(getAttributeValue(subLine
)));
1241 } else if (LTTngControlServiceConstants
.OUTPUT_ATTRIBUTE
.matcher(subLine
).matches()) {
1242 if (channelInfo
!= null) {
1243 channelInfo
.setOutputType(getAttributeValue(subLine
));
1246 } else if (LTTngControlServiceConstants
.EVENT_SECTION_PATTERN
.matcher(subLine
).matches()) {
1247 List
<IEventInfo
> events
= new ArrayList
<>();
1248 index
= parseEvents(output
, index
, events
);
1249 if (channelInfo
!= null) {
1250 channelInfo
.setEvents(events
);
1252 // we want to stay at the current index to be able to
1255 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(subLine
).matches()) {
1258 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(subLine
).matches()) {
1263 } else if (noKernelChannelMatcher
.matches() || noUstChannelMatcher
.matches()) {
1264 // domain indicates that no channels were found -> return
1274 * Parses the event information within a domain.
1277 * - a command output array
1278 * @param currentIndex
1279 * - current index in command output array
1281 * - list for returning event information
1282 * @return the new current index in command output array
1284 protected int parseEvents(String
[] output
, int currentIndex
, List
<IEventInfo
> events
) {
1285 int index
= currentIndex
;
1287 while (index
< output
.length
) {
1288 String line
= output
[index
];
1289 if (LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(line
).matches()) {
1292 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(line
).matches()) {
1295 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
).matches()) {
1300 Matcher matcher
= LTTngControlServiceConstants
.EVENT_PATTERN
.matcher(line
);
1301 Matcher matcher2
= LTTngControlServiceConstants
.WILDCARD_EVENT_PATTERN
.matcher(line
);
1303 if (matcher
.matches()) {
1304 IEventInfo eventInfo
= new EventInfo(matcher
.group(1).trim());
1305 eventInfo
.setLogLevelType(matcher
.group(2).trim());
1306 eventInfo
.setLogLevel(matcher
.group(3).trim());
1307 eventInfo
.setEventType(matcher
.group(4).trim());
1308 eventInfo
.setState(matcher
.group(5));
1309 String filter
= matcher
.group(6);
1310 if (filter
!= null) {
1311 // remove '[' and ']'
1312 filter
= filter
.substring(1, filter
.length() - 1);
1313 eventInfo
.setFilterExpression(filter
);
1315 events
.add(eventInfo
);
1317 } else if (matcher2
.matches()) {
1318 IEventInfo eventInfo
= new EventInfo(matcher2
.group(1).trim());
1319 eventInfo
.setLogLevel(TraceLogLevel
.LEVEL_UNKNOWN
);
1320 eventInfo
.setEventType(matcher2
.group(2).trim());
1321 eventInfo
.setState(matcher2
.group(3));
1322 String filter
= matcher2
.group(4);
1323 if (filter
!= null) {
1324 // remove '[' and ']'
1325 filter
= filter
.substring(1, filter
.length() - 1);
1326 eventInfo
.setFilterExpression(filter
);
1329 if ((eventInfo
.getEventType() == TraceEventType
.PROBE
) ||
1330 (eventInfo
.getEventType() == TraceEventType
.FUNCTION
)) {
1331 IProbeEventInfo probeEvent
= new ProbeEventInfo(eventInfo
.getName());
1332 probeEvent
.setLogLevel(eventInfo
.getLogLevel());
1333 probeEvent
.setEventType(eventInfo
.getEventType());
1334 probeEvent
.setState(eventInfo
.getState());
1336 // Overwrite eventinfo
1337 eventInfo
= probeEvent
;
1339 // myevent2 (type: probe) [enabled]
1341 // myevent0 (type: function) [enabled]
1343 // symbol: init_post
1345 while (index
< output
.length
) {
1346 String probeLine
= output
[index
];
1348 Matcher addrMatcher
= LTTngControlServiceConstants
.PROBE_ADDRESS_PATTERN
.matcher(probeLine
);
1349 Matcher offsetMatcher
= LTTngControlServiceConstants
.PROBE_OFFSET_PATTERN
.matcher(probeLine
);
1350 Matcher symbolMatcher
= LTTngControlServiceConstants
.PROBE_SYMBOL_PATTERN
.matcher(probeLine
);
1351 if (addrMatcher
.matches()) {
1352 String addr
= addrMatcher
.group(2).trim();
1353 probeEvent
.setAddress(addr
);
1354 } else if (offsetMatcher
.matches()) {
1355 String offset
= offsetMatcher
.group(2).trim();
1356 probeEvent
.setOffset(offset
);
1357 } else if (symbolMatcher
.matches()) {
1358 String symbol
= symbolMatcher
.group(2).trim();
1359 probeEvent
.setSymbol(symbol
);
1360 } else if ((LTTngControlServiceConstants
.EVENT_PATTERN
.matcher(probeLine
).matches()) || (LTTngControlServiceConstants
.WILDCARD_EVENT_PATTERN
.matcher(probeLine
).matches())) {
1362 } else if (LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(probeLine
).matches()) {
1364 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(probeLine
).matches()) {
1367 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(probeLine
).matches()) {
1373 events
.add(eventInfo
);
1375 events
.add(eventInfo
);
1388 * Parses a line with attributes: <attribute Name>: <attribute value>
1391 * - attribute line to parse
1392 * @return the attribute value as string
1394 protected String
getAttributeValue(String line
) {
1395 String
[] temp
= line
.split("\\: "); //$NON-NLS-1$
1400 * Parses the event information within a provider.
1403 * - a command output array
1404 * @param currentIndex
1405 * - current index in command output array
1407 * - list for returning event information
1408 * @return the new current index in command output array
1410 protected int getProviderEventInfo(String
[] output
, int currentIndex
, List
<IBaseEventInfo
> events
) {
1411 int index
= currentIndex
;
1412 IBaseEventInfo eventInfo
= null;
1413 while (index
< output
.length
) {
1414 String line
= output
[index
];
1415 Matcher matcher
= LTTngControlServiceConstants
.PROVIDER_EVENT_PATTERN
.matcher(line
);
1416 if (matcher
.matches()) {
1417 // sched_kthread_stop (loglevel: TRACE_EMERG0) (type:
1419 eventInfo
= new BaseEventInfo(matcher
.group(1).trim());
1420 eventInfo
.setLogLevel(matcher
.group(2).trim());
1421 eventInfo
.setEventType(matcher
.group(3).trim());
1422 events
.add(eventInfo
);
1424 } else if (LTTngControlServiceConstants
.EVENT_FIELD_PATTERN
.matcher(line
).matches()) {
1425 if (eventInfo
!= null) {
1426 List
<IFieldInfo
> fields
= new ArrayList
<>();
1427 index
= getFieldInfo(output
, index
, fields
);
1428 eventInfo
.setFields(fields
);
1433 else if (LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
).matches()) {
1443 * Parse a field's information.
1446 * A command output array
1447 * @param currentIndex
1448 * The current index in the command output array
1450 * List for returning the field information
1451 * @return The new current index in the command output array
1453 protected int getFieldInfo(String
[] output
, int currentIndex
, List
<IFieldInfo
> fields
) {
1454 int index
= currentIndex
;
1455 IFieldInfo fieldInfo
= null;
1456 while (index
< output
.length
) {
1457 String line
= output
[index
];
1458 Matcher matcher
= LTTngControlServiceConstants
.EVENT_FIELD_PATTERN
.matcher(line
);
1459 if (matcher
.matches()) {
1460 // field: content (string)
1461 fieldInfo
= new FieldInfo(matcher
.group(2).trim());
1462 fieldInfo
.setFieldType(matcher
.group(3).trim());
1463 fields
.add(fieldInfo
);
1464 } else if (LTTngControlServiceConstants
.PROVIDER_EVENT_PATTERN
.matcher(line
).matches()) {
1466 } else if (LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
).matches()) {
1475 * Formats a command parameter for the command execution i.e. adds quotes at
1476 * the beginning and end if necessary.
1479 * - parameter to format
1480 * @return formated parameter
1482 protected String
formatParameter(String parameter
) {
1483 if (parameter
!= null) {
1484 StringBuffer newString
= new StringBuffer();
1485 newString
.append(parameter
);
1487 if (parameter
.contains(" ") || parameter
.contains("*")) { //$NON-NLS-1$ //$NON-NLS-2$
1488 newString
.insert(0, "\""); //$NON-NLS-1$
1489 newString
.append("\""); //$NON-NLS-1$
1491 return newString
.toString();
1498 * array of string that makes up a command line
1499 * @return string buffer with created command line
1501 protected StringBuffer
createCommand(String
... strings
) {
1502 StringBuffer command
= new StringBuffer();
1503 command
.append(LTTngControlServiceConstants
.CONTROL_COMMAND
);
1504 command
.append(getTracingGroupOption());
1505 command
.append(getVerboseOption());
1506 for (String string
: strings
) {
1507 command
.append(string
);
1513 * @return the tracing group option if configured in the preferences
1515 protected String
getTracingGroupOption() {
1516 if (!ControlPreferences
.getInstance().isDefaultTracingGroup() && !ControlPreferences
.getInstance().getTracingGroup().equals("")) { //$NON-NLS-1$
1517 return LTTngControlServiceConstants
.OPTION_TRACING_GROUP
+ ControlPreferences
.getInstance().getTracingGroup();
1519 return ""; //$NON-NLS-1$
1523 * @return the verbose option as configured in the preferences
1525 protected String
getVerboseOption() {
1526 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1527 String level
= ControlPreferences
.getInstance().getVerboseLevel();
1528 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_VERBOSE
.equals(level
)) {
1529 return LTTngControlServiceConstants
.OPTION_VERBOSE
;
1531 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_V_VERBOSE
.equals(level
)) {
1532 return LTTngControlServiceConstants
.OPTION_VERY_VERBOSE
;
1534 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_V_V_VERBOSE
.equals(level
)) {
1535 return LTTngControlServiceConstants
.OPTION_VERY_VERY_VERBOSE
;
1538 return ""; //$NON-NLS-1$
1542 * Method that logs the command and command result if logging is enabled as
1543 * well as forwards the command execution to the shell.
1546 * - the command to execute
1548 * - a progress monitor
1549 * @return the command result
1550 * @throws ExecutionException
1551 * If the command fails
1553 protected ICommandResult
executeCommand(String command
,
1554 IProgressMonitor monitor
) throws ExecutionException
{
1555 return executeCommand(command
, monitor
, true);
1559 * Method that logs the command and command result if logging is enabled as
1560 * well as forwards the command execution to the shell.
1563 * - the command to execute
1565 * - a progress monitor
1566 * @param checkForError
1567 * - true to verify command result, else false
1568 * @return the command result
1569 * @throws ExecutionException
1570 * in case of error result
1572 protected ICommandResult
executeCommand(String command
,
1573 IProgressMonitor monitor
, boolean checkForError
)
1574 throws ExecutionException
{
1575 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1576 ControlCommandLogger
.log(command
);
1579 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
1581 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1582 ControlCommandLogger
.log(formatOutput(result
));
1585 if (checkForError
&& isError(result
)) {
1586 throw new ExecutionException(Messages
.TraceControl_CommandError
1587 + " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$