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
;
21 import java
.util
.regex
.Pattern
;
23 import org
.eclipse
.core
.commands
.ExecutionException
;
24 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
25 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.IBaseEventInfo
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.IChannelInfo
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.IDomainInfo
;
29 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.IEventInfo
;
30 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.IFieldInfo
;
31 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.IProbeEventInfo
;
32 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.ISessionInfo
;
33 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.ISnapshotInfo
;
34 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.IUstProviderInfo
;
35 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.LogLevelType
;
36 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.TraceEventType
;
37 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.TraceLogLevel
;
38 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.impl
.BaseEventInfo
;
39 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.impl
.BufferType
;
40 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.impl
.ChannelInfo
;
41 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.impl
.DomainInfo
;
42 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.impl
.EventInfo
;
43 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.impl
.FieldInfo
;
44 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.impl
.ProbeEventInfo
;
45 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.impl
.SessionInfo
;
46 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.impl
.SnapshotInfo
;
47 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.impl
.UstProviderInfo
;
48 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.logging
.ControlCommandLogger
;
49 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.messages
.Messages
;
50 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.preferences
.ControlPreferences
;
51 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.remote
.ICommandResult
;
52 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.remote
.ICommandShell
;
56 * Service for sending LTTng trace control commands to remote host.
59 * @author Bernd Hufmann
61 public class LTTngControlService
implements ILttngControlService
{
63 // ------------------------------------------------------------------------
65 // ------------------------------------------------------------------------
67 * The command shell implementation
69 private final ICommandShell fCommandShell
;
74 private LttngVersion fVersion
= null;
76 // ------------------------------------------------------------------------
78 // ------------------------------------------------------------------------
84 * - the command shell implementation to use
86 public LTTngControlService(ICommandShell shell
) {
87 fCommandShell
= shell
;
90 // ------------------------------------------------------------------------
92 // ------------------------------------------------------------------------
95 public String
getVersionString() {
96 if (fVersion
== null) {
97 return "Unknown"; //$NON-NLS-1$
99 return fVersion
.toString();
103 public LttngVersion
getVersion() {
108 * Sets the version of the LTTng 2.0 control service.
113 public void setVersion(String version
) {
114 fVersion
= new LttngVersion(version
);
118 * Sets the version of the LTTng 2.x control service.
123 public void setVersion(LttngVersion version
) {
128 public boolean isVersionSupported(String version
) {
129 LttngVersion tmp
= new LttngVersion(version
);
130 return (fVersion
!= null && fVersion
.compareTo(tmp
) >= 0) ?
true : false;
134 * Returns the command shell implementation.
136 * @return the command shell implementation
138 protected ICommandShell
getCommandShell() {
139 return fCommandShell
;
142 // ------------------------------------------------------------------------
144 // ------------------------------------------------------------------------
147 public String
[] getSessionNames(IProgressMonitor monitor
) throws ExecutionException
{
148 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST
);
150 ICommandResult result
= executeCommand(command
.toString(), monitor
);
153 // Available tracing sessions:
154 // 1) mysession1 (/home/user/lttng-traces/mysession1-20120123-083928)
156 // 2) mysession (/home/user/lttng-traces/mysession-20120123-083318)
159 // Use lttng list <session_name> for more details
161 ArrayList
<String
> retArray
= new ArrayList
<>();
163 while (index
< result
.getOutput().length
) {
164 String line
= result
.getOutput()[index
];
165 Matcher matcher
= LTTngControlServiceConstants
.SESSION_PATTERN
.matcher(line
);
166 if (matcher
.matches()) {
167 retArray
.add(matcher
.group(2).trim());
171 return retArray
.toArray(new String
[retArray
.size()]);
175 * Check if there is a pattern to be ignored into a sequence of string
178 * an arrays of string
180 * the pattern to search for
181 * @return if the pattern exist into the array of string
183 protected boolean ignoredPattern(String
[] input
, Pattern pattern
) {
184 for (String line
: input
) {
185 Matcher matcher
= pattern
.matcher(line
);
186 if (matcher
.matches()) {
194 public ISessionInfo
getSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
195 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST
, sessionName
);
196 ICommandResult result
= executeCommand(command
.toString(), monitor
);
201 // Tracing session mysession2: [inactive]
202 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
203 ISessionInfo sessionInfo
= new SessionInfo(sessionName
);
205 while (index
< result
.getOutput().length
) {
206 // Tracing session mysession2: [inactive]
207 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
209 // === Domain: Kernel ===
211 String line
= result
.getOutput()[index
];
212 Matcher matcher
= LTTngControlServiceConstants
.TRACE_SESSION_PATTERN
.matcher(line
);
213 if (matcher
.matches()) {
214 sessionInfo
.setSessionState(matcher
.group(2));
219 matcher
= LTTngControlServiceConstants
.TRACE_SNAPSHOT_SESSION_PATTERN
.matcher(line
);
220 if (matcher
.matches()) {
221 sessionInfo
.setSessionState(matcher
.group(2));
222 // real name will be set later
223 ISnapshotInfo snapshotInfo
= new SnapshotInfo(""); //$NON-NLS-1$
224 sessionInfo
.setSnapshotInfo(snapshotInfo
);
229 if (!sessionInfo
.isSnapshotSession()) {
230 matcher
= LTTngControlServiceConstants
.TRACE_NETWORK_PATH_PATTERN
.matcher(line
);
231 if (matcher
.matches()) {
232 sessionInfo
.setStreamedTrace(true);
235 matcher
= LTTngControlServiceConstants
.TRACE_SESSION_PATH_PATTERN
.matcher(line
);
236 if (matcher
.matches()) {
237 sessionInfo
.setSessionPath(matcher
.group(1).trim());
243 matcher
= LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(line
);
244 if (matcher
.matches()) {
246 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_KernelDomainDisplayName
);
249 domainInfo
.setIsKernel(true);
252 ArrayList
<IChannelInfo
> channels
= new ArrayList
<>();
253 index
= parseDomain(result
.getOutput(), index
, channels
, domainInfo
);
255 if (channels
.size() > 0) {
257 sessionInfo
.addDomain(domainInfo
);
260 domainInfo
.setChannels(channels
);
265 matcher
= LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
);
266 if (matcher
.matches()) {
267 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_UstGlobalDomainDisplayName
);
270 domainInfo
.setIsKernel(false);
273 ArrayList
<IChannelInfo
> channels
= new ArrayList
<>();
274 index
= parseDomain(result
.getOutput(), index
, channels
, domainInfo
);
276 if (channels
.size() > 0) {
278 sessionInfo
.addDomain(domainInfo
);
281 domainInfo
.setChannels(channels
);
288 if (sessionInfo
.isSnapshotSession()) {
289 ISnapshotInfo snapshot
= getSnapshotInfo(sessionName
, monitor
);
290 sessionInfo
.setSnapshotInfo(snapshot
);
297 public ISnapshotInfo
getSnapshotInfo(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
298 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST_SNAPSHOT_OUTPUT
, LTTngControlServiceConstants
.OPTION_SESSION
, sessionName
);
299 ICommandResult result
= executeCommand(command
.toString(), monitor
);
304 // [1] snapshot-1: /home/user/lttng-traces/my-20130909-114431
306 // [3] snapshot-3: net4://172.0.0.1/
307 ISnapshotInfo snapshotInfo
= new SnapshotInfo(""); //$NON-NLS-1$
309 while (index
< result
.getOutput().length
) {
310 String line
= result
.getOutput()[index
];
311 Matcher matcher
= LTTngControlServiceConstants
.LIST_SNAPSHOT_OUTPUT_PATTERN
.matcher(line
);
312 if (matcher
.matches()) {
313 snapshotInfo
.setId(Integer
.valueOf(matcher
.group(1)));
314 snapshotInfo
.setName(matcher
.group(2));
315 snapshotInfo
.setSnapshotPath(matcher
.group(3));
317 Matcher matcher2
= LTTngControlServiceConstants
.SNAPSHOT_NETWORK_PATH_PATTERN
.matcher(snapshotInfo
.getSnapshotPath());
318 if (matcher2
.matches()) {
319 snapshotInfo
.setStreamedSnapshot(true);
332 public List
<IBaseEventInfo
> getKernelProvider(IProgressMonitor monitor
) throws ExecutionException
{
333 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST_KERNEL
);
334 ICommandResult result
= executeCommand(command
.toString(), monitor
, false);
336 List
<IBaseEventInfo
> events
= new ArrayList
<>();
338 if (result
.getErrorOutput() != null) {
339 // Ignore the following 2 cases:
340 // Spawning a session daemon
341 // Error: Unable to list kernel events
343 // Error: Unable to list kernel events
345 if (ignoredPattern(result
.getErrorOutput(), LTTngControlServiceConstants
.LIST_KERNEL_NO_KERNEL_PROVIDER_PATTERN
)) {
350 if (isError(result
)) {
351 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$
356 // sched_kthread_stop (type: tracepoint)
357 getProviderEventInfo(result
.getOutput(), 0, events
);
362 public List
<IUstProviderInfo
> getUstProvider() throws ExecutionException
{
363 return getUstProvider(new NullProgressMonitor());
367 public List
<IUstProviderInfo
> getUstProvider(IProgressMonitor monitor
) throws ExecutionException
{
368 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST_UST
);
370 if (isVersionSupported("2.1.0")) { //$NON-NLS-1$
371 command
.append(LTTngControlServiceConstants
.OPTION_FIELDS
);
374 ICommandResult result
= executeCommand(command
.toString(), monitor
, false);
375 List
<IUstProviderInfo
> allProviders
= new ArrayList
<>();
377 // Workaround for versions 2.0.x which causes a segmentation fault for
379 // if LTTng Tools is compiled without UST support.
380 if (!isVersionSupported("2.1.0") && (result
.getResult() != 0)) { //$NON-NLS-1$
384 if (result
.getErrorOutput() != null) {
385 // Ignore the following 2 cases:
386 // Spawning a session daemon
387 // Error: Unable to list UST events: Listing UST events failed
389 // Error: Unable to list UST events: Listing UST events failed
391 if (ignoredPattern(result
.getErrorOutput(), LTTngControlServiceConstants
.LIST_UST_NO_UST_PROVIDER_PATTERN
)) {
396 if (isError(result
)) {
397 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$
400 // Note that field print-outs exists for version >= 2.1.0
406 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
407 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
409 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
410 // field: doublefield (float)
411 // field: floatfield (float)
412 // field: stringfield (string)
415 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
416 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
418 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
419 // field: doublefield (float)
420 // field: floatfield (float)
421 // field: stringfield (string)
423 IUstProviderInfo provider
= null;
426 while (index
< result
.getOutput().length
) {
427 String line
= result
.getOutput()[index
];
428 Matcher matcher
= LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
);
429 if (matcher
.matches()) {
430 provider
= new UstProviderInfo(matcher
.group(2).trim());
431 provider
.setPid(Integer
.valueOf(matcher
.group(1).trim()));
432 List
<IBaseEventInfo
> events
= new ArrayList
<>();
433 index
= getProviderEventInfo(result
.getOutput(), ++index
, events
);
434 provider
.setEvents(events
);
435 allProviders
.add(provider
);
444 public ISessionInfo
createSession(ISessionInfo sessionInfo
, IProgressMonitor monitor
) throws ExecutionException
{
445 if (sessionInfo
.isStreamedTrace()) {
446 return createStreamedSession(sessionInfo
, monitor
);
449 StringBuffer command
= prepareSessionCreationCommand(sessionInfo
);
451 ICommandResult result
= executeCommand(command
.toString(), monitor
);
453 // Session myssession2 created.
454 // Traces will be written in
455 // /home/user/lttng-traces/myssession2-20120209-095418
456 String
[] output
= result
.getOutput();
458 // Get and session name and path
463 while (index
< output
.length
) {
464 String line
= output
[index
];
465 Matcher nameMatcher
= LTTngControlServiceConstants
.CREATE_SESSION_NAME_PATTERN
.matcher(line
);
466 Matcher pathMatcher
= LTTngControlServiceConstants
.CREATE_SESSION_PATH_PATTERN
.matcher(line
);
467 if (nameMatcher
.matches()) {
468 name
= String
.valueOf(nameMatcher
.group(1).trim());
469 } else if (pathMatcher
.matches()) {
470 path
= String
.valueOf(pathMatcher
.group(1).trim());
475 // Verify session name
476 if ((name
== null) || (!"".equals(sessionInfo
.getName()) && !name
.equals(sessionInfo
.getName()))) { //$NON-NLS-1$
477 // Unexpected name returned
478 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
479 Messages
.TraceControl_UnexpectedNameError
+ ": " + name
); //$NON-NLS-1$
482 sessionInfo
.setName(name
);
483 // Verify session path
484 if (!sessionInfo
.isSnapshotSession() &&
485 ((path
== null) || ((sessionInfo
.getSessionPath() != null) && (!path
.contains(sessionInfo
.getSessionPath()))))) {
487 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
488 Messages
.TraceControl_UnexpectedPathError
+ ": " + name
); //$NON-NLS-1$
491 if (sessionInfo
.isSnapshotSession()) {
492 // Make it a snapshot session - content of snapshot info need to
493 // set afterwards using getSession() or getSnapshotInfo()
494 sessionInfo
.setSnapshotInfo(new SnapshotInfo("")); //$NON-NLS-1$
496 sessionInfo
.setSessionPath(path
);
504 * Basic generation of command for session creation
507 * the session to create
508 * @return the basic command for command creation
510 protected StringBuffer
prepareSessionCreationCommand(ISessionInfo sessionInfo
) {
511 String newName
= formatParameter(sessionInfo
.getName());
512 String newPath
= formatParameter(sessionInfo
.getSessionPath());
514 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_CREATE_SESSION
, newName
);
516 if (newPath
!= null && !"".equals(newPath
)) { //$NON-NLS-1$
517 command
.append(LTTngControlServiceConstants
.OPTION_OUTPUT_PATH
);
518 command
.append(newPath
);
521 if (sessionInfo
.isSnapshotSession()) {
522 command
.append(LTTngControlServiceConstants
.OPTION_SNAPSHOT
);
527 private ISessionInfo
createStreamedSession(ISessionInfo sessionInfo
, IProgressMonitor monitor
) throws ExecutionException
{
529 StringBuffer command
= prepareStreamedSessionCreationCommand(sessionInfo
);
531 ICommandResult result
= executeCommand(command
.toString(), monitor
);
534 String
[] output
= result
.getOutput();
536 // Get and session name and path
541 while (index
< output
.length
) {
542 String line
= output
[index
];
543 Matcher nameMatcher
= LTTngControlServiceConstants
.CREATE_SESSION_NAME_PATTERN
.matcher(line
);
544 Matcher pathMatcher
= LTTngControlServiceConstants
.CREATE_SESSION_PATH_PATTERN
.matcher(line
);
546 if (nameMatcher
.matches()) {
547 name
= String
.valueOf(nameMatcher
.group(1).trim());
548 } else if (pathMatcher
.matches() && (sessionInfo
.getNetworkUrl() != null)) {
549 path
= String
.valueOf(pathMatcher
.group(1).trim());
554 // Verify session name
555 if ((name
== null) || (!"".equals(sessionInfo
.getName()) && !name
.equals(sessionInfo
.getName()))) { //$NON-NLS-1$
556 // Unexpected name returned
557 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
558 Messages
.TraceControl_UnexpectedNameError
+ ": " + name
); //$NON-NLS-1$
561 sessionInfo
.setName(name
);
563 sessionInfo
.setStreamedTrace(true);
565 // Verify session path
566 if (sessionInfo
.getNetworkUrl() != null) {
567 if (!sessionInfo
.isSnapshotSession() && (path
== null)) {
569 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
570 Messages
.TraceControl_UnexpectedPathError
+ ": " + name
); //$NON-NLS-1$
573 if (sessionInfo
.isSnapshotSession()) {
574 sessionInfo
.setStreamedTrace(false);
576 sessionInfo
.setSessionPath(path
);
577 // Check file protocol
578 Matcher matcher
= LTTngControlServiceConstants
.TRACE_FILE_PROTOCOL_PATTERN
.matcher(path
);
579 if (matcher
.matches()) {
580 sessionInfo
.setStreamedTrace(false);
585 // When using controlUrl and dataUrl the full session path is not known
586 // yet and will be set later on when listing the session
592 * Basic generation of command for streamed session creation
595 * the session to create
596 * @return the basic command for command creation
598 protected StringBuffer
prepareStreamedSessionCreationCommand(ISessionInfo sessionInfo
) {
599 String newName
= formatParameter(sessionInfo
.getName());
600 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_CREATE_SESSION
, newName
);
602 if (sessionInfo
.isSnapshotSession()) {
603 command
.append(LTTngControlServiceConstants
.OPTION_SNAPSHOT
);
604 } else if (sessionInfo
.isLive()) {
605 command
.append(LTTngControlServiceConstants
.OPTION_LIVE
);
606 if (sessionInfo
.getLiveDelay() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
607 command
.append(sessionInfo
.getLiveDelay());
611 if (sessionInfo
.getNetworkUrl() != null) {
612 command
.append(LTTngControlServiceConstants
.OPTION_NETWORK_URL
);
613 command
.append(sessionInfo
.getNetworkUrl());
615 command
.append(LTTngControlServiceConstants
.OPTION_CONTROL_URL
);
616 command
.append(sessionInfo
.getControlUrl());
618 command
.append(LTTngControlServiceConstants
.OPTION_DATA_URL
);
619 command
.append(sessionInfo
.getDataUrl());
625 public void destroySession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
626 String newName
= formatParameter(sessionName
);
628 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_DESTROY_SESSION
, newName
);
630 ICommandResult result
= executeCommand(command
.toString(), monitor
, false);
631 String
[] errorOutput
= result
.getErrorOutput();
633 boolean isError
= isError(result
);
634 if (isError
&& (errorOutput
!= null)) {
635 if (ignoredPattern(result
.getErrorOutput(), LTTngControlServiceConstants
.SESSION_NOT_FOUND_ERROR_PATTERN
)) {
642 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$
645 // Session <sessionName> destroyed
649 public void startSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
651 String newSessionName
= formatParameter(sessionName
);
653 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_START_SESSION
, newSessionName
);
655 executeCommand(command
.toString(), monitor
);
657 // Session <sessionName> started
661 public void stopSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
662 String newSessionName
= formatParameter(sessionName
);
663 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_STOP_SESSION
, newSessionName
);
665 executeCommand(command
.toString(), monitor
);
667 // Session <sessionName> stopped
672 public void enableChannels(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IChannelInfo info
, IProgressMonitor monitor
) throws ExecutionException
{
674 // no channels to enable
675 if (channelNames
.isEmpty()) {
679 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_CHANNEL
);
681 for (Iterator
<String
> iterator
= channelNames
.iterator(); iterator
.hasNext();) {
682 String channel
= iterator
.next();
683 command
.append(channel
);
684 if (iterator
.hasNext()) {
690 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
692 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
695 String newSessionName
= formatParameter(sessionName
);
696 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
697 command
.append(newSessionName
);
700 // --discard Discard event when buffers are full (default)
702 // --overwrite Flight recorder mode
703 if (info
.isOverwriteMode()) {
704 command
.append(LTTngControlServiceConstants
.OPTION_OVERWRITE
);
706 // --subbuf-size SIZE Subbuffer size in bytes
707 // (default: 4096, kernel default: 262144)
708 if (info
.getSubBufferSize() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
709 command
.append(LTTngControlServiceConstants
.OPTION_SUB_BUFFER_SIZE
);
710 command
.append(String
.valueOf(info
.getSubBufferSize()));
713 // --num-subbuf NUM Number of subbufers
714 if (info
.getNumberOfSubBuffers() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
715 command
.append(LTTngControlServiceConstants
.OPTION_NUM_SUB_BUFFERS
);
716 command
.append(String
.valueOf(info
.getNumberOfSubBuffers()));
719 // --switch-timer USEC Switch timer interval in usec
720 if (info
.getSwitchTimer() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
721 command
.append(LTTngControlServiceConstants
.OPTION_SWITCH_TIMER
);
722 command
.append(String
.valueOf(info
.getSwitchTimer()));
725 // --read-timer USEC Read timer interval in usec
726 if (info
.getReadTimer() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
727 command
.append(LTTngControlServiceConstants
.OPTION_READ_TIMER
);
728 command
.append(String
.valueOf(info
.getReadTimer()));
731 if (isVersionSupported("2.2.0")) { //$NON-NLS-1$
732 // --buffers-uid Every application sharing the same UID use the
733 // same buffers --buffers-pid Buffers are allocated per PID
735 if (info
.getBufferType() == BufferType
.BUFFER_PER_PID
) {
736 command
.append(LTTngControlServiceConstants
.OPTION_PER_PID_BUFFERS
);
738 } else if (info
.getBufferType() == BufferType
.BUFFER_PER_UID
) {
739 command
.append(LTTngControlServiceConstants
.OPTION_PER_UID_BUFFERS
);
743 // -C SIZE Maximum size of trace files in bytes
744 if (info
.getMaxSizeTraceFiles() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
745 command
.append(LTTngControlServiceConstants
.OPTION_MAX_SIZE_TRACE_FILES
);
746 command
.append(String
.valueOf(info
.getMaxSizeTraceFiles()));
749 // -W NUM Maximum number of trace files
750 if (info
.getMaxNumberTraceFiles() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
751 command
.append(LTTngControlServiceConstants
.OPTION_MAX_TRACE_FILES
);
752 command
.append(String
.valueOf(info
.getMaxNumberTraceFiles()));
757 executeCommand(command
.toString(), monitor
);
762 public void disableChannels(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
764 // no channels to enable
765 if (channelNames
.isEmpty()) {
769 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_DISABLE_CHANNEL
);
771 for (Iterator
<String
> iterator
= channelNames
.iterator(); iterator
.hasNext();) {
772 String channel
= iterator
.next();
773 command
.append(channel
);
774 if (iterator
.hasNext()) {
780 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
782 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
785 String newSessionName
= formatParameter(sessionName
);
786 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
787 command
.append(newSessionName
);
789 executeCommand(command
.toString(), monitor
);
793 public void enableEvents(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, String filterExpression
, IProgressMonitor monitor
) throws ExecutionException
{
795 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
797 if (eventNames
== null || eventNames
.isEmpty()) {
798 command
.append(LTTngControlServiceConstants
.OPTION_ALL
);
801 StringBuffer eventNameParameter
= new StringBuffer();
802 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
803 String event
= iterator
.next();
804 eventNameParameter
.append(event
);
805 if (iterator
.hasNext()) {
806 eventNameParameter
.append(',');
809 command
.append(formatParameter(eventNameParameter
.toString()));
813 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
815 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
818 String newSessionName
= formatParameter(sessionName
);
820 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
821 command
.append(newSessionName
);
823 if (channelName
!= null) {
824 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
825 command
.append(channelName
);
828 command
.append(LTTngControlServiceConstants
.OPTION_TRACEPOINT
);
830 if (filterExpression
!= null) {
831 command
.append(LTTngControlServiceConstants
.OPTION_FILTER
);
832 command
.append('\'');
833 command
.append(filterExpression
);
834 command
.append('\'');
837 executeCommand(command
.toString(), monitor
);
842 public void enableSyscalls(String sessionName
, String channelName
, IProgressMonitor monitor
) throws ExecutionException
{
844 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
846 command
.append(LTTngControlServiceConstants
.OPTION_ALL
);
847 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
849 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 command
.append(LTTngControlServiceConstants
.OPTION_SYSCALL
);
861 executeCommand(command
.toString(), monitor
);
865 public void enableProbe(String sessionName
, String channelName
, String eventName
, boolean isFunction
, String probe
, IProgressMonitor monitor
) throws ExecutionException
{
866 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
868 command
.append(eventName
);
869 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
871 String newSessionName
= formatParameter(sessionName
);
872 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
873 command
.append(newSessionName
);
875 if (channelName
!= null) {
876 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
877 command
.append(channelName
);
880 command
.append(LTTngControlServiceConstants
.OPTION_FUNCTION_PROBE
);
882 command
.append(LTTngControlServiceConstants
.OPTION_PROBE
);
885 command
.append(probe
);
887 executeCommand(command
.toString(), monitor
);
891 public void enableLogLevel(String sessionName
, String channelName
, String eventName
, LogLevelType logLevelType
, TraceLogLevel level
, String filterExpression
, IProgressMonitor monitor
) throws ExecutionException
{
892 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
894 command
.append(eventName
);
895 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
897 String newSessionName
= formatParameter(sessionName
);
898 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
899 command
.append(newSessionName
);
901 if (channelName
!= null) {
902 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
903 command
.append(channelName
);
906 if (logLevelType
== LogLevelType
.LOGLEVEL
) {
907 command
.append(LTTngControlServiceConstants
.OPTION_LOGLEVEL
);
908 } else if (logLevelType
== LogLevelType
.LOGLEVEL_ONLY
) {
909 command
.append(LTTngControlServiceConstants
.OPTION_LOGLEVEL_ONLY
);
914 command
.append(level
.getInName());
916 executeCommand(command
.toString(), monitor
);
920 public void disableEvent(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
921 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_DISABLE_EVENT
);
923 if (eventNames
== null) {
924 command
.append(LTTngControlServiceConstants
.OPTION_ALL
);
926 // no events to disable
927 if (eventNames
.isEmpty()) {
931 StringBuffer eventNameParameter
= new StringBuffer();
932 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
933 String event
= iterator
.next();
934 eventNameParameter
.append(event
);
935 if (iterator
.hasNext()) {
936 eventNameParameter
.append(',');
939 command
.append(formatParameter(eventNameParameter
.toString()));
943 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
945 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
948 String newSessionName
= formatParameter(sessionName
);
949 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
950 command
.append(newSessionName
);
952 if (channelName
!= null) {
953 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
954 command
.append(channelName
);
957 executeCommand(command
.toString(), monitor
);
961 public List
<String
> getContextList(IProgressMonitor monitor
) throws ExecutionException
{
963 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ADD_CONTEXT
, LTTngControlServiceConstants
.OPTION_HELP
);
965 ICommandResult result
= executeCommand(command
.toString(), monitor
);
967 String
[] output
= result
.getOutput();
969 List
<String
> contexts
= new ArrayList
<>(0);
972 boolean inList
= false;
973 while (index
< output
.length
) {
974 String line
= result
.getOutput()[index
];
976 Matcher startMatcher
= LTTngControlServiceConstants
.ADD_CONTEXT_HELP_CONTEXTS_INTRO
.matcher(line
);
977 Matcher endMatcher
= LTTngControlServiceConstants
.ADD_CONTEXT_HELP_CONTEXTS_END_LINE
.matcher(line
);
979 if (startMatcher
.matches()) {
981 } else if (endMatcher
.matches()) {
983 } else if (inList
== true) {
984 String
[] tmp
= line
.split(","); //$NON-NLS-1$
985 for (int i
= 0; i
< tmp
.length
; i
++) {
986 contexts
.add(tmp
[i
].trim());
995 public void addContexts(String sessionName
, String channelName
, String eventName
, boolean isKernel
, List
<String
> contextNames
, IProgressMonitor monitor
) throws ExecutionException
{
996 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ADD_CONTEXT
);
998 String newSessionName
= formatParameter(sessionName
);
999 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
1000 command
.append(newSessionName
);
1002 if (channelName
!= null) {
1003 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
1004 command
.append(channelName
);
1007 if (eventName
!= null) {
1008 command
.append(LTTngControlServiceConstants
.OPTION_EVENT
);
1009 command
.append(eventName
);
1013 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
1015 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
1018 for (Iterator
<String
> iterator
= contextNames
.iterator(); iterator
.hasNext();) {
1019 String context
= iterator
.next();
1020 command
.append(LTTngControlServiceConstants
.OPTION_CONTEXT_TYPE
);
1021 command
.append(context
);
1024 executeCommand(command
.toString(), monitor
);
1029 public void calibrate(boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
1030 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_CALIBRATE
);
1033 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
1035 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
1038 command
.append(LTTngControlServiceConstants
.OPTION_FUNCTION_PROBE
);
1040 executeCommand(command
.toString(), monitor
);
1044 public void recordSnapshot(String sessionName
, IProgressMonitor monitor
)
1045 throws ExecutionException
{
1046 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_RECORD_SNAPSHOT
);
1048 String newSessionName
= formatParameter(sessionName
);
1049 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
1050 command
.append(newSessionName
);
1052 executeCommand(command
.toString(), monitor
);
1056 public void runCommands(IProgressMonitor monitor
, List
<String
> commands
) throws ExecutionException
{
1057 for (String command
: commands
) {
1058 if (monitor
.isCanceled()) {
1062 if (command
.isEmpty() || command
.startsWith("#")) { //$NON-NLS-1$
1065 executeCommand(command
, monitor
);
1069 // ------------------------------------------------------------------------
1071 // ------------------------------------------------------------------------
1074 * Checks if command result is an error result.
1077 * - the command result to check
1078 * @return true if error else false
1080 protected boolean isError(ICommandResult result
) {
1081 // Check return code and length of returned strings
1083 if ((result
.getResult()) != 0) {
1087 // Look for error pattern
1089 while (index
< result
.getErrorOutput().length
) {
1090 String line
= result
.getErrorOutput()[index
];
1091 Matcher matcher
= LTTngControlServiceConstants
.ERROR_PATTERN
.matcher(line
);
1092 if (matcher
.matches()) {
1102 * Formats the output string as single string.
1106 * @return - the formatted output
1108 public static String
formatOutput(ICommandResult result
) {
1109 if ((result
== null) || ((result
.getOutput() == null || result
.getOutput().length
== 0) && (result
.getErrorOutput() == null || result
.getErrorOutput().length
== 0))) {
1110 return ""; //$NON-NLS-1$
1112 String
[] output
= result
.getOutput();
1113 String
[] errorOutput
= result
.getErrorOutput();
1114 StringBuffer ret
= new StringBuffer();
1115 ret
.append("Error Ouptut:\n"); //$NON-NLS-1$
1116 for (int i
= 0; i
< errorOutput
.length
; i
++) {
1117 ret
.append(errorOutput
[i
]).append("\n"); //$NON-NLS-1$
1119 ret
.append("Return Value: "); //$NON-NLS-1$
1120 ret
.append(result
.getResult());
1121 ret
.append("\n"); //$NON-NLS-1$
1122 for (int i
= 0; i
< output
.length
; i
++) {
1123 ret
.append(output
[i
]).append("\n"); //$NON-NLS-1$
1125 return ret
.toString();
1129 * Parses the domain information.
1132 * - a command output array
1133 * @param currentIndex
1134 * - current index in command output array
1136 * - list for returning channel information
1138 * - The domain information
1139 * @return the new current index in command output array
1141 protected int parseDomain(String
[] output
, int currentIndex
, List
<IChannelInfo
> channels
, IDomainInfo domainInfo
) {
1142 int index
= currentIndex
;
1144 // if kernel set the buffer type to shared
1145 if (domainInfo
.isKernel()) {
1146 domainInfo
.setBufferType(BufferType
.BUFFER_SHARED
);
1151 // - channnel1: [enabled]
1154 // overwrite mode: 0
1155 // subbufers size: 262144
1156 // number of subbufers: 4
1157 // switch timer interval: 0
1158 // read timer interval: 200
1161 while (index
< output
.length
) {
1162 String line
= output
[index
];
1164 if (isVersionSupported("2.2.0")) { //$NON-NLS-1$
1165 Matcher bufferTypeMatcher
= LTTngControlServiceConstants
.BUFFER_TYPE_PATTERN
.matcher(line
);
1166 if (bufferTypeMatcher
.matches()) {
1167 String bufferTypeString
= getAttributeValue(line
);
1168 if (BufferType
.BUFFER_PER_PID
.getInName().equals(bufferTypeString
)) {
1169 domainInfo
.setBufferType(BufferType
.BUFFER_PER_PID
);
1170 } else if (BufferType
.BUFFER_PER_UID
.getInName().equals(bufferTypeString
)) {
1171 domainInfo
.setBufferType(BufferType
.BUFFER_PER_UID
);
1173 domainInfo
.setBufferType(BufferType
.BUFFER_TYPE_UNKNOWN
);
1177 domainInfo
.setBufferType(BufferType
.BUFFER_TYPE_UNKNOWN
);
1179 Matcher outerMatcher
= LTTngControlServiceConstants
.CHANNELS_SECTION_PATTERN
.matcher(line
);
1180 Matcher noKernelChannelMatcher
= LTTngControlServiceConstants
.DOMAIN_NO_KERNEL_CHANNEL_PATTERN
.matcher(line
);
1181 Matcher noUstChannelMatcher
= LTTngControlServiceConstants
.DOMAIN_NO_UST_CHANNEL_PATTERN
.matcher(line
);
1182 if (outerMatcher
.matches()) {
1183 IChannelInfo channelInfo
= null;
1184 while (index
< output
.length
) {
1185 String subLine
= output
[index
];
1187 Matcher innerMatcher
= LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(subLine
);
1188 if (innerMatcher
.matches()) {
1189 channelInfo
= new ChannelInfo(""); //$NON-NLS-1$
1191 channelInfo
.setName(innerMatcher
.group(1));
1193 // get channel enablement
1194 channelInfo
.setState(innerMatcher
.group(2));
1197 channelInfo
.setBufferType(domainInfo
.getBufferType());
1200 channels
.add(channelInfo
);
1202 } else if (LTTngControlServiceConstants
.OVERWRITE_MODE_ATTRIBUTE
.matcher(subLine
).matches()) {
1203 String value
= getAttributeValue(subLine
);
1204 if (channelInfo
!= null) {
1205 channelInfo
.setOverwriteMode(!LTTngControlServiceConstants
.OVERWRITE_MODE_ATTRIBUTE_FALSE
.equals(value
));
1207 } else if (LTTngControlServiceConstants
.SUBBUFFER_SIZE_ATTRIBUTE
.matcher(subLine
).matches()) {
1208 if (channelInfo
!= null) {
1209 channelInfo
.setSubBufferSize(Long
.valueOf(getAttributeValue(subLine
)));
1212 } else if (LTTngControlServiceConstants
.NUM_SUBBUFFERS_ATTRIBUTE
.matcher(subLine
).matches()) {
1213 if (channelInfo
!= null) {
1214 channelInfo
.setNumberOfSubBuffers(Integer
.valueOf(getAttributeValue(subLine
)));
1217 } else if (LTTngControlServiceConstants
.SWITCH_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
1218 if (channelInfo
!= null) {
1219 channelInfo
.setSwitchTimer(Long
.valueOf(getAttributeValue(subLine
)));
1222 } else if (LTTngControlServiceConstants
.READ_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
1223 if (channelInfo
!= null) {
1224 channelInfo
.setReadTimer(Long
.valueOf(getAttributeValue(subLine
)));
1227 } else if (LTTngControlServiceConstants
.OUTPUT_ATTRIBUTE
.matcher(subLine
).matches()) {
1228 if (channelInfo
!= null) {
1229 channelInfo
.setOutputType(getAttributeValue(subLine
));
1232 } else if (LTTngControlServiceConstants
.EVENT_SECTION_PATTERN
.matcher(subLine
).matches()) {
1233 List
<IEventInfo
> events
= new ArrayList
<>();
1234 index
= parseEvents(output
, index
, events
);
1235 if (channelInfo
!= null) {
1236 channelInfo
.setEvents(events
);
1238 // we want to stay at the current index to be able to
1241 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(subLine
).matches()) {
1244 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(subLine
).matches()) {
1249 } else if (noKernelChannelMatcher
.matches() || noUstChannelMatcher
.matches()) {
1250 // domain indicates that no channels were found -> return
1260 * Parses the event information within a domain.
1263 * - a command output array
1264 * @param currentIndex
1265 * - current index in command output array
1267 * - list for returning event information
1268 * @return the new current index in command output array
1270 protected int parseEvents(String
[] output
, int currentIndex
, List
<IEventInfo
> events
) {
1271 int index
= currentIndex
;
1273 while (index
< output
.length
) {
1274 String line
= output
[index
];
1275 if (LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(line
).matches()) {
1278 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(line
).matches()) {
1281 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
).matches()) {
1286 Matcher matcher
= LTTngControlServiceConstants
.EVENT_PATTERN
.matcher(line
);
1287 Matcher matcher2
= LTTngControlServiceConstants
.WILDCARD_EVENT_PATTERN
.matcher(line
);
1289 if (matcher
.matches()) {
1290 IEventInfo eventInfo
= new EventInfo(matcher
.group(1).trim());
1291 eventInfo
.setLogLevelType(matcher
.group(2).trim());
1292 eventInfo
.setLogLevel(matcher
.group(3).trim());
1293 eventInfo
.setEventType(matcher
.group(4).trim());
1294 eventInfo
.setState(matcher
.group(5));
1295 String filter
= matcher
.group(6);
1296 if (filter
!= null) {
1297 // remove '[' and ']'
1298 filter
= filter
.substring(1, filter
.length() - 1);
1299 eventInfo
.setFilterExpression(filter
);
1301 events
.add(eventInfo
);
1303 } else if (matcher2
.matches()) {
1304 IEventInfo eventInfo
= new EventInfo(matcher2
.group(1).trim());
1305 eventInfo
.setLogLevel(TraceLogLevel
.LEVEL_UNKNOWN
);
1306 eventInfo
.setEventType(matcher2
.group(2).trim());
1307 eventInfo
.setState(matcher2
.group(3));
1308 String filter
= matcher2
.group(4);
1309 if (filter
!= null) {
1310 // remove '[' and ']'
1311 filter
= filter
.substring(1, filter
.length() - 1);
1312 eventInfo
.setFilterExpression(filter
);
1315 if ((eventInfo
.getEventType() == TraceEventType
.PROBE
) ||
1316 (eventInfo
.getEventType() == TraceEventType
.FUNCTION
)) {
1317 IProbeEventInfo probeEvent
= new ProbeEventInfo(eventInfo
.getName());
1318 probeEvent
.setLogLevel(eventInfo
.getLogLevel());
1319 probeEvent
.setEventType(eventInfo
.getEventType());
1320 probeEvent
.setState(eventInfo
.getState());
1322 // Overwrite eventinfo
1323 eventInfo
= probeEvent
;
1325 // myevent2 (type: probe) [enabled]
1327 // myevent0 (type: function) [enabled]
1329 // symbol: init_post
1331 while (index
< output
.length
) {
1332 String probeLine
= output
[index
];
1334 Matcher addrMatcher
= LTTngControlServiceConstants
.PROBE_ADDRESS_PATTERN
.matcher(probeLine
);
1335 Matcher offsetMatcher
= LTTngControlServiceConstants
.PROBE_OFFSET_PATTERN
.matcher(probeLine
);
1336 Matcher symbolMatcher
= LTTngControlServiceConstants
.PROBE_SYMBOL_PATTERN
.matcher(probeLine
);
1337 if (addrMatcher
.matches()) {
1338 String addr
= addrMatcher
.group(2).trim();
1339 probeEvent
.setAddress(addr
);
1340 } else if (offsetMatcher
.matches()) {
1341 String offset
= offsetMatcher
.group(2).trim();
1342 probeEvent
.setOffset(offset
);
1343 } else if (symbolMatcher
.matches()) {
1344 String symbol
= symbolMatcher
.group(2).trim();
1345 probeEvent
.setSymbol(symbol
);
1346 } else if ((LTTngControlServiceConstants
.EVENT_PATTERN
.matcher(probeLine
).matches()) || (LTTngControlServiceConstants
.WILDCARD_EVENT_PATTERN
.matcher(probeLine
).matches())) {
1348 } else if (LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(probeLine
).matches()) {
1350 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(probeLine
).matches()) {
1353 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(probeLine
).matches()) {
1359 events
.add(eventInfo
);
1361 events
.add(eventInfo
);
1374 * Parses a line with attributes: <attribute Name>: <attribute value>
1377 * - attribute line to parse
1378 * @return the attribute value as string
1380 protected String
getAttributeValue(String line
) {
1381 String
[] temp
= line
.split("\\: "); //$NON-NLS-1$
1386 * Parses the event information within a provider.
1389 * - a command output array
1390 * @param currentIndex
1391 * - current index in command output array
1393 * - list for returning event information
1394 * @return the new current index in command output array
1396 protected int getProviderEventInfo(String
[] output
, int currentIndex
, List
<IBaseEventInfo
> events
) {
1397 int index
= currentIndex
;
1398 IBaseEventInfo eventInfo
= null;
1399 while (index
< output
.length
) {
1400 String line
= output
[index
];
1401 Matcher matcher
= LTTngControlServiceConstants
.PROVIDER_EVENT_PATTERN
.matcher(line
);
1402 if (matcher
.matches()) {
1403 // sched_kthread_stop (loglevel: TRACE_EMERG0) (type:
1405 eventInfo
= new BaseEventInfo(matcher
.group(1).trim());
1406 eventInfo
.setLogLevel(matcher
.group(2).trim());
1407 eventInfo
.setEventType(matcher
.group(3).trim());
1408 events
.add(eventInfo
);
1410 } else if (LTTngControlServiceConstants
.EVENT_FIELD_PATTERN
.matcher(line
).matches()) {
1411 if (eventInfo
!= null) {
1412 List
<IFieldInfo
> fields
= new ArrayList
<>();
1413 index
= getFieldInfo(output
, index
, fields
);
1414 eventInfo
.setFields(fields
);
1419 else if (LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
).matches()) {
1429 * Parse a field's information.
1432 * A command output array
1433 * @param currentIndex
1434 * The current index in the command output array
1436 * List for returning the field information
1437 * @return The new current index in the command output array
1439 protected int getFieldInfo(String
[] output
, int currentIndex
, List
<IFieldInfo
> fields
) {
1440 int index
= currentIndex
;
1441 IFieldInfo fieldInfo
= null;
1442 while (index
< output
.length
) {
1443 String line
= output
[index
];
1444 Matcher matcher
= LTTngControlServiceConstants
.EVENT_FIELD_PATTERN
.matcher(line
);
1445 if (matcher
.matches()) {
1446 // field: content (string)
1447 fieldInfo
= new FieldInfo(matcher
.group(2).trim());
1448 fieldInfo
.setFieldType(matcher
.group(3).trim());
1449 fields
.add(fieldInfo
);
1450 } else if (LTTngControlServiceConstants
.PROVIDER_EVENT_PATTERN
.matcher(line
).matches()) {
1452 } else if (LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
).matches()) {
1461 * Formats a command parameter for the command execution i.e. adds quotes at
1462 * the beginning and end if necessary.
1465 * - parameter to format
1466 * @return formated parameter
1468 protected String
formatParameter(String parameter
) {
1469 if (parameter
!= null) {
1470 StringBuffer newString
= new StringBuffer();
1471 newString
.append(parameter
);
1473 if (parameter
.contains(" ") || parameter
.contains("*")) { //$NON-NLS-1$ //$NON-NLS-2$
1474 newString
.insert(0, "\""); //$NON-NLS-1$
1475 newString
.append("\""); //$NON-NLS-1$
1477 return newString
.toString();
1484 * array of string that makes up a command line
1485 * @return string buffer with created command line
1487 protected StringBuffer
createCommand(String
... strings
) {
1488 StringBuffer command
= new StringBuffer();
1489 command
.append(LTTngControlServiceConstants
.CONTROL_COMMAND
);
1490 command
.append(getTracingGroupOption());
1491 command
.append(getVerboseOption());
1492 for (String string
: strings
) {
1493 command
.append(string
);
1499 * @return the tracing group option if configured in the preferences
1501 protected String
getTracingGroupOption() {
1502 if (!ControlPreferences
.getInstance().isDefaultTracingGroup() && !ControlPreferences
.getInstance().getTracingGroup().equals("")) { //$NON-NLS-1$
1503 return LTTngControlServiceConstants
.OPTION_TRACING_GROUP
+ ControlPreferences
.getInstance().getTracingGroup();
1505 return ""; //$NON-NLS-1$
1509 * @return the verbose option as configured in the preferences
1511 protected String
getVerboseOption() {
1512 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1513 String level
= ControlPreferences
.getInstance().getVerboseLevel();
1514 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_VERBOSE
.equals(level
)) {
1515 return LTTngControlServiceConstants
.OPTION_VERBOSE
;
1517 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_V_VERBOSE
.equals(level
)) {
1518 return LTTngControlServiceConstants
.OPTION_VERY_VERBOSE
;
1520 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_V_V_VERBOSE
.equals(level
)) {
1521 return LTTngControlServiceConstants
.OPTION_VERY_VERY_VERBOSE
;
1524 return ""; //$NON-NLS-1$
1528 * Method that logs the command and command result if logging is enabled as
1529 * well as forwards the command execution to the shell.
1532 * - the command to execute
1534 * - a progress monitor
1535 * @return the command result
1536 * @throws ExecutionException
1537 * If the command fails
1539 protected ICommandResult
executeCommand(String command
,
1540 IProgressMonitor monitor
) throws ExecutionException
{
1541 return executeCommand(command
, monitor
, true);
1545 * Method that logs the command and command result if logging is enabled as
1546 * well as forwards the command execution to the shell.
1549 * - the command to execute
1551 * - a progress monitor
1552 * @param checkForError
1553 * - true to verify command result, else false
1554 * @return the command result
1555 * @throws ExecutionException
1556 * in case of error result
1558 protected ICommandResult
executeCommand(String command
,
1559 IProgressMonitor monitor
, boolean checkForError
)
1560 throws ExecutionException
{
1561 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1562 ControlCommandLogger
.log(command
);
1565 ICommandResult result
= fCommandShell
.executeCommand(
1566 command
.toString(), monitor
);
1568 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1569 ControlCommandLogger
.log(formatOutput(result
));
1572 if (checkForError
&& isError(result
)) {
1573 throw new ExecutionException(Messages
.TraceControl_CommandError
1574 + " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$