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