Fixed code review findings + upgrade to lttng-tools 2.0-pre20
[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;
15import java.util.List;
16import java.util.regex.Matcher;
17import java.util.regex.Pattern;
18import java.util.regex.PatternSyntaxException;
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 */
4775bcbf 64 private final static String COMMAND_LIST_UST = COMMAND_LIST + "-u"; //$NON-NLS-1$
eb1bab5b
BH
65
66 // Parsing constants
67 /**
68 * Pattern to match for error output
69 */
4775bcbf 70 private final static Pattern ERROR_PATTERN = Pattern.compile("\\s*Error\\:.*"); //$NON-NLS-1$
eb1bab5b
BH
71 /**
72 * Pattern to match for session information (lttng list)
73 */
4775bcbf 74 private final static Pattern SESSION_PATTERN = Pattern.compile("\\s+(\\d+)\\)\\s+(.*)\\s+\\((.*)\\)\\s+\\[(active|inactive)\\].*"); //$NON-NLS-1$
eb1bab5b
BH
75 /**
76 * Pattern to match for session information (lttng list <session>)
77 */
4775bcbf 78 private final static Pattern TRACE_SESSION_PATTERN = Pattern.compile("\\s*Tracing\\s+session\\s+(.*)\\:\\s+\\[(active|inactive)\\].*"); //$NON-NLS-1$
eb1bab5b
BH
79 /**
80 * Pattern to match for session path information (lttng list <session>)
81 */
4775bcbf 82 private final static Pattern TRACE_SESSION_PATH_PATTERN = Pattern.compile("\\s*Trace\\s+path\\:\\s+(.*)"); //$NON-NLS-1$
eb1bab5b
BH
83 /**
84 * Pattern to match for kernel domain information (lttng list <session>)
85 */
4775bcbf 86 private final static Pattern DOMAIN_KERNEL_PATTERN = Pattern.compile("=== Domain: Kernel ==="); //$NON-NLS-1$
eb1bab5b
BH
87 /**
88 * Pattern to match for ust domain information (lttng list <session>)
89 */
4775bcbf 90 private final static Pattern DOMAIN_UST_GLOBAL_PATTERN = Pattern.compile("=== Domain: UST global ==="); //$NON-NLS-1$
eb1bab5b
BH
91 /**
92 * Pattern to match for channels section (lttng list <session>)
93 */
4775bcbf 94 private final static Pattern CHANNELS_SECTION_PATTERN = Pattern.compile("\\s*Channels\\:"); //$NON-NLS-1$
eb1bab5b
BH
95 /**
96 * Pattern to match for channel information (lttng list <session>)
97 */
4775bcbf 98 private final static Pattern CHANNEL_PATTERN = Pattern.compile("\\s*-\\s+(.*)\\:\\s+\\[(enabled|disabled)\\]"); //$NON-NLS-1$
eb1bab5b
BH
99 /**
100 * Pattern to match for events section information (lttng list <session>)
101 */
4775bcbf 102 private final static Pattern EVENT_SECTION_PATTERN = Pattern.compile("\\s*Events\\:"); //$NON-NLS-1$
eb1bab5b 103 /**
4775bcbf
BH
104 * Pattern to match for event information (no enabled events) (lttng list
105 * <session>)
eb1bab5b 106 */
4775bcbf 107 // private final static String EVENT_NONE_PATTERN = "\\s+None"; //$NON-NLS-1$
eb1bab5b
BH
108 /**
109 * Pattern to match for event information (lttng list <session>)
110 */
4775bcbf
BH
111 private final static Pattern EVENT_PATTERN = Pattern.compile("\\s+(.*)\\s+\\(loglevel:\\s+(.*)\\s+\\(\\d*\\)\\)\\s+\\(type:\\s+(.*)\\)\\s+\\[(enabled|disabled)\\].*"); //$NON-NLS-1$
112 /**
113 * Pattern to match a wildcarded event information (lttng list <session>)
114 */
115 private final static Pattern WILDCARD_EVENT_PATTERN = Pattern.compile("\\s+(.*)\\s+\\(type:\\s+(.*)\\)\\s+\\[(enabled|disabled)\\].*"); //$NON-NLS-1$
eb1bab5b 116 /**
4775bcbf
BH
117 * Pattern to match for channel (overwite mode) information (lttng list
118 * <session>)
eb1bab5b 119 */
4775bcbf 120 private final static Pattern OVERWRITE_MODE_ATTRIBUTE = Pattern.compile("\\s+overwrite\\s+mode\\:.*"); //$NON-NLS-1$
eb1bab5b
BH
121 /**
122 * Pattern to match indicating false for overwrite mode
123 */
124 private final static String OVERWRITE_MODE_ATTRIBUTE_FALSE = "0"; //$NON-NLS-1$
125 /**
4775bcbf
BH
126 * Pattern to match for channel (sub-buffer size) information (lttng list
127 * <session>)
eb1bab5b 128 */
4775bcbf 129 private final static Pattern SUBBUFFER_SIZE_ATTRIBUTE = Pattern.compile("\\s+subbufers\\s+size\\:.*"); //$NON-NLS-1$
eb1bab5b 130 /**
4775bcbf
BH
131 * Pattern to match for channel (number of sub-buffers) information (lttng
132 * list <session>)
eb1bab5b 133 */
4775bcbf 134 private final static Pattern NUM_SUBBUFFERS_ATTRIBUTE = Pattern.compile("\\s+number\\s+of\\s+subbufers\\:.*"); //$NON-NLS-1$
eb1bab5b 135 /**
4775bcbf
BH
136 * Pattern to match for channel (switch timer) information (lttng list
137 * <session>)
eb1bab5b 138 */
4775bcbf 139 private final static Pattern SWITCH_TIMER_ATTRIBUTE = Pattern.compile("\\s+switch\\s+timer\\s+interval\\:.*"); //$NON-NLS-1$
eb1bab5b 140 /**
4775bcbf
BH
141 * Pattern to match for channel (read timer) information (lttng list
142 * <session>)
eb1bab5b 143 */
4775bcbf 144 private final static Pattern READ_TIMER_ATTRIBUTE = Pattern.compile("\\s+read\\s+timer\\s+interval\\:.*"); //$NON-NLS-1$
eb1bab5b 145 /**
4775bcbf
BH
146 * Pattern to match for channel (output type) information (lttng list
147 * <session>)
eb1bab5b 148 */
4775bcbf 149 private final static Pattern OUTPUT_ATTRIBUTE = Pattern.compile("\\s+output\\:.*"); //$NON-NLS-1$
eb1bab5b
BH
150 /**
151 * Pattern to match for provider information (lttng list -k/-u)
152 */
4775bcbf 153 private final static Pattern PROVIDER_EVENT_PATTERN = Pattern.compile("\\s*(.*)\\s+\\(loglevel:\\s+(.*)\\s+\\(\\d*\\)\\)\\s+\\(type:\\s+(.*)\\)"); //$NON-NLS-1$
eb1bab5b
BH
154 /**
155 * Pattern to match for UST provider information (lttng list -u)
4775bcbf
BH
156 */
157 private final static Pattern UST_PROVIDER_PATTERN = Pattern.compile("\\s*PID\\:\\s+(\\d+)\\s+-\\s+Name\\:\\s+(.*)"); //$NON-NLS-1$
eb1bab5b
BH
158
159 // ------------------------------------------------------------------------
160 // Attributes
161 // ------------------------------------------------------------------------
162 /**
163 * The command shell implementation
164 */
165 private ICommandShell fCommandShell = null;
166
167 // ------------------------------------------------------------------------
168 // Constructors
169 // ------------------------------------------------------------------------
170
171 /**
172 * Constructor
4775bcbf
BH
173 *
174 * @param shell
175 * - the command shell implementation to use
eb1bab5b
BH
176 */
177 public LTTngControlService(ICommandShell shell) {
178 fCommandShell = shell;
179 }
4775bcbf 180
eb1bab5b
BH
181 // ------------------------------------------------------------------------
182 // Operations
4775bcbf 183 // ------------------------------------------------------------------------
eb1bab5b
BH
184
185 /*
186 * (non-Javadoc)
4775bcbf
BH
187 *
188 * @see
189 * org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService
190 * #getSessionNames()
eb1bab5b
BH
191 */
192 @Override
193 public String[] getSessionNames() throws ExecutionException {
194 return getSessionNames(new NullProgressMonitor());
195 }
196
197 /*
198 * (non-Javadoc)
4775bcbf
BH
199 *
200 * @see
201 * org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService
202 * #getSessionNames(org.eclipse.core.runtime.IProgressMonitor)
eb1bab5b
BH
203 */
204 @Override
205 public String[] getSessionNames(IProgressMonitor monitor) throws ExecutionException {
206
4775bcbf
BH
207 String command = COMMAND_LIST;
208 ICommandResult result = fCommandShell.executeCommand(command, monitor);
209
210 if (isError(result)) {
211 // TODO: no session available shouldn't be an error!
212 if (result.getOutput().length > 0 && ERROR_PATTERN.matcher(result.getOutput()[0]).matches()) {
213 // no sessions available
214 return new String[0];
215 }
216 throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
217 }
218
219 // Output:
220 // Available tracing sessions:
221 // 1) mysession1 (/home/user/lttng-traces/mysession1-20120123-083928)
222 // [inactive]
223 // 2) mysession (/home/user/lttng-traces/mysession-20120123-083318)
224 // [inactive]
225 //
226 // Use lttng list <session_name> for more details
227
228 ArrayList<String> retArray = new ArrayList<String>();
229 int index = 0;
230 while (index < result.getOutput().length) {
231 String line = result.getOutput()[index];
232 Matcher matcher = SESSION_PATTERN.matcher(line);
233 if (matcher.matches()) {
234 retArray.add(matcher.group(2).trim());
235 }
236 index++;
237 }
238 return retArray.toArray(new String[retArray.size()]);
eb1bab5b
BH
239 }
240
241 /*
242 * (non-Javadoc)
4775bcbf
BH
243 *
244 * @see
245 * org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService
246 * #getSession(java.lang.String)
eb1bab5b
BH
247 */
248 @Override
249 public ISessionInfo getSession(String sessionName) throws ExecutionException {
250 return getSession(sessionName, new NullProgressMonitor());
251 }
252
253 /*
254 * (non-Javadoc)
4775bcbf
BH
255 *
256 * @see
257 * org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService
258 * #getSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
eb1bab5b
BH
259 */
260 @Override
261 public ISessionInfo getSession(String sessionName, IProgressMonitor monitor) throws ExecutionException {
262 String command = COMMAND_LIST + sessionName;
263 ICommandResult result = fCommandShell.executeCommand(command, monitor);
264
265 if (isError(result)) {
266 throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
267 }
268
269 int index = 0;
270
271 // Output:
4775bcbf
BH
272 // Tracing session mysession2: [inactive]
273 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
eb1bab5b
BH
274 ISessionInfo sessionInfo = new SessionInfo(sessionName);
275
4775bcbf
BH
276 while (index < result.getOutput().length) {
277 // Tracing session mysession2: [inactive]
278 // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
279 //
280 // === Domain: Kernel ===
281 //
282 String line = result.getOutput()[index];
283 Matcher matcher = TRACE_SESSION_PATTERN.matcher(line);
284 if (matcher.matches()) {
285 sessionInfo.setSessionState(matcher.group(2));
286 index++;
287 continue;
288 }
289
290 matcher = TRACE_SESSION_PATH_PATTERN.matcher(line);
291 if (matcher.matches()) {
292 sessionInfo.setSessionPath(matcher.group(1).trim());
293 index++;
294 continue;
295 }
eb1bab5b 296
4775bcbf
BH
297 matcher = DOMAIN_KERNEL_PATTERN.matcher(line);
298 if (matcher.matches()) {
299 // Create Domain
300 IDomainInfo domainInfo = new DomainInfo(Messages.TraceControl_KernelDomainDisplayName);
301 sessionInfo.addDomain(domainInfo);
eb1bab5b 302
4775bcbf
BH
303 // in domain kernel
304 ArrayList<IChannelInfo> channels = new ArrayList<IChannelInfo>();
305 index = parseDomain(result.getOutput(), index, channels);
eb1bab5b 306
4775bcbf
BH
307 // set channels
308 domainInfo.setChannels(channels);
309 continue;
310 }
eb1bab5b 311
4775bcbf
BH
312 matcher = DOMAIN_UST_GLOBAL_PATTERN.matcher(line);
313 if (matcher.matches()) {
314 IDomainInfo domainInfo = new DomainInfo(Messages.TraceControl_UstGlobalDomainDisplayName);
315 sessionInfo.addDomain(domainInfo);
eb1bab5b 316
4775bcbf
BH
317 // in domain kernel
318 ArrayList<IChannelInfo> channels = new ArrayList<IChannelInfo>();
319 index = parseDomain(result.getOutput(), index, channels);
320
321 // set channels
322 domainInfo.setChannels(channels);
323 continue;
eb1bab5b 324 }
4775bcbf
BH
325 index++;
326 }
eb1bab5b
BH
327 return sessionInfo;
328 }
4775bcbf 329
eb1bab5b
BH
330 /*
331 * (non-Javadoc)
4775bcbf
BH
332 *
333 * @see
334 * org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService
335 * #getKernelProvider()
eb1bab5b
BH
336 */
337 @Override
338 public List<IBaseEventInfo> getKernelProvider() throws ExecutionException {
339 return getKernelProvider(new NullProgressMonitor());
340 }
4775bcbf 341
eb1bab5b
BH
342 /*
343 * (non-Javadoc)
4775bcbf
BH
344 *
345 * @see
346 * org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService
347 * #getKernelProvider(org.eclipse.core.runtime.IProgressMonitor)
eb1bab5b
BH
348 */
349 @Override
350 public List<IBaseEventInfo> getKernelProvider(IProgressMonitor monitor) throws ExecutionException {
351 String command = COMMAND_LIST_KERNEL;
352 ICommandResult result = fCommandShell.executeCommand(command, monitor);
353 if (isError(result)) {
354 throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
355 }
4775bcbf
BH
356
357 // Kernel events:
358 // -------------
359 // sched_kthread_stop (type: tracepoint)
eb1bab5b
BH
360 List<IBaseEventInfo> events = new ArrayList<IBaseEventInfo>();
361 getProviderEventInfo(result.getOutput(), 0, events);
362 return events;
363 }
364
365 /*
366 * (non-Javadoc)
4775bcbf
BH
367 *
368 * @see
369 * org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService
370 * #getUstProvider()
eb1bab5b
BH
371 */
372 @Override
373 public List<IUstProviderInfo> getUstProvider() throws ExecutionException {
374 return getUstProvider(new NullProgressMonitor());
375 }
4775bcbf 376
eb1bab5b
BH
377 /*
378 * (non-Javadoc)
4775bcbf
BH
379 *
380 * @see
381 * org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService
382 * #getUstProvider(org.eclipse.core.runtime.IProgressMonitor)
eb1bab5b
BH
383 */
384 @Override
385 public List<IUstProviderInfo> getUstProvider(IProgressMonitor monitor) throws ExecutionException {
386 String command = COMMAND_LIST_UST;
387 ICommandResult result = fCommandShell.executeCommand(command, monitor);
388
389 if (isError(result)) {
390 throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
391 }
4775bcbf
BH
392
393 // UST events:
394 // -------------
395 //
396 // PID: 3635 - Name:
397 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
398 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
399 // tracepoint)
400 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
401 //
402 // PID: 6459 - Name:
403 // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
404 // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
405 // tracepoint)
406 // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
eb1bab5b
BH
407
408 List<IUstProviderInfo> allProviders = new ArrayList<IUstProviderInfo>();
409 IUstProviderInfo provider = null;
4775bcbf 410
eb1bab5b
BH
411 int index = 0;
412 while (index < result.getOutput().length) {
413 String line = result.getOutput()[index];
4775bcbf
BH
414 Matcher matcher = UST_PROVIDER_PATTERN.matcher(line);
415 if (matcher.matches()) {
eb1bab5b 416
4775bcbf
BH
417 provider = new UstProviderInfo(matcher.group(2).trim());
418 provider.setPid(Integer.valueOf(matcher.group(1).trim()));
419 List<IBaseEventInfo> events = new ArrayList<IBaseEventInfo>();
420 index = getProviderEventInfo(result.getOutput(), ++index, events);
421 provider.setEvents(events);
422 allProviders.add(provider);
eb1bab5b
BH
423
424 } else {
425 index++;
426 }
4775bcbf 427
eb1bab5b
BH
428 }
429 return allProviders;
430 }
431
432 // ------------------------------------------------------------------------
433 // Helper methods
434 // ------------------------------------------------------------------------
435 /**
436 * Checks if command result is an error result.
4775bcbf
BH
437 *
438 * @param result
439 * - the command result to check
eb1bab5b
BH
440 * @return true if error else false
441 */
442 private boolean isError(ICommandResult result) {
4775bcbf 443 if ((result.getResult()) != 0 || (result.getOutput().length < 1 || ERROR_PATTERN.matcher(result.getOutput()[0]).matches())) {
eb1bab5b
BH
444 return true;
445 }
446 return false;
447 }
4775bcbf 448
eb1bab5b
BH
449 /**
450 * Formats the output string as single string.
4775bcbf
BH
451 *
452 * @param output
453 * - output array
eb1bab5b
BH
454 * @return - the formatted output
455 */
456 private String formatOutput(String[] output) {
457 if (output == null || output.length == 0) {
458 return ""; //$NON-NLS-1$
459 }
460
461 StringBuffer ret = new StringBuffer();
462 for (int i = 0; i < output.length; i++) {
463 ret.append(output[i] + "\n"); //$NON-NLS-1$
464 }
465 return ret.toString();
466 }
4775bcbf 467
eb1bab5b
BH
468 /**
469 * Parses the domain information.
470 *
4775bcbf
BH
471 * @param output
472 * - a command output array
473 * @param currentIndex
474 * - current index in command output array
475 * @param channels
476 * - list for returning channel information
477 * @return the new current index in command output array
eb1bab5b
BH
478 * @throws PatternSyntaxException
479 */
480 private int parseDomain(String[] output, int currentIndex, List<IChannelInfo> channels) throws PatternSyntaxException {
481 int index = currentIndex;
482
4775bcbf
BH
483 // Channels:
484 // -------------
485 // - channnel1: [enabled]
486 //
487 // Attributes:
488 // overwrite mode: 0
489 // subbufers size: 262144
490 // number of subbufers: 4
491 // switch timer interval: 0
492 // read timer interval: 200
493 // output: splice()
494
eb1bab5b
BH
495 while (index < output.length) {
496 String line = output[index];
4775bcbf
BH
497
498 Matcher outerMatcher = CHANNELS_SECTION_PATTERN.matcher(line);
499 if (outerMatcher.matches()) {
eb1bab5b
BH
500 IChannelInfo channelInfo = null;
501 while (index < output.length) {
502 String subLine = output[index];
4775bcbf
BH
503
504 Matcher innerMatcher = CHANNEL_PATTERN.matcher(subLine);
505 if (innerMatcher.matches()) {
eb1bab5b 506 channelInfo = new ChannelInfo(""); //$NON-NLS-1$
4775bcbf
BH
507 // get channel name
508 channelInfo.setName(innerMatcher.group(1));
509
510 // get channel enablement
511 channelInfo.setState(innerMatcher.group(2));
512
513 // add channel
514 channels.add(channelInfo);
515
516 } else if (OVERWRITE_MODE_ATTRIBUTE.matcher(subLine).matches()) {
eb1bab5b
BH
517 String value = getAttributeValue(subLine);
518 channelInfo.setOverwriteMode(!OVERWRITE_MODE_ATTRIBUTE_FALSE.equals(value));
4775bcbf 519 } else if (SUBBUFFER_SIZE_ATTRIBUTE.matcher(subLine).matches()) {
eb1bab5b 520 channelInfo.setSubBufferSize(Long.valueOf(getAttributeValue(subLine)));
4775bcbf
BH
521
522 } else if (NUM_SUBBUFFERS_ATTRIBUTE.matcher(subLine).matches()) {
eb1bab5b 523 channelInfo.setNumberOfSubBuffers(Integer.valueOf(getAttributeValue(subLine)));
4775bcbf
BH
524
525 } else if (SWITCH_TIMER_ATTRIBUTE.matcher(subLine).matches()) {
eb1bab5b 526 channelInfo.setSwitchTimer(Long.valueOf(getAttributeValue(subLine)));
4775bcbf
BH
527
528 } else if (READ_TIMER_ATTRIBUTE.matcher(subLine).matches()) {
eb1bab5b 529 channelInfo.setReadTimer(Long.valueOf(getAttributeValue(subLine)));
4775bcbf
BH
530
531 } else if (OUTPUT_ATTRIBUTE.matcher(subLine).matches()) {
eb1bab5b 532 channelInfo.setOutputType(getAttributeValue(subLine));
4775bcbf
BH
533
534 } else if (EVENT_SECTION_PATTERN.matcher(subLine).matches()) {
535 List<IEventInfo> events = new ArrayList<IEventInfo>();
eb1bab5b
BH
536 index = parseEvents(output, index, events);
537 channelInfo.setEvents(events);
4775bcbf
BH
538 // we want to stay at the current index to be able to
539 // exit the domain
eb1bab5b 540 continue;
4775bcbf 541 } else if (DOMAIN_KERNEL_PATTERN.matcher(subLine).matches()) {
eb1bab5b
BH
542 return index;
543
4775bcbf 544 } else if (DOMAIN_UST_GLOBAL_PATTERN.matcher(subLine).matches()) {
eb1bab5b
BH
545 return index;
546 }
547 index++;
548 }
549 }
550 index++;
551 }
552 return index;
553 }
554
555 /**
556 * Parses the event information within a domain.
557 *
4775bcbf
BH
558 * @param output
559 * - a command output array
560 * @param currentIndex
561 * - current index in command output array
562 * @param events
563 * - list for returning event information
eb1bab5b
BH
564 * @return the new current index in command output array
565 * @throws PatternSyntaxException
566 */
567 private int parseEvents(String[] output, int currentIndex, List<IEventInfo> events) throws PatternSyntaxException {
568 int index = currentIndex;
569
570 while (index < output.length) {
571 String line = output[index];
4775bcbf 572 if (CHANNEL_PATTERN.matcher(line).matches()) {
eb1bab5b
BH
573 // end of channel
574 return index;
4775bcbf 575 } else if (DOMAIN_KERNEL_PATTERN.matcher(line).matches()) {
eb1bab5b
BH
576 // end of domain
577 return index;
4775bcbf 578 } else if (DOMAIN_UST_GLOBAL_PATTERN.matcher(line).matches()) {
eb1bab5b
BH
579 // end of domain
580 return index;
4775bcbf
BH
581 }
582
583 Matcher matcher = EVENT_PATTERN.matcher(line);
584 Matcher matcher2 = WILDCARD_EVENT_PATTERN.matcher(line);
585
586 if (matcher.matches()) {
587 IEventInfo eventInfo = new EventInfo(matcher.group(1).trim());
588 eventInfo.setLogLevel(matcher.group(2).trim());
589 eventInfo.setEventType(matcher.group(3).trim());
590 eventInfo.setState(matcher.group(4));
591 events.add(eventInfo);
592 } else if (matcher2.matches()) {
593 IEventInfo eventInfo = new EventInfo(matcher2.group(1).trim());
594 eventInfo.setLogLevel(TraceLogLevel.LEVEL_UNKNOWN);
595 eventInfo.setEventType(matcher2.group(2).trim());
596 eventInfo.setState(matcher2.group(3));
597 events.add(eventInfo);
eb1bab5b
BH
598 }
599// else if (line.matches(EVENT_NONE_PATTERN)) {
600 // do nothing
601// } else
602 index++;
603 }
604
605 return index;
606 }
607
608 /**
609 * Parses a line with attributes: <attribute Name>: <attribute value>
610 *
4775bcbf
BH
611 * @param line
612 * - attribute line to parse
eb1bab5b
BH
613 * @return the attribute value as string
614 * @throws PatternSyntaxException
615 */
616 private String getAttributeValue(String line) {
617 String[] temp = line.split("\\: "); //$NON-NLS-1$
618 return temp[1];
619 }
620
621 /**
4775bcbf 622 * Parses the event information within a provider.
eb1bab5b 623 *
4775bcbf
BH
624 * @param output
625 * - a command output array
626 * @param currentIndex
627 * - current index in command output array
628 * @param events
629 * - list for returning event information
eb1bab5b
BH
630 * @return the new current index in command output array
631 */
632 private int getProviderEventInfo(String[] output, int currentIndex, List<IBaseEventInfo> events) {
633 int index = currentIndex;
634 while (index < output.length) {
635 String line = output[index];
4775bcbf
BH
636 Matcher matcher = PROVIDER_EVENT_PATTERN.matcher(line);
637 if (matcher.matches()) {
638 // sched_kthread_stop (loglevel: TRACE_EMERG0) (type:
639 // tracepoint)
640 IBaseEventInfo eventInfo = new BaseEventInfo(matcher.group(1).trim());
641 eventInfo.setLogLevel(matcher.group(2).trim());
642 eventInfo.setEventType(matcher.group(3).trim());
643 events.add(eventInfo);
644 } else if (UST_PROVIDER_PATTERN.matcher(line).matches()) {
eb1bab5b
BH
645 return index;
646 }
647 index++;
648 }
649 return index;
650 }
651
652}
This page took 0.053468 seconds and 5 git commands to generate.