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