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