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