1 /**********************************************************************
2 * Copyright (c) 2012, 2014 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Bernd Hufmann - Initial API and implementation
11 * Bernd Hufmann - Updated for support of LTTng Tools 2.1
12 * Simon Delisle - Updated for support of LTTng Tools 2.2
13 * Marc-Andre Laperle - Support for creating a live session
14 **********************************************************************/
15 package org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.service
;
17 import java
.util
.ArrayList
;
18 import java
.util
.Iterator
;
19 import java
.util
.List
;
20 import java
.util
.regex
.Matcher
;
22 import org
.eclipse
.core
.commands
.ExecutionException
;
23 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
24 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.IBaseEventInfo
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.IChannelInfo
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.IDomainInfo
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.IEventInfo
;
29 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.IFieldInfo
;
30 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.IProbeEventInfo
;
31 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.ISessionInfo
;
32 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.ISnapshotInfo
;
33 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.IUstProviderInfo
;
34 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.LogLevelType
;
35 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.TraceEventType
;
36 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.TraceLogLevel
;
37 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.impl
.BaseEventInfo
;
38 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.impl
.BufferType
;
39 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.impl
.ChannelInfo
;
40 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.impl
.DomainInfo
;
41 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.impl
.EventInfo
;
42 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.impl
.FieldInfo
;
43 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.impl
.ProbeEventInfo
;
44 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.impl
.SessionInfo
;
45 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.impl
.SnapshotInfo
;
46 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.impl
.UstProviderInfo
;
47 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.logging
.ControlCommandLogger
;
48 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.messages
.Messages
;
49 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.preferences
.ControlPreferences
;
50 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.remote
.ICommandResult
;
51 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.remote
.ICommandShell
;
55 * Service for sending LTTng trace control commands to remote host.
58 * @author Bernd Hufmann
60 public class LTTngControlService
implements ILttngControlService
{
62 // ------------------------------------------------------------------------
64 // ------------------------------------------------------------------------
66 * The command shell implementation
68 private final ICommandShell fCommandShell
;
73 private LttngVersion fVersion
= null;
75 // ------------------------------------------------------------------------
77 // ------------------------------------------------------------------------
83 * - the command shell implementation to use
85 public LTTngControlService(ICommandShell shell
) {
86 fCommandShell
= shell
;
89 // ------------------------------------------------------------------------
91 // ------------------------------------------------------------------------
94 public String
getVersionString() {
95 if (fVersion
== null) {
96 return "Unknown"; //$NON-NLS-1$
98 return fVersion
.toString();
102 public LttngVersion
getVersion() {
107 * Sets the version of the LTTng 2.0 control service.
108 * @param version - a version to set
110 public void setVersion(String version
) {
111 fVersion
= new LttngVersion(version
);
115 * Sets the version of the LTTng 2.x control service.
116 * @param version - a version to set
118 public void setVersion(LttngVersion version
) {
123 public boolean isVersionSupported(String version
) {
124 LttngVersion tmp
= new LttngVersion(version
);
125 return (fVersion
!= null && fVersion
.compareTo(tmp
) >= 0) ?
true : false;
129 * Returns the command shell implementation.
131 * @return the command shell implementation
133 protected ICommandShell
getCommandShell() {
134 return fCommandShell
;
137 // ------------------------------------------------------------------------
139 // ------------------------------------------------------------------------
142 public String
[] getSessionNames(IProgressMonitor monitor
) throws ExecutionException
{
143 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST
);
145 ICommandResult result
= executeCommand(command
.toString(), monitor
);
148 // Available tracing sessions:
149 // 1) mysession1 (/home/user/lttng-traces/mysession1-20120123-083928) [inactive]
150 // 2) mysession (/home/user/lttng-traces/mysession-20120123-083318) [inactive]
152 // Use lttng list <session_name> for more details
154 ArrayList
<String
> retArray
= new ArrayList
<>();
156 while (index
< result
.getOutput().length
) {
157 String line
= result
.getOutput()[index
];
158 Matcher matcher
= LTTngControlServiceConstants
.SESSION_PATTERN
.matcher(line
);
159 if (matcher
.matches()) {
160 retArray
.add(matcher
.group(2).trim());
164 return retArray
.toArray(new String
[retArray
.size()]);
168 public ISessionInfo
getSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
169 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST
, sessionName
);
170 ICommandResult result
= executeCommand(command
.toString(), monitor
);
175 // Tracing session mysession2: [inactive]
176 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
177 ISessionInfo sessionInfo
= new SessionInfo(sessionName
);
179 while (index
< result
.getOutput().length
) {
180 // Tracing session mysession2: [inactive]
181 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
183 // === Domain: Kernel ===
185 String line
= result
.getOutput()[index
];
186 Matcher matcher
= LTTngControlServiceConstants
.TRACE_SESSION_PATTERN
.matcher(line
);
187 if (matcher
.matches()) {
188 sessionInfo
.setSessionState(matcher
.group(2));
193 matcher
= LTTngControlServiceConstants
.TRACE_SNAPSHOT_SESSION_PATTERN
.matcher(line
);
194 if (matcher
.matches()) {
195 sessionInfo
.setSessionState(matcher
.group(2));
196 // real name will be set later
197 ISnapshotInfo snapshotInfo
= new SnapshotInfo(""); //$NON-NLS-1$
198 sessionInfo
.setSnapshotInfo(snapshotInfo
);
203 if (!sessionInfo
.isSnapshotSession()) {
204 matcher
= LTTngControlServiceConstants
.TRACE_NETWORK_PATH_PATTERN
.matcher(line
);
205 if (matcher
.matches()) {
206 sessionInfo
.setStreamedTrace(true);
209 matcher
= LTTngControlServiceConstants
.TRACE_SESSION_PATH_PATTERN
.matcher(line
);
210 if (matcher
.matches()) {
211 sessionInfo
.setSessionPath(matcher
.group(1).trim());
217 matcher
= LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(line
);
218 if (matcher
.matches()) {
220 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_KernelDomainDisplayName
);
223 domainInfo
.setIsKernel(true);
226 ArrayList
<IChannelInfo
> channels
= new ArrayList
<>();
227 index
= parseDomain(result
.getOutput(), index
, channels
, domainInfo
);
229 if (channels
.size() > 0) {
231 sessionInfo
.addDomain(domainInfo
);
234 domainInfo
.setChannels(channels
);
239 matcher
= LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
);
240 if (matcher
.matches()) {
241 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_UstGlobalDomainDisplayName
);
244 domainInfo
.setIsKernel(false);
247 ArrayList
<IChannelInfo
> channels
= new ArrayList
<>();
248 index
= parseDomain(result
.getOutput(), index
, channels
, domainInfo
);
250 if (channels
.size() > 0) {
252 sessionInfo
.addDomain(domainInfo
);
255 domainInfo
.setChannels(channels
);
262 if (sessionInfo
.isSnapshotSession()) {
263 ISnapshotInfo snapshot
= getSnapshotInfo(sessionName
, monitor
);
264 sessionInfo
.setSnapshotInfo(snapshot
);
271 public ISnapshotInfo
getSnapshotInfo(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
272 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST_SNAPSHOT_OUTPUT
, LTTngControlServiceConstants
.OPTION_SESSION
, sessionName
);
273 ICommandResult result
= executeCommand(command
.toString(), monitor
);
278 // [1] snapshot-1: /home/user/lttng-traces/my-20130909-114431
280 // [3] snapshot-3: net4://172.0.0.1/
281 ISnapshotInfo snapshotInfo
= new SnapshotInfo(""); //$NON-NLS-1$
283 while (index
< result
.getOutput().length
) {
284 String line
= result
.getOutput()[index
];
285 Matcher matcher
= LTTngControlServiceConstants
.LIST_SNAPSHOT_OUTPUT_PATTERN
.matcher(line
);
286 if (matcher
.matches()) {
287 snapshotInfo
.setId(Integer
.valueOf(matcher
.group(1)));
288 snapshotInfo
.setName(matcher
.group(2));
289 snapshotInfo
.setSnapshotPath(matcher
.group(3));
291 Matcher matcher2
= LTTngControlServiceConstants
.SNAPSHOT_NETWORK_PATH_PATTERN
.matcher(snapshotInfo
.getSnapshotPath());
292 if (matcher2
.matches()) {
293 snapshotInfo
.setStreamedSnapshot(true);
306 public List
<IBaseEventInfo
> getKernelProvider(IProgressMonitor monitor
) throws ExecutionException
{
307 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST_KERNEL
);
308 ICommandResult result
= executeCommand(command
.toString(), monitor
, false);
310 List
<IBaseEventInfo
> events
= new ArrayList
<>();
312 if (result
.getErrorOutput() != null) {
313 // Ignore the following 2 cases:
314 // Spawning a session daemon
315 // Error: Unable to list kernel events
317 // Error: Unable to list kernel events
320 while (index
< result
.getErrorOutput().length
) {
321 String line
= result
.getErrorOutput()[index
];
322 Matcher matcher
= LTTngControlServiceConstants
.LIST_KERNEL_NO_KERNEL_PROVIDER_PATTERN
.matcher(line
);
323 if (matcher
.matches()) {
330 if (isError(result
)) {
331 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$
336 // sched_kthread_stop (type: tracepoint)
337 getProviderEventInfo(result
.getOutput(), 0, events
);
342 public List
<IUstProviderInfo
> getUstProvider() throws ExecutionException
{
343 return getUstProvider(new NullProgressMonitor());
347 public List
<IUstProviderInfo
> getUstProvider(IProgressMonitor monitor
) throws ExecutionException
{
348 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST_UST
);
350 if (isVersionSupported("2.1.0")) { //$NON-NLS-1$
351 command
.append(LTTngControlServiceConstants
.OPTION_FIELDS
);
354 ICommandResult result
= executeCommand(command
.toString(), monitor
, false);
355 List
<IUstProviderInfo
> allProviders
= new ArrayList
<>();
357 // Workaround for versions 2.0.x which causes a segmentation fault for this command
358 // if LTTng Tools is compiled without UST support.
359 if (!isVersionSupported("2.1.0") && (result
.getResult() != 0)) { //$NON-NLS-1$
363 if (result
.getErrorOutput() != null) {
364 // Ignore the following 2 cases:
365 // Spawning a session daemon
366 // Error: Unable to list UST events: Listing UST events failed
368 // Error: Unable to list UST events: Listing UST events failed
371 while (index
< result
.getErrorOutput().length
) {
372 String line
= result
.getErrorOutput()[index
];
373 Matcher matcher
= LTTngControlServiceConstants
.LIST_UST_NO_UST_PROVIDER_PATTERN
.matcher(line
);
374 if (matcher
.matches()) {
381 if (isError(result
)) {
382 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$
385 // Note that field print-outs exists for version >= 2.1.0
391 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
392 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
394 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
395 // field: doublefield (float)
396 // field: floatfield (float)
397 // field: stringfield (string)
400 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
401 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
403 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
404 // field: doublefield (float)
405 // field: floatfield (float)
406 // field: stringfield (string)
408 IUstProviderInfo provider
= null;
411 while (index
< result
.getOutput().length
) {
412 String line
= result
.getOutput()[index
];
413 Matcher matcher
= LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
);
414 if (matcher
.matches()) {
415 provider
= new UstProviderInfo(matcher
.group(2).trim());
416 provider
.setPid(Integer
.valueOf(matcher
.group(1).trim()));
417 List
<IBaseEventInfo
> events
= new ArrayList
<>();
418 index
= getProviderEventInfo(result
.getOutput(), ++index
, events
);
419 provider
.setEvents(events
);
420 allProviders
.add(provider
);
429 public ISessionInfo
createSession(ISessionInfo sessionInfo
, IProgressMonitor monitor
) throws ExecutionException
{
430 if (sessionInfo
.isStreamedTrace()) {
431 return createStreamedSession(sessionInfo
, monitor
);
434 StringBuffer command
= prepareSessionCreationCommand(sessionInfo
);
436 ICommandResult result
= executeCommand(command
.toString(), monitor
);
438 //Session myssession2 created.
439 //Traces will be written in /home/user/lttng-traces/myssession2-20120209-095418
440 String
[] output
= result
.getOutput();
442 // Get and session name and path
447 while (index
< output
.length
) {
448 String line
= output
[index
];
449 Matcher nameMatcher
= LTTngControlServiceConstants
.CREATE_SESSION_NAME_PATTERN
.matcher(line
);
450 Matcher pathMatcher
= LTTngControlServiceConstants
.CREATE_SESSION_PATH_PATTERN
.matcher(line
);
451 if (nameMatcher
.matches()) {
452 name
= String
.valueOf(nameMatcher
.group(1).trim());
453 } else if (pathMatcher
.matches()) {
454 path
= String
.valueOf(pathMatcher
.group(1).trim());
459 // Verify session name
460 if ((name
== null) || (!"".equals(sessionInfo
.getName()) && !name
.equals(sessionInfo
.getName()))) { //$NON-NLS-1$
461 // Unexpected name returned
462 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
463 Messages
.TraceControl_UnexpectedNameError
+ ": " + name
); //$NON-NLS-1$
466 sessionInfo
.setName(name
);
467 // Verify session path
468 if (!sessionInfo
.isSnapshotSession() &&
469 ((path
== null) || ((sessionInfo
.getSessionPath() != null) && (!path
.contains(sessionInfo
.getSessionPath()))))) {
471 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
472 Messages
.TraceControl_UnexpectedPathError
+ ": " + name
); //$NON-NLS-1$
475 if (sessionInfo
.isSnapshotSession()) {
476 // Make it a snapshot session - content of snapshot info need to
477 // set afterwards using getSession() or getSnapshotInfo()
478 sessionInfo
.setSnapshotInfo(new SnapshotInfo("")); //$NON-NLS-1$
480 sessionInfo
.setSessionPath(path
);
491 protected StringBuffer
prepareSessionCreationCommand(ISessionInfo sessionInfo
) {
492 String newName
= formatParameter(sessionInfo
.getName());
493 String newPath
= formatParameter(sessionInfo
.getSessionPath());
495 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_CREATE_SESSION
, newName
);
497 if (newPath
!= null && !"".equals(newPath
)) { //$NON-NLS-1$
498 command
.append(LTTngControlServiceConstants
.OPTION_OUTPUT_PATH
);
499 command
.append(newPath
);
502 if (sessionInfo
.isSnapshotSession()) {
503 command
.append(LTTngControlServiceConstants
.OPTION_SNAPSHOT
);
508 private ISessionInfo
createStreamedSession(ISessionInfo sessionInfo
, IProgressMonitor monitor
) throws ExecutionException
{
510 StringBuffer command
= prepareStreamedSessionCreationCommand(sessionInfo
);
512 ICommandResult result
= executeCommand(command
.toString(), monitor
);
515 String
[] output
= result
.getOutput();
517 // Get and session name and path
522 while (index
< output
.length
) {
523 String line
= output
[index
];
524 Matcher nameMatcher
= LTTngControlServiceConstants
.CREATE_SESSION_NAME_PATTERN
.matcher(line
);
525 Matcher pathMatcher
= LTTngControlServiceConstants
.CREATE_SESSION_PATH_PATTERN
.matcher(line
);
527 if (nameMatcher
.matches()) {
528 name
= String
.valueOf(nameMatcher
.group(1).trim());
529 } else if (pathMatcher
.matches() && (sessionInfo
.getNetworkUrl() != null)) {
530 path
= String
.valueOf(pathMatcher
.group(1).trim());
535 // Verify session name
536 if ((name
== null) || (!"".equals(sessionInfo
.getName()) && !name
.equals(sessionInfo
.getName()))) { //$NON-NLS-1$
537 // Unexpected name returned
538 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
539 Messages
.TraceControl_UnexpectedNameError
+ ": " + name
); //$NON-NLS-1$
542 sessionInfo
.setName(name
);
544 sessionInfo
.setStreamedTrace(true);
546 // Verify session path
547 if (sessionInfo
.getNetworkUrl() != null) {
548 if (!sessionInfo
.isSnapshotSession() && (path
== null)) {
550 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
551 Messages
.TraceControl_UnexpectedPathError
+ ": " + name
); //$NON-NLS-1$
554 if (sessionInfo
.isSnapshotSession()) {
555 sessionInfo
.setStreamedTrace(false);
557 sessionInfo
.setSessionPath(path
);
558 // Check file protocol
559 Matcher matcher
= LTTngControlServiceConstants
.TRACE_FILE_PROTOCOL_PATTERN
.matcher(path
);
560 if (matcher
.matches()) {
561 sessionInfo
.setStreamedTrace(false);
566 // When using controlUrl and dataUrl the full session path is not known yet
567 // and will be set later on when listing the session
576 protected StringBuffer
prepareStreamedSessionCreationCommand(ISessionInfo sessionInfo
) {
577 String newName
= formatParameter(sessionInfo
.getName());
578 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_CREATE_SESSION
, newName
);
580 if (sessionInfo
.isSnapshotSession()) {
581 command
.append(LTTngControlServiceConstants
.OPTION_SNAPSHOT
);
582 } else if (sessionInfo
.isLive()) {
583 command
.append(LTTngControlServiceConstants
.OPTION_LIVE
);
584 if (sessionInfo
.getLiveDelay() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
585 command
.append(sessionInfo
.getLiveDelay());
589 if (sessionInfo
.getNetworkUrl() != null) {
590 command
.append(LTTngControlServiceConstants
.OPTION_NETWORK_URL
);
591 command
.append(sessionInfo
.getNetworkUrl());
593 command
.append(LTTngControlServiceConstants
.OPTION_CONTROL_URL
);
594 command
.append(sessionInfo
.getControlUrl());
596 command
.append(LTTngControlServiceConstants
.OPTION_DATA_URL
);
597 command
.append(sessionInfo
.getDataUrl());
603 public void destroySession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
604 String newName
= formatParameter(sessionName
);
606 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_DESTROY_SESSION
, newName
);
608 ICommandResult result
= executeCommand(command
.toString(), monitor
, false);
609 String
[] errorOutput
= result
.getErrorOutput();
611 boolean isError
= isError(result
);
612 if (isError
&& (errorOutput
!= null)) {
614 while (index
< errorOutput
.length
) {
615 String line
= errorOutput
[index
];
616 Matcher matcher
= LTTngControlServiceConstants
.SESSION_NOT_FOUND_ERROR_PATTERN
.matcher(line
);
617 if (matcher
.matches()) {
618 // Don't treat this as an error
626 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$
629 //Session <sessionName> destroyed
633 public void startSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
635 String newSessionName
= formatParameter(sessionName
);
637 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_START_SESSION
, newSessionName
);
639 executeCommand(command
.toString(), monitor
);
641 //Session <sessionName> started
645 public void stopSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
646 String newSessionName
= formatParameter(sessionName
);
647 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_STOP_SESSION
, newSessionName
);
649 executeCommand(command
.toString(), monitor
);
651 //Session <sessionName> stopped
656 public void enableChannels(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IChannelInfo info
, IProgressMonitor monitor
) throws ExecutionException
{
658 // no channels to enable
659 if (channelNames
.isEmpty()) {
663 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_CHANNEL
);
665 for (Iterator
<String
> iterator
= channelNames
.iterator(); iterator
.hasNext();) {
666 String channel
= iterator
.next();
667 command
.append(channel
);
668 if (iterator
.hasNext()) {
674 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
676 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
679 String newSessionName
= formatParameter(sessionName
);
680 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
681 command
.append(newSessionName
);
684 // --discard Discard event when buffers are full (default)
686 // --overwrite Flight recorder mode
687 if (info
.isOverwriteMode()) {
688 command
.append(LTTngControlServiceConstants
.OPTION_OVERWRITE
);
690 // --subbuf-size SIZE Subbuffer size in bytes
691 // (default: 4096, kernel default: 262144)
692 if (info
.getSubBufferSize() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
693 command
.append(LTTngControlServiceConstants
.OPTION_SUB_BUFFER_SIZE
);
694 command
.append(String
.valueOf(info
.getSubBufferSize()));
697 // --num-subbuf NUM Number of subbufers
698 if (info
.getNumberOfSubBuffers() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
699 command
.append(LTTngControlServiceConstants
.OPTION_NUM_SUB_BUFFERS
);
700 command
.append(String
.valueOf(info
.getNumberOfSubBuffers()));
703 // --switch-timer USEC Switch timer interval in usec
704 if (info
.getSwitchTimer() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
705 command
.append(LTTngControlServiceConstants
.OPTION_SWITCH_TIMER
);
706 command
.append(String
.valueOf(info
.getSwitchTimer()));
709 // --read-timer USEC Read timer interval in usec
710 if (info
.getReadTimer() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
711 command
.append(LTTngControlServiceConstants
.OPTION_READ_TIMER
);
712 command
.append(String
.valueOf(info
.getReadTimer()));
715 if (isVersionSupported("2.2.0")) { //$NON-NLS-1$
716 // --buffers-uid Every application sharing the same UID use the same buffers
717 // --buffers-pid Buffers are allocated per PID
719 if (info
.getBufferType() == BufferType
.BUFFER_PER_PID
) {
720 command
.append(LTTngControlServiceConstants
.OPTION_PER_PID_BUFFERS
);
722 } else if (info
.getBufferType() == BufferType
.BUFFER_PER_UID
) {
723 command
.append(LTTngControlServiceConstants
.OPTION_PER_UID_BUFFERS
);
727 // -C SIZE Maximum size of trace files in bytes
728 if (info
.getMaxSizeTraceFiles() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
729 command
.append(LTTngControlServiceConstants
.OPTION_MAX_SIZE_TRACE_FILES
);
730 command
.append(String
.valueOf(info
.getMaxSizeTraceFiles()));
733 // -W NUM Maximum number of trace files
734 if (info
.getMaxNumberTraceFiles() != LTTngControlServiceConstants
.UNUSED_VALUE
) {
735 command
.append(LTTngControlServiceConstants
.OPTION_MAX_TRACE_FILES
);
736 command
.append(String
.valueOf(info
.getMaxNumberTraceFiles()));
741 executeCommand(command
.toString(), monitor
);
746 public void disableChannels(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
748 // no channels to enable
749 if (channelNames
.isEmpty()) {
753 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_DISABLE_CHANNEL
);
755 for (Iterator
<String
> iterator
= channelNames
.iterator(); iterator
.hasNext();) {
756 String channel
= iterator
.next();
757 command
.append(channel
);
758 if (iterator
.hasNext()) {
764 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
766 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
769 String newSessionName
= formatParameter(sessionName
);
770 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
771 command
.append(newSessionName
);
773 executeCommand(command
.toString(), monitor
);
777 public void enableEvents(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, String filterExpression
, IProgressMonitor monitor
) throws ExecutionException
{
779 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
781 if (eventNames
== null || eventNames
.isEmpty()) {
782 command
.append(LTTngControlServiceConstants
.OPTION_ALL
);
785 StringBuffer eventNameParameter
= new StringBuffer();
786 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
787 String event
= iterator
.next();
788 eventNameParameter
.append(event
);
789 if (iterator
.hasNext()) {
790 eventNameParameter
.append(',');
793 command
.append(formatParameter(eventNameParameter
.toString()));
797 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
799 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
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_TRACEPOINT
);
814 if (filterExpression
!= null) {
815 command
.append(LTTngControlServiceConstants
.OPTION_FILTER
);
816 command
.append('\'');
817 command
.append(filterExpression
);
818 command
.append('\'');
821 executeCommand(command
.toString(), monitor
);
826 public void enableSyscalls(String sessionName
, String channelName
, IProgressMonitor monitor
) throws ExecutionException
{
828 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
830 command
.append(LTTngControlServiceConstants
.OPTION_ALL
);
831 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
833 String newSessionName
= formatParameter(sessionName
);
835 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
836 command
.append(newSessionName
);
838 if (channelName
!= null) {
839 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
840 command
.append(channelName
);
843 command
.append(LTTngControlServiceConstants
.OPTION_SYSCALL
);
845 executeCommand(command
.toString(), monitor
);
849 public void enableProbe(String sessionName
, String channelName
, String eventName
, boolean isFunction
, String probe
, IProgressMonitor monitor
) throws ExecutionException
{
850 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
852 command
.append(eventName
);
853 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
855 String newSessionName
= formatParameter(sessionName
);
856 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
857 command
.append(newSessionName
);
859 if (channelName
!= null) {
860 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
861 command
.append(channelName
);
864 command
.append(LTTngControlServiceConstants
.OPTION_FUNCTION_PROBE
);
866 command
.append(LTTngControlServiceConstants
.OPTION_PROBE
);
869 command
.append(probe
);
871 executeCommand(command
.toString(), monitor
);
875 public void enableLogLevel(String sessionName
, String channelName
, String eventName
, LogLevelType logLevelType
, TraceLogLevel level
, String filterExpression
, IProgressMonitor monitor
) throws ExecutionException
{
876 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ENABLE_EVENT
);
878 command
.append(eventName
);
879 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
881 String newSessionName
= formatParameter(sessionName
);
882 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
883 command
.append(newSessionName
);
885 if (channelName
!= null) {
886 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
887 command
.append(channelName
);
890 if (logLevelType
== LogLevelType
.LOGLEVEL
) {
891 command
.append(LTTngControlServiceConstants
.OPTION_LOGLEVEL
);
892 } else if (logLevelType
== LogLevelType
.LOGLEVEL_ONLY
) {
893 command
.append(LTTngControlServiceConstants
.OPTION_LOGLEVEL_ONLY
);
898 command
.append(level
.getInName());
900 executeCommand(command
.toString(), monitor
);
904 public void disableEvent(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
905 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_DISABLE_EVENT
);
907 if (eventNames
== null) {
908 command
.append(LTTngControlServiceConstants
.OPTION_ALL
);
910 // no events to disable
911 if (eventNames
.isEmpty()) {
915 StringBuffer eventNameParameter
= new StringBuffer();
916 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
917 String event
= iterator
.next();
918 eventNameParameter
.append(event
);
919 if (iterator
.hasNext()) {
920 eventNameParameter
.append(',');
923 command
.append(formatParameter(eventNameParameter
.toString()));
927 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
929 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
932 String newSessionName
= formatParameter(sessionName
);
933 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
934 command
.append(newSessionName
);
936 if (channelName
!= null) {
937 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
938 command
.append(channelName
);
941 executeCommand(command
.toString(), monitor
);
945 public List
<String
> getContextList(IProgressMonitor monitor
) throws ExecutionException
{
947 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ADD_CONTEXT
, LTTngControlServiceConstants
.OPTION_HELP
);
949 ICommandResult result
= executeCommand(command
.toString(), monitor
);
951 String
[] output
= result
.getOutput();
953 List
<String
> contexts
= new ArrayList
<>(0);
956 boolean inList
= false;
957 while (index
< output
.length
) {
958 String line
= result
.getOutput()[index
];
960 Matcher startMatcher
= LTTngControlServiceConstants
.ADD_CONTEXT_HELP_CONTEXTS_INTRO
.matcher(line
);
961 Matcher endMatcher
= LTTngControlServiceConstants
.ADD_CONTEXT_HELP_CONTEXTS_END_LINE
.matcher(line
);
963 if (startMatcher
.matches()) {
965 } else if (endMatcher
.matches()) {
967 } else if (inList
== true) {
968 String
[] tmp
= line
.split(","); //$NON-NLS-1$
969 for (int i
= 0; i
< tmp
.length
; i
++) {
970 contexts
.add(tmp
[i
].trim());
979 public void addContexts(String sessionName
, String channelName
, String eventName
, boolean isKernel
, List
<String
> contextNames
, IProgressMonitor monitor
) throws ExecutionException
{
980 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_ADD_CONTEXT
);
982 String newSessionName
= formatParameter(sessionName
);
983 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
984 command
.append(newSessionName
);
986 if (channelName
!= null) {
987 command
.append(LTTngControlServiceConstants
.OPTION_CHANNEL
);
988 command
.append(channelName
);
991 if (eventName
!= null) {
992 command
.append(LTTngControlServiceConstants
.OPTION_EVENT
);
993 command
.append(eventName
);
997 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
999 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
1002 for (Iterator
<String
> iterator
= contextNames
.iterator(); iterator
.hasNext();) {
1003 String context
= iterator
.next();
1004 command
.append(LTTngControlServiceConstants
.OPTION_CONTEXT_TYPE
);
1005 command
.append(context
);
1008 executeCommand(command
.toString(), monitor
);
1013 public void calibrate(boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
1014 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_CALIBRATE
);
1017 command
.append(LTTngControlServiceConstants
.OPTION_KERNEL
);
1019 command
.append(LTTngControlServiceConstants
.OPTION_UST
);
1022 command
.append(LTTngControlServiceConstants
.OPTION_FUNCTION_PROBE
);
1024 executeCommand(command
.toString(), monitor
);
1028 public void recordSnapshot(String sessionName
, IProgressMonitor monitor
)
1029 throws ExecutionException
{
1030 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_RECORD_SNAPSHOT
);
1032 String newSessionName
= formatParameter(sessionName
);
1033 command
.append(LTTngControlServiceConstants
.OPTION_SESSION
);
1034 command
.append(newSessionName
);
1036 executeCommand(command
.toString(), monitor
);
1040 public void runCommands(IProgressMonitor monitor
, List
<String
> commands
) throws ExecutionException
{
1041 for (String command
: commands
) {
1042 if (monitor
.isCanceled()) {
1046 if (command
.isEmpty() || command
.startsWith("#")) { //$NON-NLS-1$
1049 executeCommand(command
, monitor
);
1053 // ------------------------------------------------------------------------
1055 // ------------------------------------------------------------------------
1058 * Checks if command result is an error result.
1061 * - the command result to check
1062 * @return true if error else false
1064 protected boolean isError(ICommandResult result
) {
1065 // Check return code and length of returned strings
1067 if ((result
.getResult()) != 0) {
1071 // Look for error pattern
1073 while (index
< result
.getErrorOutput().length
) {
1074 String line
= result
.getErrorOutput()[index
];
1075 Matcher matcher
= LTTngControlServiceConstants
.ERROR_PATTERN
.matcher(line
);
1076 if (matcher
.matches()) {
1086 * Formats the output string as single string.
1090 * @return - the formatted output
1092 public static String
formatOutput(ICommandResult result
) {
1093 if ((result
== null) || ((result
.getOutput() == null || result
.getOutput().length
== 0) && (result
.getErrorOutput() == null || result
.getErrorOutput().length
== 0))) {
1094 return ""; //$NON-NLS-1$
1096 String
[] output
= result
.getOutput();
1097 String
[] errorOutput
= result
.getErrorOutput();
1098 StringBuffer ret
= new StringBuffer();
1099 ret
.append("Return Value: "); //$NON-NLS-1$
1100 ret
.append(result
.getResult());
1101 ret
.append("\n"); //$NON-NLS-1$
1102 for (int i
= 0; i
< output
.length
; i
++) {
1103 ret
.append(output
[i
]).append("\n"); //$NON-NLS-1$
1105 ret
.append("Error stream:\n"); //$NON-NLS-1$
1106 for (int i
= 0; i
< errorOutput
.length
; i
++) {
1107 ret
.append(errorOutput
[i
]).append("\n"); //$NON-NLS-1$
1109 return ret
.toString();
1113 * Parses the domain information.
1116 * - a command output array
1117 * @param currentIndex
1118 * - current index in command output array
1120 * - list for returning channel information
1122 * - The domain information
1123 * @return the new current index in command output array
1125 protected int parseDomain(String
[] output
, int currentIndex
, List
<IChannelInfo
> channels
, IDomainInfo domainInfo
) {
1126 int index
= currentIndex
;
1128 // if kernel set the buffer type to shared
1129 if (domainInfo
.isKernel()) {
1130 domainInfo
.setBufferType(BufferType
.BUFFER_SHARED
);
1135 // - channnel1: [enabled]
1138 // overwrite mode: 0
1139 // subbufers size: 262144
1140 // number of subbufers: 4
1141 // switch timer interval: 0
1142 // read timer interval: 200
1145 while (index
< output
.length
) {
1146 String line
= output
[index
];
1148 if (isVersionSupported("2.2.0")) { //$NON-NLS-1$
1149 Matcher bufferTypeMatcher
= LTTngControlServiceConstants
.BUFFER_TYPE_PATTERN
.matcher(line
);
1150 if (bufferTypeMatcher
.matches()) {
1151 String bufferTypeString
= getAttributeValue(line
);
1152 if (BufferType
.BUFFER_PER_PID
.getInName().equals(bufferTypeString
)) {
1153 domainInfo
.setBufferType(BufferType
.BUFFER_PER_PID
);
1154 } else if (BufferType
.BUFFER_PER_UID
.getInName().equals(bufferTypeString
)) {
1155 domainInfo
.setBufferType(BufferType
.BUFFER_PER_UID
);
1157 domainInfo
.setBufferType(BufferType
.BUFFER_TYPE_UNKNOWN
);
1161 domainInfo
.setBufferType(BufferType
.BUFFER_TYPE_UNKNOWN
);
1163 Matcher outerMatcher
= LTTngControlServiceConstants
.CHANNELS_SECTION_PATTERN
.matcher(line
);
1164 Matcher noKernelChannelMatcher
= LTTngControlServiceConstants
.DOMAIN_NO_KERNEL_CHANNEL_PATTERN
.matcher(line
);
1165 Matcher noUstChannelMatcher
= LTTngControlServiceConstants
.DOMAIN_NO_UST_CHANNEL_PATTERN
.matcher(line
);
1166 if (outerMatcher
.matches()) {
1167 IChannelInfo channelInfo
= null;
1168 while (index
< output
.length
) {
1169 String subLine
= output
[index
];
1171 Matcher innerMatcher
= LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(subLine
);
1172 if (innerMatcher
.matches()) {
1173 channelInfo
= new ChannelInfo(""); //$NON-NLS-1$
1175 channelInfo
.setName(innerMatcher
.group(1));
1177 // get channel enablement
1178 channelInfo
.setState(innerMatcher
.group(2));
1181 channelInfo
.setBufferType(domainInfo
.getBufferType());
1184 channels
.add(channelInfo
);
1186 } else if (LTTngControlServiceConstants
.OVERWRITE_MODE_ATTRIBUTE
.matcher(subLine
).matches()) {
1187 String value
= getAttributeValue(subLine
);
1188 if (channelInfo
!= null) {
1189 channelInfo
.setOverwriteMode(!LTTngControlServiceConstants
.OVERWRITE_MODE_ATTRIBUTE_FALSE
.equals(value
));
1191 } else if (LTTngControlServiceConstants
.SUBBUFFER_SIZE_ATTRIBUTE
.matcher(subLine
).matches()) {
1192 if (channelInfo
!= null) {
1193 channelInfo
.setSubBufferSize(Long
.valueOf(getAttributeValue(subLine
)));
1196 } else if (LTTngControlServiceConstants
.NUM_SUBBUFFERS_ATTRIBUTE
.matcher(subLine
).matches()) {
1197 if (channelInfo
!= null) {
1198 channelInfo
.setNumberOfSubBuffers(Integer
.valueOf(getAttributeValue(subLine
)));
1201 } else if (LTTngControlServiceConstants
.SWITCH_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
1202 if (channelInfo
!= null) {
1203 channelInfo
.setSwitchTimer(Long
.valueOf(getAttributeValue(subLine
)));
1206 } else if (LTTngControlServiceConstants
.READ_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
1207 if (channelInfo
!= null) {
1208 channelInfo
.setReadTimer(Long
.valueOf(getAttributeValue(subLine
)));
1211 } else if (LTTngControlServiceConstants
.OUTPUT_ATTRIBUTE
.matcher(subLine
).matches()) {
1212 if (channelInfo
!= null) {
1213 channelInfo
.setOutputType(getAttributeValue(subLine
));
1216 } else if (LTTngControlServiceConstants
.EVENT_SECTION_PATTERN
.matcher(subLine
).matches()) {
1217 List
<IEventInfo
> events
= new ArrayList
<>();
1218 index
= parseEvents(output
, index
, events
);
1219 if (channelInfo
!= null) {
1220 channelInfo
.setEvents(events
);
1222 // we want to stay at the current index to be able to
1225 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(subLine
).matches()) {
1228 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(subLine
).matches()) {
1233 } else if (noKernelChannelMatcher
.matches() || noUstChannelMatcher
.matches()) {
1234 // domain indicates that no channels were found -> return
1244 * Parses the event information within a domain.
1247 * - a command output array
1248 * @param currentIndex
1249 * - current index in command output array
1251 * - list for returning event information
1252 * @return the new current index in command output array
1254 protected int parseEvents(String
[] output
, int currentIndex
, List
<IEventInfo
> events
) {
1255 int index
= currentIndex
;
1257 while (index
< output
.length
) {
1258 String line
= output
[index
];
1259 if (LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(line
).matches()) {
1262 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(line
).matches()) {
1265 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
).matches()) {
1270 Matcher matcher
= LTTngControlServiceConstants
.EVENT_PATTERN
.matcher(line
);
1271 Matcher matcher2
= LTTngControlServiceConstants
.WILDCARD_EVENT_PATTERN
.matcher(line
);
1273 if (matcher
.matches()) {
1274 IEventInfo eventInfo
= new EventInfo(matcher
.group(1).trim());
1275 eventInfo
.setLogLevelType(matcher
.group(2).trim());
1276 eventInfo
.setLogLevel(matcher
.group(3).trim());
1277 eventInfo
.setEventType(matcher
.group(4).trim());
1278 eventInfo
.setState(matcher
.group(5));
1279 String filter
= matcher
.group(6);
1280 if (filter
!= null) {
1281 filter
= filter
.substring(1, filter
.length() - 1); // remove '[' and ']'
1282 eventInfo
.setFilterExpression(filter
);
1284 events
.add(eventInfo
);
1286 } else if (matcher2
.matches()) {
1287 IEventInfo eventInfo
= new EventInfo(matcher2
.group(1).trim());
1288 eventInfo
.setLogLevel(TraceLogLevel
.LEVEL_UNKNOWN
);
1289 eventInfo
.setEventType(matcher2
.group(2).trim());
1290 eventInfo
.setState(matcher2
.group(3));
1291 String filter
= matcher2
.group(4);
1292 if (filter
!= null) {
1293 filter
= filter
.substring(1, filter
.length() - 1); // remove '[' and ']'
1294 eventInfo
.setFilterExpression(filter
);
1297 if ((eventInfo
.getEventType() == TraceEventType
.PROBE
) ||
1298 (eventInfo
.getEventType() == TraceEventType
.FUNCTION
)){
1299 IProbeEventInfo probeEvent
= new ProbeEventInfo(eventInfo
.getName());
1300 probeEvent
.setLogLevel(eventInfo
.getLogLevel());
1301 probeEvent
.setEventType(eventInfo
.getEventType());
1302 probeEvent
.setState(eventInfo
.getState());
1304 // Overwrite eventinfo
1305 eventInfo
= probeEvent
;
1307 // myevent2 (type: probe) [enabled]
1309 // myevent0 (type: function) [enabled]
1311 // symbol: init_post
1313 while (index
< output
.length
) {
1314 String probeLine
= output
[index
];
1316 Matcher addrMatcher
= LTTngControlServiceConstants
.PROBE_ADDRESS_PATTERN
.matcher(probeLine
);
1317 Matcher offsetMatcher
= LTTngControlServiceConstants
.PROBE_OFFSET_PATTERN
.matcher(probeLine
);
1318 Matcher symbolMatcher
= LTTngControlServiceConstants
.PROBE_SYMBOL_PATTERN
.matcher(probeLine
);
1319 if (addrMatcher
.matches()) {
1320 String addr
= addrMatcher
.group(2).trim();
1321 probeEvent
.setAddress(addr
);
1322 } else if (offsetMatcher
.matches()) {
1323 String offset
= offsetMatcher
.group(2).trim();
1324 probeEvent
.setOffset(offset
);
1325 } else if (symbolMatcher
.matches()) {
1326 String symbol
= symbolMatcher
.group(2).trim();
1327 probeEvent
.setSymbol(symbol
);
1328 } else if ((LTTngControlServiceConstants
.EVENT_PATTERN
.matcher(probeLine
).matches()) || (LTTngControlServiceConstants
.WILDCARD_EVENT_PATTERN
.matcher(probeLine
).matches())) {
1330 } else if (LTTngControlServiceConstants
.CHANNEL_PATTERN
.matcher(probeLine
).matches()) {
1332 } else if (LTTngControlServiceConstants
.DOMAIN_KERNEL_PATTERN
.matcher(probeLine
).matches()) {
1335 } else if (LTTngControlServiceConstants
.DOMAIN_UST_GLOBAL_PATTERN
.matcher(probeLine
).matches()) {
1341 events
.add(eventInfo
);
1343 events
.add(eventInfo
);
1356 * Parses a line with attributes: <attribute Name>: <attribute value>
1359 * - attribute line to parse
1360 * @return the attribute value as string
1362 protected String
getAttributeValue(String line
) {
1363 String
[] temp
= line
.split("\\: "); //$NON-NLS-1$
1368 * Parses the event information within a provider.
1371 * - a command output array
1372 * @param currentIndex
1373 * - current index in command output array
1375 * - list for returning event information
1376 * @return the new current index in command output array
1378 protected int getProviderEventInfo(String
[] output
, int currentIndex
, List
<IBaseEventInfo
> events
) {
1379 int index
= currentIndex
;
1380 IBaseEventInfo eventInfo
= null;
1381 while (index
< output
.length
) {
1382 String line
= output
[index
];
1383 Matcher matcher
= LTTngControlServiceConstants
.PROVIDER_EVENT_PATTERN
.matcher(line
);
1384 if (matcher
.matches()) {
1385 // sched_kthread_stop (loglevel: TRACE_EMERG0) (type: tracepoint)
1386 eventInfo
= new BaseEventInfo(matcher
.group(1).trim());
1387 eventInfo
.setLogLevel(matcher
.group(2).trim());
1388 eventInfo
.setEventType(matcher
.group(3).trim());
1389 events
.add(eventInfo
);
1391 } else if (LTTngControlServiceConstants
.EVENT_FIELD_PATTERN
.matcher(line
).matches()) {
1392 if (eventInfo
!= null) {
1393 List
<IFieldInfo
> fields
= new ArrayList
<>();
1394 index
= getFieldInfo(output
, index
, fields
);
1395 eventInfo
.setFields(fields
);
1400 else if (LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
).matches()) {
1411 * Parse a field's information.
1414 * A command output array
1415 * @param currentIndex
1416 * The current index in the command output array
1418 * List for returning the field information
1419 * @return The new current index in the command output array
1421 protected int getFieldInfo(String
[] output
, int currentIndex
, List
<IFieldInfo
> fields
) {
1422 int index
= currentIndex
;
1423 IFieldInfo fieldInfo
= null;
1424 while (index
< output
.length
) {
1425 String line
= output
[index
];
1426 Matcher matcher
= LTTngControlServiceConstants
.EVENT_FIELD_PATTERN
.matcher(line
);
1427 if (matcher
.matches()) {
1428 // field: content (string)
1429 fieldInfo
= new FieldInfo(matcher
.group(2).trim());
1430 fieldInfo
.setFieldType(matcher
.group(3).trim());
1431 fields
.add(fieldInfo
);
1432 } else if (LTTngControlServiceConstants
.PROVIDER_EVENT_PATTERN
.matcher(line
).matches()) {
1434 } else if (LTTngControlServiceConstants
.UST_PROVIDER_PATTERN
.matcher(line
).matches()) {
1443 * Formats a command parameter for the command execution i.e. adds quotes
1444 * at the beginning and end if necessary.
1445 * @param parameter - parameter to format
1446 * @return formated parameter
1448 protected String
formatParameter(String parameter
) {
1449 if (parameter
!= null) {
1450 StringBuffer newString
= new StringBuffer();
1451 newString
.append(parameter
);
1453 if (parameter
.contains(" ") || parameter
.contains("*")) { //$NON-NLS-1$ //$NON-NLS-2$
1454 newString
.insert(0, "\""); //$NON-NLS-1$
1455 newString
.append("\""); //$NON-NLS-1$
1457 return newString
.toString();
1463 * @param strings array of string that makes up a command line
1464 * @return string buffer with created command line
1466 protected StringBuffer
createCommand(String
... strings
) {
1467 StringBuffer command
= new StringBuffer();
1468 command
.append(LTTngControlServiceConstants
.CONTROL_COMMAND
);
1469 command
.append(getTracingGroupOption());
1470 command
.append(getVerboseOption());
1471 for (String string
: strings
) {
1472 command
.append(string
);
1478 * @return the tracing group option if configured in the preferences
1480 protected String
getTracingGroupOption() {
1481 if (!ControlPreferences
.getInstance().isDefaultTracingGroup() && !ControlPreferences
.getInstance().getTracingGroup().equals("")) { //$NON-NLS-1$
1482 return LTTngControlServiceConstants
.OPTION_TRACING_GROUP
+ ControlPreferences
.getInstance().getTracingGroup();
1484 return ""; //$NON-NLS-1$
1488 * @return the verbose option as configured in the preferences
1490 protected String
getVerboseOption() {
1491 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1492 String level
= ControlPreferences
.getInstance().getVerboseLevel();
1493 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_VERBOSE
.equals(level
)) {
1494 return LTTngControlServiceConstants
.OPTION_VERBOSE
;
1496 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_V_VERBOSE
.equals(level
)) {
1497 return LTTngControlServiceConstants
.OPTION_VERY_VERBOSE
;
1499 if (ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_V_V_VERBOSE
.equals(level
)) {
1500 return LTTngControlServiceConstants
.OPTION_VERY_VERY_VERBOSE
;
1503 return ""; //$NON-NLS-1$
1507 * Method that logs the command and command result if logging is enabled as
1508 * well as forwards the command execution to the shell.
1511 * - the command to execute
1513 * - a progress monitor
1514 * @return the command result
1515 * @throws ExecutionException
1516 * If the command fails
1518 protected ICommandResult
executeCommand(String command
,
1519 IProgressMonitor monitor
) throws ExecutionException
{
1520 return executeCommand(command
, monitor
, true);
1524 * Method that logs the command and command result if logging is enabled as
1525 * well as forwards the command execution to the shell.
1528 * - the command to execute
1530 * - a progress monitor
1531 * @param checkForError
1532 * - true to verify command result, else false
1533 * @return the command result
1534 * @throws ExecutionException
1535 * in case of error result
1537 protected ICommandResult
executeCommand(String command
,
1538 IProgressMonitor monitor
, boolean checkForError
)
1539 throws ExecutionException
{
1540 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1541 ControlCommandLogger
.log(command
);
1544 ICommandResult result
= fCommandShell
.executeCommand(
1545 command
.toString(), monitor
);
1547 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
1548 ControlCommandLogger
.log(formatOutput(result
));
1551 if (checkForError
&& isError(result
)) {
1552 throw new ExecutionException(Messages
.TraceControl_CommandError
1553 + " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$