1 /**********************************************************************
2 * Copyright (c) 2012 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 **********************************************************************/
12 package org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.service
;
14 import java
.util
.ArrayList
;
15 import java
.util
.Iterator
;
16 import java
.util
.List
;
17 import java
.util
.regex
.Matcher
;
18 import java
.util
.regex
.Pattern
;
20 import org
.eclipse
.core
.commands
.ExecutionException
;
21 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
22 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
23 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.Messages
;
24 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.IBaseEventInfo
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.IChannelInfo
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.IDomainInfo
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.IEventInfo
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.IProbeEventInfo
;
29 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.ISessionInfo
;
30 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.IUstProviderInfo
;
31 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.LogLevelType
;
32 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.TraceEventType
;
33 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.TraceLogLevel
;
34 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.BaseEventInfo
;
35 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.ChannelInfo
;
36 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.DomainInfo
;
37 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.EventInfo
;
38 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.ProbeEventInfo
;
39 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.SessionInfo
;
40 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.UstProviderInfo
;
43 * <b><u>LTTngControlService</u></b>
45 * Service for sending LTTng trace control commands to remote host.
48 public class LTTngControlService
implements ILttngControlService
{
49 // ------------------------------------------------------------------------
51 // ------------------------------------------------------------------------
54 * The lttng tools command.
56 private final static String CONTROL_COMMAND
= "lttng"; //$NON-NLS-1$
58 * Command: lttng list.
60 private final static String COMMAND_LIST
= CONTROL_COMMAND
+ " list "; //$NON-NLS-1$
62 * Command to list kernel tracer information.
64 private final static String COMMAND_LIST_KERNEL
= COMMAND_LIST
+ "-k"; //$NON-NLS-1$
66 * Command to list user space trace information.
68 private final static String COMMAND_LIST_UST
= COMMAND_LIST
+ "-u"; //$NON-NLS-1$
70 * Command to create a session.
72 private final static String COMMAND_CREATE_SESSION
= CONTROL_COMMAND
+ " create "; //$NON-NLS-1$
74 * Command to destroy a session.
76 private final static String COMMAND_DESTROY_SESSION
= CONTROL_COMMAND
+ " destroy "; //$NON-NLS-1$
78 * Command to destroy a session.
80 private final static String COMMAND_START_SESSION
= CONTROL_COMMAND
+ " start "; //$NON-NLS-1$
82 * Command to destroy a session.
84 private final static String COMMAND_STOP_SESSION
= CONTROL_COMMAND
+ " stop "; //$NON-NLS-1$
86 * Command to enable a channel.
88 private final static String COMMAND_ENABLE_CHANNEL
= CONTROL_COMMAND
+ " enable-channel "; //$NON-NLS-1$
90 * Command to disable a channel.
92 private final static String COMMAND_DISABLE_CHANNEL
= CONTROL_COMMAND
+ " disable-channel "; //$NON-NLS-1$
94 * Command to enable a event.
96 private final static String COMMAND_ENABLE_EVENT
= CONTROL_COMMAND
+ " enable-event "; //$NON-NLS-1$
98 * Command to disable a event.
100 private final static String COMMAND_DISABLE_EVENT
= CONTROL_COMMAND
+ " disable-event "; //$NON-NLS-1$
102 // Command options constants
104 * Command line option for kernel tracer.
106 private final static String OPTION_KERNEL
= " -k "; //$NON-NLS-1$
108 * Command line option for UST tracer.
110 private final static String OPTION_UST
= " -u "; //$NON-NLS-1$
112 * Command line option for specifying a session.
114 private final static String OPTION_SESSION
= " -s "; //$NON-NLS-1$
116 * Command line option for specifying a channel.
118 private final static String OPTION_CHANNEL
= " -c "; //$NON-NLS-1$
120 * Command line option for specifying all events.
122 private final static String OPTION_ALL
= " -a "; //$NON-NLS-1$
124 * Command line option for specifying tracepoint events.
126 private final static String OPTION_TRACEPOINT
= " --tracepoint "; //$NON-NLS-1$
128 * Command line option for specifying syscall events.
130 private final static String OPTION_SYSCALL
= " --syscall "; //$NON-NLS-1$
132 * Command line option for specifying a dynamic probe.
134 private final static String OPTION_PROBE
= " --probe "; //$NON-NLS-1$
136 * Command line option for specifying a dynamic function entry/return probe.
138 private final static String OPTION_FUNCTION_PROBE
= " --function "; //$NON-NLS-1$
140 * Command line option for specifying a log level range.
142 private final static String OPTION_LOGLEVEL
= " --loglevel "; //$NON-NLS-1$
144 * Command line option for specifying a specific log level.
146 private final static String OPTION_LOGLEVEL_ONLY
= " --loglevel-only "; //$NON-NLS-1$
148 * Optional command line option for configuring a channel's overwrite mode.
150 private final static String OPTION_OVERWRITE
= " --overwrite "; //$NON-NLS-1$
152 * Optional command line option for configuring a channel's number of sub buffers.
154 private final static String OPTION_NUM_SUB_BUFFERS
= " --num-subbuf "; //$NON-NLS-1$
156 * Optional command line option for configuring a channel's sub buffer size.
158 private final static String OPTION_SUB_BUFFER_SIZE
= " --subbuf-size "; //$NON-NLS-1$
160 * Optional command line option for configuring a channel's switch timer interval.
162 private final static String OPTION_SWITCH_TIMER
= " --switch-timer "; //$NON-NLS-1$
164 * Optional command line option for configuring a channel's read timer interval.
166 private final static String OPTION_READ_TIMER
= " --read-timer "; //$NON-NLS-1$
170 * Pattern to match for error output
172 private final static Pattern ERROR_PATTERN
= Pattern
.compile("\\s*Error\\:.*"); //$NON-NLS-1$
174 * Pattern to match for session information (lttng list)
176 private final static Pattern SESSION_PATTERN
= Pattern
.compile("\\s+(\\d+)\\)\\s+(.*)\\s+\\((.*)\\)\\s+\\[(active|inactive)\\].*"); //$NON-NLS-1$
178 * Pattern to match for session information (lttng list <session>)
180 private final static Pattern TRACE_SESSION_PATTERN
= Pattern
.compile("\\s*Tracing\\s+session\\s+(.*)\\:\\s+\\[(active|inactive)\\].*"); //$NON-NLS-1$
182 * Pattern to match for session path information (lttng list <session>)
184 private final static Pattern TRACE_SESSION_PATH_PATTERN
= Pattern
.compile("\\s*Trace\\s+path\\:\\s+(.*)"); //$NON-NLS-1$
186 * Pattern to match for kernel domain information (lttng list <session>)
188 private final static Pattern DOMAIN_KERNEL_PATTERN
= Pattern
.compile("=== Domain: Kernel ==="); //$NON-NLS-1$
190 * Pattern to match for ust domain information (lttng list <session>)
192 private final static Pattern DOMAIN_UST_GLOBAL_PATTERN
= Pattern
.compile("=== Domain: UST global ==="); //$NON-NLS-1$
194 * Pattern to match for channels section (lttng list <session>)
196 private final static Pattern CHANNELS_SECTION_PATTERN
= Pattern
.compile("\\s*Channels\\:"); //$NON-NLS-1$
198 * Pattern to match for channel information (lttng list <session>)
200 private final static Pattern CHANNEL_PATTERN
= Pattern
.compile("\\s*-\\s+(.*)\\:\\s+\\[(enabled|disabled)\\]"); //$NON-NLS-1$
202 * Pattern to match for events section information (lttng list <session>)
204 private final static Pattern EVENT_SECTION_PATTERN
= Pattern
.compile("\\s*Events\\:"); //$NON-NLS-1$
206 * Pattern to match for event information (no enabled events) (lttng list <session>)
208 // private final static String EVENT_NONE_PATTERN = "\\s+None"; //$NON-NLS-1$
210 * Pattern to match for event information (lttng list <session>)
212 private final static Pattern EVENT_PATTERN
= Pattern
.compile("\\s+(.*)\\s+\\(loglevel:\\s+(.*)\\s+\\(\\d*\\)\\)\\s+\\(type:\\s+(.*)\\)\\s+\\[(enabled|disabled)\\].*"); //$NON-NLS-1$
214 * Pattern to match a wildcarded event information (lttng list <session>)
216 private final static Pattern WILDCARD_EVENT_PATTERN
= Pattern
.compile("\\s+(.*)\\s+\\(type:\\s+(.*)\\)\\s+\\[(enabled|disabled)\\].*"); //$NON-NLS-1$
218 * Pattern to match a probe address information (lttng list <session>)
220 private final static Pattern PROBE_ADDRESS_PATTERN
= Pattern
.compile("\\s+(addr)\\:\\s+(0x[0-9a-fA-F]{1,8})"); //$NON-NLS-1$
222 * Pattern to match a probe OFFSET information (lttng list <session>)
224 private final static Pattern PROBE_OFFSET_PATTERN
= Pattern
.compile("\\s+(offset)\\:\\s+(0x[0-9a-fA-F]{1,8})"); //$NON-NLS-1$
226 * Pattern to match a probe SYMBOL information (lttng list <session>)
228 private final static Pattern PROBE_SYMBOL_PATTERN
= Pattern
.compile("\\s+(symbol)\\:\\s+(.+)"); //$NON-NLS-1$
230 * Pattern to match for channel (overwite mode) information (lttng list
233 private final static Pattern OVERWRITE_MODE_ATTRIBUTE
= Pattern
.compile("\\s+overwrite\\s+mode\\:.*"); //$NON-NLS-1$
235 * Pattern to match indicating false for overwrite mode
237 private final static String OVERWRITE_MODE_ATTRIBUTE_FALSE
= "0"; //$NON-NLS-1$
239 * Pattern to match for channel (sub-buffer size) information (lttng list
242 private final static Pattern SUBBUFFER_SIZE_ATTRIBUTE
= Pattern
.compile("\\s+subbufers\\s+size\\:.*"); //$NON-NLS-1$
244 * Pattern to match for channel (number of sub-buffers) information (lttng
247 private final static Pattern NUM_SUBBUFFERS_ATTRIBUTE
= Pattern
.compile("\\s+number\\s+of\\s+subbufers\\:.*"); //$NON-NLS-1$
249 * Pattern to match for channel (switch timer) information (lttng list
252 private final static Pattern SWITCH_TIMER_ATTRIBUTE
= Pattern
.compile("\\s+switch\\s+timer\\s+interval\\:.*"); //$NON-NLS-1$
254 * Pattern to match for channel (read timer) information (lttng list
257 private final static Pattern READ_TIMER_ATTRIBUTE
= Pattern
.compile("\\s+read\\s+timer\\s+interval\\:.*"); //$NON-NLS-1$
259 * Pattern to match for channel (output type) information (lttng list
262 private final static Pattern OUTPUT_ATTRIBUTE
= Pattern
.compile("\\s+output\\:.*"); //$NON-NLS-1$
264 * Pattern to match for provider information (lttng list -k/-u)
266 private final static Pattern PROVIDER_EVENT_PATTERN
= Pattern
.compile("\\s*(.*)\\s+\\(loglevel:\\s+(.*)\\s+\\(\\d*\\)\\)\\s+\\(type:\\s+(.*)\\)"); //$NON-NLS-1$
268 * Pattern to match for UST provider information (lttng list -u)
270 private final static Pattern UST_PROVIDER_PATTERN
= Pattern
.compile("\\s*PID\\:\\s+(\\d+)\\s+-\\s+Name\\:\\s+(.*)"); //$NON-NLS-1$
272 * Pattern to match for session information (lttng create <session name>)
274 private final static Pattern CREATE_SESSION_NAME_PATTERN
= Pattern
.compile("\\s*Session\\s+(.*)\\s+created\\."); //$NON-NLS-1$
276 * Pattern to match for session path information (lttng create <session name>)
278 private final static Pattern CREATE_SESSION_PATH_PATTERN
= Pattern
.compile("\\s*Traces\\s+will\\s+be\\s+written\\s+in\\s+(.*).*"); //$NON-NLS-1$
280 * Pattern to match for session command output for "session name not found".
282 private final static Pattern SESSION_NOT_FOUND_ERROR_PATTERN
= Pattern
.compile("\\s*Error:\\s+Session\\s+name\\s+not\\s+found"); //$NON-NLS-1$
284 // ------------------------------------------------------------------------
286 // ------------------------------------------------------------------------
288 * The command shell implementation
290 private ICommandShell fCommandShell
= null;
292 // ------------------------------------------------------------------------
294 // ------------------------------------------------------------------------
300 * - the command shell implementation to use
302 public LTTngControlService(ICommandShell shell
) {
303 fCommandShell
= shell
;
306 // ------------------------------------------------------------------------
308 // ------------------------------------------------------------------------
314 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
315 * #getSessionNames(org.eclipse.core.runtime.IProgressMonitor)
318 public String
[] getSessionNames(IProgressMonitor monitor
) throws ExecutionException
{
320 String command
= COMMAND_LIST
;
321 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
323 if (isError(result
)) {
324 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
328 // Available tracing sessions:
329 // 1) mysession1 (/home/user/lttng-traces/mysession1-20120123-083928)
331 // 2) mysession (/home/user/lttng-traces/mysession-20120123-083318)
334 // Use lttng list <session_name> for more details
336 ArrayList
<String
> retArray
= new ArrayList
<String
>();
338 while (index
< result
.getOutput().length
) {
339 String line
= result
.getOutput()[index
];
340 Matcher matcher
= SESSION_PATTERN
.matcher(line
);
341 if (matcher
.matches()) {
342 retArray
.add(matcher
.group(2).trim());
346 return retArray
.toArray(new String
[retArray
.size()]);
353 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
354 * #getSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
357 public ISessionInfo
getSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
359 String command
= COMMAND_LIST
+ sessionName
;
360 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
363 if (isError(result
)) {
364 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
370 // Tracing session mysession2: [inactive]
371 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
372 ISessionInfo sessionInfo
= new SessionInfo(sessionName
);
374 while (index
< result
.getOutput().length
) {
375 // Tracing session mysession2: [inactive]
376 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
378 // === Domain: Kernel ===
380 String line
= result
.getOutput()[index
];
381 Matcher matcher
= TRACE_SESSION_PATTERN
.matcher(line
);
382 if (matcher
.matches()) {
383 sessionInfo
.setSessionState(matcher
.group(2));
388 matcher
= TRACE_SESSION_PATH_PATTERN
.matcher(line
);
389 if (matcher
.matches()) {
390 sessionInfo
.setSessionPath(matcher
.group(1).trim());
395 matcher
= DOMAIN_KERNEL_PATTERN
.matcher(line
);
396 if (matcher
.matches()) {
398 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_KernelDomainDisplayName
);
399 sessionInfo
.addDomain(domainInfo
);
402 ArrayList
<IChannelInfo
> channels
= new ArrayList
<IChannelInfo
>();
403 index
= parseDomain(result
.getOutput(), index
, channels
);
406 domainInfo
.setChannels(channels
);
409 domainInfo
.setIsKernel(true);
413 matcher
= DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
);
414 if (matcher
.matches()) {
415 IDomainInfo domainInfo
= new DomainInfo(Messages
.TraceControl_UstGlobalDomainDisplayName
);
416 sessionInfo
.addDomain(domainInfo
);
419 ArrayList
<IChannelInfo
> channels
= new ArrayList
<IChannelInfo
>();
420 index
= parseDomain(result
.getOutput(), index
, channels
);
423 domainInfo
.setChannels(channels
);
426 domainInfo
.setIsKernel(false);
438 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
439 * #getKernelProvider(org.eclipse.core.runtime.IProgressMonitor)
442 public List
<IBaseEventInfo
> getKernelProvider(IProgressMonitor monitor
) throws ExecutionException
{
443 String command
= COMMAND_LIST_KERNEL
;
444 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
445 if (isError(result
)) {
446 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
451 // sched_kthread_stop (type: tracepoint)
452 List
<IBaseEventInfo
> events
= new ArrayList
<IBaseEventInfo
>();
453 getProviderEventInfo(result
.getOutput(), 0, events
);
461 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
465 public List
<IUstProviderInfo
> getUstProvider() throws ExecutionException
{
466 return getUstProvider(new NullProgressMonitor());
473 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
474 * #getUstProvider(org.eclipse.core.runtime.IProgressMonitor)
477 public List
<IUstProviderInfo
> getUstProvider(IProgressMonitor monitor
) throws ExecutionException
{
478 String command
= COMMAND_LIST_UST
;
479 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
481 if (isError(result
)) {
482 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
489 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
490 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
492 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
495 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
496 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
498 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
500 List
<IUstProviderInfo
> allProviders
= new ArrayList
<IUstProviderInfo
>();
501 IUstProviderInfo provider
= null;
504 while (index
< result
.getOutput().length
) {
505 String line
= result
.getOutput()[index
];
506 Matcher matcher
= UST_PROVIDER_PATTERN
.matcher(line
);
507 if (matcher
.matches()) {
509 provider
= new UstProviderInfo(matcher
.group(2).trim());
510 provider
.setPid(Integer
.valueOf(matcher
.group(1).trim()));
511 List
<IBaseEventInfo
> events
= new ArrayList
<IBaseEventInfo
>();
512 index
= getProviderEventInfo(result
.getOutput(), ++index
, events
);
513 provider
.setEvents(events
);
514 allProviders
.add(provider
);
526 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#createSession(java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
529 public ISessionInfo
createSession(String sessionName
, String sessionPath
, IProgressMonitor monitor
) throws ExecutionException
{
531 String newName
= formatParameter(sessionName
);
532 String newPath
= formatParameter(sessionPath
);
534 String command
= COMMAND_CREATE_SESSION
+ newName
;
535 if (newPath
!= null && !"".equals(newPath
)) { //$NON-NLS-1$
536 command
+= " -o " + newPath
; //$NON-NLS-1$
539 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
541 if (isError(result
)) {
542 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
544 //Session myssession2 created.
545 //Traces will be written in /home/user/lttng-traces/myssession2-20120209-095418
546 String
[] output
= result
.getOutput();
548 // Get and verify session name
549 Matcher matcher
= CREATE_SESSION_NAME_PATTERN
.matcher(output
[0]);
552 if (matcher
.matches()) {
553 name
= String
.valueOf(matcher
.group(1).trim());
555 // Output format not expected
556 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
557 Messages
.TraceControl_UnexpectedCommnadOutputFormat
+ ":\n" + //$NON-NLS-1$
558 formatOutput(result
.getOutput()));
561 if ((name
== null) || (!name
.equals(sessionName
))) {
562 // Unexpected name returned
563 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
564 Messages
.TraceControl_UnexpectedNameError
+ ": " + name
); //$NON-NLS-1$
567 // Get and verify session path
568 matcher
= CREATE_SESSION_PATH_PATTERN
.matcher(output
[1]);
571 if (matcher
.matches()) {
572 path
= String
.valueOf(matcher
.group(1).trim());
574 // Output format not expected
575 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
576 Messages
.TraceControl_UnexpectedCommnadOutputFormat
+ ":\n" + //$NON-NLS-1$
577 formatOutput(result
.getOutput()));
580 if ((path
== null) || ((sessionPath
!= null) && (!path
.contains(sessionPath
)))) {
582 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
583 Messages
.TraceControl_UnexpectedPathError
+ ": " + name
); //$NON-NLS-1$
586 SessionInfo sessionInfo
= new SessionInfo(name
);
587 sessionInfo
.setSessionPath(path
);
593 public void destroySession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
594 String newName
= formatParameter(sessionName
);
595 String command
= COMMAND_DESTROY_SESSION
+ newName
;
597 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
598 String
[] output
= result
.getOutput();
600 if (isError(result
)) {
601 // In case "session not found" treat it as success
602 if ((output
== null) || (!SESSION_NOT_FOUND_ERROR_PATTERN
.matcher(output
[0]).matches())) {
603 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
606 //Session <sessionName> destroyed
611 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#startSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
614 public void startSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
616 String newSessionName
= formatParameter(sessionName
);
618 String command
= COMMAND_START_SESSION
+ newSessionName
;
620 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
622 if (isError(result
)) {
623 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
625 //Session <sessionName> started
630 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#stopSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
633 public void stopSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
634 String newSessionName
= formatParameter(sessionName
);
635 String command
= COMMAND_STOP_SESSION
+ newSessionName
;
637 ICommandResult result
= fCommandShell
.executeCommand(command
, monitor
);
639 if (isError(result
)) {
640 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
642 //Session <sessionName> stopped
648 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#enableChannel(java.lang.String, java.util.List, boolean, org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo, org.eclipse.core.runtime.IProgressMonitor)
651 public void enableChannels(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IChannelInfo info
, IProgressMonitor monitor
) throws ExecutionException
{
653 // no channels to enable
654 if (channelNames
.size() == 0) {
658 String newSessionName
= formatParameter(sessionName
);
660 StringBuffer command
= new StringBuffer(COMMAND_ENABLE_CHANNEL
);
662 for (Iterator
<String
> iterator
= channelNames
.iterator(); iterator
.hasNext();) {
663 String channel
= (String
) iterator
.next();
664 command
.append(channel
);
665 if (iterator
.hasNext()) {
666 command
.append(","); //$NON-NLS-1$
671 command
.append(OPTION_KERNEL
);
673 command
.append(OPTION_UST
);
676 command
.append(OPTION_SESSION
);
677 command
.append(newSessionName
);
680 // --discard Discard event when buffers are full (default)
682 // --overwrite Flight recorder mode
683 if (info
.isOverwriteMode()) {
684 command
.append(OPTION_OVERWRITE
);
686 // --subbuf-size SIZE Subbuffer size in bytes
687 // (default: 4096, kernel default: 262144)
688 command
.append(OPTION_SUB_BUFFER_SIZE
);
689 command
.append(String
.valueOf(info
.getSubBufferSize()));
691 // --num-subbuf NUM Number of subbufers
692 // (default: 8, kernel default: 4)
693 command
.append(OPTION_NUM_SUB_BUFFERS
);
694 command
.append(String
.valueOf(info
.getNumberOfSubBuffers()));
696 // --switch-timer USEC Switch timer interval in usec (default: 0)
697 command
.append(OPTION_SWITCH_TIMER
);
698 command
.append(String
.valueOf(info
.getSwitchTimer()));
700 // --read-timer USEC Read timer interval in usec (default: 200)
701 command
.append(OPTION_READ_TIMER
);
702 command
.append(String
.valueOf(info
.getReadTimer()));
705 ICommandResult result
= fCommandShell
.executeCommand(command
.toString(), monitor
);
707 if (isError(result
)) {
708 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
714 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#disableChannel(java.lang.String, java.util.List, org.eclipse.core.runtime.IProgressMonitor)
717 public void disableChannels(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
719 // no channels to enable
720 if (channelNames
.size() == 0) {
724 String newSessionName
= formatParameter(sessionName
);
726 StringBuffer command
= new StringBuffer(COMMAND_DISABLE_CHANNEL
);
728 for (Iterator
<String
> iterator
= channelNames
.iterator(); iterator
.hasNext();) {
729 String channel
= (String
) iterator
.next();
730 command
.append(channel
);
731 if (iterator
.hasNext()) {
732 command
.append(","); //$NON-NLS-1$
737 command
.append(OPTION_KERNEL
);
739 command
.append(OPTION_UST
);
742 command
.append(OPTION_SESSION
);
743 command
.append(newSessionName
);
745 ICommandResult result
= fCommandShell
.executeCommand(command
.toString(), monitor
);
747 if (isError(result
)) {
748 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
754 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#enableEvent(java.lang.String, java.lang.String, java.util.List, boolean, org.eclipse.core.runtime.IProgressMonitor)
757 public void enableEvents(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
759 String newSessionName
= formatParameter(sessionName
);
761 StringBuffer command
= new StringBuffer(COMMAND_ENABLE_EVENT
);
763 if (eventNames
== null || eventNames
.size() == 0) {
764 command
.append(OPTION_ALL
);
767 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
768 String event
= (String
) iterator
.next();
769 command
.append(event
);
770 if (iterator
.hasNext()) {
771 command
.append(","); //$NON-NLS-1$
777 command
.append(OPTION_KERNEL
);
779 command
.append(OPTION_UST
);
782 command
.append(OPTION_SESSION
);
783 command
.append(newSessionName
);
785 if (channelName
!= null) {
786 command
.append(OPTION_CHANNEL
);
787 command
.append(channelName
);
790 command
.append(OPTION_TRACEPOINT
);
792 ICommandResult result
= fCommandShell
.executeCommand(command
.toString(), monitor
);
794 if (isError(result
)) {
795 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
801 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#enableSyscalls(java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
804 public void enableSyscalls(String sessionName
, String channelName
, IProgressMonitor monitor
) throws ExecutionException
{
805 String newSessionName
= formatParameter(sessionName
);
807 StringBuffer command
= new StringBuffer(COMMAND_ENABLE_EVENT
);
809 command
.append(OPTION_ALL
);
810 command
.append(OPTION_KERNEL
);
812 command
.append(OPTION_SESSION
);
813 command
.append(newSessionName
);
815 if (channelName
!= null) {
816 command
.append(OPTION_CHANNEL
);
817 command
.append(channelName
);
820 command
.append(OPTION_SYSCALL
);
822 ICommandResult result
= fCommandShell
.executeCommand(command
.toString(), monitor
);
824 if (isError(result
)) {
825 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
831 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#enableProbe(java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
834 public void enableProbe(String sessionName
, String channelName
, String eventName
, boolean isFunction
, String probe
, IProgressMonitor monitor
) throws ExecutionException
{
835 String newSessionName
= formatParameter(sessionName
);
837 StringBuffer command
= new StringBuffer(COMMAND_ENABLE_EVENT
);
839 command
.append(eventName
);
840 command
.append(OPTION_KERNEL
);
842 command
.append(OPTION_SESSION
);
843 command
.append(newSessionName
);
845 if (channelName
!= null) {
846 command
.append(OPTION_CHANNEL
);
847 command
.append(channelName
);
850 command
.append(OPTION_FUNCTION_PROBE
);
852 command
.append(OPTION_PROBE
);
855 command
.append(probe
);
857 ICommandResult result
= fCommandShell
.executeCommand(command
.toString(), monitor
);
859 if (isError(result
)) {
860 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
866 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#enableLogLevel(java.lang.String, java.lang.String, java.lang.String, org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.LogLevelType, org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceLogLevel, org.eclipse.core.runtime.IProgressMonitor)
869 public void enableLogLevel(String sessionName
, String channelName
, String eventName
, LogLevelType logLevelType
, TraceLogLevel level
, IProgressMonitor monitor
) throws ExecutionException
{
870 String newSessionName
= formatParameter(sessionName
);
872 StringBuffer command
= new StringBuffer(COMMAND_ENABLE_EVENT
);
874 command
.append(eventName
);
875 command
.append(OPTION_UST
);
877 command
.append(OPTION_SESSION
);
878 command
.append(newSessionName
);
880 if (channelName
!= null) {
881 command
.append(OPTION_CHANNEL
);
882 command
.append(channelName
);
885 if (logLevelType
== LogLevelType
.LOGLEVEL
) {
886 command
.append(OPTION_LOGLEVEL
);
887 } else if (logLevelType
== LogLevelType
.LOGLEVEL_ONLY
) {
888 command
.append(OPTION_LOGLEVEL_ONLY
);
893 command
.append(level
.getInName());
895 ICommandResult result
= fCommandShell
.executeCommand(command
.toString(), monitor
);
897 if (isError(result
)) {
898 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
904 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#disableEvent(java.lang.String, java.lang.String, java.util.List, boolean, org.eclipse.core.runtime.IProgressMonitor)
907 public void disableEvent(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
908 String newSessionName
= formatParameter(sessionName
);
910 StringBuffer command
= new StringBuffer(COMMAND_DISABLE_EVENT
);
911 if (eventNames
== null) {
912 command
.append(OPTION_ALL
);
914 // no events to enable
915 if (eventNames
.size() == 0) {
919 for (Iterator
<String
> iterator
= eventNames
.iterator(); iterator
.hasNext();) {
920 String event
= (String
) iterator
.next();
921 command
.append(event
);
922 if (iterator
.hasNext()) {
923 command
.append(","); //$NON-NLS-1$
929 command
.append(OPTION_KERNEL
);
931 command
.append(OPTION_UST
);
934 command
.append(OPTION_SESSION
);
935 command
.append(newSessionName
);
937 if (channelName
!= null) {
938 command
.append(OPTION_CHANNEL
);
939 command
.append(channelName
);
942 ICommandResult result
= fCommandShell
.executeCommand(command
.toString(), monitor
);
944 if (isError(result
)) {
945 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + formatOutput(result
.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
949 // ------------------------------------------------------------------------
951 // ------------------------------------------------------------------------
953 * Checks if command result is an error result.
956 * - the command result to check
957 * @return true if error else false
959 private boolean isError(ICommandResult result
) {
960 if ((result
.getResult()) != 0 || (result
.getOutput().length
< 1 || ERROR_PATTERN
.matcher(result
.getOutput()[0]).matches())) {
967 * Formats the output string as single string.
971 * @return - the formatted output
973 private String
formatOutput(String
[] output
) {
974 if (output
== null || output
.length
== 0) {
975 return ""; //$NON-NLS-1$
978 StringBuffer ret
= new StringBuffer();
979 for (int i
= 0; i
< output
.length
; i
++) {
980 ret
.append(output
[i
] + "\n"); //$NON-NLS-1$
982 return ret
.toString();
986 * Parses the domain information.
989 * - a command output array
990 * @param currentIndex
991 * - current index in command output array
993 * - list for returning channel information
994 * @return the new current index in command output array
996 private int parseDomain(String
[] output
, int currentIndex
, List
<IChannelInfo
> channels
) {
997 int index
= currentIndex
;
1001 // - channnel1: [enabled]
1004 // overwrite mode: 0
1005 // subbufers size: 262144
1006 // number of subbufers: 4
1007 // switch timer interval: 0
1008 // read timer interval: 200
1011 while (index
< output
.length
) {
1012 String line
= output
[index
];
1014 Matcher outerMatcher
= CHANNELS_SECTION_PATTERN
.matcher(line
);
1015 if (outerMatcher
.matches()) {
1016 IChannelInfo channelInfo
= null;
1017 while (index
< output
.length
) {
1018 String subLine
= output
[index
];
1020 Matcher innerMatcher
= CHANNEL_PATTERN
.matcher(subLine
);
1021 if (innerMatcher
.matches()) {
1022 channelInfo
= new ChannelInfo(""); //$NON-NLS-1$
1024 channelInfo
.setName(innerMatcher
.group(1));
1026 // get channel enablement
1027 channelInfo
.setState(innerMatcher
.group(2));
1030 channels
.add(channelInfo
);
1032 } else if (OVERWRITE_MODE_ATTRIBUTE
.matcher(subLine
).matches()) {
1033 String value
= getAttributeValue(subLine
);
1034 channelInfo
.setOverwriteMode(!OVERWRITE_MODE_ATTRIBUTE_FALSE
.equals(value
));
1035 } else if (SUBBUFFER_SIZE_ATTRIBUTE
.matcher(subLine
).matches()) {
1036 channelInfo
.setSubBufferSize(Long
.valueOf(getAttributeValue(subLine
)));
1038 } else if (NUM_SUBBUFFERS_ATTRIBUTE
.matcher(subLine
).matches()) {
1039 channelInfo
.setNumberOfSubBuffers(Integer
.valueOf(getAttributeValue(subLine
)));
1041 } else if (SWITCH_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
1042 channelInfo
.setSwitchTimer(Long
.valueOf(getAttributeValue(subLine
)));
1044 } else if (READ_TIMER_ATTRIBUTE
.matcher(subLine
).matches()) {
1045 channelInfo
.setReadTimer(Long
.valueOf(getAttributeValue(subLine
)));
1047 } else if (OUTPUT_ATTRIBUTE
.matcher(subLine
).matches()) {
1048 channelInfo
.setOutputType(getAttributeValue(subLine
));
1050 } else if (EVENT_SECTION_PATTERN
.matcher(subLine
).matches()) {
1051 List
<IEventInfo
> events
= new ArrayList
<IEventInfo
>();
1052 index
= parseEvents(output
, index
, events
);
1053 channelInfo
.setEvents(events
);
1054 // we want to stay at the current index to be able to
1057 } else if (DOMAIN_KERNEL_PATTERN
.matcher(subLine
).matches()) {
1060 } else if (DOMAIN_UST_GLOBAL_PATTERN
.matcher(subLine
).matches()) {
1072 * Parses the event information within a domain.
1075 * - a command output array
1076 * @param currentIndex
1077 * - current index in command output array
1079 * - list for returning event information
1080 * @return the new current index in command output array
1082 private int parseEvents(String
[] output
, int currentIndex
, List
<IEventInfo
> events
) {
1083 int index
= currentIndex
;
1085 while (index
< output
.length
) {
1086 String line
= output
[index
];
1087 if (CHANNEL_PATTERN
.matcher(line
).matches()) {
1090 } else if (DOMAIN_KERNEL_PATTERN
.matcher(line
).matches()) {
1093 } else if (DOMAIN_UST_GLOBAL_PATTERN
.matcher(line
).matches()) {
1098 Matcher matcher
= EVENT_PATTERN
.matcher(line
);
1099 Matcher matcher2
= WILDCARD_EVENT_PATTERN
.matcher(line
);
1101 if (matcher
.matches()) {
1102 IEventInfo eventInfo
= new EventInfo(matcher
.group(1).trim());
1103 eventInfo
.setLogLevel(matcher
.group(2).trim());
1104 eventInfo
.setEventType(matcher
.group(3).trim());
1105 eventInfo
.setState(matcher
.group(4));
1106 events
.add(eventInfo
);
1108 } else if (matcher2
.matches()) {
1109 IEventInfo eventInfo
= new EventInfo(matcher2
.group(1).trim());
1110 eventInfo
.setLogLevel(TraceLogLevel
.LEVEL_UNKNOWN
);
1111 eventInfo
.setEventType(matcher2
.group(2).trim());
1112 eventInfo
.setState(matcher2
.group(3));
1114 if (eventInfo
.getEventType() == TraceEventType
.PROBE
) {
1115 IProbeEventInfo probeEvent
= new ProbeEventInfo(eventInfo
.getName());
1116 probeEvent
.setLogLevel(eventInfo
.getLogLevel());
1117 probeEvent
.setEventType(eventInfo
.getEventType());
1118 probeEvent
.setState(eventInfo
.getState());
1120 // Overwrite eventinfo
1121 eventInfo
= probeEvent
;
1123 // myevent2 (type: probe) [enabled]
1125 // myevent0 (type: probe) [enabled]
1127 // symbol: init_post
1129 while (index
< output
.length
) {
1130 String probeLine
= output
[index
];
1132 Matcher addrMatcher
= PROBE_ADDRESS_PATTERN
.matcher(probeLine
);
1133 Matcher offsetMatcher
= PROBE_OFFSET_PATTERN
.matcher(probeLine
);
1134 Matcher symbolMatcher
= PROBE_SYMBOL_PATTERN
.matcher(probeLine
);
1135 if (addrMatcher
.matches()) {
1136 String addr
= addrMatcher
.group(2).trim();
1137 probeEvent
.setAddress(addr
);
1138 } else if (offsetMatcher
.matches()) {
1139 String offset
= offsetMatcher
.group(2).trim();
1140 probeEvent
.setOffset(offset
);
1141 } else if (symbolMatcher
.matches()) {
1142 String symbol
= symbolMatcher
.group(2).trim();
1143 probeEvent
.setSymbol(symbol
);
1144 } else if ((EVENT_PATTERN
.matcher(probeLine
).matches()) || (WILDCARD_EVENT_PATTERN
.matcher(probeLine
).matches())) {
1146 } else if (CHANNEL_PATTERN
.matcher(probeLine
).matches()) {
1148 } else if (DOMAIN_KERNEL_PATTERN
.matcher(probeLine
).matches()) {
1151 } else if (DOMAIN_UST_GLOBAL_PATTERN
.matcher(probeLine
).matches()) {
1157 events
.add(eventInfo
);
1159 events
.add(eventInfo
);
1166 // else if (line.matches(EVENT_NONE_PATTERN)) {
1176 * Parses a line with attributes: <attribute Name>: <attribute value>
1179 * - attribute line to parse
1180 * @return the attribute value as string
1182 private String
getAttributeValue(String line
) {
1183 String
[] temp
= line
.split("\\: "); //$NON-NLS-1$
1188 * Parses the event information within a provider.
1191 * - a command output array
1192 * @param currentIndex
1193 * - current index in command output array
1195 * - list for returning event information
1196 * @return the new current index in command output array
1198 private int getProviderEventInfo(String
[] output
, int currentIndex
, List
<IBaseEventInfo
> events
) {
1199 int index
= currentIndex
;
1200 while (index
< output
.length
) {
1201 String line
= output
[index
];
1202 Matcher matcher
= PROVIDER_EVENT_PATTERN
.matcher(line
);
1203 if (matcher
.matches()) {
1204 // sched_kthread_stop (loglevel: TRACE_EMERG0) (type:
1206 IBaseEventInfo eventInfo
= new BaseEventInfo(matcher
.group(1).trim());
1207 eventInfo
.setLogLevel(matcher
.group(2).trim());
1208 eventInfo
.setEventType(matcher
.group(3).trim());
1209 events
.add(eventInfo
);
1210 } else if (UST_PROVIDER_PATTERN
.matcher(line
).matches()) {
1219 * Formats a command parameter for the command execution i.e. adds quotes
1220 * at the beginning and end if necessary.
1221 * @param parameter - parameter to format
1222 * @return formated parameter
1224 private String
formatParameter(String parameter
) {
1225 if (parameter
!= null) {
1226 String newString
= String
.valueOf(parameter
);
1228 if (parameter
.contains(" ")) { //$NON-NLS-1$
1229 newString
= "\"" + newString
+ "\""; //$NON-NLS-1$ //$NON-NLS-2$