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