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