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