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