Add support for LTTng 2.0 command calibrate
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui / src / org / eclipse / linuxtools / internal / lttng2 / ui / views / control / service / LTTngControlService.java
CommitLineData
eb1bab5b
BH
1/**********************************************************************
2 * Copyright (c) 2012 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
115b4a01 12package org.eclipse.linuxtools.internal.lttng2.ui.views.control.service;
eb1bab5b
BH
13
14import java.util.ArrayList;
bbb3538a 15import java.util.Iterator;
eb1bab5b
BH
16import java.util.List;
17import java.util.regex.Matcher;
18import java.util.regex.Pattern;
eb1bab5b
BH
19
20import org.eclipse.core.commands.ExecutionException;
21import org.eclipse.core.runtime.IProgressMonitor;
22import org.eclipse.core.runtime.NullProgressMonitor;
115b4a01
BH
23import org.eclipse.linuxtools.internal.lttng2.ui.views.control.Messages;
24import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IBaseEventInfo;
25import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo;
26import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IDomainInfo;
27import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IEventInfo;
28import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IProbeEventInfo;
29import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ISessionInfo;
30import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IUstProviderInfo;
31import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.LogLevelType;
32import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceEventType;
33import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceLogLevel;
34import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.BaseEventInfo;
35import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.ChannelInfo;
36import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.DomainInfo;
37import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.EventInfo;
38import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.ProbeEventInfo;
39import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.SessionInfo;
40import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.UstProviderInfo;
4775bcbf 41
eb1bab5b
BH
42/**
43 * <b><u>LTTngControlService</u></b>
44 * <p>
45 * Service for sending LTTng trace control commands to remote host.
46 * </p>
47 */
48public class LTTngControlService implements ILttngControlService {
49 // ------------------------------------------------------------------------
50 // Constants
51 // ------------------------------------------------------------------------
52 // Command constants
53 /**
54 * The lttng tools command.
55 */
56 private final static String CONTROL_COMMAND = "lttng"; //$NON-NLS-1$
57 /**
4775bcbf 58 * Command: lttng list.
eb1bab5b
BH
59 */
60 private final static String COMMAND_LIST = CONTROL_COMMAND + " list "; //$NON-NLS-1$
61 /**
4775bcbf 62 * Command to list kernel tracer information.
eb1bab5b 63 */
4775bcbf 64 private final static String COMMAND_LIST_KERNEL = COMMAND_LIST + "-k"; //$NON-NLS-1$
eb1bab5b 65 /**
4775bcbf 66 * Command to list user space trace information.
eb1bab5b 67 */
bbb3538a
BH
68 private final static String COMMAND_LIST_UST = COMMAND_LIST + "-u"; //$NON-NLS-1$
69 /**
70 * Command to create a session.
71 */
72 private final static String COMMAND_CREATE_SESSION = CONTROL_COMMAND + " create "; //$NON-NLS-1$
73 /**
74 * Command to destroy a session.
75 */
76 private final static String COMMAND_DESTROY_SESSION = CONTROL_COMMAND + " destroy "; //$NON-NLS-1$
77 /**
78 * Command to destroy a session.
79 */
80 private final static String COMMAND_START_SESSION = CONTROL_COMMAND + " start "; //$NON-NLS-1$
81 /**
82 * Command to destroy a session.
83 */
84 private final static String COMMAND_STOP_SESSION = CONTROL_COMMAND + " stop "; //$NON-NLS-1$
85 /**
86 * Command to enable a channel.
87 */
88 private final static String COMMAND_ENABLE_CHANNEL = CONTROL_COMMAND + " enable-channel "; //$NON-NLS-1$
89 /**
6503ae0f 90 * Command to disable a channel.
bbb3538a
BH
91 */
92 private final static String COMMAND_DISABLE_CHANNEL = CONTROL_COMMAND + " disable-channel "; //$NON-NLS-1$
6503ae0f
BH
93 /**
94 * Command to enable a event.
95 */
96 private final static String COMMAND_ENABLE_EVENT = CONTROL_COMMAND + " enable-event "; //$NON-NLS-1$
97 /**
98 * Command to disable a event.
99 */
100 private final static String COMMAND_DISABLE_EVENT = CONTROL_COMMAND + " disable-event "; //$NON-NLS-1$
b793fbe1
BH
101 /**
102 * Command to add a context to channels and/or events
103 */
104 private final static String COMMAND_ADD_CONTEXT = CONTROL_COMMAND + " add-context "; //$NON-NLS-1$
b720ac44
BH
105 /**
106 * Command to execute calibrate command to quantify LTTng overhead
107 */
108 private final static String COMMAND_CALIBRATE = CONTROL_COMMAND + " calibrate "; //$NON-NLS-1$
109
6503ae0f 110 // Command options constants
c56972bb
BH
111 /**
112 * Command line option for output path.
113 */
114 private final static String OPTION_OUTPUT_PATH = " -o "; //$NON-NLS-1$
6503ae0f
BH
115 /**
116 * Command line option for kernel tracer.
117 */
118 private final static String OPTION_KERNEL = " -k "; //$NON-NLS-1$
119 /**
120 * Command line option for UST tracer.
121 */
122 private final static String OPTION_UST = " -u "; //$NON-NLS-1$
123 /**
124 * Command line option for specifying a session.
125 */
126 private final static String OPTION_SESSION = " -s "; //$NON-NLS-1$
127 /**
128 * Command line option for specifying a channel.
129 */
130 private final static String OPTION_CHANNEL = " -c "; //$NON-NLS-1$
b793fbe1
BH
131 /**
132 * Command line option for specifying a event.
133 */
134 private final static String OPTION_EVENT = " -e "; //$NON-NLS-1$
3e91c9c0
BH
135 /**
136 * Command line option for specifying all events.
137 */
138 private final static String OPTION_ALL = " -a "; //$NON-NLS-1$
b793fbe1
BH
139 /**
140 * Command line option for specifying a context.
141 */
142 private final static String OPTION_CONTEXT_TYPE = " -t "; //$NON-NLS-1$
498704b3
BH
143 /**
144 * Command line option for specifying tracepoint events.
145 */
146 private final static String OPTION_TRACEPOINT = " --tracepoint "; //$NON-NLS-1$
147 /**
148 * Command line option for specifying syscall events.
149 */
150 private final static String OPTION_SYSCALL = " --syscall "; //$NON-NLS-1$
151 /**
152 * Command line option for specifying a dynamic probe.
153 */
154 private final static String OPTION_PROBE = " --probe "; //$NON-NLS-1$
155 /**
156 * Command line option for specifying a dynamic function entry/return probe.
157 */
158 private final static String OPTION_FUNCTION_PROBE = " --function "; //$NON-NLS-1$
ccc66d01
BH
159 /**
160 * Command line option for specifying a log level range.
161 */
162 private final static String OPTION_LOGLEVEL = " --loglevel "; //$NON-NLS-1$
163 /**
164 * Command line option for specifying a specific log level.
165 */
166 private final static String OPTION_LOGLEVEL_ONLY = " --loglevel-only "; //$NON-NLS-1$
6503ae0f
BH
167 /**
168 * Optional command line option for configuring a channel's overwrite mode.
169 */
170 private final static String OPTION_OVERWRITE = " --overwrite "; //$NON-NLS-1$
171 /**
172 * Optional command line option for configuring a channel's number of sub buffers.
173 */
174 private final static String OPTION_NUM_SUB_BUFFERS = " --num-subbuf "; //$NON-NLS-1$
175 /**
176 * Optional command line option for configuring a channel's sub buffer size.
177 */
178 private final static String OPTION_SUB_BUFFER_SIZE = " --subbuf-size "; //$NON-NLS-1$
179 /**
180 * Optional command line option for configuring a channel's switch timer interval.
181 */
182 private final static String OPTION_SWITCH_TIMER = " --switch-timer "; //$NON-NLS-1$
183 /**
184 * Optional command line option for configuring a channel's read timer interval.
185 */
186 private final static String OPTION_READ_TIMER = " --read-timer "; //$NON-NLS-1$
b793fbe1
BH
187 /**
188 * Command line option for printing the help of a specif command
189 */
190 private final static String OPTION_HELP = " -h "; //$NON-NLS-1$
6503ae0f 191
eb1bab5b
BH
192 // Parsing constants
193 /**
194 * Pattern to match for error output
195 */
4775bcbf 196 private final static Pattern ERROR_PATTERN = Pattern.compile("\\s*Error\\:.*"); //$NON-NLS-1$
eb1bab5b
BH
197 /**
198 * Pattern to match for session information (lttng list)
199 */
4775bcbf 200 private final static Pattern SESSION_PATTERN = Pattern.compile("\\s+(\\d+)\\)\\s+(.*)\\s+\\((.*)\\)\\s+\\[(active|inactive)\\].*"); //$NON-NLS-1$
eb1bab5b
BH
201 /**
202 * Pattern to match for session information (lttng list <session>)
203 */
4775bcbf 204 private final static Pattern TRACE_SESSION_PATTERN = Pattern.compile("\\s*Tracing\\s+session\\s+(.*)\\:\\s+\\[(active|inactive)\\].*"); //$NON-NLS-1$
eb1bab5b
BH
205 /**
206 * Pattern to match for session path information (lttng list <session>)
207 */
4775bcbf 208 private final static Pattern TRACE_SESSION_PATH_PATTERN = Pattern.compile("\\s*Trace\\s+path\\:\\s+(.*)"); //$NON-NLS-1$
eb1bab5b
BH
209 /**
210 * Pattern to match for kernel domain information (lttng list <session>)
211 */
4775bcbf 212 private final static Pattern DOMAIN_KERNEL_PATTERN = Pattern.compile("=== Domain: Kernel ==="); //$NON-NLS-1$
eb1bab5b
BH
213 /**
214 * Pattern to match for ust domain information (lttng list <session>)
215 */
4775bcbf 216 private final static Pattern DOMAIN_UST_GLOBAL_PATTERN = Pattern.compile("=== Domain: UST global ==="); //$NON-NLS-1$
eb1bab5b
BH
217 /**
218 * Pattern to match for channels section (lttng list <session>)
219 */
4775bcbf 220 private final static Pattern CHANNELS_SECTION_PATTERN = Pattern.compile("\\s*Channels\\:"); //$NON-NLS-1$
eb1bab5b
BH
221 /**
222 * Pattern to match for channel information (lttng list <session>)
223 */
4775bcbf 224 private final static Pattern CHANNEL_PATTERN = Pattern.compile("\\s*-\\s+(.*)\\:\\s+\\[(enabled|disabled)\\]"); //$NON-NLS-1$
eb1bab5b
BH
225 /**
226 * Pattern to match for events section information (lttng list <session>)
227 */
4775bcbf 228 private final static Pattern EVENT_SECTION_PATTERN = Pattern.compile("\\s*Events\\:"); //$NON-NLS-1$
eb1bab5b 229 /**
6503ae0f 230 * Pattern to match for event information (no enabled events) (lttng list <session>)
eb1bab5b 231 */
4775bcbf 232 // private final static String EVENT_NONE_PATTERN = "\\s+None"; //$NON-NLS-1$
eb1bab5b
BH
233 /**
234 * Pattern to match for event information (lttng list <session>)
235 */
4775bcbf
BH
236 private final static Pattern EVENT_PATTERN = Pattern.compile("\\s+(.*)\\s+\\(loglevel:\\s+(.*)\\s+\\(\\d*\\)\\)\\s+\\(type:\\s+(.*)\\)\\s+\\[(enabled|disabled)\\].*"); //$NON-NLS-1$
237 /**
238 * Pattern to match a wildcarded event information (lttng list <session>)
239 */
240 private final static Pattern WILDCARD_EVENT_PATTERN = Pattern.compile("\\s+(.*)\\s+\\(type:\\s+(.*)\\)\\s+\\[(enabled|disabled)\\].*"); //$NON-NLS-1$
d132bcc7
BH
241 /**
242 * Pattern to match a probe address information (lttng list <session>)
243 */
244 private final static Pattern PROBE_ADDRESS_PATTERN = Pattern.compile("\\s+(addr)\\:\\s+(0x[0-9a-fA-F]{1,8})"); //$NON-NLS-1$
245 /**
246 * Pattern to match a probe OFFSET information (lttng list <session>)
247 */
248 private final static Pattern PROBE_OFFSET_PATTERN = Pattern.compile("\\s+(offset)\\:\\s+(0x[0-9a-fA-F]{1,8})"); //$NON-NLS-1$
249 /**
250 * Pattern to match a probe SYMBOL information (lttng list <session>)
251 */
252 private final static Pattern PROBE_SYMBOL_PATTERN = Pattern.compile("\\s+(symbol)\\:\\s+(.+)"); //$NON-NLS-1$
eb1bab5b 253 /**
4775bcbf
BH
254 * Pattern to match for channel (overwite mode) information (lttng list
255 * <session>)
eb1bab5b 256 */
4775bcbf 257 private final static Pattern OVERWRITE_MODE_ATTRIBUTE = Pattern.compile("\\s+overwrite\\s+mode\\:.*"); //$NON-NLS-1$
eb1bab5b
BH
258 /**
259 * Pattern to match indicating false for overwrite mode
260 */
261 private final static String OVERWRITE_MODE_ATTRIBUTE_FALSE = "0"; //$NON-NLS-1$
262 /**
4775bcbf
BH
263 * Pattern to match for channel (sub-buffer size) information (lttng list
264 * <session>)
eb1bab5b 265 */
4775bcbf 266 private final static Pattern SUBBUFFER_SIZE_ATTRIBUTE = Pattern.compile("\\s+subbufers\\s+size\\:.*"); //$NON-NLS-1$
eb1bab5b 267 /**
4775bcbf
BH
268 * Pattern to match for channel (number of sub-buffers) information (lttng
269 * list <session>)
eb1bab5b 270 */
4775bcbf 271 private final static Pattern NUM_SUBBUFFERS_ATTRIBUTE = Pattern.compile("\\s+number\\s+of\\s+subbufers\\:.*"); //$NON-NLS-1$
eb1bab5b 272 /**
4775bcbf
BH
273 * Pattern to match for channel (switch timer) information (lttng list
274 * <session>)
eb1bab5b 275 */
4775bcbf 276 private final static Pattern SWITCH_TIMER_ATTRIBUTE = Pattern.compile("\\s+switch\\s+timer\\s+interval\\:.*"); //$NON-NLS-1$
eb1bab5b 277 /**
4775bcbf
BH
278 * Pattern to match for channel (read timer) information (lttng list
279 * <session>)
eb1bab5b 280 */
4775bcbf 281 private final static Pattern READ_TIMER_ATTRIBUTE = Pattern.compile("\\s+read\\s+timer\\s+interval\\:.*"); //$NON-NLS-1$
eb1bab5b 282 /**
4775bcbf
BH
283 * Pattern to match for channel (output type) information (lttng list
284 * <session>)
eb1bab5b 285 */
4775bcbf 286 private final static Pattern OUTPUT_ATTRIBUTE = Pattern.compile("\\s+output\\:.*"); //$NON-NLS-1$
eb1bab5b
BH
287 /**
288 * Pattern to match for provider information (lttng list -k/-u)
289 */
4775bcbf 290 private final static Pattern PROVIDER_EVENT_PATTERN = Pattern.compile("\\s*(.*)\\s+\\(loglevel:\\s+(.*)\\s+\\(\\d*\\)\\)\\s+\\(type:\\s+(.*)\\)"); //$NON-NLS-1$
eb1bab5b
BH
291 /**
292 * Pattern to match for UST provider information (lttng list -u)
4775bcbf
BH
293 */
294 private final static Pattern UST_PROVIDER_PATTERN = Pattern.compile("\\s*PID\\:\\s+(\\d+)\\s+-\\s+Name\\:\\s+(.*)"); //$NON-NLS-1$
bbb3538a
BH
295 /**
296 * Pattern to match for session information (lttng create <session name>)
297 */
298 private final static Pattern CREATE_SESSION_NAME_PATTERN = Pattern.compile("\\s*Session\\s+(.*)\\s+created\\."); //$NON-NLS-1$
299 /**
300 * Pattern to match for session path information (lttng create <session name>)
301 */
302 private final static Pattern CREATE_SESSION_PATH_PATTERN = Pattern.compile("\\s*Traces\\s+will\\s+be\\s+written\\s+in\\s+(.*).*"); //$NON-NLS-1$
303 /**
304 * Pattern to match for session command output for "session name not found".
305 */
306 private final static Pattern SESSION_NOT_FOUND_ERROR_PATTERN = Pattern.compile("\\s*Error:\\s+Session\\s+name\\s+not\\s+found"); //$NON-NLS-1$
b793fbe1
BH
307 /**
308 * Pattern to match introduction line of context list.
309 */
310 private final static Pattern ADD_CONTEXT_HELP_CONTEXTS_INTRO = Pattern.compile("\\s*TYPE can\\s+be\\s+one\\s+of\\s+the\\s+strings\\s+below.*"); //$NON-NLS-1$
311
312 /**
313 * Pattern to match introduction line of context list.
314 */
315 private final static Pattern ADD_CONTEXT_HELP_CONTEXTS_END_LINE = Pattern.compile("\\s*Example.*"); //$NON-NLS-1$
bbb3538a 316
eb1bab5b
BH
317 // ------------------------------------------------------------------------
318 // Attributes
319 // ------------------------------------------------------------------------
320 /**
321 * The command shell implementation
322 */
323 private ICommandShell fCommandShell = null;
324
325 // ------------------------------------------------------------------------
326 // Constructors
327 // ------------------------------------------------------------------------
328
329 /**
330 * Constructor
4775bcbf
BH
331 *
332 * @param shell
333 * - the command shell implementation to use
eb1bab5b
BH
334 */
335 public LTTngControlService(ICommandShell shell) {
336 fCommandShell = shell;
337 }
4775bcbf 338
eb1bab5b
BH
339 // ------------------------------------------------------------------------
340 // Operations
4775bcbf 341 // ------------------------------------------------------------------------
eb1bab5b 342
eb1bab5b
BH
343 /*
344 * (non-Javadoc)
4775bcbf
BH
345 *
346 * @see
115b4a01 347 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
4775bcbf 348 * #getSessionNames(org.eclipse.core.runtime.IProgressMonitor)
eb1bab5b
BH
349 */
350 @Override
351 public String[] getSessionNames(IProgressMonitor monitor) throws ExecutionException {
352
4775bcbf
BH
353 String command = COMMAND_LIST;
354 ICommandResult result = fCommandShell.executeCommand(command, monitor);
355
356 if (isError(result)) {
4775bcbf
BH
357 throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
358 }
359
360 // Output:
361 // Available tracing sessions:
362 // 1) mysession1 (/home/user/lttng-traces/mysession1-20120123-083928)
363 // [inactive]
364 // 2) mysession (/home/user/lttng-traces/mysession-20120123-083318)
365 // [inactive]
366 //
367 // Use lttng list <session_name> for more details
368
369 ArrayList<String> retArray = new ArrayList<String>();
370 int index = 0;
371 while (index < result.getOutput().length) {
372 String line = result.getOutput()[index];
373 Matcher matcher = SESSION_PATTERN.matcher(line);
374 if (matcher.matches()) {
375 retArray.add(matcher.group(2).trim());
376 }
377 index++;
378 }
379 return retArray.toArray(new String[retArray.size()]);
eb1bab5b
BH
380 }
381
eb1bab5b
BH
382 /*
383 * (non-Javadoc)
4775bcbf
BH
384 *
385 * @see
115b4a01 386 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
4775bcbf 387 * #getSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
eb1bab5b
BH
388 */
389 @Override
390 public ISessionInfo getSession(String sessionName, IProgressMonitor monitor) throws ExecutionException {
d132bcc7 391
eb1bab5b
BH
392 String command = COMMAND_LIST + sessionName;
393 ICommandResult result = fCommandShell.executeCommand(command, monitor);
c56972bb 394
eb1bab5b
BH
395 if (isError(result)) {
396 throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
397 }
398
399 int index = 0;
400
401 // Output:
4775bcbf
BH
402 // Tracing session mysession2: [inactive]
403 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
eb1bab5b
BH
404 ISessionInfo sessionInfo = new SessionInfo(sessionName);
405
4775bcbf
BH
406 while (index < result.getOutput().length) {
407 // Tracing session mysession2: [inactive]
408 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
409 //
410 // === Domain: Kernel ===
411 //
412 String line = result.getOutput()[index];
413 Matcher matcher = TRACE_SESSION_PATTERN.matcher(line);
414 if (matcher.matches()) {
415 sessionInfo.setSessionState(matcher.group(2));
416 index++;
417 continue;
418 }
419
420 matcher = TRACE_SESSION_PATH_PATTERN.matcher(line);
421 if (matcher.matches()) {
422 sessionInfo.setSessionPath(matcher.group(1).trim());
423 index++;
424 continue;
425 }
eb1bab5b 426
4775bcbf
BH
427 matcher = DOMAIN_KERNEL_PATTERN.matcher(line);
428 if (matcher.matches()) {
429 // Create Domain
430 IDomainInfo domainInfo = new DomainInfo(Messages.TraceControl_KernelDomainDisplayName);
431 sessionInfo.addDomain(domainInfo);
eb1bab5b 432
4775bcbf
BH
433 // in domain kernel
434 ArrayList<IChannelInfo> channels = new ArrayList<IChannelInfo>();
435 index = parseDomain(result.getOutput(), index, channels);
eb1bab5b 436
4775bcbf
BH
437 // set channels
438 domainInfo.setChannels(channels);
bbb3538a
BH
439
440 // set kernel flag
441 domainInfo.setIsKernel(true);
4775bcbf
BH
442 continue;
443 }
eb1bab5b 444
4775bcbf
BH
445 matcher = DOMAIN_UST_GLOBAL_PATTERN.matcher(line);
446 if (matcher.matches()) {
447 IDomainInfo domainInfo = new DomainInfo(Messages.TraceControl_UstGlobalDomainDisplayName);
448 sessionInfo.addDomain(domainInfo);
eb1bab5b 449
bbb3538a 450 // in domain UST
4775bcbf
BH
451 ArrayList<IChannelInfo> channels = new ArrayList<IChannelInfo>();
452 index = parseDomain(result.getOutput(), index, channels);
453
454 // set channels
455 domainInfo.setChannels(channels);
bbb3538a
BH
456
457 // set kernel flag
458 domainInfo.setIsKernel(false);
4775bcbf 459 continue;
eb1bab5b 460 }
4775bcbf
BH
461 index++;
462 }
eb1bab5b
BH
463 return sessionInfo;
464 }
4775bcbf 465
eb1bab5b
BH
466 /*
467 * (non-Javadoc)
4775bcbf
BH
468 *
469 * @see
115b4a01 470 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
4775bcbf 471 * #getKernelProvider(org.eclipse.core.runtime.IProgressMonitor)
eb1bab5b
BH
472 */
473 @Override
474 public List<IBaseEventInfo> getKernelProvider(IProgressMonitor monitor) throws ExecutionException {
475 String command = COMMAND_LIST_KERNEL;
476 ICommandResult result = fCommandShell.executeCommand(command, monitor);
477 if (isError(result)) {
478 throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
479 }
4775bcbf
BH
480
481 // Kernel events:
482 // -------------
483 // sched_kthread_stop (type: tracepoint)
eb1bab5b
BH
484 List<IBaseEventInfo> events = new ArrayList<IBaseEventInfo>();
485 getProviderEventInfo(result.getOutput(), 0, events);
486 return events;
487 }
488
489 /*
490 * (non-Javadoc)
4775bcbf
BH
491 *
492 * @see
115b4a01 493 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
4775bcbf 494 * #getUstProvider()
eb1bab5b
BH
495 */
496 @Override
497 public List<IUstProviderInfo> getUstProvider() throws ExecutionException {
498 return getUstProvider(new NullProgressMonitor());
499 }
4775bcbf 500
eb1bab5b
BH
501 /*
502 * (non-Javadoc)
4775bcbf
BH
503 *
504 * @see
115b4a01 505 * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
4775bcbf 506 * #getUstProvider(org.eclipse.core.runtime.IProgressMonitor)
eb1bab5b
BH
507 */
508 @Override
509 public List<IUstProviderInfo> getUstProvider(IProgressMonitor monitor) throws ExecutionException {
510 String command = COMMAND_LIST_UST;
511 ICommandResult result = fCommandShell.executeCommand(command, monitor);
512
513 if (isError(result)) {
514 throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
515 }
4775bcbf
BH
516
517 // UST events:
518 // -------------
519 //
520 // PID: 3635 - Name:
521 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
522 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
523 // tracepoint)
524 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
525 //
526 // PID: 6459 - Name:
527 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
528 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
529 // tracepoint)
530 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
eb1bab5b
BH
531
532 List<IUstProviderInfo> allProviders = new ArrayList<IUstProviderInfo>();
533 IUstProviderInfo provider = null;
4775bcbf 534
eb1bab5b
BH
535 int index = 0;
536 while (index < result.getOutput().length) {
537 String line = result.getOutput()[index];
4775bcbf
BH
538 Matcher matcher = UST_PROVIDER_PATTERN.matcher(line);
539 if (matcher.matches()) {
eb1bab5b 540
4775bcbf
BH
541 provider = new UstProviderInfo(matcher.group(2).trim());
542 provider.setPid(Integer.valueOf(matcher.group(1).trim()));
543 List<IBaseEventInfo> events = new ArrayList<IBaseEventInfo>();
544 index = getProviderEventInfo(result.getOutput(), ++index, events);
545 provider.setEvents(events);
546 allProviders.add(provider);
eb1bab5b
BH
547
548 } else {
549 index++;
550 }
4775bcbf 551
eb1bab5b
BH
552 }
553 return allProviders;
554 }
555
bbb3538a
BH
556 /*
557 * (non-Javadoc)
115b4a01 558 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#createSession(java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
bbb3538a
BH
559 */
560 @Override
561 public ISessionInfo createSession(String sessionName, String sessionPath, IProgressMonitor monitor) throws ExecutionException {
562
563 String newName = formatParameter(sessionName);
564 String newPath = formatParameter(sessionPath);
565
c56972bb
BH
566 StringBuffer command = new StringBuffer();
567 command.append(COMMAND_CREATE_SESSION);
568 command.append(newName);
569
bbb3538a 570 if (newPath != null && !"".equals(newPath)) { //$NON-NLS-1$
c56972bb
BH
571 command.append(OPTION_OUTPUT_PATH);
572 command.append(newPath);
bbb3538a
BH
573 }
574
c56972bb 575 ICommandResult result = fCommandShell.executeCommand(command.toString(), monitor);
bbb3538a
BH
576
577 if (isError(result)) {
578 throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
579 }
580 //Session myssession2 created.
581 //Traces will be written in /home/user/lttng-traces/myssession2-20120209-095418
582 String[] output = result.getOutput();
583
584 // Get and verify session name
585 Matcher matcher = CREATE_SESSION_NAME_PATTERN.matcher(output[0]);
586 String name = null;
587
588 if (matcher.matches()) {
589 name = String.valueOf(matcher.group(1).trim());
590 } else {
591 // Output format not expected
592 throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
593 Messages.TraceControl_UnexpectedCommnadOutputFormat + ":\n" + //$NON-NLS-1$
594 formatOutput(result.getOutput()));
595 }
596
597 if ((name == null) || (!name.equals(sessionName))) {
598 // Unexpected name returned
599 throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
600 Messages.TraceControl_UnexpectedNameError + ": " + name); //$NON-NLS-1$
601 }
602
603 // Get and verify session path
604 matcher = CREATE_SESSION_PATH_PATTERN.matcher(output[1]);
605 String path = null;
606
607 if (matcher.matches()) {
608 path = String.valueOf(matcher.group(1).trim());
609 } else {
610 // Output format not expected
611 throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
612 Messages.TraceControl_UnexpectedCommnadOutputFormat + ":\n" + //$NON-NLS-1$
613 formatOutput(result.getOutput()));
614 }
615
616 if ((path == null) || ((sessionPath != null) && (!path.contains(sessionPath)))) {
617 // Unexpected path
618 throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
619 Messages.TraceControl_UnexpectedPathError + ": " + name); //$NON-NLS-1$
620 }
621
622 SessionInfo sessionInfo = new SessionInfo(name);
623 sessionInfo.setSessionPath(path);
624
625 return sessionInfo;
626 }
627
628 @Override
629 public void destroySession(String sessionName, IProgressMonitor monitor) throws ExecutionException {
630 String newName = formatParameter(sessionName);
631 String command = COMMAND_DESTROY_SESSION + newName;
632
633 ICommandResult result = fCommandShell.executeCommand(command, monitor);
634 String[] output = result.getOutput();
635
c56972bb 636 if (isError(result) && ((output == null) || (!SESSION_NOT_FOUND_ERROR_PATTERN.matcher(output[0]).matches()))) {
bbb3538a 637 throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
c56972bb 638 }
bbb3538a
BH
639 //Session <sessionName> destroyed
640 }
c56972bb 641
bbb3538a
BH
642 /*
643 * (non-Javadoc)
115b4a01 644 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#startSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
bbb3538a
BH
645 */
646 @Override
647 public void startSession(String sessionName, IProgressMonitor monitor) throws ExecutionException {
648
649 String newSessionName = formatParameter(sessionName);
650
651 String command = COMMAND_START_SESSION + newSessionName;
652
653 ICommandResult result = fCommandShell.executeCommand(command, monitor);
654
655 if (isError(result)) {
656 throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
657 }
658 //Session <sessionName> started
659 }
660
661 /*
662 * (non-Javadoc)
115b4a01 663 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#stopSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
bbb3538a
BH
664 */
665 @Override
666 public void stopSession(String sessionName, IProgressMonitor monitor) throws ExecutionException {
667 String newSessionName = formatParameter(sessionName);
668 String command = COMMAND_STOP_SESSION + newSessionName;
669
670 ICommandResult result = fCommandShell.executeCommand(command, monitor);
671
672 if (isError(result)) {
673 throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
674 }
675 //Session <sessionName> stopped
676
677 }
678
679 /*
680 * (non-Javadoc)
115b4a01 681 * @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)
bbb3538a
BH
682 */
683 @Override
498704b3 684 public void enableChannels(String sessionName, List<String> channelNames, boolean isKernel, IChannelInfo info, IProgressMonitor monitor) throws ExecutionException {
bbb3538a
BH
685
686 // no channels to enable
c56972bb 687 if (channelNames.isEmpty()) {
bbb3538a
BH
688 return;
689 }
690
691 String newSessionName = formatParameter(sessionName);
692
693 StringBuffer command = new StringBuffer(COMMAND_ENABLE_CHANNEL);
694
695 for (Iterator<String> iterator = channelNames.iterator(); iterator.hasNext();) {
696 String channel = (String) iterator.next();
697 command.append(channel);
698 if (iterator.hasNext()) {
c56972bb 699 command.append(',');
bbb3538a
BH
700 }
701 }
702
703 if (isKernel) {
6503ae0f 704 command.append(OPTION_KERNEL);
bbb3538a 705 } else {
6503ae0f 706 command.append(OPTION_UST);
bbb3538a
BH
707 }
708
6503ae0f 709 command.append(OPTION_SESSION);
bbb3538a
BH
710 command.append(newSessionName);
711
712 if (info != null) {
713// --discard Discard event when buffers are full (default)
bbb3538a
BH
714
715// --overwrite Flight recorder mode
716 if (info.isOverwriteMode()) {
6503ae0f 717 command.append(OPTION_OVERWRITE);
bbb3538a
BH
718 }
719// --subbuf-size SIZE Subbuffer size in bytes
720// (default: 4096, kernel default: 262144)
6503ae0f 721 command.append(OPTION_SUB_BUFFER_SIZE);
bbb3538a
BH
722 command.append(String.valueOf(info.getSubBufferSize()));
723
724// --num-subbuf NUM Number of subbufers
725// (default: 8, kernel default: 4)
6503ae0f 726 command.append(OPTION_NUM_SUB_BUFFERS);
bbb3538a
BH
727 command.append(String.valueOf(info.getNumberOfSubBuffers()));
728
729// --switch-timer USEC Switch timer interval in usec (default: 0)
6503ae0f 730 command.append(OPTION_SWITCH_TIMER);
bbb3538a
BH
731 command.append(String.valueOf(info.getSwitchTimer()));
732
733// --read-timer USEC Read timer interval in usec (default: 200)
6503ae0f 734 command.append(OPTION_READ_TIMER);
bbb3538a
BH
735 command.append(String.valueOf(info.getReadTimer()));
736 }
737
738 ICommandResult result = fCommandShell.executeCommand(command.toString(), monitor);
739
740 if (isError(result)) {
741 throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
742 }
bbb3538a
BH
743 }
744
745 /*
746 * (non-Javadoc)
115b4a01 747 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#disableChannel(java.lang.String, java.util.List, org.eclipse.core.runtime.IProgressMonitor)
bbb3538a
BH
748 */
749 @Override
498704b3 750 public void disableChannels(String sessionName, List<String> channelNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException {
bbb3538a
BH
751
752 // no channels to enable
c56972bb 753 if (channelNames.isEmpty()) {
bbb3538a
BH
754 return;
755 }
756
757 String newSessionName = formatParameter(sessionName);
758
759 StringBuffer command = new StringBuffer(COMMAND_DISABLE_CHANNEL);
760
761 for (Iterator<String> iterator = channelNames.iterator(); iterator.hasNext();) {
762 String channel = (String) iterator.next();
763 command.append(channel);
764 if (iterator.hasNext()) {
c56972bb 765 command.append(',');
bbb3538a
BH
766 }
767 }
768
769 if (isKernel) {
6503ae0f
BH
770 command.append(OPTION_KERNEL);
771 } else {
772 command.append(OPTION_UST);
773 }
774
775 command.append(OPTION_SESSION);
776 command.append(newSessionName);
777
778 ICommandResult result = fCommandShell.executeCommand(command.toString(), monitor);
779
780 if (isError(result)) {
781 throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
782 }
783 }
784
785 /*
786 * (non-Javadoc)
115b4a01 787 * @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)
6503ae0f
BH
788 */
789 @Override
498704b3 790 public void enableEvents(String sessionName, String channelName, List<String> eventNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException {
6503ae0f
BH
791
792 String newSessionName = formatParameter(sessionName);
793
794 StringBuffer command = new StringBuffer(COMMAND_ENABLE_EVENT);
795
c56972bb 796 if (eventNames == null || eventNames.isEmpty()) {
3e91c9c0
BH
797 command.append(OPTION_ALL);
798 } else {
3e91c9c0
BH
799
800 for (Iterator<String> iterator = eventNames.iterator(); iterator.hasNext();) {
801 String event = (String) iterator.next();
802 command.append(event);
803 if (iterator.hasNext()) {
c56972bb 804 command.append(',');
3e91c9c0 805 }
6503ae0f
BH
806 }
807 }
808
809 if (isKernel) {
810 command.append(OPTION_KERNEL);
bbb3538a 811 } else {
6503ae0f 812 command.append(OPTION_UST);
bbb3538a
BH
813 }
814
6503ae0f 815 command.append(OPTION_SESSION);
bbb3538a
BH
816 command.append(newSessionName);
817
6503ae0f
BH
818 if (channelName != null) {
819 command.append(OPTION_CHANNEL);
820 command.append(channelName);
821 }
498704b3
BH
822
823 command.append(OPTION_TRACEPOINT);
824
825 ICommandResult result = fCommandShell.executeCommand(command.toString(), monitor);
826
827 if (isError(result)) {
828 throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
829 }
830 }
6503ae0f 831
498704b3
BH
832 /*
833 * (non-Javadoc)
115b4a01 834 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#enableSyscalls(java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
498704b3
BH
835 */
836 @Override
837 public void enableSyscalls(String sessionName, String channelName, IProgressMonitor monitor) throws ExecutionException {
838 String newSessionName = formatParameter(sessionName);
839
840 StringBuffer command = new StringBuffer(COMMAND_ENABLE_EVENT);
841
842 command.append(OPTION_ALL);
843 command.append(OPTION_KERNEL);
844
845 command.append(OPTION_SESSION);
846 command.append(newSessionName);
847
848 if (channelName != null) {
849 command.append(OPTION_CHANNEL);
850 command.append(channelName);
851 }
852
853 command.append(OPTION_SYSCALL);
854
bbb3538a
BH
855 ICommandResult result = fCommandShell.executeCommand(command.toString(), monitor);
856
857 if (isError(result)) {
858 throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
498704b3
BH
859 }
860 }
861
862 /*
863 * (non-Javadoc)
115b4a01 864 * @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)
498704b3
BH
865 */
866 @Override
d132bcc7 867 public void enableProbe(String sessionName, String channelName, String eventName, boolean isFunction, String probe, IProgressMonitor monitor) throws ExecutionException {
498704b3
BH
868 String newSessionName = formatParameter(sessionName);
869
870 StringBuffer command = new StringBuffer(COMMAND_ENABLE_EVENT);
871
872 command.append(eventName);
873 command.append(OPTION_KERNEL);
874
875 command.append(OPTION_SESSION);
876 command.append(newSessionName);
877
878 if (channelName != null) {
879 command.append(OPTION_CHANNEL);
880 command.append(channelName);
bbb3538a 881 }
d132bcc7
BH
882 if (isFunction) {
883 command.append(OPTION_FUNCTION_PROBE);
884 } else {
885 command.append(OPTION_PROBE);
498704b3
BH
886 }
887
498704b3
BH
888 command.append(probe);
889
890 ICommandResult result = fCommandShell.executeCommand(command.toString(), monitor);
891
892 if (isError(result)) {
893 throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
d132bcc7 894 }
498704b3 895 }
ccc66d01
BH
896
897 /*
898 * (non-Javadoc)
115b4a01 899 * @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)
ccc66d01
BH
900 */
901 @Override
902 public void enableLogLevel(String sessionName, String channelName, String eventName, LogLevelType logLevelType, TraceLogLevel level, IProgressMonitor monitor) throws ExecutionException {
903 String newSessionName = formatParameter(sessionName);
904
905 StringBuffer command = new StringBuffer(COMMAND_ENABLE_EVENT);
906
907 command.append(eventName);
908 command.append(OPTION_UST);
909
910 command.append(OPTION_SESSION);
911 command.append(newSessionName);
912
913 if (channelName != null) {
914 command.append(OPTION_CHANNEL);
915 command.append(channelName);
916 }
917
918 if (logLevelType == LogLevelType.LOGLEVEL) {
919 command.append(OPTION_LOGLEVEL);
920 } else if (logLevelType == LogLevelType.LOGLEVEL_ONLY) {
921 command.append(OPTION_LOGLEVEL_ONLY);
922
923 } else {
924 return;
925 }
926 command.append(level.getInName());
927
928 ICommandResult result = fCommandShell.executeCommand(command.toString(), monitor);
929
930 if (isError(result)) {
931 throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
932 }
933 }
934
6503ae0f
BH
935 /*
936 * (non-Javadoc)
115b4a01 937 * @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)
6503ae0f
BH
938 */
939 @Override
940 public void disableEvent(String sessionName, String channelName, List<String> eventNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException {
6503ae0f
BH
941 String newSessionName = formatParameter(sessionName);
942
943 StringBuffer command = new StringBuffer(COMMAND_DISABLE_EVENT);
3e91c9c0
BH
944 if (eventNames == null) {
945 command.append(OPTION_ALL);
946 } else {
947 // no events to enable
c56972bb 948 if (eventNames.isEmpty()) {
3e91c9c0
BH
949 return;
950 }
6503ae0f 951
3e91c9c0
BH
952 for (Iterator<String> iterator = eventNames.iterator(); iterator.hasNext();) {
953 String event = (String) iterator.next();
954 command.append(event);
955 if (iterator.hasNext()) {
c56972bb 956 command.append(',');
3e91c9c0 957 }
6503ae0f
BH
958 }
959 }
960
961 if (isKernel) {
962 command.append(OPTION_KERNEL);
963 } else {
964 command.append(OPTION_UST);
965 }
966
967 command.append(OPTION_SESSION);
968 command.append(newSessionName);
969
970 if (channelName != null) {
971 command.append(OPTION_CHANNEL);
972 command.append(channelName);
973 }
974
975 ICommandResult result = fCommandShell.executeCommand(command.toString(), monitor);
976
977 if (isError(result)) {
978 throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
979 }
980 }
b793fbe1
BH
981
982 /*
983 * (non-Javadoc)
984 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#getContexts(org.eclipse.core.runtime.IProgressMonitor)
985 */
986 @Override
987 public List<String> getContextList(IProgressMonitor monitor) throws ExecutionException {
988
989 String command = COMMAND_ADD_CONTEXT + OPTION_HELP;
990
991 ICommandResult result = fCommandShell.executeCommand(command, monitor);
992
993 if (isError(result)) {
994 throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
995 }
996
997 String[] output = result.getOutput();
998
999 List<String> contexts = new ArrayList<String>(0);
1000
1001 int index = 0;
1002 boolean inList = false;
1003 while (index < output.length) {
1004 String line = result.getOutput()[index];
1005
1006 Matcher startMatcher = ADD_CONTEXT_HELP_CONTEXTS_INTRO.matcher(line);
1007 Matcher endMatcher = ADD_CONTEXT_HELP_CONTEXTS_END_LINE.matcher(line);
1008
1009 if (startMatcher.matches()) {
1010 inList = true;
1011 } else if (endMatcher.matches()) {
1012 break;
1013 } else if (inList == true) {
1014 String[] tmp = line.split(","); //$NON-NLS-1$
1015 for (int i = 0; i < tmp.length; i++) {
1016 contexts.add(tmp[i].trim());
1017 }
1018 }
1019 index++;
1020 }
1021 return contexts;
1022 }
1023
1024 /*
1025 * (non-Javadoc)
1026 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#addContexts(java.lang.String, java.lang.String, java.lang.String, boolean, java.util.List, org.eclipse.core.runtime.IProgressMonitor)
1027 */
1028 @Override
1029 public void addContexts(String sessionName, String channelName, String eventName, boolean isKernel, List<String> contextNames, IProgressMonitor monitor) throws ExecutionException {
1030
1031 String newSessionName = formatParameter(sessionName);
1032 StringBuffer command = new StringBuffer(COMMAND_ADD_CONTEXT);
1033
1034 command.append(OPTION_SESSION);
1035 command.append(newSessionName);
1036
1037 if (channelName != null) {
1038 command.append(OPTION_CHANNEL);
1039 command.append(channelName);
1040 }
1041
1042 if (eventName != null) {
1043 command.append(OPTION_EVENT);
1044 command.append(eventName);
1045 }
1046
1047 if (isKernel) {
1048 command.append(OPTION_KERNEL);
1049 } else {
1050 command.append(OPTION_UST);
1051 }
1052
1053 for (Iterator<String> iterator = contextNames.iterator(); iterator.hasNext();) {
1054 String context = (String) iterator.next();
1055 command.append(OPTION_CONTEXT_TYPE);
1056 command.append(context);
1057 }
1058
1059 ICommandResult result = fCommandShell.executeCommand(command.toString(), monitor);
1060
1061 if (isError(result)) {
1062 throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
1063 }
1064 }
1065
b720ac44
BH
1066 /*
1067 * (non-Javadoc)
1068 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#calibrate(boolean, org.eclipse.core.runtime.IProgressMonitor)
1069 */
1070 @Override
1071 public void calibrate(boolean isKernel, IProgressMonitor monitor) throws ExecutionException {
1072// String newSessionName = formatParameter(sessionName);
1073 StringBuffer command = new StringBuffer(COMMAND_CALIBRATE);
1074//
1075// command.append(OPTION_SESSION);
1076// command.append(newSessionName);
1077
1078 if (isKernel) {
1079 command.append(OPTION_KERNEL);
1080 } else {
1081 command.append(OPTION_UST);
1082 }
1083
1084 command.append(OPTION_FUNCTION_PROBE);
1085
1086 ICommandResult result = fCommandShell.executeCommand(command.toString(), monitor);
1087
1088 if (isError(result)) {
1089 throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
1090 }
1091 }
1092
eb1bab5b
BH
1093 // ------------------------------------------------------------------------
1094 // Helper methods
1095 // ------------------------------------------------------------------------
1096 /**
1097 * Checks if command result is an error result.
4775bcbf
BH
1098 *
1099 * @param result
1100 * - the command result to check
eb1bab5b
BH
1101 * @return true if error else false
1102 */
1103 private boolean isError(ICommandResult result) {
4775bcbf 1104 if ((result.getResult()) != 0 || (result.getOutput().length < 1 || ERROR_PATTERN.matcher(result.getOutput()[0]).matches())) {
eb1bab5b
BH
1105 return true;
1106 }
1107 return false;
1108 }
4775bcbf 1109
eb1bab5b
BH
1110 /**
1111 * Formats the output string as single string.
4775bcbf
BH
1112 *
1113 * @param output
1114 * - output array
eb1bab5b
BH
1115 * @return - the formatted output
1116 */
1117 private String formatOutput(String[] output) {
1118 if (output == null || output.length == 0) {
1119 return ""; //$NON-NLS-1$
1120 }
1121
1122 StringBuffer ret = new StringBuffer();
1123 for (int i = 0; i < output.length; i++) {
1124 ret.append(output[i] + "\n"); //$NON-NLS-1$
1125 }
1126 return ret.toString();
1127 }
4775bcbf 1128
eb1bab5b
BH
1129 /**
1130 * Parses the domain information.
1131 *
4775bcbf
BH
1132 * @param output
1133 * - a command output array
1134 * @param currentIndex
1135 * - current index in command output array
1136 * @param channels
1137 * - list for returning channel information
1138 * @return the new current index in command output array
eb1bab5b 1139 */
887a93a3 1140 private int parseDomain(String[] output, int currentIndex, List<IChannelInfo> channels) {
eb1bab5b
BH
1141 int index = currentIndex;
1142
4775bcbf
BH
1143 // Channels:
1144 // -------------
1145 // - channnel1: [enabled]
1146 //
1147 // Attributes:
1148 // overwrite mode: 0
1149 // subbufers size: 262144
1150 // number of subbufers: 4
1151 // switch timer interval: 0
1152 // read timer interval: 200
1153 // output: splice()
1154
eb1bab5b
BH
1155 while (index < output.length) {
1156 String line = output[index];
4775bcbf
BH
1157
1158 Matcher outerMatcher = CHANNELS_SECTION_PATTERN.matcher(line);
1159 if (outerMatcher.matches()) {
eb1bab5b
BH
1160 IChannelInfo channelInfo = null;
1161 while (index < output.length) {
1162 String subLine = output[index];
4775bcbf
BH
1163
1164 Matcher innerMatcher = CHANNEL_PATTERN.matcher(subLine);
1165 if (innerMatcher.matches()) {
eb1bab5b 1166 channelInfo = new ChannelInfo(""); //$NON-NLS-1$
4775bcbf
BH
1167 // get channel name
1168 channelInfo.setName(innerMatcher.group(1));
1169
1170 // get channel enablement
1171 channelInfo.setState(innerMatcher.group(2));
1172
1173 // add channel
1174 channels.add(channelInfo);
1175
1176 } else if (OVERWRITE_MODE_ATTRIBUTE.matcher(subLine).matches()) {
eb1bab5b
BH
1177 String value = getAttributeValue(subLine);
1178 channelInfo.setOverwriteMode(!OVERWRITE_MODE_ATTRIBUTE_FALSE.equals(value));
4775bcbf 1179 } else if (SUBBUFFER_SIZE_ATTRIBUTE.matcher(subLine).matches()) {
eb1bab5b 1180 channelInfo.setSubBufferSize(Long.valueOf(getAttributeValue(subLine)));
4775bcbf
BH
1181
1182 } else if (NUM_SUBBUFFERS_ATTRIBUTE.matcher(subLine).matches()) {
eb1bab5b 1183 channelInfo.setNumberOfSubBuffers(Integer.valueOf(getAttributeValue(subLine)));
4775bcbf
BH
1184
1185 } else if (SWITCH_TIMER_ATTRIBUTE.matcher(subLine).matches()) {
eb1bab5b 1186 channelInfo.setSwitchTimer(Long.valueOf(getAttributeValue(subLine)));
4775bcbf
BH
1187
1188 } else if (READ_TIMER_ATTRIBUTE.matcher(subLine).matches()) {
eb1bab5b 1189 channelInfo.setReadTimer(Long.valueOf(getAttributeValue(subLine)));
4775bcbf
BH
1190
1191 } else if (OUTPUT_ATTRIBUTE.matcher(subLine).matches()) {
eb1bab5b 1192 channelInfo.setOutputType(getAttributeValue(subLine));
4775bcbf
BH
1193
1194 } else if (EVENT_SECTION_PATTERN.matcher(subLine).matches()) {
1195 List<IEventInfo> events = new ArrayList<IEventInfo>();
eb1bab5b
BH
1196 index = parseEvents(output, index, events);
1197 channelInfo.setEvents(events);
4775bcbf
BH
1198 // we want to stay at the current index to be able to
1199 // exit the domain
eb1bab5b 1200 continue;
4775bcbf 1201 } else if (DOMAIN_KERNEL_PATTERN.matcher(subLine).matches()) {
eb1bab5b
BH
1202 return index;
1203
4775bcbf 1204 } else if (DOMAIN_UST_GLOBAL_PATTERN.matcher(subLine).matches()) {
eb1bab5b
BH
1205 return index;
1206 }
1207 index++;
1208 }
1209 }
1210 index++;
1211 }
1212 return index;
1213 }
1214
1215 /**
1216 * Parses the event information within a domain.
1217 *
4775bcbf
BH
1218 * @param output
1219 * - a command output array
1220 * @param currentIndex
1221 * - current index in command output array
1222 * @param events
1223 * - list for returning event information
eb1bab5b 1224 * @return the new current index in command output array
eb1bab5b 1225 */
887a93a3 1226 private int parseEvents(String[] output, int currentIndex, List<IEventInfo> events) {
eb1bab5b
BH
1227 int index = currentIndex;
1228
1229 while (index < output.length) {
1230 String line = output[index];
4775bcbf 1231 if (CHANNEL_PATTERN.matcher(line).matches()) {
eb1bab5b
BH
1232 // end of channel
1233 return index;
4775bcbf 1234 } else if (DOMAIN_KERNEL_PATTERN.matcher(line).matches()) {
eb1bab5b
BH
1235 // end of domain
1236 return index;
4775bcbf 1237 } else if (DOMAIN_UST_GLOBAL_PATTERN.matcher(line).matches()) {
eb1bab5b
BH
1238 // end of domain
1239 return index;
4775bcbf
BH
1240 }
1241
1242 Matcher matcher = EVENT_PATTERN.matcher(line);
1243 Matcher matcher2 = WILDCARD_EVENT_PATTERN.matcher(line);
1244
1245 if (matcher.matches()) {
1246 IEventInfo eventInfo = new EventInfo(matcher.group(1).trim());
1247 eventInfo.setLogLevel(matcher.group(2).trim());
1248 eventInfo.setEventType(matcher.group(3).trim());
1249 eventInfo.setState(matcher.group(4));
1250 events.add(eventInfo);
d132bcc7 1251 index++;
4775bcbf
BH
1252 } else if (matcher2.matches()) {
1253 IEventInfo eventInfo = new EventInfo(matcher2.group(1).trim());
1254 eventInfo.setLogLevel(TraceLogLevel.LEVEL_UNKNOWN);
1255 eventInfo.setEventType(matcher2.group(2).trim());
1256 eventInfo.setState(matcher2.group(3));
d132bcc7
BH
1257
1258 if (eventInfo.getEventType() == TraceEventType.PROBE) {
1259 IProbeEventInfo probeEvent = new ProbeEventInfo(eventInfo.getName());
1260 probeEvent.setLogLevel(eventInfo.getLogLevel());
1261 probeEvent.setEventType(eventInfo.getEventType());
1262 probeEvent.setState(eventInfo.getState());
1263
1264 // Overwrite eventinfo
1265 eventInfo = probeEvent;
1266
1267 // myevent2 (type: probe) [enabled]
1268 // addr: 0xc0101340
1269 // myevent0 (type: probe) [enabled]
1270 // offset: 0x0
1271 // symbol: init_post
1272 index++;
1273 while (index < output.length) {
1274 String probeLine = output[index];
1275 // parse probe
1276 Matcher addrMatcher = PROBE_ADDRESS_PATTERN.matcher(probeLine);
1277 Matcher offsetMatcher = PROBE_OFFSET_PATTERN.matcher(probeLine);
1278 Matcher symbolMatcher = PROBE_SYMBOL_PATTERN.matcher(probeLine);
1279 if (addrMatcher.matches()) {
1280 String addr = addrMatcher.group(2).trim();
1281 probeEvent.setAddress(addr);
1282 } else if (offsetMatcher.matches()) {
1283 String offset = offsetMatcher.group(2).trim();
1284 probeEvent.setOffset(offset);
1285 } else if (symbolMatcher.matches()) {
1286 String symbol = symbolMatcher.group(2).trim();
1287 probeEvent.setSymbol(symbol);
1288 } else if ((EVENT_PATTERN.matcher(probeLine).matches()) || (WILDCARD_EVENT_PATTERN.matcher(probeLine).matches())) {
1289 break;
1290 } else if (CHANNEL_PATTERN.matcher(probeLine).matches()) {
1291 break;
1292 } else if (DOMAIN_KERNEL_PATTERN.matcher(probeLine).matches()) {
1293 // end of domain
1294 break;
1295 } else if (DOMAIN_UST_GLOBAL_PATTERN.matcher(probeLine).matches()) {
1296 // end of domain
1297 break;
1298 }
1299 index++;
1300 }
1301 events.add(eventInfo);
1302 } else {
1303 events.add(eventInfo);
1304 index++;
1305 continue;
1306 }
1307 } else {
1308 index++;
eb1bab5b
BH
1309 }
1310// else if (line.matches(EVENT_NONE_PATTERN)) {
1311 // do nothing
1312// } else
d132bcc7 1313
eb1bab5b
BH
1314 }
1315
1316 return index;
1317 }
1318
1319 /**
1320 * Parses a line with attributes: <attribute Name>: <attribute value>
1321 *
4775bcbf
BH
1322 * @param line
1323 * - attribute line to parse
eb1bab5b 1324 * @return the attribute value as string
eb1bab5b
BH
1325 */
1326 private String getAttributeValue(String line) {
1327 String[] temp = line.split("\\: "); //$NON-NLS-1$
1328 return temp[1];
1329 }
1330
1331 /**
4775bcbf 1332 * Parses the event information within a provider.
eb1bab5b 1333 *
4775bcbf
BH
1334 * @param output
1335 * - a command output array
1336 * @param currentIndex
1337 * - current index in command output array
1338 * @param events
1339 * - list for returning event information
eb1bab5b
BH
1340 * @return the new current index in command output array
1341 */
1342 private int getProviderEventInfo(String[] output, int currentIndex, List<IBaseEventInfo> events) {
1343 int index = currentIndex;
1344 while (index < output.length) {
1345 String line = output[index];
4775bcbf
BH
1346 Matcher matcher = PROVIDER_EVENT_PATTERN.matcher(line);
1347 if (matcher.matches()) {
1348 // sched_kthread_stop (loglevel: TRACE_EMERG0) (type:
1349 // tracepoint)
1350 IBaseEventInfo eventInfo = new BaseEventInfo(matcher.group(1).trim());
1351 eventInfo.setLogLevel(matcher.group(2).trim());
1352 eventInfo.setEventType(matcher.group(3).trim());
1353 events.add(eventInfo);
1354 } else if (UST_PROVIDER_PATTERN.matcher(line).matches()) {
eb1bab5b
BH
1355 return index;
1356 }
1357 index++;
1358 }
1359 return index;
1360 }
1361
bbb3538a
BH
1362 /**
1363 * Formats a command parameter for the command execution i.e. adds quotes
1364 * at the beginning and end if necessary.
1365 * @param parameter - parameter to format
1366 * @return formated parameter
1367 */
1368 private String formatParameter(String parameter) {
1369 if (parameter != null) {
c56972bb
BH
1370 StringBuffer newString = new StringBuffer();
1371 newString.append(parameter);
bbb3538a
BH
1372
1373 if (parameter.contains(" ")) { //$NON-NLS-1$
c56972bb
BH
1374 newString.insert(0, "\""); //$NON-NLS-1$
1375 newString.append("\""); //$NON-NLS-1$
bbb3538a 1376 }
c56972bb 1377 return newString.toString();
bbb3538a
BH
1378 }
1379 return null;
1380 }
eb1bab5b 1381}
This page took 0.090969 seconds and 5 git commands to generate.