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 **********************************************************************/
15 package org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.service
;
17 import java
.util
.ArrayList
;
18 import java
.util
.Iterator
;
19 import java
.util
.List
;
20 import java
.util
.regex
.Matcher
;
22 import org
.eclipse
.core
.commands
.ExecutionException
;
23 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
24 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.IBaseEventInfo
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.IChannelInfo
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.IDomainInfo
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.IEventInfo
;
29 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.IFieldInfo
;
30 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.IProbeEventInfo
;
31 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.ISessionInfo
;
32 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.ISnapshotInfo
;
33 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.IUstProviderInfo
;
34 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.LogLevelType
;
35 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.TraceEventType
;
36 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.TraceLogLevel
;
37 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.impl
.BaseEventInfo
;
38 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.impl
.BufferType
;
39 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.impl
.ChannelInfo
;
40 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.impl
.DomainInfo
;
41 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.impl
.EventInfo
;
42 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.impl
.FieldInfo
;
43 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.impl
.ProbeEventInfo
;
44 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.impl
.SessionInfo
;
45 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.impl
.SnapshotInfo
;
46 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.impl
.UstProviderInfo
;
47 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.logging
.ControlCommandLogger
;
48 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.messages
.Messages
;
49 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.preferences
.ControlPreferences
;
50 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.remote
.ICommandResult
;
51 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.remote
.ICommandShell
;
55 * Service for sending LTTng trace control commands to remote host.
58 * @author Bernd Hufmann
60 public class LTTngControlService
implements ILttngControlService
{
62 // ------------------------------------------------------------------------
64 // ------------------------------------------------------------------------
66 * The command shell implementation
68 private final ICommandShell fCommandShell
;
73 private LttngVersion fVersion
= null;
75 // ------------------------------------------------------------------------
77 // ------------------------------------------------------------------------
83 * - the command shell implementation to use
85 public LTTngControlService(ICommandShell shell
) {
86 fCommandShell
= shell
;
89 // ------------------------------------------------------------------------
91 // ------------------------------------------------------------------------
94 public String
getVersionString() {
95 if (fVersion
== null) {
96 return "Unknown"; //$NON-NLS-1$
98 return fVersion
.toString();
102 public LttngVersion
getVersion() {
107 * Sets the version of the LTTng 2.0 control service.
108 * @param version - a version to set
110 public void setVersion(String version
) {
111 fVersion
= new LttngVersion(version
);
115 * Sets the version of the LTTng 2.x control service.
116 * @param version - a version to set
118 public void setVersion(LttngVersion version
) {
123 public boolean isVersionSupported(String version
) {
124 LttngVersion tmp
= new LttngVersion(version
);
125 return (fVersion
!= null && fVersion
.compareTo(tmp
) >= 0) ?
true : false;
129 * Returns the command shell implementation.
131 * @return the command shell implementation
133 protected ICommandShell
getCommandShell() {
134 return fCommandShell
;
137 // ------------------------------------------------------------------------
139 // ------------------------------------------------------------------------
142 public String
[] getSessionNames(IProgressMonitor monitor
) throws ExecutionException
{
143 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST
);
145 ICommandResult result
= executeCommand(command
.toString(), monitor
);
148 // Available tracing sessions:
149 // 1) mysession1 (/home/user/lttng-traces/mysession1-20120123-083928) [inactive]
150 // 2) mysession (/home/user/lttng-traces/mysession-20120123-083318) [inactive]
152 // Use lttng list <session_name> for more details
154 ArrayList
<String
> retArray
= new ArrayList
<>();
156 while (index
< result
.getOutput().length
) {
157 String line
= result
.getOutput()[index
];
158 Matcher matcher
= LTTngControlServiceConstants
.SESSION_PATTERN
.matcher(line
);
159 if (matcher
.matches()) {
160 retArray
.add(matcher
.group(2).trim());
164 return retArray
.toArray(new String
[retArray
.size()]);
168 public ISessionInfo
getSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
169 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST
, sessionName
);
170 ICommandResult result
= executeCommand(command
.toString(), monitor
);
175 // Tracing session mysession2: [inactive]
176 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
177 ISessionInfo sessionInfo
= new SessionInfo(sessionName
);
179 while (index
< result
.getOutput().length
) {
180 // Tracing session mysession2: [inactive]
181 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
183 // === Domain: Kernel ===
185 String line
= result
.getOutput()[index
];
186 Matcher matcher
= LTTngControlServiceConstants
.TRACE_SESSION_PATTERN
.matcher(line
);
187 if (matcher
.matches()) {
188 sessionInfo
.setSessionState(matcher
.group(2));
193 matcher
= LTTngControlServiceConstants
.TRACE_SNAPSHOT_SESSION_PATTERN
.matcher(line
);
194 if (matcher
.matches()) {
195 sessionInfo
.setSessionState(matcher
.group(2));
196 // real name will be set later
197 ISnapshotInfo snapshotInfo
= new SnapshotInfo(""); //$NON-NLS-1$
198 sessionInfo
.setSnapshotInfo(snapshotInfo
);
203 if (!sessionInfo
.isSnapshotSession()) {
204 matcher
= LTTngControlServiceConstants
.TRACE_NETWORK_PATH_PATTERN
.matcher(line
);
205 if (matcher
.matches()) {
206 sessionInfo
.setStreamedTrace(true);
209 matcher
= LTTngControlServiceConstants
.TRACE_SESSION_PATH_PATTERN
.matcher(line
);
210 if (matcher
.matches()) {
211 sessionInfo
.setSessionPath(matcher
.group(1).trim());
217 matcher
= LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(line
);
218 if (matcher
.matches()) {
220 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_KernelDomainDisplayName
);
223 domainInfo
.setIsKernel(true);
226 ArrayList
<IChannelInfo
> channels
= new ArrayList
<>();
227 index
= parseDomain(result
.getOutput(), index
, channels
, domainInfo
);
229 if (channels
.size() > 0) {
231 sessionInfo
.addDomain(domainInfo
);
234 domainInfo
.setChannels(channels
);
239 matcher
= LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
);
240 if (matcher
.matches()) {
241 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_UstGlobalDomainDisplayName
);
244 domainInfo
.setIsKernel(false);
247 ArrayList
<IChannelInfo
> channels
= new ArrayList
<>();
248 index
= parseDomain(result
.getOutput(), index
, channels
, domainInfo
);
250 if (channels
.size() > 0) {
252 sessionInfo
.addDomain(domainInfo
);
255 domainInfo
.setChannels(channels
);
262 if (sessionInfo
.isSnapshotSession()) {
263 ISnapshotInfo snapshot
= getSnapshotInfo(sessionName
, monitor
);
264 sessionInfo
.setSnapshotInfo(snapshot
);
271 public ISnapshotInfo
getSnapshotInfo(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
272 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST_SNAPSHOT_OUTPUT
, LTTngControlServiceConstants
.OPTION_SESSION
, sessionName
);
273 ICommandResult result
= executeCommand(command
.toString(), monitor
);
278 // [1] snapshot-1: /home/user/lttng-traces/my-20130909-114431
280 // [3] snapshot-3: net4://172.0.0.1/
281 ISnapshotInfo snapshotInfo
= new SnapshotInfo(""); //$NON-NLS-1$
283 while (index
< result
.getOutput().length
) {
284 String line
= result
.getOutput()[index
];
285 Matcher matcher
= LTTngControlServiceConstants
.LIST_SNAPSHOT_OUTPUT_PATTERN
.matcher(line
);
286 if (matcher
.matches()) {
287 snapshotInfo
.setId(Integer
.valueOf(matcher
.group(1)));
288 snapshotInfo
.setName(matcher
.group(2));
289 snapshotInfo
.setSnapshotPath(matcher
.group(3));
291 Matcher matcher2
= LTTngControlServiceConstants
.SNAPSHOT_NETWORK_PATH_PATTERN
.matcher(snapshotInfo
.getSnapshotPath());
292 if (matcher2
.matches()) {
293 snapshotInfo
.setStreamedSnapshot(true);
306 public List
<IBaseEventInfo
> getKernelProvider(IProgressMonitor monitor
) throws ExecutionException
{
307 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST_KERNEL
);
308 ICommandResult result
= executeCommand(command
.toString(), monitor
, false);
310 List
<IBaseEventInfo
> events
= new ArrayList
<>();
312 if (result
.getErrorOutput() != null) {
313 // Ignore the following 2 cases:
314 // Spawning a session daemon
315 // Error: Unable to list kernel events
317 // Error: Unable to list kernel events
320 while (index
< result
.getErrorOutput().length
) {
321 String line
= result
.getErrorOutput()[index
];
322 Matcher matcher
= LTTngControlServiceConstants
.LIST_KERNEL_NO_KERNEL_PROVIDER_PATTERN
.matcher(line
);
323 if (matcher
.matches()) {
330 if (isError(result
)) {
331 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$
336 // sched_kthread_stop (type: tracepoint)
337 getProviderEventInfo(result
.getOutput(), 0, events
);
342 public List
<IUstProviderInfo
> getUstProvider() throws ExecutionException
{
343 return getUstProvider(new NullProgressMonitor());
347 public List
<IUstProviderInfo
> getUstProvider(IProgressMonitor monitor
) throws ExecutionException
{
348 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST_UST
);
350 if (isVersionSupported("2.1.0")) { //$NON-NLS-1$
351 command
.append(LTTngControlServiceConstants
.OPTION_FIELDS
);
354 ICommandResult result
= executeCommand(command
.toString(), monitor
, false);
355 List
<IUstProviderInfo
> allProviders
= new ArrayList
<>();
357 // Workaround for versions 2.0.x which causes a segmentation fault for this command
358 // if LTTng Tools is compiled without UST support.
359 if (!isVersionSupported("2.1.0") && (result
.getResult() != 0)) { //$NON-NLS-1$
363 if (result
.getErrorOutput() != null) {
364 // Ignore the following 2 cases:
365 // Spawning a session daemon
366 // Error: Unable to list UST events: Listing UST events failed
368 // Error: Unable to list UST events: Listing UST events failed
371 while (index
< result
.getErrorOutput().length
) {
372 String line
= result
.getErrorOutput()[index
];
373 Matcher matcher
= LTTngControlServiceConstants
.LIST_UST_NO_UST_PROVIDER_PATTERN
.matcher(line
);
374 if (matcher
.matches()) {
381 if (isError(result
)) {
382 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$
385 // Note that field print-outs exists for version >= 2.1.0
391 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
392 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
394 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
395 // field: doublefield (float)
396 // field: floatfield (float)
397 // field: stringfield (string)
400 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
401 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
403 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
404 // field: doublefield (float)
405 // field: floatfield (float)
406 // field: stringfield (string)
408 IUstProviderInfo provider
= null;
411 while (index
< result
.getOutput().length
) {
412 String line
= result
.getOutput()[index
];
413 Matcher matcher
= LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
);
414 if (matcher
.matches()) {
415 provider
= new UstProviderInfo(matcher
.group(2).trim());
416 provider
.setPid(Integer
.valueOf(matcher
.group(1).trim()));
417 List
<IBaseEventInfo
> events
= new ArrayList
<>();
418 index
= getProviderEventInfo(result
.getOutput(), ++index
, events
);
419 provider
.setEvents(events
);
420 allProviders
.add(provider
);
429 public ISessionInfo
createSession(ISessionInfo sessionInfo
, IProgressMonitor monitor
) throws ExecutionException
{
430 if (sessionInfo
.isStreamedTrace()) {
431 return createStreamedSession(sessionInfo
, monitor
);
434 String newName
= formatParameter(sessionInfo
.getName());
435 String newPath
= formatParameter(sessionInfo
.getSessionPath());
437 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_CREATE_SESSION
, newName
);
439 if (newPath
!= null && !"".equals(newPath
)) { //$NON-NLS-1$
440 command
.append(LTTngControlServiceConstants
.OPTION_OUTPUT_PATH
);
441 command
.append(newPath
);
444 if (sessionInfo
.isSnapshotSession()) {
445 command
.append(LTTngControlServiceConstants
.OPTION_SNAPSHOT
);
448 ICommandResult result
= executeCommand(command
.toString(), monitor
);
450 //Session myssession2 created.
451 //Traces will be written in /home/user/lttng-traces/myssession2-20120209-095418
452 String
[] output
= result
.getOutput();
454 // Get and session name and path
459 while (index
< output
.length
) {
460 String line
= output
[index
];
461 Matcher nameMatcher
= LTTngControlServiceConstants
.CREATE_SESSION_NAME_PATTERN
.matcher(line
);
462 Matcher pathMatcher
= LTTngControlServiceConstants
.CREATE_SESSION_PATH_PATTERN
.matcher(line
);
463 if (nameMatcher
.matches()) {
464 name
= String
.valueOf(nameMatcher
.group(1).trim());
465 } else if (pathMatcher
.matches()) {
466 path
= String
.valueOf(pathMatcher
.group(1).trim());
471 // Verify session name
472 if ((name
== null) || (!"".equals(sessionInfo
.getName()) && !name
.equals(sessionInfo
.getName()))) { //$NON-NLS-1$
473 // Unexpected name returned
474 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
475 Messages
.TraceControl_UnexpectedNameError
+ ": " + name
); //$NON-NLS-1$
478 sessionInfo
.setName(name
);
479 // Verify session path
480 if (!sessionInfo
.isSnapshotSession() &&
481 ((path
== null) || ((sessionInfo
.getSessionPath() != null) && (!path
.contains(sessionInfo
.getSessionPath()))))) {
483 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
484 Messages
.TraceControl_UnexpectedPathError
+ ": " + name
); //$NON-NLS-1$
487 if (sessionInfo
.isSnapshotSession()) {
488 // Make it a snapshot session - content of snapshot info need to
489 // set afterwards using getSession() or getSnapshotInfo()
490 sessionInfo
.setSnapshotInfo(new SnapshotInfo("")); //$NON-NLS-1$
492 sessionInfo
.setSessionPath(path
);
499 private ISessionInfo
createStreamedSession(ISessionInfo sessionInfo
, IProgressMonitor monitor
) throws ExecutionException
{
501 String newName
= formatParameter(sessionInfo
.getName());
502 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_CREATE_SESSION
, newName
);
504 if (sessionInfo
.isSnapshotSession()) {
505 command
.append(LTTngControlServiceConstants
.OPTION_SNAPSHOT
);
506 } else if (sessionInfo
.isLive()) {
507 command
.append(LTTngControlServiceConstants
.OPTION_LIVE
);
508 if (sessionInfo
.getLiveDelay() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
509 command
.append(sessionInfo
.getLiveDelay());
513 if (sessionInfo
.getNetworkUrl() != null) {
514 command
.append(LTTngControlServiceConstants
.OPTION_NETWORK_URL
);
515 command
.append(sessionInfo
.getNetworkUrl());
517 command
.append(LTTngControlServiceConstants
.OPTION_CONTROL_URL
);
518 command
.append(sessionInfo
.getControlUrl());
520 command
.append(LTTngControlServiceConstants
.OPTION_DATA_URL
);
521 command
.append(sessionInfo
.getDataUrl());
524 ICommandResult result
= executeCommand(command
.toString(), monitor
);
527 String
[] output
= result
.getOutput();
529 // Get and session name and path
534 while (index
< output
.length
) {
535 String line
= output
[index
];
536 Matcher nameMatcher
= LTTngControlServiceConstants
.CREATE_SESSION_NAME_PATTERN
.matcher(line
);
537 Matcher pathMatcher
= LTTngControlServiceConstants
.CREATE_SESSION_PATH_PATTERN
.matcher(line
);
539 if (nameMatcher
.matches()) {
540 name
= String
.valueOf(nameMatcher
.group(1).trim());
541 } else if (pathMatcher
.matches() && (sessionInfo
.getNetworkUrl() != null)) {
542 path
= String
.valueOf(pathMatcher
.group(1).trim());
547 // Verify session name
548 if ((name
== null) || (!"".equals(sessionInfo
.getName()) && !name
.equals(sessionInfo
.getName()))) { //$NON-NLS-1$
549 // Unexpected name returned
550 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
551 Messages
.TraceControl_UnexpectedNameError
+ ": " + name
); //$NON-NLS-1$
554 sessionInfo
.setName(name
);
556 sessionInfo
.setStreamedTrace(true);
558 // Verify session path
559 if (sessionInfo
.getNetworkUrl() != null) {
560 if (!sessionInfo
.isSnapshotSession() && (path
== null)) {
562 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
563 Messages
.TraceControl_UnexpectedPathError
+ ": " + name
); //$NON-NLS-1$
566 if (sessionInfo
.isSnapshotSession()) {
567 sessionInfo
.setStreamedTrace(false);
569 sessionInfo
.setSessionPath(path
);
570 // Check file protocol
571 Matcher matcher
= LTTngControlServiceConstants
.TRACE_FILE_PROTOCOL_PATTERN
.matcher(path
);
572 if (matcher
.matches()) {
573 sessionInfo
.setStreamedTrace(false);
578 // When using controlUrl and dataUrl the full session path is not known yet
579 // and will be set later on when listing the session
585 public void destroySession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
586 String newName
= formatParameter(sessionName
);
588 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_DESTROY_SESSION
, newName
);
590 ICommandResult result
= executeCommand(command
.toString(), monitor
, false);
591 String
[] errorOutput
= result
.getErrorOutput();
593 boolean isError
= isError(result
);
594 if (isError
&& (errorOutput
!= null)) {
596 while (index
< errorOutput
.length
) {
597 String line
= errorOutput
[index
];
598 Matcher matcher
= LTTngControlServiceConstants
.SESSION_NOT_FOUND_ERROR_PATTERN
.matcher(line
);
599 if (matcher
.matches()) {
600 // Don't treat this as an error
608 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$
611 //Session <sessionName> destroyed
615 public void startSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
617 String newSessionName
= formatParameter(sessionName
);
619 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_START_SESSION
, newSessionName
);
621 executeCommand(command
.toString(), monitor
);
623 //Session <sessionName> started
627 public void stopSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
628 String newSessionName
= formatParameter(sessionName
);
629 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_STOP_SESSION
, newSessionName
);
631 executeCommand(command
.toString(), monitor
);
633 //Session <sessionName> stopped
638 public void enableChannels(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IChannelInfo info
, IProgressMonitor monitor
) throws ExecutionException
{
640 // no channels to enable
641 if (channelNames
.isEmpty()) {
645 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_CHANNEL
);
647 for (Iterator
<String
> iterator
= channelNames
.iterator(); iterator
.hasNext();) {
648 String channel
= iterator
.next();
649 command
.append(channel
);
650 if (iterator
.hasNext()) {
656 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
658 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
661 String newSessionName
= formatParameter(sessionName
);
662 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
663 command
.append(newSessionName
);
666 // --discard Discard event when buffers are full (default)
668 // --overwrite Flight recorder mode
669 if (info
.isOverwriteMode()) {
670 command
.append(LTTngControlServiceConstants
.OPTION_OVERWRITE
);
672 // --subbuf-size SIZE Subbuffer size in bytes
673 // (default: 4096, kernel default: 262144)
674 if (info
.getSubBufferSize() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
675 command
.append(LTTngControlServiceConstants
.OPTION_SUB_BUFFER_SIZE
);
676 command
.append(String
.valueOf(info
.getSubBufferSize()));
679 // --num-subbuf NUM Number of subbufers
680 if (info
.getNumberOfSubBuffers() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
681 command
.append(LTTngControlServiceConstants
.OPTION_NUM_SUB_BUFFERS
);
682 command
.append(String
.valueOf(info
.getNumberOfSubBuffers()));
685 // --switch-timer USEC Switch timer interval in usec
686 if (info
.getSwitchTimer() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
687 command
.append(LTTngControlServiceConstants
.OPTION_SWITCH_TIMER
);
688 command
.append(String
.valueOf(info
.getSwitchTimer()));
691 // --read-timer USEC Read timer interval in usec
692 if (info
.getReadTimer() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
693 command
.append(LTTngControlServiceConstants
.OPTION_READ_TIMER
);
694 command
.append(String
.valueOf(info
.getReadTimer()));
697 if (isVersionSupported("2.2.0")) { //$NON-NLS-1$
698 // --buffers-uid Every application sharing the same UID use the same buffers
699 // --buffers-pid Buffers are allocated per PID
701 if (info
.getBufferType() == BufferType
.BUFFER_PER_PID
) {
702 command
.append(LTTngControlServiceConstants
.OPTION_PER_PID_BUFFERS
);
704 } else if (info
.getBufferType() == BufferType
.BUFFER_PER_UID
) {
705 command
.append(LTTngControlServiceConstants
.OPTION_PER_UID_BUFFERS
);
709 // -C SIZE Maximum size of trace files in bytes
710 if (info
.getMaxSizeTraceFiles() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
711 command
.append(LTTngControlServiceConstants
.OPTION_MAX_SIZE_TRACE_FILES
);
712 command
.append(String
.valueOf(info
.getMaxSizeTraceFiles()));
715 // -W NUM Maximum number of trace files
716 if (info
.getMaxNumberTraceFiles() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
717 command
.append(LTTngControlServiceConstants
.OPTION_MAX_TRACE_FILES
);
718 command
.append(String
.valueOf(info
.getMaxNumberTraceFiles()));
723 executeCommand(command
.toString(), monitor
);
728 public void disableChannels(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
730 // no channels to enable
731 if (channelNames
.isEmpty()) {
735 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_DISABLE_CHANNEL
);
737 for (Iterator
<String
> iterator
= channelNames
.iterator(); iterator
.hasNext();) {
738 String channel
= iterator
.next();
739 command
.append(channel
);
740 if (iterator
.hasNext()) {
746 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
748 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
751 String newSessionName
= formatParameter(sessionName
);
752 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
753 command
.append(newSessionName
);
755 executeCommand(command
.toString(), monitor
);
759 public void enableEvents(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, String filterExpression
, IProgressMonitor monitor
) throws ExecutionException
{
761 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
763 if (eventNames
== null || eventNames
.isEmpty()) {
764 command
.append(LTTngControlServiceConstants
.OPTION_ALL
);
767 StringBuffer eventNameParameter
= new StringBuffer();
768 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
769 String event
= iterator
.next();
770 eventNameParameter
.append(event
);
771 if (iterator
.hasNext()) {
772 eventNameParameter
.append(',');
775 command
.append(formatParameter(eventNameParameter
.toString()));
779 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
781 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
784 String newSessionName
= formatParameter(sessionName
);
786 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
787 command
.append(newSessionName
);
789 if (channelName
!= null) {
790 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
791 command
.append(channelName
);
794 command
.append(LTTngControlServiceConstants
.OPTION_TRACEPOINT
);
796 if (filterExpression
!= null) {
797 command
.append(LTTngControlServiceConstants
.OPTION_FILTER
);
798 command
.append('\'');
799 command
.append(filterExpression
);
800 command
.append('\'');
803 executeCommand(command
.toString(), monitor
);
808 public void enableSyscalls(String sessionName
, String channelName
, IProgressMonitor monitor
) throws ExecutionException
{
810 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
812 command
.append(LTTngControlServiceConstants
.OPTION_ALL
);
813 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
815 String newSessionName
= formatParameter(sessionName
);
817 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
818 command
.append(newSessionName
);
820 if (channelName
!= null) {
821 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
822 command
.append(channelName
);
825 command
.append(LTTngControlServiceConstants
.OPTION_SYSCALL
);
827 executeCommand(command
.toString(), monitor
);
831 public void enableProbe(String sessionName
, String channelName
, String eventName
, boolean isFunction
, String probe
, IProgressMonitor monitor
) throws ExecutionException
{
832 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
834 command
.append(eventName
);
835 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
837 String newSessionName
= formatParameter(sessionName
);
838 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
839 command
.append(newSessionName
);
841 if (channelName
!= null) {
842 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
843 command
.append(channelName
);
846 command
.append(LTTngControlServiceConstants
.OPTION_FUNCTION_PROBE
);
848 command
.append(LTTngControlServiceConstants
.OPTION_PROBE
);
851 command
.append(probe
);
853 executeCommand(command
.toString(), monitor
);
857 public void enableLogLevel(String sessionName
, String channelName
, String eventName
, LogLevelType logLevelType
, TraceLogLevel level
, String filterExpression
, IProgressMonitor monitor
) throws ExecutionException
{
858 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
860 command
.append(eventName
);
861 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
863 String newSessionName
= formatParameter(sessionName
);
864 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
865 command
.append(newSessionName
);
867 if (channelName
!= null) {
868 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
869 command
.append(channelName
);
872 if (logLevelType
== LogLevelType
.LOGLEVEL
) {
873 command
.append(LTTngControlServiceConstants
.OPTION_LOGLEVEL
);
874 } else if (logLevelType
== LogLevelType
.LOGLEVEL_ONLY
) {
875 command
.append(LTTngControlServiceConstants
.OPTION_LOGLEVEL_ONLY
);
880 command
.append(level
.getInName());
882 executeCommand(command
.toString(), monitor
);
886 public void disableEvent(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
887 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_DISABLE_EVENT
);
889 if (eventNames
== null) {
890 command
.append(LTTngControlServiceConstants
.OPTION_ALL
);
892 // no events to disable
893 if (eventNames
.isEmpty()) {
897 StringBuffer eventNameParameter
= new StringBuffer();
898 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
899 String event
= iterator
.next();
900 eventNameParameter
.append(event
);
901 if (iterator
.hasNext()) {
902 eventNameParameter
.append(',');
905 command
.append(formatParameter(eventNameParameter
.toString()));
909 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
911 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
914 String newSessionName
= formatParameter(sessionName
);
915 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
916 command
.append(newSessionName
);
918 if (channelName
!= null) {
919 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
920 command
.append(channelName
);
923 executeCommand(command
.toString(), monitor
);
927 public List
<String
> getContextList(IProgressMonitor monitor
) throws ExecutionException
{
929 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ADD_CONTEXT
, LTTngControlServiceConstants
.OPTION_HELP
);
931 ICommandResult result
= executeCommand(command
.toString(), monitor
);
933 String
[] output
= result
.getOutput();
935 List
<String
> contexts
= new ArrayList
<>(0);
938 boolean inList
= false;
939 while (index
< output
.length
) {
940 String line
= result
.getOutput()[index
];
942 Matcher startMatcher
= LTTngControlServiceConstants
.ADD_CONTEXT_HELP_CONTEXTS_INTRO
.matcher(line
);
943 Matcher endMatcher
= LTTngControlServiceConstants
.ADD_CONTEXT_HELP_CONTEXTS_END_LINE
.matcher(line
);
945 if (startMatcher
.matches()) {
947 } else if (endMatcher
.matches()) {
949 } else if (inList
== true) {
950 String
[] tmp
= line
.split(","); //$NON-NLS-1$
951 for (int i
= 0; i
< tmp
.length
; i
++) {
952 contexts
.add(tmp
[i
].trim());
961 public void addContexts(String sessionName
, String channelName
, String eventName
, boolean isKernel
, List
<String
> contextNames
, IProgressMonitor monitor
) throws ExecutionException
{
962 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ADD_CONTEXT
);
964 String newSessionName
= formatParameter(sessionName
);
965 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
966 command
.append(newSessionName
);
968 if (channelName
!= null) {
969 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
970 command
.append(channelName
);
973 if (eventName
!= null) {
974 command
.append(LTTngControlServiceConstants
.OPTION_EVENT
);
975 command
.append(eventName
);
979 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
981 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
984 for (Iterator
<String
> iterator
= contextNames
.iterator(); iterator
.hasNext();) {
985 String context
= iterator
.next();
986 command
.append(LTTngControlServiceConstants
.OPTION_CONTEXT_TYPE
);
987 command
.append(context
);
990 executeCommand(command
.toString(), monitor
);
995 public void calibrate(boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
996 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_CALIBRATE
);
999 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
1001 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
1004 command
.append(LTTngControlServiceConstants
.OPTION_FUNCTION_PROBE
);
1006 executeCommand(command
.toString(), monitor
);
1010 public void recordSnapshot(String sessionName
, IProgressMonitor monitor
)
1011 throws ExecutionException
{
1012 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_RECORD_SNAPSHOT
);
1014 String newSessionName
= formatParameter(sessionName
);
1015 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
1016 command
.append(newSessionName
);
1018 executeCommand(command
.toString(), monitor
);
1022 public void runCommands(IProgressMonitor monitor
, List
<String
> commands
) throws ExecutionException
{
1023 for (String command
: commands
) {
1024 if (monitor
.isCanceled()) {
1028 if (command
.isEmpty() || command
.startsWith("#")) { //$NON-NLS-1$
1031 executeCommand(command
, monitor
);
1035 // ------------------------------------------------------------------------
1037 // ------------------------------------------------------------------------
1040 * Checks if command result is an error result.
1043 * - the command result to check
1044 * @return true if error else false
1046 protected boolean isError(ICommandResult result
) {
1047 // Check return code and length of returned strings
1049 if ((result
.getResult()) != 0) {
1053 // Look for error pattern
1055 while (index
< result
.getErrorOutput().length
) {
1056 String line
= result
.getErrorOutput()[index
];
1057 Matcher matcher
= LTTngControlServiceConstants
.ERROR_PATTERN
.matcher(line
);
1058 if (matcher
.matches()) {
1068 * Formats the output string as single string.
1072 * @return - the formatted output
1074 public static String
formatOutput(ICommandResult result
) {
1075 if ((result
== null) || ((result
.getOutput() == null || result
.getOutput().length
== 0) && (result
.getErrorOutput() == null || result
.getErrorOutput().length
== 0))) {
1076 return ""; //$NON-NLS-1$
1078 String
[] output
= result
.getOutput();
1079 String
[] errorOutput
= result
.getErrorOutput();
1080 StringBuffer ret
= new StringBuffer();
1081 ret
.append("Return Value: "); //$NON-NLS-1$
1082 ret
.append(result
.getResult());
1083 ret
.append("\n"); //$NON-NLS-1$
1084 for (int i
= 0; i
< output
.length
; i
++) {
1085 ret
.append(output
[i
]).append("\n"); //$NON-NLS-1$
1087 ret
.append("Error stream:\n"); //$NON-NLS-1$
1088 for (int i
= 0; i
< errorOutput
.length
; i
++) {
1089 ret
.append(errorOutput
[i
]).append("\n"); //$NON-NLS-1$
1091 return ret
.toString();
1095 * Parses the domain information.
1098 * - a command output array
1099 * @param currentIndex
1100 * - current index in command output array
1102 * - list for returning channel information
1104 * - The domain information
1105 * @return the new current index in command output array
1107 protected int parseDomain(String
[] output
, int currentIndex
, List
<IChannelInfo
> channels
, IDomainInfo domainInfo
) {
1108 int index
= currentIndex
;
1110 // if kernel set the buffer type to shared
1111 if (domainInfo
.isKernel()) {
1112 domainInfo
.setBufferType(BufferType
.BUFFER_SHARED
);
1117 // - channnel1: [enabled]
1120 // overwrite mode: 0
1121 // subbufers size: 262144
1122 // number of subbufers: 4
1123 // switch timer interval: 0
1124 // read timer interval: 200
1127 while (index
< output
.length
) {
1128 String line
= output
[index
];
1130 if (isVersionSupported("2.2.0")) { //$NON-NLS-1$
1131 Matcher bufferTypeMatcher
= LTTngControlServiceConstants
.BUFFER_TYPE_PATTERN
.matcher(line
);
1132 if (bufferTypeMatcher
.matches()) {
1133 String bufferTypeString
= getAttributeValue(line
);
1134 if (BufferType
.BUFFER_PER_PID
.getInName().equals(bufferTypeString
)) {
1135 domainInfo
.setBufferType(BufferType
.BUFFER_PER_PID
);
1136 } else if (BufferType
.BUFFER_PER_UID
.getInName().equals(bufferTypeString
)) {
1137 domainInfo
.setBufferType(BufferType
.BUFFER_PER_UID
);
1139 domainInfo
.setBufferType(BufferType
.BUFFER_TYPE_UNKNOWN
);
1143 domainInfo
.setBufferType(BufferType
.BUFFER_TYPE_UNKNOWN
);
1145 Matcher outerMatcher
= LTTngControlServiceConstants
.CHANNELS_SECTION_PATTERN
.matcher(line
);
1146 Matcher noKernelChannelMatcher
= LTTngControlServiceConstants
.DOMAIN_NO_KERNEL_CHANNEL_PATTERN
.matcher(line
);
1147 Matcher noUstChannelMatcher
= LTTngControlServiceConstants
.DOMAIN_NO_UST_CHANNEL_PATTERN
.matcher(line
);
1148 if (outerMatcher
.matches()) {
1149 IChannelInfo channelInfo
= null;
1150 while (index
< output
.length
) {
1151 String subLine
= output
[index
];
1153 Matcher innerMatcher
= LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(subLine
);
1154 if (innerMatcher
.matches()) {
1155 channelInfo
= new ChannelInfo(""); //$NON-NLS-1$
1157 channelInfo
.setName(innerMatcher
.group(1));
1159 // get channel enablement
1160 channelInfo
.setState(innerMatcher
.group(2));
1163 channelInfo
.setBufferType(domainInfo
.getBufferType());
1166 channels
.add(channelInfo
);
1168 } else if (LTTngControlServiceConstants
.OVERWRITE_MODE_ATTRIBUTE
.matcher(subLine
).matches()) {
1169 String value
= getAttributeValue(subLine
);
1170 if (channelInfo
!= null) {
1171 channelInfo
.setOverwriteMode(!LTTngControlServiceConstants
.OVERWRITE_MODE_ATTRIBUTE_FALSE
.equals(value
));
1173 } else if (LTTngControlServiceConstants
.SUBBUFFER_SIZE_ATTRIBUTE
.matcher(subLine
).matches()) {
1174 if (channelInfo
!= null) {
1175 channelInfo
.setSubBufferSize(Long
.valueOf(getAttributeValue(subLine
)));
1178 } else if (LTTngControlServiceConstants
.NUM_SUBBUFFERS_ATTRIBUTE
.matcher(subLine
).matches()) {
1179 if (channelInfo
!= null) {
1180 channelInfo
.setNumberOfSubBuffers(Integer
.valueOf(getAttributeValue(subLine
)));
1183 } else if (LTTngControlServiceConstants
.SWITCH_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
1184 if (channelInfo
!= null) {
1185 channelInfo
.setSwitchTimer(Long
.valueOf(getAttributeValue(subLine
)));
1188 } else if (LTTngControlServiceConstants
.READ_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
1189 if (channelInfo
!= null) {
1190 channelInfo
.setReadTimer(Long
.valueOf(getAttributeValue(subLine
)));
1193 } else if (LTTngControlServiceConstants
.OUTPUT_ATTRIBUTE
.matcher(subLine
).matches()) {
1194 if (channelInfo
!= null) {
1195 channelInfo
.setOutputType(getAttributeValue(subLine
));
1198 } else if (LTTngControlServiceConstants
.EVENT_SECTION_PATTERN
.matcher(subLine
).matches()) {
1199 List
<IEventInfo
> events
= new ArrayList
<>();
1200 index
= parseEvents(output
, index
, events
);
1201 if (channelInfo
!= null) {
1202 channelInfo
.setEvents(events
);
1204 // we want to stay at the current index to be able to
1207 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(subLine
).matches()) {
1210 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(subLine
).matches()) {
1215 } else if (noKernelChannelMatcher
.matches() || noUstChannelMatcher
.matches()) {
1216 // domain indicates that no channels were found -> return
1226 * Parses the event information within a domain.
1229 * - a command output array
1230 * @param currentIndex
1231 * - current index in command output array
1233 * - list for returning event information
1234 * @return the new current index in command output array
1236 protected int parseEvents(String
[] output
, int currentIndex
, List
<IEventInfo
> events
) {
1237 int index
= currentIndex
;
1239 while (index
< output
.length
) {
1240 String line
= output
[index
];
1241 if (LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(line
).matches()) {
1244 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(line
).matches()) {
1247 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
).matches()) {
1252 Matcher matcher
= LTTngControlServiceConstants
.EVENT_PATTERN
.matcher(line
);
1253 Matcher matcher2
= LTTngControlServiceConstants
.WILDCARD_EVENT_PATTERN
.matcher(line
);
1255 if (matcher
.matches()) {
1256 IEventInfo eventInfo
= new EventInfo(matcher
.group(1).trim());
1257 eventInfo
.setLogLevelType(matcher
.group(2).trim());
1258 eventInfo
.setLogLevel(matcher
.group(3).trim());
1259 eventInfo
.setEventType(matcher
.group(4).trim());
1260 eventInfo
.setState(matcher
.group(5));
1261 String filter
= matcher
.group(6);
1262 if (filter
!= null) {
1263 filter
= filter
.substring(1, filter
.length() - 1); // remove '[' and ']'
1264 eventInfo
.setFilterExpression(filter
);
1266 events
.add(eventInfo
);
1268 } else if (matcher2
.matches()) {
1269 IEventInfo eventInfo
= new EventInfo(matcher2
.group(1).trim());
1270 eventInfo
.setLogLevel(TraceLogLevel
.LEVEL_UNKNOWN
);
1271 eventInfo
.setEventType(matcher2
.group(2).trim());
1272 eventInfo
.setState(matcher2
.group(3));
1273 String filter
= matcher2
.group(4);
1274 if (filter
!= null) {
1275 filter
= filter
.substring(1, filter
.length() - 1); // remove '[' and ']'
1276 eventInfo
.setFilterExpression(filter
);
1279 if ((eventInfo
.getEventType() == TraceEventType
.PROBE
) ||
1280 (eventInfo
.getEventType() == TraceEventType
.FUNCTION
)){
1281 IProbeEventInfo probeEvent
= new ProbeEventInfo(eventInfo
.getName());
1282 probeEvent
.setLogLevel(eventInfo
.getLogLevel());
1283 probeEvent
.setEventType(eventInfo
.getEventType());
1284 probeEvent
.setState(eventInfo
.getState());
1286 // Overwrite eventinfo
1287 eventInfo
= probeEvent
;
1289 // myevent2 (type: probe) [enabled]
1291 // myevent0 (type: function) [enabled]
1293 // symbol: init_post
1295 while (index
< output
.length
) {
1296 String probeLine
= output
[index
];
1298 Matcher addrMatcher
= LTTngControlServiceConstants
.PROBE_ADDRESS_PATTERN
.matcher(probeLine
);
1299 Matcher offsetMatcher
= LTTngControlServiceConstants
.PROBE_OFFSET_PATTERN
.matcher(probeLine
);
1300 Matcher symbolMatcher
= LTTngControlServiceConstants
.PROBE_SYMBOL_PATTERN
.matcher(probeLine
);
1301 if (addrMatcher
.matches()) {
1302 String addr
= addrMatcher
.group(2).trim();
1303 probeEvent
.setAddress(addr
);
1304 } else if (offsetMatcher
.matches()) {
1305 String offset
= offsetMatcher
.group(2).trim();
1306 probeEvent
.setOffset(offset
);
1307 } else if (symbolMatcher
.matches()) {
1308 String symbol
= symbolMatcher
.group(2).trim();
1309 probeEvent
.setSymbol(symbol
);
1310 } else if ((LTTngControlServiceConstants
.EVENT_PATTERN
.matcher(probeLine
).matches()) || (LTTngControlServiceConstants
.WILDCARD_EVENT_PATTERN
.matcher(probeLine
).matches())) {
1312 } else if (LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(probeLine
).matches()) {
1314 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(probeLine
).matches()) {
1317 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(probeLine
).matches()) {
1323 events
.add(eventInfo
);
1325 events
.add(eventInfo
);
1338 * Parses a line with attributes: <attribute Name>: <attribute value>
1341 * - attribute line to parse
1342 * @return the attribute value as string
1344 protected String
getAttributeValue(String line
) {
1345 String
[] temp
= line
.split("\\: "); //$NON-NLS-1$
1350 * Parses the event information within a provider.
1353 * - a command output array
1354 * @param currentIndex
1355 * - current index in command output array
1357 * - list for returning event information
1358 * @return the new current index in command output array
1360 protected int getProviderEventInfo(String
[] output
, int currentIndex
, List
<IBaseEventInfo
> events
) {
1361 int index
= currentIndex
;
1362 IBaseEventInfo eventInfo
= null;
1363 while (index
< output
.length
) {
1364 String line
= output
[index
];
1365 Matcher matcher
= LTTngControlServiceConstants
.PROVIDER_EVENT_PATTERN
.matcher(line
);
1366 if (matcher
.matches()) {
1367 // sched_kthread_stop (loglevel: TRACE_EMERG0) (type: tracepoint)
1368 eventInfo
= new BaseEventInfo(matcher
.group(1).trim());
1369 eventInfo
.setLogLevel(matcher
.group(2).trim());
1370 eventInfo
.setEventType(matcher
.group(3).trim());
1371 events
.add(eventInfo
);
1373 } else if (LTTngControlServiceConstants
.EVENT_FIELD_PATTERN
.matcher(line
).matches()) {
1374 if (eventInfo
!= null) {
1375 List
<IFieldInfo
> fields
= new ArrayList
<>();
1376 index
= getFieldInfo(output
, index
, fields
);
1377 eventInfo
.setFields(fields
);
1382 else if (LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
).matches()) {
1393 * Parse a field's information.
1396 * A command output array
1397 * @param currentIndex
1398 * The current index in the command output array
1400 * List for returning the field information
1401 * @return The new current index in the command output array
1403 protected int getFieldInfo(String
[] output
, int currentIndex
, List
<IFieldInfo
> fields
) {
1404 int index
= currentIndex
;
1405 IFieldInfo fieldInfo
= null;
1406 while (index
< output
.length
) {
1407 String line
= output
[index
];
1408 Matcher matcher
= LTTngControlServiceConstants
.EVENT_FIELD_PATTERN
.matcher(line
);
1409 if (matcher
.matches()) {
1410 // field: content (string)
1411 fieldInfo
= new FieldInfo(matcher
.group(2).trim());
1412 fieldInfo
.setFieldType(matcher
.group(3).trim());
1413 fields
.add(fieldInfo
);
1414 } else if (LTTngControlServiceConstants
.PROVIDER_EVENT_PATTERN
.matcher(line
).matches()) {
1416 } else if (LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
).matches()) {
1425 * Formats a command parameter for the command execution i.e. adds quotes
1426 * at the beginning and end if necessary.
1427 * @param parameter - parameter to format
1428 * @return formated parameter
1430 protected String
formatParameter(String parameter
) {
1431 if (parameter
!= null) {
1432 StringBuffer newString
= new StringBuffer();
1433 newString
.append(parameter
);
1435 if (parameter
.contains(" ") || parameter
.contains("*")) { //$NON-NLS-1$ //$NON-NLS-2$
1436 newString
.insert(0, "\""); //$NON-NLS-1$
1437 newString
.append("\""); //$NON-NLS-1$
1439 return newString
.toString();
1445 * @param strings array of string that makes up a command line
1446 * @return string buffer with created command line
1448 protected StringBuffer
createCommand(String
... strings
) {
1449 StringBuffer command
= new StringBuffer();
1450 command
.append(LTTngControlServiceConstants
.CONTROL_COMMAND
);
1451 command
.append(getTracingGroupOption());
1452 command
.append(getVerboseOption());
1453 for (String string
: strings
) {
1454 command
.append(string
);
1460 * @return the tracing group option if configured in the preferences
1462 protected String
getTracingGroupOption() {
1463 if (!ControlPreferences
.getInstance().isDefaultTracingGroup() && !ControlPreferences
.getInstance().getTracingGroup().equals("")) { //$NON-NLS-1$
1464 return LTTngControlServiceConstants
.OPTION_TRACING_GROUP
+ ControlPreferences
.getInstance().getTracingGroup();
1466 return ""; //$NON-NLS-1$
1470 * @return the verbose option as configured in the preferences
1472 protected String
getVerboseOption() {
1473 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1474 String level
= ControlPreferences
.getInstance().getVerboseLevel();
1475 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_VERBOSE
.equals(level
)) {
1476 return LTTngControlServiceConstants
.OPTION_VERBOSE
;
1478 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_V_VERBOSE
.equals(level
)) {
1479 return LTTngControlServiceConstants
.OPTION_VERY_VERBOSE
;
1481 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_V_V_VERBOSE
.equals(level
)) {
1482 return LTTngControlServiceConstants
.OPTION_VERY_VERY_VERBOSE
;
1485 return ""; //$NON-NLS-1$
1489 * Method that logs the command and command result if logging is enabled as
1490 * well as forwards the command execution to the shell.
1493 * - the command to execute
1495 * - a progress monitor
1496 * @return the command result
1497 * @throws ExecutionException
1498 * If the command fails
1500 protected ICommandResult
executeCommand(String command
,
1501 IProgressMonitor monitor
) throws ExecutionException
{
1502 return executeCommand(command
, monitor
, true);
1506 * Method that logs the command and command result if logging is enabled as
1507 * well as forwards the command execution to the shell.
1510 * - the command to execute
1512 * - a progress monitor
1513 * @param checkForError
1514 * - true to verify command result, else false
1515 * @return the command result
1516 * @throws ExecutionException
1517 * in case of error result
1519 protected ICommandResult
executeCommand(String command
,
1520 IProgressMonitor monitor
, boolean checkForError
)
1521 throws ExecutionException
{
1522 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1523 ControlCommandLogger
.log(command
);
1526 ICommandResult result
= fCommandShell
.executeCommand(
1527 command
.toString(), monitor
);
1529 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1530 ControlCommandLogger
.log(formatOutput(result
));
1533 if (checkForError
&& isError(result
)) {
1534 throw new ExecutionException(Messages
.TraceControl_CommandError
1535 + " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$