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