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