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
getVersion() {
95 if (fVersion
== null) {
96 return "Unknown"; //$NON-NLS-1$
98 return fVersion
.toString();
102 * Sets the version of the LTTng 2.0 control service.
103 * @param version - a version to set
105 public void setVersion(String version
) {
106 fVersion
= new LttngVersion(version
);
110 public boolean isVersionSupported(String version
) {
111 LttngVersion tmp
= new LttngVersion(version
);
112 return (fVersion
!= null && fVersion
.compareTo(tmp
) >= 0) ?
true : false;
116 * Returns the command shell implementation.
118 * @return the command shell implementation
120 protected ICommandShell
getCommandShell() {
121 return fCommandShell
;
124 // ------------------------------------------------------------------------
126 // ------------------------------------------------------------------------
129 public String
[] getSessionNames(IProgressMonitor monitor
) throws ExecutionException
{
130 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST
);
132 ICommandResult result
= executeCommand(command
.toString(), monitor
);
135 // Available tracing sessions:
136 // 1) mysession1 (/home/user/lttng-traces/mysession1-20120123-083928) [inactive]
137 // 2) mysession (/home/user/lttng-traces/mysession-20120123-083318) [inactive]
139 // Use lttng list <session_name> for more details
141 ArrayList
<String
> retArray
= new ArrayList
<>();
143 while (index
< result
.getOutput().length
) {
144 String line
= result
.getOutput()[index
];
145 Matcher matcher
= LTTngControlServiceConstants
.SESSION_PATTERN
.matcher(line
);
146 if (matcher
.matches()) {
147 retArray
.add(matcher
.group(2).trim());
151 return retArray
.toArray(new String
[retArray
.size()]);
155 public ISessionInfo
getSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
156 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST
, sessionName
);
157 ICommandResult result
= executeCommand(command
.toString(), monitor
);
162 // Tracing session mysession2: [inactive]
163 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
164 ISessionInfo sessionInfo
= new SessionInfo(sessionName
);
166 while (index
< result
.getOutput().length
) {
167 // Tracing session mysession2: [inactive]
168 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
170 // === Domain: Kernel ===
172 String line
= result
.getOutput()[index
];
173 Matcher matcher
= LTTngControlServiceConstants
.TRACE_SESSION_PATTERN
.matcher(line
);
174 if (matcher
.matches()) {
175 sessionInfo
.setSessionState(matcher
.group(2));
180 matcher
= LTTngControlServiceConstants
.TRACE_SNAPSHOT_SESSION_PATTERN
.matcher(line
);
181 if (matcher
.matches()) {
182 sessionInfo
.setSessionState(matcher
.group(2));
183 // real name will be set later
184 ISnapshotInfo snapshotInfo
= new SnapshotInfo(""); //$NON-NLS-1$
185 sessionInfo
.setSnapshotInfo(snapshotInfo
);
190 if (!sessionInfo
.isSnapshotSession()) {
191 matcher
= LTTngControlServiceConstants
.TRACE_NETWORK_PATH_PATTERN
.matcher(line
);
192 if (matcher
.matches()) {
193 sessionInfo
.setStreamedTrace(true);
196 matcher
= LTTngControlServiceConstants
.TRACE_SESSION_PATH_PATTERN
.matcher(line
);
197 if (matcher
.matches()) {
198 sessionInfo
.setSessionPath(matcher
.group(1).trim());
204 matcher
= LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(line
);
205 if (matcher
.matches()) {
207 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_KernelDomainDisplayName
);
210 domainInfo
.setIsKernel(true);
213 ArrayList
<IChannelInfo
> channels
= new ArrayList
<>();
214 index
= parseDomain(result
.getOutput(), index
, channels
, domainInfo
);
216 if (channels
.size() > 0) {
218 sessionInfo
.addDomain(domainInfo
);
221 domainInfo
.setChannels(channels
);
226 matcher
= LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
);
227 if (matcher
.matches()) {
228 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_UstGlobalDomainDisplayName
);
231 domainInfo
.setIsKernel(false);
234 ArrayList
<IChannelInfo
> channels
= new ArrayList
<>();
235 index
= parseDomain(result
.getOutput(), index
, channels
, domainInfo
);
237 if (channels
.size() > 0) {
239 sessionInfo
.addDomain(domainInfo
);
242 domainInfo
.setChannels(channels
);
249 if (sessionInfo
.isSnapshotSession()) {
250 ISnapshotInfo snapshot
= getSnapshotInfo(sessionName
, monitor
);
251 sessionInfo
.setSnapshotInfo(snapshot
);
258 public ISnapshotInfo
getSnapshotInfo(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
259 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST_SNAPSHOT_OUTPUT
, LTTngControlServiceConstants
.OPTION_SESSION
, sessionName
);
260 ICommandResult result
= executeCommand(command
.toString(), monitor
);
265 // [1] snapshot-1: /home/user/lttng-traces/my-20130909-114431
267 // [3] snapshot-3: net4://172.0.0.1/
268 ISnapshotInfo snapshotInfo
= new SnapshotInfo(""); //$NON-NLS-1$
270 while (index
< result
.getOutput().length
) {
271 String line
= result
.getOutput()[index
];
272 Matcher matcher
= LTTngControlServiceConstants
.LIST_SNAPSHOT_OUTPUT_PATTERN
.matcher(line
);
273 if (matcher
.matches()) {
274 snapshotInfo
.setId(Integer
.valueOf(matcher
.group(1)));
275 snapshotInfo
.setName(matcher
.group(2));
276 snapshotInfo
.setSnapshotPath(matcher
.group(3));
278 Matcher matcher2
= LTTngControlServiceConstants
.SNAPSHOT_NETWORK_PATH_PATTERN
.matcher(snapshotInfo
.getSnapshotPath());
279 if (matcher2
.matches()) {
280 snapshotInfo
.setStreamedSnapshot(true);
293 public List
<IBaseEventInfo
> getKernelProvider(IProgressMonitor monitor
) throws ExecutionException
{
294 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST_KERNEL
);
295 ICommandResult result
= executeCommand(command
.toString(), monitor
, false);
297 List
<IBaseEventInfo
> events
= new ArrayList
<>();
299 if (result
.getErrorOutput() != null) {
300 // Ignore the following 2 cases:
301 // Spawning a session daemon
302 // Error: Unable to list kernel events
304 // Error: Unable to list kernel events
307 while (index
< result
.getErrorOutput().length
) {
308 String line
= result
.getErrorOutput()[index
];
309 Matcher matcher
= LTTngControlServiceConstants
.LIST_KERNEL_NO_KERNEL_PROVIDER_PATTERN
.matcher(line
);
310 if (matcher
.matches()) {
317 if (isError(result
)) {
318 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$
323 // sched_kthread_stop (type: tracepoint)
324 getProviderEventInfo(result
.getOutput(), 0, events
);
329 public List
<IUstProviderInfo
> getUstProvider() throws ExecutionException
{
330 return getUstProvider(new NullProgressMonitor());
334 public List
<IUstProviderInfo
> getUstProvider(IProgressMonitor monitor
) throws ExecutionException
{
335 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST_UST
);
337 if (isVersionSupported("2.1.0")) { //$NON-NLS-1$
338 command
.append(LTTngControlServiceConstants
.OPTION_FIELDS
);
341 ICommandResult result
= executeCommand(command
.toString(), monitor
, false);
342 List
<IUstProviderInfo
> allProviders
= new ArrayList
<>();
344 // Workaround for versions 2.0.x which causes a segmentation fault for this command
345 // if LTTng Tools is compiled without UST support.
346 if (!isVersionSupported("2.1.0") && (result
.getResult() != 0)) { //$NON-NLS-1$
350 if (result
.getErrorOutput() != null) {
351 // Ignore the following 2 cases:
352 // Spawning a session daemon
353 // Error: Unable to list UST events: Listing UST events failed
355 // Error: Unable to list UST events: Listing UST events failed
358 while (index
< result
.getErrorOutput().length
) {
359 String line
= result
.getErrorOutput()[index
];
360 Matcher matcher
= LTTngControlServiceConstants
.LIST_UST_NO_UST_PROVIDER_PATTERN
.matcher(line
);
361 if (matcher
.matches()) {
368 if (isError(result
)) {
369 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$
372 // Note that field print-outs exists for version >= 2.1.0
378 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
379 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
381 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
382 // field: doublefield (float)
383 // field: floatfield (float)
384 // field: stringfield (string)
387 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
388 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
390 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
391 // field: doublefield (float)
392 // field: floatfield (float)
393 // field: stringfield (string)
395 IUstProviderInfo provider
= null;
398 while (index
< result
.getOutput().length
) {
399 String line
= result
.getOutput()[index
];
400 Matcher matcher
= LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
);
401 if (matcher
.matches()) {
402 provider
= new UstProviderInfo(matcher
.group(2).trim());
403 provider
.setPid(Integer
.valueOf(matcher
.group(1).trim()));
404 List
<IBaseEventInfo
> events
= new ArrayList
<>();
405 index
= getProviderEventInfo(result
.getOutput(), ++index
, events
);
406 provider
.setEvents(events
);
407 allProviders
.add(provider
);
416 public ISessionInfo
createSession(ISessionInfo sessionInfo
, IProgressMonitor monitor
) throws ExecutionException
{
417 if (sessionInfo
.isStreamedTrace()) {
418 return createStreamedSession(sessionInfo
, monitor
);
421 String newName
= formatParameter(sessionInfo
.getName());
422 String newPath
= formatParameter(sessionInfo
.getSessionPath());
424 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_CREATE_SESSION
, newName
);
426 if (newPath
!= null && !"".equals(newPath
)) { //$NON-NLS-1$
427 command
.append(LTTngControlServiceConstants
.OPTION_OUTPUT_PATH
);
428 command
.append(newPath
);
431 if (sessionInfo
.isSnapshotSession()) {
432 command
.append(LTTngControlServiceConstants
.OPTION_SNAPSHOT
);
435 ICommandResult result
= executeCommand(command
.toString(), monitor
);
437 //Session myssession2 created.
438 //Traces will be written in /home/user/lttng-traces/myssession2-20120209-095418
439 String
[] output
= result
.getOutput();
441 // Get and session name and path
446 while (index
< output
.length
) {
447 String line
= output
[index
];
448 Matcher nameMatcher
= LTTngControlServiceConstants
.CREATE_SESSION_NAME_PATTERN
.matcher(line
);
449 Matcher pathMatcher
= LTTngControlServiceConstants
.CREATE_SESSION_PATH_PATTERN
.matcher(line
);
450 if (nameMatcher
.matches()) {
451 name
= String
.valueOf(nameMatcher
.group(1).trim());
452 } else if (pathMatcher
.matches()) {
453 path
= String
.valueOf(pathMatcher
.group(1).trim());
458 // Verify session name
459 if ((name
== null) || (!"".equals(sessionInfo
.getName()) && !name
.equals(sessionInfo
.getName()))) { //$NON-NLS-1$
460 // Unexpected name returned
461 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
462 Messages
.TraceControl_UnexpectedNameError
+ ": " + name
); //$NON-NLS-1$
465 sessionInfo
.setName(name
);
466 // Verify session path
467 if (!sessionInfo
.isSnapshotSession() &&
468 ((path
== null) || ((sessionInfo
.getSessionPath() != null) && (!path
.contains(sessionInfo
.getSessionPath()))))) {
470 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
471 Messages
.TraceControl_UnexpectedPathError
+ ": " + name
); //$NON-NLS-1$
474 if (sessionInfo
.isSnapshotSession()) {
475 // Make it a snapshot session - content of snapshot info need to
476 // set afterwards using getSession() or getSnapshotInfo()
477 sessionInfo
.setSnapshotInfo(new SnapshotInfo("")); //$NON-NLS-1$
479 sessionInfo
.setSessionPath(path
);
486 private ISessionInfo
createStreamedSession(ISessionInfo sessionInfo
, IProgressMonitor monitor
) throws ExecutionException
{
488 String newName
= formatParameter(sessionInfo
.getName());
489 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_CREATE_SESSION
, newName
);
491 if (sessionInfo
.isSnapshotSession()) {
492 command
.append(LTTngControlServiceConstants
.OPTION_SNAPSHOT
);
493 } else if (sessionInfo
.isLive()) {
494 command
.append(LTTngControlServiceConstants
.OPTION_LIVE
);
495 if (sessionInfo
.getLiveDelay() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
496 command
.append(sessionInfo
.getLiveDelay());
500 if (sessionInfo
.getNetworkUrl() != null) {
501 command
.append(LTTngControlServiceConstants
.OPTION_NETWORK_URL
);
502 command
.append(sessionInfo
.getNetworkUrl());
504 command
.append(LTTngControlServiceConstants
.OPTION_CONTROL_URL
);
505 command
.append(sessionInfo
.getControlUrl());
507 command
.append(LTTngControlServiceConstants
.OPTION_DATA_URL
);
508 command
.append(sessionInfo
.getDataUrl());
511 ICommandResult result
= executeCommand(command
.toString(), monitor
);
514 String
[] output
= result
.getOutput();
516 // Get and session name and path
521 while (index
< output
.length
) {
522 String line
= output
[index
];
523 Matcher nameMatcher
= LTTngControlServiceConstants
.CREATE_SESSION_NAME_PATTERN
.matcher(line
);
524 Matcher pathMatcher
= LTTngControlServiceConstants
.CREATE_SESSION_PATH_PATTERN
.matcher(line
);
526 if (nameMatcher
.matches()) {
527 name
= String
.valueOf(nameMatcher
.group(1).trim());
528 } else if (pathMatcher
.matches() && (sessionInfo
.getNetworkUrl() != null)) {
529 path
= String
.valueOf(pathMatcher
.group(1).trim());
534 // Verify session name
535 if ((name
== null) || (!"".equals(sessionInfo
.getName()) && !name
.equals(sessionInfo
.getName()))) { //$NON-NLS-1$
536 // Unexpected name returned
537 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
538 Messages
.TraceControl_UnexpectedNameError
+ ": " + name
); //$NON-NLS-1$
541 sessionInfo
.setName(name
);
543 sessionInfo
.setStreamedTrace(true);
545 // Verify session path
546 if (sessionInfo
.getNetworkUrl() != null) {
547 if (!sessionInfo
.isSnapshotSession() && (path
== null)) {
549 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
550 Messages
.TraceControl_UnexpectedPathError
+ ": " + name
); //$NON-NLS-1$
553 if (sessionInfo
.isSnapshotSession()) {
554 sessionInfo
.setStreamedTrace(false);
556 sessionInfo
.setSessionPath(path
);
557 // Check file protocol
558 Matcher matcher
= LTTngControlServiceConstants
.TRACE_FILE_PROTOCOL_PATTERN
.matcher(path
);
559 if (matcher
.matches()) {
560 sessionInfo
.setStreamedTrace(false);
565 // When using controlUrl and dataUrl the full session path is not known yet
566 // and will be set later on when listing the session
572 public void destroySession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
573 String newName
= formatParameter(sessionName
);
575 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_DESTROY_SESSION
, newName
);
577 ICommandResult result
= executeCommand(command
.toString(), monitor
, false);
578 String
[] errorOutput
= result
.getErrorOutput();
580 boolean isError
= isError(result
);
581 if (isError
&& (errorOutput
!= null)) {
583 while (index
< errorOutput
.length
) {
584 String line
= errorOutput
[index
];
585 Matcher matcher
= LTTngControlServiceConstants
.SESSION_NOT_FOUND_ERROR_PATTERN
.matcher(line
);
586 if (matcher
.matches()) {
587 // Don't treat this as an error
595 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$
598 //Session <sessionName> destroyed
602 public void startSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
604 String newSessionName
= formatParameter(sessionName
);
606 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_START_SESSION
, newSessionName
);
608 executeCommand(command
.toString(), monitor
);
610 //Session <sessionName> started
614 public void stopSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
615 String newSessionName
= formatParameter(sessionName
);
616 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_STOP_SESSION
, newSessionName
);
618 executeCommand(command
.toString(), monitor
);
620 //Session <sessionName> stopped
625 public void enableChannels(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IChannelInfo info
, IProgressMonitor monitor
) throws ExecutionException
{
627 // no channels to enable
628 if (channelNames
.isEmpty()) {
632 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_CHANNEL
);
634 for (Iterator
<String
> iterator
= channelNames
.iterator(); iterator
.hasNext();) {
635 String channel
= iterator
.next();
636 command
.append(channel
);
637 if (iterator
.hasNext()) {
643 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
645 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
648 String newSessionName
= formatParameter(sessionName
);
649 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
650 command
.append(newSessionName
);
653 // --discard Discard event when buffers are full (default)
655 // --overwrite Flight recorder mode
656 if (info
.isOverwriteMode()) {
657 command
.append(LTTngControlServiceConstants
.OPTION_OVERWRITE
);
659 // --subbuf-size SIZE Subbuffer size in bytes
660 // (default: 4096, kernel default: 262144)
661 if (info
.getSubBufferSize() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
662 command
.append(LTTngControlServiceConstants
.OPTION_SUB_BUFFER_SIZE
);
663 command
.append(String
.valueOf(info
.getSubBufferSize()));
666 // --num-subbuf NUM Number of subbufers
667 if (info
.getNumberOfSubBuffers() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
668 command
.append(LTTngControlServiceConstants
.OPTION_NUM_SUB_BUFFERS
);
669 command
.append(String
.valueOf(info
.getNumberOfSubBuffers()));
672 // --switch-timer USEC Switch timer interval in usec
673 if (info
.getSwitchTimer() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
674 command
.append(LTTngControlServiceConstants
.OPTION_SWITCH_TIMER
);
675 command
.append(String
.valueOf(info
.getSwitchTimer()));
678 // --read-timer USEC Read timer interval in usec
679 if (info
.getReadTimer() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
680 command
.append(LTTngControlServiceConstants
.OPTION_READ_TIMER
);
681 command
.append(String
.valueOf(info
.getReadTimer()));
684 if (isVersionSupported("2.2.0")) { //$NON-NLS-1$
685 // --buffers-uid Every application sharing the same UID use the same buffers
686 // --buffers-pid Buffers are allocated per PID
688 if (info
.getBufferType() == BufferType
.BUFFER_PER_PID
) {
689 command
.append(LTTngControlServiceConstants
.OPTION_PER_PID_BUFFERS
);
691 } else if (info
.getBufferType() == BufferType
.BUFFER_PER_UID
) {
692 command
.append(LTTngControlServiceConstants
.OPTION_PER_UID_BUFFERS
);
696 // -C SIZE Maximum size of trace files in bytes
697 if (info
.getMaxSizeTraceFiles() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
698 command
.append(LTTngControlServiceConstants
.OPTION_MAX_SIZE_TRACE_FILES
);
699 command
.append(String
.valueOf(info
.getMaxSizeTraceFiles()));
702 // -W NUM Maximum number of trace files
703 if (info
.getMaxNumberTraceFiles() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
704 command
.append(LTTngControlServiceConstants
.OPTION_MAX_TRACE_FILES
);
705 command
.append(String
.valueOf(info
.getMaxNumberTraceFiles()));
710 executeCommand(command
.toString(), monitor
);
715 public void disableChannels(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
717 // no channels to enable
718 if (channelNames
.isEmpty()) {
722 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_DISABLE_CHANNEL
);
724 for (Iterator
<String
> iterator
= channelNames
.iterator(); iterator
.hasNext();) {
725 String channel
= iterator
.next();
726 command
.append(channel
);
727 if (iterator
.hasNext()) {
733 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
735 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
738 String newSessionName
= formatParameter(sessionName
);
739 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
740 command
.append(newSessionName
);
742 executeCommand(command
.toString(), monitor
);
746 public void enableEvents(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, String filterExpression
, IProgressMonitor monitor
) throws ExecutionException
{
748 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
750 if (eventNames
== null || eventNames
.isEmpty()) {
751 command
.append(LTTngControlServiceConstants
.OPTION_ALL
);
754 StringBuffer eventNameParameter
= new StringBuffer();
755 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
756 String event
= iterator
.next();
757 eventNameParameter
.append(event
);
758 if (iterator
.hasNext()) {
759 eventNameParameter
.append(',');
762 command
.append(formatParameter(eventNameParameter
.toString()));
766 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
768 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
771 String newSessionName
= formatParameter(sessionName
);
773 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
774 command
.append(newSessionName
);
776 if (channelName
!= null) {
777 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
778 command
.append(channelName
);
781 command
.append(LTTngControlServiceConstants
.OPTION_TRACEPOINT
);
783 if (filterExpression
!= null) {
784 command
.append(LTTngControlServiceConstants
.OPTION_FILTER
);
785 command
.append('\'');
786 command
.append(filterExpression
);
787 command
.append('\'');
790 executeCommand(command
.toString(), monitor
);
795 public void enableSyscalls(String sessionName
, String channelName
, IProgressMonitor monitor
) throws ExecutionException
{
797 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
799 command
.append(LTTngControlServiceConstants
.OPTION_ALL
);
800 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
802 String newSessionName
= formatParameter(sessionName
);
804 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
805 command
.append(newSessionName
);
807 if (channelName
!= null) {
808 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
809 command
.append(channelName
);
812 command
.append(LTTngControlServiceConstants
.OPTION_SYSCALL
);
814 executeCommand(command
.toString(), monitor
);
818 public void enableProbe(String sessionName
, String channelName
, String eventName
, boolean isFunction
, String probe
, IProgressMonitor monitor
) throws ExecutionException
{
819 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
821 command
.append(eventName
);
822 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
824 String newSessionName
= formatParameter(sessionName
);
825 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
826 command
.append(newSessionName
);
828 if (channelName
!= null) {
829 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
830 command
.append(channelName
);
833 command
.append(LTTngControlServiceConstants
.OPTION_FUNCTION_PROBE
);
835 command
.append(LTTngControlServiceConstants
.OPTION_PROBE
);
838 command
.append(probe
);
840 executeCommand(command
.toString(), monitor
);
844 public void enableLogLevel(String sessionName
, String channelName
, String eventName
, LogLevelType logLevelType
, TraceLogLevel level
, String filterExpression
, IProgressMonitor monitor
) throws ExecutionException
{
845 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
847 command
.append(eventName
);
848 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
850 String newSessionName
= formatParameter(sessionName
);
851 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
852 command
.append(newSessionName
);
854 if (channelName
!= null) {
855 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
856 command
.append(channelName
);
859 if (logLevelType
== LogLevelType
.LOGLEVEL
) {
860 command
.append(LTTngControlServiceConstants
.OPTION_LOGLEVEL
);
861 } else if (logLevelType
== LogLevelType
.LOGLEVEL_ONLY
) {
862 command
.append(LTTngControlServiceConstants
.OPTION_LOGLEVEL_ONLY
);
867 command
.append(level
.getInName());
869 executeCommand(command
.toString(), monitor
);
873 public void disableEvent(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
874 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_DISABLE_EVENT
);
876 if (eventNames
== null) {
877 command
.append(LTTngControlServiceConstants
.OPTION_ALL
);
879 // no events to disable
880 if (eventNames
.isEmpty()) {
884 StringBuffer eventNameParameter
= new StringBuffer();
885 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
886 String event
= iterator
.next();
887 eventNameParameter
.append(event
);
888 if (iterator
.hasNext()) {
889 eventNameParameter
.append(',');
892 command
.append(formatParameter(eventNameParameter
.toString()));
896 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
898 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
901 String newSessionName
= formatParameter(sessionName
);
902 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
903 command
.append(newSessionName
);
905 if (channelName
!= null) {
906 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
907 command
.append(channelName
);
910 executeCommand(command
.toString(), monitor
);
914 public List
<String
> getContextList(IProgressMonitor monitor
) throws ExecutionException
{
916 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ADD_CONTEXT
, LTTngControlServiceConstants
.OPTION_HELP
);
918 ICommandResult result
= executeCommand(command
.toString(), monitor
);
920 String
[] output
= result
.getOutput();
922 List
<String
> contexts
= new ArrayList
<>(0);
925 boolean inList
= false;
926 while (index
< output
.length
) {
927 String line
= result
.getOutput()[index
];
929 Matcher startMatcher
= LTTngControlServiceConstants
.ADD_CONTEXT_HELP_CONTEXTS_INTRO
.matcher(line
);
930 Matcher endMatcher
= LTTngControlServiceConstants
.ADD_CONTEXT_HELP_CONTEXTS_END_LINE
.matcher(line
);
932 if (startMatcher
.matches()) {
934 } else if (endMatcher
.matches()) {
936 } else if (inList
== true) {
937 String
[] tmp
= line
.split(","); //$NON-NLS-1$
938 for (int i
= 0; i
< tmp
.length
; i
++) {
939 contexts
.add(tmp
[i
].trim());
948 public void addContexts(String sessionName
, String channelName
, String eventName
, boolean isKernel
, List
<String
> contextNames
, IProgressMonitor monitor
) throws ExecutionException
{
949 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ADD_CONTEXT
);
951 String newSessionName
= formatParameter(sessionName
);
952 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
953 command
.append(newSessionName
);
955 if (channelName
!= null) {
956 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
957 command
.append(channelName
);
960 if (eventName
!= null) {
961 command
.append(LTTngControlServiceConstants
.OPTION_EVENT
);
962 command
.append(eventName
);
966 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
968 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
971 for (Iterator
<String
> iterator
= contextNames
.iterator(); iterator
.hasNext();) {
972 String context
= iterator
.next();
973 command
.append(LTTngControlServiceConstants
.OPTION_CONTEXT_TYPE
);
974 command
.append(context
);
977 executeCommand(command
.toString(), monitor
);
982 public void calibrate(boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
983 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_CALIBRATE
);
986 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
988 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
991 command
.append(LTTngControlServiceConstants
.OPTION_FUNCTION_PROBE
);
993 executeCommand(command
.toString(), monitor
);
997 public void recordSnapshot(String sessionName
, IProgressMonitor monitor
)
998 throws ExecutionException
{
999 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_RECORD_SNAPSHOT
);
1001 String newSessionName
= formatParameter(sessionName
);
1002 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
1003 command
.append(newSessionName
);
1005 executeCommand(command
.toString(), monitor
);
1009 public void runCommands(IProgressMonitor monitor
, List
<String
> commands
) throws ExecutionException
{
1010 for (String command
: commands
) {
1011 if (monitor
.isCanceled()) {
1015 if (command
.isEmpty() || command
.startsWith("#")) { //$NON-NLS-1$
1018 executeCommand(command
, monitor
);
1022 // ------------------------------------------------------------------------
1024 // ------------------------------------------------------------------------
1027 * Checks if command result is an error result.
1030 * - the command result to check
1031 * @return true if error else false
1033 protected boolean isError(ICommandResult result
) {
1034 // Check return code and length of returned strings
1036 if ((result
.getResult()) != 0) {
1040 // Look for error pattern
1042 while (index
< result
.getErrorOutput().length
) {
1043 String line
= result
.getErrorOutput()[index
];
1044 Matcher matcher
= LTTngControlServiceConstants
.ERROR_PATTERN
.matcher(line
);
1045 if (matcher
.matches()) {
1055 * Formats the output string as single string.
1059 * @return - the formatted output
1061 public static String
formatOutput(ICommandResult result
) {
1062 if ((result
== null) || ((result
.getOutput() == null || result
.getOutput().length
== 0) && (result
.getErrorOutput() == null || result
.getErrorOutput().length
== 0))) {
1063 return ""; //$NON-NLS-1$
1065 String
[] output
= result
.getOutput();
1066 String
[] errorOutput
= result
.getErrorOutput();
1067 StringBuffer ret
= new StringBuffer();
1068 ret
.append("Return Value: "); //$NON-NLS-1$
1069 ret
.append(result
.getResult());
1070 ret
.append("\n"); //$NON-NLS-1$
1071 for (int i
= 0; i
< output
.length
; i
++) {
1072 ret
.append(output
[i
]).append("\n"); //$NON-NLS-1$
1074 ret
.append("Error stream:\n"); //$NON-NLS-1$
1075 for (int i
= 0; i
< errorOutput
.length
; i
++) {
1076 ret
.append(errorOutput
[i
]).append("\n"); //$NON-NLS-1$
1078 return ret
.toString();
1082 * Parses the domain information.
1085 * - a command output array
1086 * @param currentIndex
1087 * - current index in command output array
1089 * - list for returning channel information
1091 * - The domain information
1092 * @return the new current index in command output array
1094 protected int parseDomain(String
[] output
, int currentIndex
, List
<IChannelInfo
> channels
, IDomainInfo domainInfo
) {
1095 int index
= currentIndex
;
1097 // if kernel set the buffer type to shared
1098 if (domainInfo
.isKernel()) {
1099 domainInfo
.setBufferType(BufferType
.BUFFER_SHARED
);
1104 // - channnel1: [enabled]
1107 // overwrite mode: 0
1108 // subbufers size: 262144
1109 // number of subbufers: 4
1110 // switch timer interval: 0
1111 // read timer interval: 200
1114 while (index
< output
.length
) {
1115 String line
= output
[index
];
1117 if (isVersionSupported("2.2.0")) { //$NON-NLS-1$
1118 Matcher bufferTypeMatcher
= LTTngControlServiceConstants
.BUFFER_TYPE_PATTERN
.matcher(line
);
1119 if (bufferTypeMatcher
.matches()) {
1120 String bufferTypeString
= getAttributeValue(line
);
1121 if (BufferType
.BUFFER_PER_PID
.getInName().equals(bufferTypeString
)) {
1122 domainInfo
.setBufferType(BufferType
.BUFFER_PER_PID
);
1123 } else if (BufferType
.BUFFER_PER_UID
.getInName().equals(bufferTypeString
)) {
1124 domainInfo
.setBufferType(BufferType
.BUFFER_PER_UID
);
1126 domainInfo
.setBufferType(BufferType
.BUFFER_TYPE_UNKNOWN
);
1130 domainInfo
.setBufferType(BufferType
.BUFFER_TYPE_UNKNOWN
);
1132 Matcher outerMatcher
= LTTngControlServiceConstants
.CHANNELS_SECTION_PATTERN
.matcher(line
);
1133 Matcher noKernelChannelMatcher
= LTTngControlServiceConstants
.DOMAIN_NO_KERNEL_CHANNEL_PATTERN
.matcher(line
);
1134 Matcher noUstChannelMatcher
= LTTngControlServiceConstants
.DOMAIN_NO_UST_CHANNEL_PATTERN
.matcher(line
);
1135 if (outerMatcher
.matches()) {
1136 IChannelInfo channelInfo
= null;
1137 while (index
< output
.length
) {
1138 String subLine
= output
[index
];
1140 Matcher innerMatcher
= LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(subLine
);
1141 if (innerMatcher
.matches()) {
1142 channelInfo
= new ChannelInfo(""); //$NON-NLS-1$
1144 channelInfo
.setName(innerMatcher
.group(1));
1146 // get channel enablement
1147 channelInfo
.setState(innerMatcher
.group(2));
1150 channelInfo
.setBufferType(domainInfo
.getBufferType());
1153 channels
.add(channelInfo
);
1155 } else if (LTTngControlServiceConstants
.OVERWRITE_MODE_ATTRIBUTE
.matcher(subLine
).matches()) {
1156 String value
= getAttributeValue(subLine
);
1157 if (channelInfo
!= null) {
1158 channelInfo
.setOverwriteMode(!LTTngControlServiceConstants
.OVERWRITE_MODE_ATTRIBUTE_FALSE
.equals(value
));
1160 } else if (LTTngControlServiceConstants
.SUBBUFFER_SIZE_ATTRIBUTE
.matcher(subLine
).matches()) {
1161 if (channelInfo
!= null) {
1162 channelInfo
.setSubBufferSize(Long
.valueOf(getAttributeValue(subLine
)));
1165 } else if (LTTngControlServiceConstants
.NUM_SUBBUFFERS_ATTRIBUTE
.matcher(subLine
).matches()) {
1166 if (channelInfo
!= null) {
1167 channelInfo
.setNumberOfSubBuffers(Integer
.valueOf(getAttributeValue(subLine
)));
1170 } else if (LTTngControlServiceConstants
.SWITCH_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
1171 if (channelInfo
!= null) {
1172 channelInfo
.setSwitchTimer(Long
.valueOf(getAttributeValue(subLine
)));
1175 } else if (LTTngControlServiceConstants
.READ_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
1176 if (channelInfo
!= null) {
1177 channelInfo
.setReadTimer(Long
.valueOf(getAttributeValue(subLine
)));
1180 } else if (LTTngControlServiceConstants
.OUTPUT_ATTRIBUTE
.matcher(subLine
).matches()) {
1181 if (channelInfo
!= null) {
1182 channelInfo
.setOutputType(getAttributeValue(subLine
));
1185 } else if (LTTngControlServiceConstants
.EVENT_SECTION_PATTERN
.matcher(subLine
).matches()) {
1186 List
<IEventInfo
> events
= new ArrayList
<>();
1187 index
= parseEvents(output
, index
, events
);
1188 if (channelInfo
!= null) {
1189 channelInfo
.setEvents(events
);
1191 // we want to stay at the current index to be able to
1194 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(subLine
).matches()) {
1197 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(subLine
).matches()) {
1202 } else if (noKernelChannelMatcher
.matches() || noUstChannelMatcher
.matches()) {
1203 // domain indicates that no channels were found -> return
1213 * Parses the event information within a domain.
1216 * - a command output array
1217 * @param currentIndex
1218 * - current index in command output array
1220 * - list for returning event information
1221 * @return the new current index in command output array
1223 protected int parseEvents(String
[] output
, int currentIndex
, List
<IEventInfo
> events
) {
1224 int index
= currentIndex
;
1226 while (index
< output
.length
) {
1227 String line
= output
[index
];
1228 if (LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(line
).matches()) {
1231 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(line
).matches()) {
1234 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
).matches()) {
1239 Matcher matcher
= LTTngControlServiceConstants
.EVENT_PATTERN
.matcher(line
);
1240 Matcher matcher2
= LTTngControlServiceConstants
.WILDCARD_EVENT_PATTERN
.matcher(line
);
1242 if (matcher
.matches()) {
1243 IEventInfo eventInfo
= new EventInfo(matcher
.group(1).trim());
1244 eventInfo
.setLogLevelType(matcher
.group(2).trim());
1245 eventInfo
.setLogLevel(matcher
.group(3).trim());
1246 eventInfo
.setEventType(matcher
.group(4).trim());
1247 eventInfo
.setState(matcher
.group(5));
1248 String filter
= matcher
.group(6);
1249 if (filter
!= null) {
1250 filter
= filter
.substring(1, filter
.length() - 1); // remove '[' and ']'
1251 eventInfo
.setFilterExpression(filter
);
1253 events
.add(eventInfo
);
1255 } else if (matcher2
.matches()) {
1256 IEventInfo eventInfo
= new EventInfo(matcher2
.group(1).trim());
1257 eventInfo
.setLogLevel(TraceLogLevel
.LEVEL_UNKNOWN
);
1258 eventInfo
.setEventType(matcher2
.group(2).trim());
1259 eventInfo
.setState(matcher2
.group(3));
1260 String filter
= matcher2
.group(4);
1261 if (filter
!= null) {
1262 filter
= filter
.substring(1, filter
.length() - 1); // remove '[' and ']'
1263 eventInfo
.setFilterExpression(filter
);
1266 if ((eventInfo
.getEventType() == TraceEventType
.PROBE
) ||
1267 (eventInfo
.getEventType() == TraceEventType
.FUNCTION
)){
1268 IProbeEventInfo probeEvent
= new ProbeEventInfo(eventInfo
.getName());
1269 probeEvent
.setLogLevel(eventInfo
.getLogLevel());
1270 probeEvent
.setEventType(eventInfo
.getEventType());
1271 probeEvent
.setState(eventInfo
.getState());
1273 // Overwrite eventinfo
1274 eventInfo
= probeEvent
;
1276 // myevent2 (type: probe) [enabled]
1278 // myevent0 (type: function) [enabled]
1280 // symbol: init_post
1282 while (index
< output
.length
) {
1283 String probeLine
= output
[index
];
1285 Matcher addrMatcher
= LTTngControlServiceConstants
.PROBE_ADDRESS_PATTERN
.matcher(probeLine
);
1286 Matcher offsetMatcher
= LTTngControlServiceConstants
.PROBE_OFFSET_PATTERN
.matcher(probeLine
);
1287 Matcher symbolMatcher
= LTTngControlServiceConstants
.PROBE_SYMBOL_PATTERN
.matcher(probeLine
);
1288 if (addrMatcher
.matches()) {
1289 String addr
= addrMatcher
.group(2).trim();
1290 probeEvent
.setAddress(addr
);
1291 } else if (offsetMatcher
.matches()) {
1292 String offset
= offsetMatcher
.group(2).trim();
1293 probeEvent
.setOffset(offset
);
1294 } else if (symbolMatcher
.matches()) {
1295 String symbol
= symbolMatcher
.group(2).trim();
1296 probeEvent
.setSymbol(symbol
);
1297 } else if ((LTTngControlServiceConstants
.EVENT_PATTERN
.matcher(probeLine
).matches()) || (LTTngControlServiceConstants
.WILDCARD_EVENT_PATTERN
.matcher(probeLine
).matches())) {
1299 } else if (LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(probeLine
).matches()) {
1301 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(probeLine
).matches()) {
1304 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(probeLine
).matches()) {
1310 events
.add(eventInfo
);
1312 events
.add(eventInfo
);
1325 * Parses a line with attributes: <attribute Name>: <attribute value>
1328 * - attribute line to parse
1329 * @return the attribute value as string
1331 protected String
getAttributeValue(String line
) {
1332 String
[] temp
= line
.split("\\: "); //$NON-NLS-1$
1337 * Parses the event information within a provider.
1340 * - a command output array
1341 * @param currentIndex
1342 * - current index in command output array
1344 * - list for returning event information
1345 * @return the new current index in command output array
1347 protected int getProviderEventInfo(String
[] output
, int currentIndex
, List
<IBaseEventInfo
> events
) {
1348 int index
= currentIndex
;
1349 IBaseEventInfo eventInfo
= null;
1350 while (index
< output
.length
) {
1351 String line
= output
[index
];
1352 Matcher matcher
= LTTngControlServiceConstants
.PROVIDER_EVENT_PATTERN
.matcher(line
);
1353 if (matcher
.matches()) {
1354 // sched_kthread_stop (loglevel: TRACE_EMERG0) (type: tracepoint)
1355 eventInfo
= new BaseEventInfo(matcher
.group(1).trim());
1356 eventInfo
.setLogLevel(matcher
.group(2).trim());
1357 eventInfo
.setEventType(matcher
.group(3).trim());
1358 events
.add(eventInfo
);
1360 } else if (LTTngControlServiceConstants
.EVENT_FIELD_PATTERN
.matcher(line
).matches()) {
1361 if (eventInfo
!= null) {
1362 List
<IFieldInfo
> fields
= new ArrayList
<>();
1363 index
= getFieldInfo(output
, index
, fields
);
1364 eventInfo
.setFields(fields
);
1369 else if (LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
).matches()) {
1380 * Parse a field's information.
1383 * A command output array
1384 * @param currentIndex
1385 * The current index in the command output array
1387 * List for returning the field information
1388 * @return The new current index in the command output array
1390 protected int getFieldInfo(String
[] output
, int currentIndex
, List
<IFieldInfo
> fields
) {
1391 int index
= currentIndex
;
1392 IFieldInfo fieldInfo
= null;
1393 while (index
< output
.length
) {
1394 String line
= output
[index
];
1395 Matcher matcher
= LTTngControlServiceConstants
.EVENT_FIELD_PATTERN
.matcher(line
);
1396 if (matcher
.matches()) {
1397 // field: content (string)
1398 fieldInfo
= new FieldInfo(matcher
.group(2).trim());
1399 fieldInfo
.setFieldType(matcher
.group(3).trim());
1400 fields
.add(fieldInfo
);
1401 } else if (LTTngControlServiceConstants
.PROVIDER_EVENT_PATTERN
.matcher(line
).matches()) {
1403 } else if (LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
).matches()) {
1412 * Formats a command parameter for the command execution i.e. adds quotes
1413 * at the beginning and end if necessary.
1414 * @param parameter - parameter to format
1415 * @return formated parameter
1417 protected String
formatParameter(String parameter
) {
1418 if (parameter
!= null) {
1419 StringBuffer newString
= new StringBuffer();
1420 newString
.append(parameter
);
1422 if (parameter
.contains(" ") || parameter
.contains("*")) { //$NON-NLS-1$ //$NON-NLS-2$
1423 newString
.insert(0, "\""); //$NON-NLS-1$
1424 newString
.append("\""); //$NON-NLS-1$
1426 return newString
.toString();
1432 * @param strings array of string that makes up a command line
1433 * @return string buffer with created command line
1435 protected StringBuffer
createCommand(String
... strings
) {
1436 StringBuffer command
= new StringBuffer();
1437 command
.append(LTTngControlServiceConstants
.CONTROL_COMMAND
);
1438 command
.append(getTracingGroupOption());
1439 command
.append(getVerboseOption());
1440 for (String string
: strings
) {
1441 command
.append(string
);
1447 * @return the tracing group option if configured in the preferences
1449 protected String
getTracingGroupOption() {
1450 if (!ControlPreferences
.getInstance().isDefaultTracingGroup() && !ControlPreferences
.getInstance().getTracingGroup().equals("")) { //$NON-NLS-1$
1451 return LTTngControlServiceConstants
.OPTION_TRACING_GROUP
+ ControlPreferences
.getInstance().getTracingGroup();
1453 return ""; //$NON-NLS-1$
1457 * @return the verbose option as configured in the preferences
1459 protected String
getVerboseOption() {
1460 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1461 String level
= ControlPreferences
.getInstance().getVerboseLevel();
1462 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_VERBOSE
.equals(level
)) {
1463 return LTTngControlServiceConstants
.OPTION_VERBOSE
;
1465 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_V_VERBOSE
.equals(level
)) {
1466 return LTTngControlServiceConstants
.OPTION_VERY_VERBOSE
;
1468 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_V_V_VERBOSE
.equals(level
)) {
1469 return LTTngControlServiceConstants
.OPTION_VERY_VERY_VERBOSE
;
1472 return ""; //$NON-NLS-1$
1476 * Method that logs the command and command result if logging is enabled as
1477 * well as forwards the command execution to the shell.
1480 * - the command to execute
1482 * - a progress monitor
1483 * @return the command result
1484 * @throws ExecutionException
1485 * If the command fails
1487 protected ICommandResult
executeCommand(String command
,
1488 IProgressMonitor monitor
) throws ExecutionException
{
1489 return executeCommand(command
, monitor
, true);
1493 * Method that logs the command and command result if logging is enabled as
1494 * well as forwards the command execution to the shell.
1497 * - the command to execute
1499 * - a progress monitor
1500 * @param checkForError
1501 * - true to verify command result, else false
1502 * @return the command result
1503 * @throws ExecutionException
1504 * in case of error result
1506 protected ICommandResult
executeCommand(String command
,
1507 IProgressMonitor monitor
, boolean checkForError
)
1508 throws ExecutionException
{
1509 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1510 ControlCommandLogger
.log(command
);
1513 ICommandResult result
= fCommandShell
.executeCommand(
1514 command
.toString(), monitor
);
1516 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1517 ControlCommandLogger
.log(formatOutput(result
));
1520 if (checkForError
&& isError(result
)) {
1521 throw new ExecutionException(Messages
.TraceControl_CommandError
1522 + " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$