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