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 BH |
18 | import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull; |
19 | ||
eb1bab5b | 20 | import java.util.ArrayList; |
774a7993 | 21 | import java.util.Arrays; |
bbb3538a | 22 | import java.util.Iterator; |
eb1bab5b BH |
23 | import java.util.List; |
24 | import java.util.regex.Matcher; | |
517c0261 | 25 | import java.util.regex.Pattern; |
eb1bab5b BH |
26 | |
27 | import org.eclipse.core.commands.ExecutionException; | |
28 | import org.eclipse.core.runtime.IProgressMonitor; | |
29 | import org.eclipse.core.runtime.NullProgressMonitor; | |
13729cbc BH |
30 | import org.eclipse.jdt.annotation.NonNull; |
31 | import org.eclipse.jdt.annotation.Nullable; | |
9bc60be7 AM |
32 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.IBaseEventInfo; |
33 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.IChannelInfo; | |
34 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.IDomainInfo; | |
35 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.IEventInfo; | |
36 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.IFieldInfo; | |
37 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.IProbeEventInfo; | |
38 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.ISessionInfo; | |
39 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.ISnapshotInfo; | |
40 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.IUstProviderInfo; | |
41 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.LogLevelType; | |
42 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceEventType; | |
43 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceLogLevel; | |
44 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.impl.BaseEventInfo; | |
45 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.impl.BufferType; | |
46 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.impl.ChannelInfo; | |
47 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.impl.DomainInfo; | |
48 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.impl.EventInfo; | |
49 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.impl.FieldInfo; | |
50 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.impl.ProbeEventInfo; | |
51 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.impl.SessionInfo; | |
52 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.impl.SnapshotInfo; | |
53 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.impl.UstProviderInfo; | |
54 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.logging.ControlCommandLogger; | |
55 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.messages.Messages; | |
56 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.preferences.ControlPreferences; | |
ec619615 BH |
57 | import org.eclipse.tracecompass.tmf.remote.core.shell.ICommandResult; |
58 | import org.eclipse.tracecompass.tmf.remote.core.shell.ICommandShell; | |
4775bcbf | 59 | |
eb1bab5b | 60 | /** |
eb1bab5b BH |
61 | * <p> |
62 | * Service for sending LTTng trace control commands to remote host. | |
63 | * </p> | |
cfdb727a | 64 | * |
dbd4432d | 65 | * @author Bernd Hufmann |
eb1bab5b BH |
66 | */ |
67 | public class LTTngControlService implements ILttngControlService { | |
cfdb727a | 68 | |
eb1bab5b BH |
69 | // ------------------------------------------------------------------------ |
70 | // Attributes | |
71 | // ------------------------------------------------------------------------ | |
72 | /** | |
73 | * The command shell implementation | |
74 | */ | |
77735e82 | 75 | private final ICommandShell fCommandShell; |
cfdb727a | 76 | |
c5f68877 BH |
77 | /** |
78 | * The version string. | |
79 | */ | |
77735e82 | 80 | private LttngVersion fVersion = null; |
eb1bab5b BH |
81 | |
82 | // ------------------------------------------------------------------------ | |
83 | // Constructors | |
84 | // ------------------------------------------------------------------------ | |
85 | ||
86 | /** | |
87 | * Constructor | |
cfdb727a | 88 | * |
4775bcbf BH |
89 | * @param shell |
90 | * - the command shell implementation to use | |
eb1bab5b BH |
91 | */ |
92 | public LTTngControlService(ICommandShell shell) { | |
93 | fCommandShell = shell; | |
94 | } | |
4775bcbf | 95 | |
276c17e7 BH |
96 | // ------------------------------------------------------------------------ |
97 | // Accessors | |
98 | // ------------------------------------------------------------------------ | |
11252342 | 99 | |
276c17e7 | 100 | @Override |
0df4af5f | 101 | public String getVersionString() { |
d4514365 BH |
102 | if (fVersion == null) { |
103 | return "Unknown"; //$NON-NLS-1$ | |
104 | } | |
105 | return 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 | */ |
276c17e7 | 119 | public void setVersion(String version) { |
3f1e748c | 120 | fVersion = new LttngVersion(version); |
276c17e7 | 121 | } |
d4514365 | 122 | |
0df4af5f JRJ |
123 | /** |
124 | * Sets the version of the LTTng 2.x control service. | |
517c0261 JRJ |
125 | * |
126 | * @param version | |
127 | * - a version to set | |
0df4af5f JRJ |
128 | */ |
129 | public void setVersion(LttngVersion version) { | |
130 | fVersion = version; | |
131 | } | |
132 | ||
d4514365 BH |
133 | @Override |
134 | public boolean isVersionSupported(String version) { | |
3f1e748c | 135 | LttngVersion tmp = new LttngVersion(version); |
d4514365 BH |
136 | return (fVersion != null && fVersion.compareTo(tmp) >= 0) ? true : false; |
137 | } | |
138 | ||
77735e82 BH |
139 | /** |
140 | * Returns the command shell implementation. | |
141 | * | |
142 | * @return the command shell implementation | |
143 | */ | |
144 | protected ICommandShell getCommandShell() { | |
145 | return fCommandShell; | |
146 | } | |
147 | ||
eb1bab5b BH |
148 | // ------------------------------------------------------------------------ |
149 | // Operations | |
4775bcbf | 150 | // ------------------------------------------------------------------------ |
cfdb727a | 151 | |
eb1bab5b BH |
152 | @Override |
153 | public String[] getSessionNames(IProgressMonitor monitor) throws ExecutionException { | |
774a7993 | 154 | List<String> command = createCommand(LTTngControlServiceConstants.COMMAND_LIST); |
eb1bab5b | 155 | |
774a7993 | 156 | ICommandResult result = executeCommand(command, monitor); |
4775bcbf BH |
157 | |
158 | // Output: | |
159 | // Available tracing sessions: | |
517c0261 JRJ |
160 | // 1) mysession1 (/home/user/lttng-traces/mysession1-20120123-083928) |
161 | // [inactive] | |
162 | // 2) mysession (/home/user/lttng-traces/mysession-20120123-083318) | |
163 | // [inactive] | |
4775bcbf BH |
164 | // |
165 | // Use lttng list <session_name> for more details | |
166 | ||
e0838ca1 | 167 | ArrayList<String> retArray = new ArrayList<>(); |
4775bcbf BH |
168 | int index = 0; |
169 | while (index < result.getOutput().length) { | |
170 | String line = result.getOutput()[index]; | |
276c17e7 | 171 | Matcher matcher = LTTngControlServiceConstants.SESSION_PATTERN.matcher(line); |
4775bcbf BH |
172 | if (matcher.matches()) { |
173 | retArray.add(matcher.group(2).trim()); | |
174 | } | |
175 | index++; | |
176 | } | |
177 | return retArray.toArray(new String[retArray.size()]); | |
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 | |
184 | * an arrays of string | |
185 | * @param pattern | |
186 | * the pattern to search for | |
187 | * @return if the pattern exist into the array of string | |
188 | */ | |
189 | protected boolean ignoredPattern(String[] input, Pattern pattern) { | |
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 { | |
774a7993 BH |
201 | List<String> command = createCommand(LTTngControlServiceConstants.COMMAND_LIST, sessionName); |
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 | ||
4775bcbf BH |
211 | while (index < result.getOutput().length) { |
212 | // Tracing session mysession2: [inactive] | |
213 | // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330 | |
214 | // | |
215 | // === Domain: Kernel === | |
216 | // | |
217 | String line = result.getOutput()[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 { | |
774a7993 BH |
317 | List<String> command = createCommand(LTTngControlServiceConstants.COMMAND_SNAPSHOT, LTTngControlServiceConstants.COMMAND_LIST_SNAPSHOT_OUTPUT, LTTngControlServiceConstants.OPTION_SESSION, sessionName); |
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 | ||
328 | while (index < result.getOutput().length) { | |
329 | String line = result.getOutput()[index]; | |
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 { | |
774a7993 BH |
352 | List<String> command = createCommand(LTTngControlServiceConstants.COMMAND_LIST, LTTngControlServiceConstants.OPTION_KERNEL); |
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)) { | |
13729cbc | 368 | throw new ExecutionException(Messages.TraceControl_CommandError + " " + toCommandString(command) + "\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 { | |
774a7993 | 385 | List<String> 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)) { | |
13729cbc | 412 | throw new ExecutionException(Messages.TraceControl_CommandError + " " + toCommandString(command) + "\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 BH |
440 | int index = 0; |
441 | while (index < result.getOutput().length) { | |
442 | String line = result.getOutput()[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 | |
774a7993 | 464 | List<String> 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 | |
bbb3538a | 471 | 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 | |
d128c979 BH |
477 | int index = 0; |
478 | while (index < output.length) { | |
479 | String line = output[index]; | |
480 | Matcher nameMatcher = LTTngControlServiceConstants.CREATE_SESSION_NAME_PATTERN.matcher(line); | |
481 | Matcher pathMatcher = LTTngControlServiceConstants.CREATE_SESSION_PATH_PATTERN.matcher(line); | |
482 | if (nameMatcher.matches()) { | |
483 | name = String.valueOf(nameMatcher.group(1).trim()); | |
484 | } else if (pathMatcher.matches()) { | |
485 | path = String.valueOf(pathMatcher.group(1).trim()); | |
486 | } | |
487 | index++; | |
bbb3538a BH |
488 | } |
489 | ||
d128c979 | 490 | // Verify session name |
f7d4d450 | 491 | if ((name == null) || (!"".equals(sessionInfo.getName()) && !name.equals(sessionInfo.getName()))) { //$NON-NLS-1$ |
bbb3538a | 492 | // Unexpected name returned |
774a7993 | 493 | throw new ExecutionException(Messages.TraceControl_CommandError + " " + toCommandString(command) + "\n" + //$NON-NLS-1$ //$NON-NLS-2$ |
cfdb727a | 494 | Messages.TraceControl_UnexpectedNameError + ": " + name); //$NON-NLS-1$ |
bbb3538a | 495 | } |
cfdb727a | 496 | |
f7d4d450 | 497 | sessionInfo.setName(name); |
d128c979 | 498 | // Verify session path |
f7d4d450 MAL |
499 | if (!sessionInfo.isSnapshotSession() && |
500 | ((path == null) || ((sessionInfo.getSessionPath() != null) && (!path.contains(sessionInfo.getSessionPath()))))) { | |
a30e79fe | 501 | // Unexpected path |
774a7993 | 502 | throw new ExecutionException(Messages.TraceControl_CommandError + " " + toCommandString(command) + "\n" + //$NON-NLS-1$ //$NON-NLS-2$ |
a30e79fe | 503 | Messages.TraceControl_UnexpectedPathError + ": " + name); //$NON-NLS-1$ |
f3b33d40 | 504 | } |
d128c979 | 505 | |
f7d4d450 | 506 | if (sessionInfo.isSnapshotSession()) { |
589d0d33 BH |
507 | // Make it a snapshot session - content of snapshot info need to |
508 | // set afterwards using getSession() or getSnapshotInfo() | |
509 | sessionInfo.setSnapshotInfo(new SnapshotInfo("")); //$NON-NLS-1$ | |
510 | } else { | |
511 | sessionInfo.setSessionPath(path); | |
512 | } | |
f3b33d40 BH |
513 | |
514 | return sessionInfo; | |
515 | ||
516 | } | |
517 | ||
67f8cadd | 518 | /** |
4f9e6a03 JRJ |
519 | * Basic generation of command for session creation |
520 | * | |
67f8cadd | 521 | * @param sessionInfo |
4f9e6a03 JRJ |
522 | * the session to create |
523 | * @return the basic command for command creation | |
67f8cadd | 524 | */ |
13729cbc | 525 | protected @NonNull List<String> prepareSessionCreationCommand(ISessionInfo sessionInfo) { |
774a7993 BH |
526 | List<String> command = createCommand(LTTngControlServiceConstants.COMMAND_CREATE_SESSION); |
527 | if (!sessionInfo.getName().isEmpty()) { | |
528 | command.add(sessionInfo.getName()); | |
529 | } | |
f3b33d40 | 530 | |
774a7993 | 531 | String newPath = sessionInfo.getSessionPath(); |
67f8cadd | 532 | if (newPath != null && !"".equals(newPath)) { //$NON-NLS-1$ |
774a7993 BH |
533 | command.add(LTTngControlServiceConstants.OPTION_OUTPUT_PATH); |
534 | command.add(newPath); | |
67f8cadd JRJ |
535 | } |
536 | ||
f7d4d450 | 537 | if (sessionInfo.isSnapshotSession()) { |
774a7993 | 538 | command.add(LTTngControlServiceConstants.OPTION_SNAPSHOT); |
589d0d33 | 539 | } |
67f8cadd JRJ |
540 | return command; |
541 | } | |
589d0d33 | 542 | |
67f8cadd | 543 | private ISessionInfo createStreamedSession(ISessionInfo sessionInfo, IProgressMonitor monitor) throws ExecutionException { |
f3b33d40 | 544 | |
13729cbc | 545 | @NonNull List<String> command = prepareStreamedSessionCreationCommand(sessionInfo); |
f3b33d40 | 546 | |
774a7993 | 547 | ICommandResult result = executeCommand(command, monitor); |
f3b33d40 | 548 | |
d128c979 | 549 | // Verify output |
f3b33d40 BH |
550 | String[] output = result.getOutput(); |
551 | ||
d128c979 | 552 | // Get and session name and path |
f3b33d40 | 553 | String name = null; |
d128c979 | 554 | String path = null; |
cfdb727a | 555 | |
d128c979 BH |
556 | int index = 0; |
557 | while (index < output.length) { | |
558 | String line = output[index]; | |
559 | Matcher nameMatcher = LTTngControlServiceConstants.CREATE_SESSION_NAME_PATTERN.matcher(line); | |
560 | Matcher pathMatcher = LTTngControlServiceConstants.CREATE_SESSION_PATH_PATTERN.matcher(line); | |
561 | ||
562 | if (nameMatcher.matches()) { | |
563 | name = String.valueOf(nameMatcher.group(1).trim()); | |
f7d4d450 | 564 | } else if (pathMatcher.matches() && (sessionInfo.getNetworkUrl() != null)) { |
d128c979 BH |
565 | path = String.valueOf(pathMatcher.group(1).trim()); |
566 | } | |
567 | index++; | |
568 | } | |
569 | ||
570 | // Verify session name | |
f7d4d450 | 571 | if ((name == null) || (!"".equals(sessionInfo.getName()) && !name.equals(sessionInfo.getName()))) { //$NON-NLS-1$ |
d128c979 | 572 | // Unexpected name returned |
774a7993 | 573 | throw new ExecutionException(Messages.TraceControl_CommandError + " " + toCommandString(command) + "\n" + //$NON-NLS-1$ //$NON-NLS-2$ |
d128c979 | 574 | Messages.TraceControl_UnexpectedNameError + ": " + name); //$NON-NLS-1$ |
bbb3538a | 575 | } |
cfdb727a | 576 | |
f7d4d450 | 577 | sessionInfo.setName(name); |
f3b33d40 | 578 | |
d128c979 BH |
579 | sessionInfo.setStreamedTrace(true); |
580 | ||
581 | // Verify session path | |
f7d4d450 MAL |
582 | if (sessionInfo.getNetworkUrl() != null) { |
583 | if (!sessionInfo.isSnapshotSession() && (path == null)) { | |
f3b33d40 | 584 | // Unexpected path |
774a7993 | 585 | throw new ExecutionException(Messages.TraceControl_CommandError + " " + toCommandString(command) + "\n" + //$NON-NLS-1$ //$NON-NLS-2$ |
f3b33d40 BH |
586 | Messages.TraceControl_UnexpectedPathError + ": " + name); //$NON-NLS-1$ |
587 | } | |
d128c979 | 588 | |
f7d4d450 | 589 | if (sessionInfo.isSnapshotSession()) { |
d128c979 | 590 | sessionInfo.setStreamedTrace(false); |
589d0d33 BH |
591 | } else { |
592 | sessionInfo.setSessionPath(path); | |
593 | // Check file protocol | |
594 | Matcher matcher = LTTngControlServiceConstants.TRACE_FILE_PROTOCOL_PATTERN.matcher(path); | |
595 | if (matcher.matches()) { | |
596 | sessionInfo.setStreamedTrace(false); | |
597 | } | |
d128c979 | 598 | } |
f3b33d40 | 599 | } |
589d0d33 | 600 | |
517c0261 JRJ |
601 | // When using controlUrl and dataUrl the full session path is not known |
602 | // yet and will be set later on when listing the session | |
bbb3538a BH |
603 | |
604 | return sessionInfo; | |
605 | } | |
cfdb727a | 606 | |
67f8cadd | 607 | /** |
4f9e6a03 JRJ |
608 | * Basic generation of command for streamed session creation |
609 | * | |
67f8cadd | 610 | * @param sessionInfo |
4f9e6a03 JRJ |
611 | * the session to create |
612 | * @return the basic command for command creation | |
67f8cadd | 613 | */ |
13729cbc | 614 | protected @NonNull List<String> prepareStreamedSessionCreationCommand(ISessionInfo sessionInfo) { |
774a7993 BH |
615 | List<String> command = createCommand(LTTngControlServiceConstants.COMMAND_CREATE_SESSION); |
616 | if (!sessionInfo.getName().isEmpty()) { | |
617 | command.add(sessionInfo.getName()); | |
618 | } | |
67f8cadd JRJ |
619 | |
620 | if (sessionInfo.isSnapshotSession()) { | |
774a7993 | 621 | command.add(LTTngControlServiceConstants.OPTION_SNAPSHOT); |
67f8cadd | 622 | } else if (sessionInfo.isLive()) { |
774a7993 | 623 | command.add(LTTngControlServiceConstants.OPTION_LIVE); |
67f8cadd | 624 | if (sessionInfo.getLiveDelay() != LTTngControlServiceConstants.UNUSED_VALUE) { |
774a7993 | 625 | command.add(String.valueOf(sessionInfo.getLiveDelay())); |
67f8cadd JRJ |
626 | } |
627 | } | |
628 | ||
629 | if (sessionInfo.getNetworkUrl() != null) { | |
774a7993 BH |
630 | command.add(LTTngControlServiceConstants.OPTION_NETWORK_URL); |
631 | command.add(sessionInfo.getNetworkUrl()); | |
67f8cadd | 632 | } else { |
774a7993 BH |
633 | command.add(LTTngControlServiceConstants.OPTION_CONTROL_URL); |
634 | command.add(sessionInfo.getControlUrl()); | |
67f8cadd | 635 | |
774a7993 BH |
636 | command.add(LTTngControlServiceConstants.OPTION_DATA_URL); |
637 | command.add(sessionInfo.getDataUrl()); | |
67f8cadd JRJ |
638 | } |
639 | return command; | |
640 | } | |
641 | ||
bbb3538a BH |
642 | @Override |
643 | public void destroySession(String sessionName, IProgressMonitor monitor) throws ExecutionException { | |
bbb3538a | 644 | |
774a7993 | 645 | List<String> command = createCommand(LTTngControlServiceConstants.COMMAND_DESTROY_SESSION, sessionName); |
afe13e7a | 646 | |
774a7993 | 647 | ICommandResult result = executeCommand(command, monitor, false); |
d128c979 | 648 | boolean isError = isError(result); |
13729cbc BH |
649 | if (isError && !ignoredPattern(result.getErrorOutput(), LTTngControlServiceConstants.SESSION_NOT_FOUND_ERROR_PATTERN)) { |
650 | throw new ExecutionException(Messages.TraceControl_CommandError + " " + toCommandString(command) + "\n" + result.toString()); //$NON-NLS-1$ //$NON-NLS-2$ | |
d128c979 BH |
651 | } |
652 | ||
517c0261 | 653 | // Session <sessionName> destroyed |
bbb3538a | 654 | } |
cfdb727a | 655 | |
bbb3538a BH |
656 | @Override |
657 | public void startSession(String sessionName, IProgressMonitor monitor) throws ExecutionException { | |
658 | ||
774a7993 | 659 | List<String> command = createCommand(LTTngControlServiceConstants.COMMAND_START_SESSION, sessionName); |
bbb3538a | 660 | |
774a7993 | 661 | executeCommand(command, monitor); |
bbb3538a | 662 | |
517c0261 | 663 | // Session <sessionName> started |
bbb3538a BH |
664 | } |
665 | ||
bbb3538a BH |
666 | @Override |
667 | public void stopSession(String sessionName, IProgressMonitor monitor) throws ExecutionException { | |
774a7993 | 668 | List<String> command = createCommand(LTTngControlServiceConstants.COMMAND_STOP_SESSION, sessionName); |
bbb3538a | 669 | |
774a7993 | 670 | executeCommand(command, monitor); |
bbb3538a | 671 | |
517c0261 | 672 | // Session <sessionName> stopped |
cfdb727a | 673 | |
bbb3538a | 674 | } |
cfdb727a | 675 | |
bbb3538a | 676 | @Override |
498704b3 | 677 | public void enableChannels(String sessionName, List<String> channelNames, boolean isKernel, IChannelInfo info, IProgressMonitor monitor) throws ExecutionException { |
bbb3538a BH |
678 | |
679 | // no channels to enable | |
c56972bb | 680 | if (channelNames.isEmpty()) { |
bbb3538a BH |
681 | return; |
682 | } | |
683 | ||
774a7993 | 684 | List<String> command = createCommand(LTTngControlServiceConstants.COMMAND_ENABLE_CHANNEL); |
bbb3538a | 685 | |
774a7993 | 686 | command.add(toCsv(channelNames)); |
bbb3538a BH |
687 | |
688 | if (isKernel) { | |
774a7993 | 689 | command.add(LTTngControlServiceConstants.OPTION_KERNEL); |
bbb3538a | 690 | } else { |
774a7993 | 691 | command.add(LTTngControlServiceConstants.OPTION_UST); |
bbb3538a BH |
692 | } |
693 | ||
774a7993 BH |
694 | command.add(LTTngControlServiceConstants.OPTION_SESSION); |
695 | command.add(sessionName); | |
bbb3538a BH |
696 | |
697 | if (info != null) { | |
517c0261 | 698 | // --discard Discard event when buffers are full (default) |
bbb3538a | 699 | |
517c0261 | 700 | // --overwrite Flight recorder mode |
bbb3538a | 701 | if (info.isOverwriteMode()) { |
774a7993 | 702 | command.add(LTTngControlServiceConstants.OPTION_OVERWRITE); |
bbb3538a | 703 | } |
517c0261 JRJ |
704 | // --subbuf-size SIZE Subbuffer size in bytes |
705 | // (default: 4096, kernel default: 262144) | |
e799e5f3 | 706 | if (info.getSubBufferSize() != LTTngControlServiceConstants.UNUSED_VALUE) { |
774a7993 BH |
707 | command.add(LTTngControlServiceConstants.OPTION_SUB_BUFFER_SIZE); |
708 | command.add(String.valueOf(info.getSubBufferSize())); | |
e799e5f3 | 709 | } |
bbb3538a | 710 | |
517c0261 | 711 | // --num-subbuf NUM Number of subbufers |
e799e5f3 | 712 | if (info.getNumberOfSubBuffers() != LTTngControlServiceConstants.UNUSED_VALUE) { |
774a7993 BH |
713 | command.add(LTTngControlServiceConstants.OPTION_NUM_SUB_BUFFERS); |
714 | command.add(String.valueOf(info.getNumberOfSubBuffers())); | |
e799e5f3 SD |
715 | } |
716 | ||
517c0261 | 717 | // --switch-timer USEC Switch timer interval in usec |
e799e5f3 | 718 | if (info.getSwitchTimer() != LTTngControlServiceConstants.UNUSED_VALUE) { |
774a7993 BH |
719 | command.add(LTTngControlServiceConstants.OPTION_SWITCH_TIMER); |
720 | command.add(String.valueOf(info.getSwitchTimer())); | |
e799e5f3 | 721 | } |
cfdb727a | 722 | |
517c0261 | 723 | // --read-timer USEC Read timer interval in usec |
e799e5f3 | 724 | if (info.getReadTimer() != LTTngControlServiceConstants.UNUSED_VALUE) { |
774a7993 BH |
725 | command.add(LTTngControlServiceConstants.OPTION_READ_TIMER); |
726 | command.add(String.valueOf(info.getReadTimer())); | |
e799e5f3 | 727 | } |
bbb3538a | 728 | |
e799e5f3 | 729 | if (isVersionSupported("2.2.0")) { //$NON-NLS-1$ |
517c0261 JRJ |
730 | // --buffers-uid Every application sharing the same UID use the |
731 | // same buffers --buffers-pid Buffers are allocated per PID | |
83051fc3 BH |
732 | if (!isKernel) { |
733 | if (info.getBufferType() == BufferType.BUFFER_PER_PID) { | |
774a7993 | 734 | command.add(LTTngControlServiceConstants.OPTION_PER_PID_BUFFERS); |
83051fc3 BH |
735 | |
736 | } else if (info.getBufferType() == BufferType.BUFFER_PER_UID) { | |
774a7993 | 737 | command.add(LTTngControlServiceConstants.OPTION_PER_UID_BUFFERS); |
83051fc3 | 738 | } |
e799e5f3 SD |
739 | } |
740 | ||
517c0261 | 741 | // -C SIZE Maximum size of trace files in bytes |
e799e5f3 | 742 | if (info.getMaxSizeTraceFiles() != LTTngControlServiceConstants.UNUSED_VALUE) { |
774a7993 BH |
743 | command.add(LTTngControlServiceConstants.OPTION_MAX_SIZE_TRACE_FILES); |
744 | command.add(String.valueOf(info.getMaxSizeTraceFiles())); | |
e799e5f3 SD |
745 | } |
746 | ||
517c0261 | 747 | // -W NUM Maximum number of trace files |
e799e5f3 | 748 | if (info.getMaxNumberTraceFiles() != LTTngControlServiceConstants.UNUSED_VALUE) { |
774a7993 BH |
749 | command.add(LTTngControlServiceConstants.OPTION_MAX_TRACE_FILES); |
750 | command.add(String.valueOf(info.getMaxNumberTraceFiles())); | |
e799e5f3 SD |
751 | } |
752 | } | |
cfdb727a | 753 | } |
bbb3538a | 754 | |
774a7993 | 755 | executeCommand(command, monitor); |
cfdb727a | 756 | |
bbb3538a BH |
757 | } |
758 | ||
bbb3538a | 759 | @Override |
498704b3 | 760 | public void disableChannels(String sessionName, List<String> channelNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException { |
cfdb727a | 761 | |
bbb3538a | 762 | // no channels to enable |
c56972bb | 763 | if (channelNames.isEmpty()) { |
bbb3538a BH |
764 | return; |
765 | } | |
766 | ||
774a7993 | 767 | List<String> command = createCommand(LTTngControlServiceConstants.COMMAND_DISABLE_CHANNEL); |
bbb3538a | 768 | |
774a7993 | 769 | command.add(toCsv(channelNames)); |
bbb3538a BH |
770 | |
771 | if (isKernel) { | |
774a7993 | 772 | command.add(LTTngControlServiceConstants.OPTION_KERNEL); |
6503ae0f | 773 | } else { |
774a7993 | 774 | command.add(LTTngControlServiceConstants.OPTION_UST); |
6503ae0f BH |
775 | } |
776 | ||
774a7993 BH |
777 | command.add(LTTngControlServiceConstants.OPTION_SESSION); |
778 | command.add(sessionName); | |
6503ae0f | 779 | |
774a7993 | 780 | executeCommand(command, monitor); |
6503ae0f | 781 | } |
cfdb727a | 782 | |
6503ae0f | 783 | @Override |
d4514365 | 784 | public void enableEvents(String sessionName, String channelName, List<String> eventNames, boolean isKernel, String filterExpression, IProgressMonitor monitor) throws ExecutionException { |
6503ae0f | 785 | |
774a7993 | 786 | List<String> command = createCommand(LTTngControlServiceConstants.COMMAND_ENABLE_EVENT); |
6503ae0f | 787 | |
c56972bb | 788 | if (eventNames == null || eventNames.isEmpty()) { |
774a7993 | 789 | command.add(LTTngControlServiceConstants.OPTION_ALL); |
3e91c9c0 | 790 | } else { |
774a7993 | 791 | command.add(toCsv(eventNames)); |
6503ae0f BH |
792 | } |
793 | ||
794 | if (isKernel) { | |
774a7993 | 795 | command.add(LTTngControlServiceConstants.OPTION_KERNEL); |
bbb3538a | 796 | } else { |
774a7993 | 797 | command.add(LTTngControlServiceConstants.OPTION_UST); |
bbb3538a BH |
798 | } |
799 | ||
774a7993 BH |
800 | command.add(LTTngControlServiceConstants.OPTION_SESSION); |
801 | command.add(sessionName); | |
bbb3538a | 802 | |
6503ae0f | 803 | if (channelName != null) { |
774a7993 BH |
804 | command.add(LTTngControlServiceConstants.OPTION_CHANNEL); |
805 | command.add(channelName); | |
6503ae0f | 806 | } |
cfdb727a | 807 | |
774a7993 | 808 | command.add(LTTngControlServiceConstants.OPTION_TRACEPOINT); |
cfdb727a | 809 | |
d4514365 | 810 | if (filterExpression != null) { |
774a7993 BH |
811 | command.add(LTTngControlServiceConstants.OPTION_FILTER); |
812 | command.add(filterExpression); | |
d4514365 BH |
813 | } |
814 | ||
774a7993 | 815 | executeCommand(command, monitor); |
cfdb727a | 816 | |
498704b3 | 817 | } |
6503ae0f | 818 | |
498704b3 BH |
819 | @Override |
820 | public void enableSyscalls(String sessionName, String channelName, IProgressMonitor monitor) throws ExecutionException { | |
afe13e7a | 821 | |
774a7993 | 822 | List<String> command = createCommand(LTTngControlServiceConstants.COMMAND_ENABLE_EVENT); |
498704b3 | 823 | |
774a7993 BH |
824 | command.add(LTTngControlServiceConstants.OPTION_ALL); |
825 | command.add(LTTngControlServiceConstants.OPTION_KERNEL); | |
498704b3 | 826 | |
afe13e7a | 827 | |
774a7993 BH |
828 | command.add(LTTngControlServiceConstants.OPTION_SESSION); |
829 | command.add(sessionName); | |
498704b3 BH |
830 | |
831 | if (channelName != null) { | |
774a7993 BH |
832 | command.add(LTTngControlServiceConstants.OPTION_CHANNEL); |
833 | command.add(channelName); | |
498704b3 | 834 | } |
cfdb727a | 835 | |
774a7993 | 836 | command.add(LTTngControlServiceConstants.OPTION_SYSCALL); |
cfdb727a | 837 | |
774a7993 | 838 | executeCommand(command, monitor); |
498704b3 | 839 | } |
cfdb727a | 840 | |
498704b3 | 841 | @Override |
d132bcc7 | 842 | public void enableProbe(String sessionName, String channelName, String eventName, boolean isFunction, String probe, IProgressMonitor monitor) throws ExecutionException { |
774a7993 | 843 | List<String> command = createCommand(LTTngControlServiceConstants.COMMAND_ENABLE_EVENT); |
498704b3 | 844 | |
774a7993 BH |
845 | command.add(eventName); |
846 | command.add(LTTngControlServiceConstants.OPTION_KERNEL); | |
498704b3 | 847 | |
774a7993 BH |
848 | command.add(LTTngControlServiceConstants.OPTION_SESSION); |
849 | command.add(sessionName); | |
498704b3 BH |
850 | |
851 | if (channelName != null) { | |
774a7993 BH |
852 | command.add(LTTngControlServiceConstants.OPTION_CHANNEL); |
853 | command.add(channelName); | |
bbb3538a | 854 | } |
d132bcc7 | 855 | if (isFunction) { |
774a7993 | 856 | command.add(LTTngControlServiceConstants.OPTION_FUNCTION_PROBE); |
d132bcc7 | 857 | } else { |
774a7993 | 858 | command.add(LTTngControlServiceConstants.OPTION_PROBE); |
498704b3 | 859 | } |
cfdb727a | 860 | |
774a7993 | 861 | command.add(probe); |
cfdb727a | 862 | |
774a7993 | 863 | executeCommand(command, monitor); |
498704b3 | 864 | } |
ccc66d01 | 865 | |
ccc66d01 | 866 | @Override |
d4514365 | 867 | public void enableLogLevel(String sessionName, String channelName, String eventName, LogLevelType logLevelType, TraceLogLevel level, String filterExpression, IProgressMonitor monitor) throws ExecutionException { |
774a7993 | 868 | List<String> command = createCommand(LTTngControlServiceConstants.COMMAND_ENABLE_EVENT); |
ccc66d01 | 869 | |
774a7993 BH |
870 | command.add(eventName); |
871 | command.add(LTTngControlServiceConstants.OPTION_UST); | |
ccc66d01 | 872 | |
774a7993 BH |
873 | command.add(LTTngControlServiceConstants.OPTION_SESSION); |
874 | command.add(sessionName); | |
ccc66d01 BH |
875 | |
876 | if (channelName != null) { | |
774a7993 BH |
877 | command.add(LTTngControlServiceConstants.OPTION_CHANNEL); |
878 | command.add(channelName); | |
ccc66d01 | 879 | } |
cfdb727a | 880 | |
ccc66d01 | 881 | if (logLevelType == LogLevelType.LOGLEVEL) { |
774a7993 | 882 | command.add(LTTngControlServiceConstants.OPTION_LOGLEVEL); |
ccc66d01 | 883 | } else if (logLevelType == LogLevelType.LOGLEVEL_ONLY) { |
774a7993 | 884 | command.add(LTTngControlServiceConstants.OPTION_LOGLEVEL_ONLY); |
cfdb727a | 885 | |
ccc66d01 BH |
886 | } else { |
887 | return; | |
888 | } | |
774a7993 | 889 | command.add(level.getInName()); |
cfdb727a | 890 | |
774a7993 | 891 | executeCommand(command, monitor); |
ccc66d01 BH |
892 | } |
893 | ||
6503ae0f BH |
894 | @Override |
895 | public void disableEvent(String sessionName, String channelName, List<String> eventNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException { | |
774a7993 | 896 | List<String> command = createCommand(LTTngControlServiceConstants.COMMAND_DISABLE_EVENT); |
6503ae0f | 897 | |
3e91c9c0 | 898 | if (eventNames == null) { |
774a7993 | 899 | command.add(LTTngControlServiceConstants.OPTION_ALL); |
3e91c9c0 | 900 | } else { |
7a6e4bfd | 901 | // no events to disable |
c56972bb | 902 | if (eventNames.isEmpty()) { |
3e91c9c0 BH |
903 | return; |
904 | } | |
6503ae0f | 905 | |
7a6e4bfd | 906 | StringBuffer eventNameParameter = new StringBuffer(); |
3e91c9c0 | 907 | for (Iterator<String> iterator = eventNames.iterator(); iterator.hasNext();) { |
cfdb727a | 908 | String event = iterator.next(); |
7a6e4bfd | 909 | eventNameParameter.append(event); |
3e91c9c0 | 910 | if (iterator.hasNext()) { |
7a6e4bfd | 911 | eventNameParameter.append(','); |
3e91c9c0 | 912 | } |
6503ae0f | 913 | } |
774a7993 | 914 | command.add(eventNameParameter.toString()); |
6503ae0f BH |
915 | } |
916 | ||
917 | if (isKernel) { | |
774a7993 | 918 | command.add(LTTngControlServiceConstants.OPTION_KERNEL); |
6503ae0f | 919 | } else { |
774a7993 | 920 | command.add(LTTngControlServiceConstants.OPTION_UST); |
6503ae0f BH |
921 | } |
922 | ||
774a7993 BH |
923 | command.add(LTTngControlServiceConstants.OPTION_SESSION); |
924 | command.add(sessionName); | |
6503ae0f BH |
925 | |
926 | if (channelName != null) { | |
774a7993 BH |
927 | command.add(LTTngControlServiceConstants.OPTION_CHANNEL); |
928 | command.add(channelName); | |
6503ae0f BH |
929 | } |
930 | ||
774a7993 | 931 | executeCommand(command, monitor); |
6503ae0f | 932 | } |
b793fbe1 | 933 | |
b793fbe1 BH |
934 | @Override |
935 | public List<String> getContextList(IProgressMonitor monitor) throws ExecutionException { | |
936 | ||
774a7993 | 937 | List<String> command = createCommand(LTTngControlServiceConstants.COMMAND_ADD_CONTEXT, LTTngControlServiceConstants.OPTION_HELP); |
b793fbe1 | 938 | |
774a7993 | 939 | ICommandResult result = executeCommand(command, monitor); |
b793fbe1 | 940 | |
cfdb727a AM |
941 | String[] output = result.getOutput(); |
942 | ||
e0838ca1 | 943 | List<String> contexts = new ArrayList<>(0); |
cfdb727a | 944 | |
b793fbe1 BH |
945 | int index = 0; |
946 | boolean inList = false; | |
947 | while (index < output.length) { | |
948 | String line = result.getOutput()[index]; | |
cfdb727a | 949 | |
276c17e7 BH |
950 | Matcher startMatcher = LTTngControlServiceConstants.ADD_CONTEXT_HELP_CONTEXTS_INTRO.matcher(line); |
951 | Matcher endMatcher = LTTngControlServiceConstants.ADD_CONTEXT_HELP_CONTEXTS_END_LINE.matcher(line); | |
b793fbe1 BH |
952 | |
953 | if (startMatcher.matches()) { | |
954 | inList = true; | |
955 | } else if (endMatcher.matches()) { | |
956 | break; | |
957 | } else if (inList == true) { | |
958 | String[] tmp = line.split(","); //$NON-NLS-1$ | |
959 | for (int i = 0; i < tmp.length; i++) { | |
960 | contexts.add(tmp[i].trim()); | |
961 | } | |
962 | } | |
963 | index++; | |
964 | } | |
965 | return contexts; | |
966 | } | |
967 | ||
b793fbe1 BH |
968 | @Override |
969 | public void addContexts(String sessionName, String channelName, String eventName, boolean isKernel, List<String> contextNames, IProgressMonitor monitor) throws ExecutionException { | |
774a7993 | 970 | List<String> command = createCommand(LTTngControlServiceConstants.COMMAND_ADD_CONTEXT); |
b793fbe1 | 971 | |
774a7993 BH |
972 | command.add(LTTngControlServiceConstants.OPTION_SESSION); |
973 | command.add(sessionName); | |
cfdb727a | 974 | |
b793fbe1 | 975 | if (channelName != null) { |
774a7993 BH |
976 | command.add(LTTngControlServiceConstants.OPTION_CHANNEL); |
977 | command.add(channelName); | |
b793fbe1 BH |
978 | } |
979 | ||
980 | if (eventName != null) { | |
774a7993 BH |
981 | command.add(LTTngControlServiceConstants.OPTION_EVENT); |
982 | command.add(eventName); | |
b793fbe1 BH |
983 | } |
984 | ||
985 | if (isKernel) { | |
774a7993 | 986 | command.add(LTTngControlServiceConstants.OPTION_KERNEL); |
b793fbe1 | 987 | } else { |
774a7993 | 988 | command.add(LTTngControlServiceConstants.OPTION_UST); |
b793fbe1 | 989 | } |
cfdb727a | 990 | |
b793fbe1 | 991 | for (Iterator<String> iterator = contextNames.iterator(); iterator.hasNext();) { |
cfdb727a | 992 | String context = iterator.next(); |
774a7993 BH |
993 | command.add(LTTngControlServiceConstants.OPTION_CONTEXT_TYPE); |
994 | command.add(context); | |
b793fbe1 BH |
995 | } |
996 | ||
774a7993 | 997 | executeCommand(command, monitor); |
cfdb727a | 998 | |
b793fbe1 BH |
999 | } |
1000 | ||
b720ac44 BH |
1001 | @Override |
1002 | public void calibrate(boolean isKernel, IProgressMonitor monitor) throws ExecutionException { | |
774a7993 | 1003 | List<String> command = createCommand(LTTngControlServiceConstants.COMMAND_CALIBRATE); |
b720ac44 BH |
1004 | |
1005 | if (isKernel) { | |
774a7993 | 1006 | command.add(LTTngControlServiceConstants.OPTION_KERNEL); |
b720ac44 | 1007 | } else { |
774a7993 | 1008 | command.add(LTTngControlServiceConstants.OPTION_UST); |
b720ac44 BH |
1009 | } |
1010 | ||
774a7993 | 1011 | command.add(LTTngControlServiceConstants.OPTION_FUNCTION_PROBE); |
b720ac44 | 1012 | |
774a7993 | 1013 | executeCommand(command, monitor); |
b720ac44 | 1014 | } |
cfdb727a | 1015 | |
589d0d33 BH |
1016 | @Override |
1017 | public void recordSnapshot(String sessionName, IProgressMonitor monitor) | |
1018 | throws ExecutionException { | |
774a7993 | 1019 | List<String> command = createCommand(LTTngControlServiceConstants.COMMAND_SNAPSHOT, LTTngControlServiceConstants.COMMAND_RECORD_SNAPSHOT); |
589d0d33 | 1020 | |
774a7993 BH |
1021 | String newSessionName = sessionName; |
1022 | command.add(LTTngControlServiceConstants.OPTION_SESSION); | |
1023 | command.add(newSessionName); | |
589d0d33 | 1024 | |
774a7993 | 1025 | executeCommand(command, monitor); |
589d0d33 BH |
1026 | } |
1027 | ||
64a37b87 | 1028 | @Override |
774a7993 BH |
1029 | public void runCommands(IProgressMonitor monitor, List<String> commandLines) throws ExecutionException { |
1030 | for (String commandLine : commandLines) { | |
64a37b87 BH |
1031 | if (monitor.isCanceled()) { |
1032 | return; | |
1033 | } | |
1034 | ||
774a7993 | 1035 | if (commandLine.isEmpty() || commandLine.startsWith("#")) { //$NON-NLS-1$ |
64a37b87 BH |
1036 | continue; |
1037 | } | |
774a7993 | 1038 | String[] args = commandLine.split("\\s+"); //$NON-NLS-1$ |
13729cbc | 1039 | List<String> command = checkNotNull(Arrays.asList(args)); |
774a7993 BH |
1040 | ICommandResult result = executeCommand(command, monitor); |
1041 | ||
1042 | if (isError(result)) { | |
13729cbc | 1043 | throw new ExecutionException(Messages.TraceControl_CommandError + " " + toCommandString(command) + "\n" + result.toString()); //$NON-NLS-1$ //$NON-NLS-2$ |
774a7993 | 1044 | } |
64a37b87 BH |
1045 | } |
1046 | } | |
1047 | ||
eb1bab5b BH |
1048 | // ------------------------------------------------------------------------ |
1049 | // Helper methods | |
1050 | // ------------------------------------------------------------------------ | |
11252342 | 1051 | |
eb1bab5b BH |
1052 | /** |
1053 | * Checks if command result is an error result. | |
cfdb727a | 1054 | * |
4775bcbf BH |
1055 | * @param result |
1056 | * - the command result to check | |
eb1bab5b BH |
1057 | * @return true if error else false |
1058 | */ | |
276c17e7 | 1059 | protected boolean isError(ICommandResult result) { |
d128c979 | 1060 | // Check return code and length of returned strings |
6418ef54 JRJ |
1061 | |
1062 | if ((result.getResult()) != 0) { | |
eb1bab5b BH |
1063 | return true; |
1064 | } | |
d128c979 BH |
1065 | |
1066 | // Look for error pattern | |
1067 | int index = 0; | |
6418ef54 JRJ |
1068 | while (index < result.getErrorOutput().length) { |
1069 | String line = result.getErrorOutput()[index]; | |
d128c979 BH |
1070 | Matcher matcher = LTTngControlServiceConstants.ERROR_PATTERN.matcher(line); |
1071 | if (matcher.matches()) { | |
1072 | return true; | |
1073 | } | |
1074 | index++; | |
1075 | } | |
1076 | ||
eb1bab5b BH |
1077 | return false; |
1078 | } | |
4775bcbf | 1079 | |
774a7993 BH |
1080 | /** |
1081 | * Creates a single command string from a command line list. | |
1082 | * @param command | |
1083 | * command line list | |
1084 | * @return single command string | |
1085 | */ | |
1086 | public static String toCommandString(List<String> command) { | |
1087 | StringBuilder builder = new StringBuilder(); | |
1088 | for (String segment : command) { | |
1089 | builder.append(segment).append(' '); | |
1090 | } | |
1091 | return builder.toString().trim(); | |
1092 | } | |
1093 | ||
1094 | /** | |
1095 | * Creates a comma separated string from list of names | |
1096 | * @param names | |
1097 | * List of name to convert | |
1098 | * @return comma separated string | |
1099 | */ | |
1100 | protected String toCsv(List<String> names) { | |
1101 | StringBuilder csvString = new StringBuilder(); | |
1102 | for (Iterator<String> iterator = names.iterator(); iterator.hasNext();) { | |
1103 | String name = iterator.next(); | |
1104 | csvString.append(name); | |
1105 | if (iterator.hasNext()) { | |
1106 | csvString.append(','); | |
1107 | } | |
1108 | } | |
1109 | return csvString.toString(); | |
1110 | } | |
1111 | ||
eb1bab5b BH |
1112 | /** |
1113 | * Parses the domain information. | |
cfdb727a | 1114 | * |
4775bcbf BH |
1115 | * @param output |
1116 | * - a command output array | |
1117 | * @param currentIndex | |
1118 | * - current index in command output array | |
1119 | * @param channels | |
1120 | * - list for returning channel information | |
ca8c54b3 SD |
1121 | * @param domainInfo |
1122 | * - The domain information | |
4775bcbf | 1123 | * @return the new current index in command output array |
eb1bab5b | 1124 | */ |
ca8c54b3 | 1125 | protected int parseDomain(String[] output, int currentIndex, List<IChannelInfo> channels, IDomainInfo domainInfo) { |
eb1bab5b BH |
1126 | int index = currentIndex; |
1127 | ||
83051fc3 BH |
1128 | // if kernel set the buffer type to shared |
1129 | if (domainInfo.isKernel()) { | |
1130 | domainInfo.setBufferType(BufferType.BUFFER_SHARED); | |
1131 | } | |
1132 | ||
4775bcbf BH |
1133 | // Channels: |
1134 | // ------------- | |
1135 | // - channnel1: [enabled] | |
1136 | // | |
1137 | // Attributes: | |
1138 | // overwrite mode: 0 | |
1139 | // subbufers size: 262144 | |
1140 | // number of subbufers: 4 | |
1141 | // switch timer interval: 0 | |
1142 | // read timer interval: 200 | |
1143 | // output: splice() | |
1144 | ||
eb1bab5b BH |
1145 | while (index < output.length) { |
1146 | String line = output[index]; | |
4775bcbf | 1147 | |
ca8c54b3 SD |
1148 | if (isVersionSupported("2.2.0")) { //$NON-NLS-1$ |
1149 | Matcher bufferTypeMatcher = LTTngControlServiceConstants.BUFFER_TYPE_PATTERN.matcher(line); | |
1150 | if (bufferTypeMatcher.matches()) { | |
83051fc3 BH |
1151 | String bufferTypeString = getAttributeValue(line); |
1152 | if (BufferType.BUFFER_PER_PID.getInName().equals(bufferTypeString)) { | |
1153 | domainInfo.setBufferType(BufferType.BUFFER_PER_PID); | |
1154 | } else if (BufferType.BUFFER_PER_UID.getInName().equals(bufferTypeString)) { | |
1155 | domainInfo.setBufferType(BufferType.BUFFER_PER_UID); | |
1156 | } else { | |
1157 | domainInfo.setBufferType(BufferType.BUFFER_TYPE_UNKNOWN); | |
1158 | } | |
ca8c54b3 SD |
1159 | } |
1160 | } else { | |
83051fc3 | 1161 | domainInfo.setBufferType(BufferType.BUFFER_TYPE_UNKNOWN); |
ca8c54b3 | 1162 | } |
276c17e7 | 1163 | Matcher outerMatcher = LTTngControlServiceConstants.CHANNELS_SECTION_PATTERN.matcher(line); |
a30e79fe BH |
1164 | Matcher noKernelChannelMatcher = LTTngControlServiceConstants.DOMAIN_NO_KERNEL_CHANNEL_PATTERN.matcher(line); |
1165 | Matcher noUstChannelMatcher = LTTngControlServiceConstants.DOMAIN_NO_UST_CHANNEL_PATTERN.matcher(line); | |
4775bcbf | 1166 | if (outerMatcher.matches()) { |
eb1bab5b BH |
1167 | IChannelInfo channelInfo = null; |
1168 | while (index < output.length) { | |
1169 | String subLine = output[index]; | |
4775bcbf | 1170 | |
276c17e7 | 1171 | Matcher innerMatcher = LTTngControlServiceConstants.CHANNEL_PATTERN.matcher(subLine); |
4775bcbf | 1172 | if (innerMatcher.matches()) { |
eb1bab5b | 1173 | channelInfo = new ChannelInfo(""); //$NON-NLS-1$ |
4775bcbf BH |
1174 | // get channel name |
1175 | channelInfo.setName(innerMatcher.group(1)); | |
1176 | ||
1177 | // get channel enablement | |
1178 | channelInfo.setState(innerMatcher.group(2)); | |
1179 | ||
83051fc3 BH |
1180 | // set BufferType |
1181 | channelInfo.setBufferType(domainInfo.getBufferType()); | |
1182 | ||
4775bcbf BH |
1183 | // add channel |
1184 | channels.add(channelInfo); | |
1185 | ||
276c17e7 | 1186 | } else if (LTTngControlServiceConstants.OVERWRITE_MODE_ATTRIBUTE.matcher(subLine).matches()) { |
eb1bab5b | 1187 | String value = getAttributeValue(subLine); |
64636df8 BH |
1188 | if (channelInfo != null) { |
1189 | channelInfo.setOverwriteMode(!LTTngControlServiceConstants.OVERWRITE_MODE_ATTRIBUTE_FALSE.equals(value)); | |
1190 | } | |
276c17e7 | 1191 | } else if (LTTngControlServiceConstants.SUBBUFFER_SIZE_ATTRIBUTE.matcher(subLine).matches()) { |
64636df8 BH |
1192 | if (channelInfo != null) { |
1193 | channelInfo.setSubBufferSize(Long.valueOf(getAttributeValue(subLine))); | |
1194 | } | |
4775bcbf | 1195 | |
276c17e7 | 1196 | } else if (LTTngControlServiceConstants.NUM_SUBBUFFERS_ATTRIBUTE.matcher(subLine).matches()) { |
64636df8 BH |
1197 | if (channelInfo != null) { |
1198 | channelInfo.setNumberOfSubBuffers(Integer.valueOf(getAttributeValue(subLine))); | |
1199 | } | |
4775bcbf | 1200 | |
276c17e7 | 1201 | } else if (LTTngControlServiceConstants.SWITCH_TIMER_ATTRIBUTE.matcher(subLine).matches()) { |
64636df8 BH |
1202 | if (channelInfo != null) { |
1203 | channelInfo.setSwitchTimer(Long.valueOf(getAttributeValue(subLine))); | |
1204 | } | |
4775bcbf | 1205 | |
276c17e7 | 1206 | } else if (LTTngControlServiceConstants.READ_TIMER_ATTRIBUTE.matcher(subLine).matches()) { |
64636df8 BH |
1207 | if (channelInfo != null) { |
1208 | channelInfo.setReadTimer(Long.valueOf(getAttributeValue(subLine))); | |
1209 | } | |
4775bcbf | 1210 | |
276c17e7 | 1211 | } else if (LTTngControlServiceConstants.OUTPUT_ATTRIBUTE.matcher(subLine).matches()) { |
64636df8 BH |
1212 | if (channelInfo != null) { |
1213 | channelInfo.setOutputType(getAttributeValue(subLine)); | |
1214 | } | |
4775bcbf | 1215 | |
276c17e7 | 1216 | } else if (LTTngControlServiceConstants.EVENT_SECTION_PATTERN.matcher(subLine).matches()) { |
e0838ca1 | 1217 | List<IEventInfo> events = new ArrayList<>(); |
eb1bab5b | 1218 | index = parseEvents(output, index, events); |
64636df8 BH |
1219 | if (channelInfo != null) { |
1220 | channelInfo.setEvents(events); | |
1221 | } | |
4775bcbf BH |
1222 | // we want to stay at the current index to be able to |
1223 | // exit the domain | |
eb1bab5b | 1224 | continue; |
276c17e7 | 1225 | } else if (LTTngControlServiceConstants.DOMAIN_KERNEL_PATTERN.matcher(subLine).matches()) { |
eb1bab5b BH |
1226 | return index; |
1227 | ||
276c17e7 | 1228 | } else if (LTTngControlServiceConstants.DOMAIN_UST_GLOBAL_PATTERN.matcher(subLine).matches()) { |
eb1bab5b BH |
1229 | return index; |
1230 | } | |
1231 | index++; | |
1232 | } | |
a30e79fe BH |
1233 | } else if (noKernelChannelMatcher.matches() || noUstChannelMatcher.matches()) { |
1234 | // domain indicates that no channels were found -> return | |
1235 | index++; | |
1236 | return index; | |
eb1bab5b BH |
1237 | } |
1238 | index++; | |
1239 | } | |
1240 | return index; | |
1241 | } | |
1242 | ||
1243 | /** | |
1244 | * Parses the event information within a domain. | |
cfdb727a | 1245 | * |
4775bcbf BH |
1246 | * @param output |
1247 | * - a command output array | |
1248 | * @param currentIndex | |
1249 | * - current index in command output array | |
1250 | * @param events | |
1251 | * - list for returning event information | |
eb1bab5b | 1252 | * @return the new current index in command output array |
eb1bab5b | 1253 | */ |
276c17e7 | 1254 | protected int parseEvents(String[] output, int currentIndex, List<IEventInfo> events) { |
eb1bab5b BH |
1255 | int index = currentIndex; |
1256 | ||
1257 | while (index < output.length) { | |
1258 | String line = output[index]; | |
276c17e7 | 1259 | if (LTTngControlServiceConstants.CHANNEL_PATTERN.matcher(line).matches()) { |
eb1bab5b BH |
1260 | // end of channel |
1261 | return index; | |
276c17e7 | 1262 | } else if (LTTngControlServiceConstants.DOMAIN_KERNEL_PATTERN.matcher(line).matches()) { |
eb1bab5b BH |
1263 | // end of domain |
1264 | return index; | |
276c17e7 | 1265 | } else if (LTTngControlServiceConstants.DOMAIN_UST_GLOBAL_PATTERN.matcher(line).matches()) { |
eb1bab5b BH |
1266 | // end of domain |
1267 | return index; | |
cfdb727a | 1268 | } |
4775bcbf | 1269 | |
276c17e7 BH |
1270 | Matcher matcher = LTTngControlServiceConstants.EVENT_PATTERN.matcher(line); |
1271 | Matcher matcher2 = LTTngControlServiceConstants.WILDCARD_EVENT_PATTERN.matcher(line); | |
4775bcbf BH |
1272 | |
1273 | if (matcher.matches()) { | |
1274 | IEventInfo eventInfo = new EventInfo(matcher.group(1).trim()); | |
54f2dcc0 BH |
1275 | eventInfo.setLogLevelType(matcher.group(2).trim()); |
1276 | eventInfo.setLogLevel(matcher.group(3).trim()); | |
1277 | eventInfo.setEventType(matcher.group(4).trim()); | |
1278 | eventInfo.setState(matcher.group(5)); | |
1279 | String filter = matcher.group(6); | |
d4514365 | 1280 | if (filter != null) { |
517c0261 JRJ |
1281 | // remove '[' and ']' |
1282 | filter = filter.substring(1, filter.length() - 1); | |
d4514365 BH |
1283 | eventInfo.setFilterExpression(filter); |
1284 | } | |
4775bcbf | 1285 | events.add(eventInfo); |
d132bcc7 | 1286 | index++; |
4775bcbf BH |
1287 | } else if (matcher2.matches()) { |
1288 | IEventInfo eventInfo = new EventInfo(matcher2.group(1).trim()); | |
1289 | eventInfo.setLogLevel(TraceLogLevel.LEVEL_UNKNOWN); | |
1290 | eventInfo.setEventType(matcher2.group(2).trim()); | |
1291 | eventInfo.setState(matcher2.group(3)); | |
d4514365 BH |
1292 | String filter = matcher2.group(4); |
1293 | if (filter != null) { | |
517c0261 JRJ |
1294 | // remove '[' and ']' |
1295 | filter = filter.substring(1, filter.length() - 1); | |
d4514365 BH |
1296 | eventInfo.setFilterExpression(filter); |
1297 | } | |
cfdb727a | 1298 | |
1f07c96c | 1299 | if ((eventInfo.getEventType() == TraceEventType.PROBE) || |
517c0261 | 1300 | (eventInfo.getEventType() == TraceEventType.FUNCTION)) { |
d132bcc7 BH |
1301 | IProbeEventInfo probeEvent = new ProbeEventInfo(eventInfo.getName()); |
1302 | probeEvent.setLogLevel(eventInfo.getLogLevel()); | |
1303 | probeEvent.setEventType(eventInfo.getEventType()); | |
1304 | probeEvent.setState(eventInfo.getState()); | |
1305 | ||
1306 | // Overwrite eventinfo | |
1307 | eventInfo = probeEvent; | |
1308 | ||
1309 | // myevent2 (type: probe) [enabled] | |
1310 | // addr: 0xc0101340 | |
1f07c96c | 1311 | // myevent0 (type: function) [enabled] |
d132bcc7 BH |
1312 | // offset: 0x0 |
1313 | // symbol: init_post | |
1314 | index++; | |
1315 | while (index < output.length) { | |
1316 | String probeLine = output[index]; | |
1317 | // parse probe | |
276c17e7 BH |
1318 | Matcher addrMatcher = LTTngControlServiceConstants.PROBE_ADDRESS_PATTERN.matcher(probeLine); |
1319 | Matcher offsetMatcher = LTTngControlServiceConstants.PROBE_OFFSET_PATTERN.matcher(probeLine); | |
1320 | Matcher symbolMatcher = LTTngControlServiceConstants.PROBE_SYMBOL_PATTERN.matcher(probeLine); | |
d132bcc7 BH |
1321 | if (addrMatcher.matches()) { |
1322 | String addr = addrMatcher.group(2).trim(); | |
1323 | probeEvent.setAddress(addr); | |
1324 | } else if (offsetMatcher.matches()) { | |
1325 | String offset = offsetMatcher.group(2).trim(); | |
1326 | probeEvent.setOffset(offset); | |
1327 | } else if (symbolMatcher.matches()) { | |
1328 | String symbol = symbolMatcher.group(2).trim(); | |
1329 | probeEvent.setSymbol(symbol); | |
276c17e7 | 1330 | } else if ((LTTngControlServiceConstants.EVENT_PATTERN.matcher(probeLine).matches()) || (LTTngControlServiceConstants.WILDCARD_EVENT_PATTERN.matcher(probeLine).matches())) { |
d132bcc7 | 1331 | break; |
276c17e7 | 1332 | } else if (LTTngControlServiceConstants.CHANNEL_PATTERN.matcher(probeLine).matches()) { |
d132bcc7 | 1333 | break; |
276c17e7 | 1334 | } else if (LTTngControlServiceConstants.DOMAIN_KERNEL_PATTERN.matcher(probeLine).matches()) { |
d132bcc7 BH |
1335 | // end of domain |
1336 | break; | |
276c17e7 | 1337 | } else if (LTTngControlServiceConstants.DOMAIN_UST_GLOBAL_PATTERN.matcher(probeLine).matches()) { |
d132bcc7 BH |
1338 | // end of domain |
1339 | break; | |
1340 | } | |
1341 | index++; | |
1342 | } | |
1343 | events.add(eventInfo); | |
1344 | } else { | |
1345 | events.add(eventInfo); | |
1346 | index++; | |
1347 | continue; | |
1348 | } | |
1349 | } else { | |
1350 | index++; | |
eb1bab5b | 1351 | } |
eb1bab5b BH |
1352 | } |
1353 | ||
1354 | return index; | |
1355 | } | |
1356 | ||
1357 | /** | |
1358 | * Parses a line with attributes: <attribute Name>: <attribute value> | |
cfdb727a | 1359 | * |
4775bcbf BH |
1360 | * @param line |
1361 | * - attribute line to parse | |
eb1bab5b | 1362 | * @return the attribute value as string |
eb1bab5b | 1363 | */ |
276c17e7 | 1364 | protected String getAttributeValue(String line) { |
eb1bab5b BH |
1365 | String[] temp = line.split("\\: "); //$NON-NLS-1$ |
1366 | return temp[1]; | |
1367 | } | |
1368 | ||
1369 | /** | |
4775bcbf | 1370 | * Parses the event information within a provider. |
cfdb727a | 1371 | * |
4775bcbf BH |
1372 | * @param output |
1373 | * - a command output array | |
1374 | * @param currentIndex | |
1375 | * - current index in command output array | |
1376 | * @param events | |
1377 | * - list for returning event information | |
eb1bab5b BH |
1378 | * @return the new current index in command output array |
1379 | */ | |
276c17e7 | 1380 | protected int getProviderEventInfo(String[] output, int currentIndex, List<IBaseEventInfo> events) { |
eb1bab5b | 1381 | int index = currentIndex; |
d4514365 | 1382 | IBaseEventInfo eventInfo = null; |
eb1bab5b BH |
1383 | while (index < output.length) { |
1384 | String line = output[index]; | |
276c17e7 | 1385 | Matcher matcher = LTTngControlServiceConstants.PROVIDER_EVENT_PATTERN.matcher(line); |
4775bcbf | 1386 | if (matcher.matches()) { |
517c0261 JRJ |
1387 | // sched_kthread_stop (loglevel: TRACE_EMERG0) (type: |
1388 | // tracepoint) | |
d4514365 | 1389 | eventInfo = new BaseEventInfo(matcher.group(1).trim()); |
4775bcbf BH |
1390 | eventInfo.setLogLevel(matcher.group(2).trim()); |
1391 | eventInfo.setEventType(matcher.group(3).trim()); | |
1392 | events.add(eventInfo); | |
d4514365 BH |
1393 | index++; |
1394 | } else if (LTTngControlServiceConstants.EVENT_FIELD_PATTERN.matcher(line).matches()) { | |
1395 | if (eventInfo != null) { | |
e0838ca1 | 1396 | List<IFieldInfo> fields = new ArrayList<>(); |
d4514365 BH |
1397 | index = getFieldInfo(output, index, fields); |
1398 | eventInfo.setFields(fields); | |
1399 | } else { | |
1400 | index++; | |
1401 | } | |
1402 | } | |
1403 | else if (LTTngControlServiceConstants.UST_PROVIDER_PATTERN.matcher(line).matches()) { | |
1404 | return index; | |
1405 | } else { | |
1406 | index++; | |
1407 | } | |
1408 | } | |
1409 | return index; | |
1410 | } | |
1411 | ||
7050e327 AM |
1412 | /** |
1413 | * Parse a field's information. | |
1414 | * | |
1415 | * @param output | |
1416 | * A command output array | |
1417 | * @param currentIndex | |
1418 | * The current index in the command output array | |
1419 | * @param fields | |
1420 | * List for returning the field information | |
1421 | * @return The new current index in the command output array | |
1422 | */ | |
d4514365 BH |
1423 | protected int getFieldInfo(String[] output, int currentIndex, List<IFieldInfo> fields) { |
1424 | int index = currentIndex; | |
1425 | IFieldInfo fieldInfo = null; | |
1426 | while (index < output.length) { | |
1427 | String line = output[index]; | |
1428 | Matcher matcher = LTTngControlServiceConstants.EVENT_FIELD_PATTERN.matcher(line); | |
1429 | if (matcher.matches()) { | |
1430 | // field: content (string) | |
1431 | fieldInfo = new FieldInfo(matcher.group(2).trim()); | |
1432 | fieldInfo.setFieldType(matcher.group(3).trim()); | |
1433 | fields.add(fieldInfo); | |
1434 | } else if (LTTngControlServiceConstants.PROVIDER_EVENT_PATTERN.matcher(line).matches()) { | |
1435 | return index; | |
276c17e7 | 1436 | } else if (LTTngControlServiceConstants.UST_PROVIDER_PATTERN.matcher(line).matches()) { |
eb1bab5b BH |
1437 | return index; |
1438 | } | |
1439 | index++; | |
1440 | } | |
1441 | return index; | |
1442 | } | |
1443 | ||
afe13e7a | 1444 | /** |
517c0261 JRJ |
1445 | * @param strings |
1446 | * array of string that makes up a command line | |
afe13e7a BH |
1447 | * @return string buffer with created command line |
1448 | */ | |
13729cbc | 1449 | protected @NonNull List<String> createCommand(String... strings) { |
774a7993 BH |
1450 | List<String> command = new ArrayList<>(); |
1451 | command.add(LTTngControlServiceConstants.CONTROL_COMMAND); | |
11b78e10 | 1452 | List<String> groupOption = getTracingGroupOption(); |
774a7993 | 1453 | if (!groupOption.isEmpty()) { |
11b78e10 | 1454 | command.addAll(groupOption); |
774a7993 BH |
1455 | } |
1456 | String verboseOption = getVerboseOption(); | |
1457 | if (!verboseOption.isEmpty()) { | |
1458 | command.add(verboseOption); | |
1459 | } | |
afe13e7a | 1460 | for (String string : strings) { |
774a7993 | 1461 | command.add(string); |
afe13e7a BH |
1462 | } |
1463 | return command; | |
1464 | } | |
1465 | ||
1466 | /** | |
1467 | * @return the tracing group option if configured in the preferences | |
1468 | */ | |
11b78e10 BH |
1469 | protected List<String> getTracingGroupOption() { |
1470 | List<String> groupOption = new ArrayList<>(); | |
afe13e7a | 1471 | if (!ControlPreferences.getInstance().isDefaultTracingGroup() && !ControlPreferences.getInstance().getTracingGroup().equals("")) { //$NON-NLS-1$ |
11b78e10 BH |
1472 | groupOption.add(LTTngControlServiceConstants.OPTION_TRACING_GROUP); |
1473 | groupOption.add(ControlPreferences.getInstance().getTracingGroup()); | |
afe13e7a | 1474 | } |
11b78e10 | 1475 | return groupOption; |
afe13e7a BH |
1476 | } |
1477 | ||
1478 | /** | |
1479 | * @return the verbose option as configured in the preferences | |
1480 | */ | |
276c17e7 | 1481 | protected String getVerboseOption() { |
afe13e7a BH |
1482 | if (ControlPreferences.getInstance().isLoggingEnabled()) { |
1483 | String level = ControlPreferences.getInstance().getVerboseLevel(); | |
1484 | if (ControlPreferences.TRACE_CONTROL_VERBOSE_LEVEL_VERBOSE.equals(level)) { | |
276c17e7 | 1485 | return LTTngControlServiceConstants.OPTION_VERBOSE; |
afe13e7a BH |
1486 | } |
1487 | if (ControlPreferences.TRACE_CONTROL_VERBOSE_LEVEL_V_VERBOSE.equals(level)) { | |
276c17e7 | 1488 | return LTTngControlServiceConstants.OPTION_VERY_VERBOSE; |
cfdb727a | 1489 | } |
afe13e7a | 1490 | if (ControlPreferences.TRACE_CONTROL_VERBOSE_LEVEL_V_V_VERBOSE.equals(level)) { |
276c17e7 | 1491 | return LTTngControlServiceConstants.OPTION_VERY_VERY_VERBOSE; |
afe13e7a BH |
1492 | } |
1493 | } | |
1494 | return ""; //$NON-NLS-1$ | |
1495 | } | |
1496 | ||
1497 | /** | |
cfdb727a AM |
1498 | * Method that logs the command and command result if logging is enabled as |
1499 | * well as forwards the command execution to the shell. | |
1500 | * | |
1501 | * @param command | |
1502 | * - the command to execute | |
1503 | * @param monitor | |
1504 | * - a progress monitor | |
afe13e7a BH |
1505 | * @return the command result |
1506 | * @throws ExecutionException | |
6f4e8ec0 | 1507 | * If the command fails |
afe13e7a | 1508 | */ |
13729cbc BH |
1509 | protected ICommandResult executeCommand(@NonNull List<String> command, |
1510 | @Nullable IProgressMonitor monitor) throws ExecutionException { | |
afe13e7a BH |
1511 | return executeCommand(command, monitor, true); |
1512 | } | |
cfdb727a | 1513 | |
afe13e7a | 1514 | /** |
cfdb727a AM |
1515 | * Method that logs the command and command result if logging is enabled as |
1516 | * well as forwards the command execution to the shell. | |
1517 | * | |
1518 | * @param command | |
1519 | * - the command to execute | |
1520 | * @param monitor | |
1521 | * - a progress monitor | |
1522 | * @param checkForError | |
1523 | * - true to verify command result, else false | |
afe13e7a | 1524 | * @return the command result |
cfdb727a AM |
1525 | * @throws ExecutionException |
1526 | * in case of error result | |
afe13e7a | 1527 | */ |
13729cbc BH |
1528 | protected ICommandResult executeCommand(@NonNull List<String> command, |
1529 | @Nullable IProgressMonitor monitor, boolean checkForError) | |
cfdb727a | 1530 | throws ExecutionException { |
afe13e7a | 1531 | if (ControlPreferences.getInstance().isLoggingEnabled()) { |
774a7993 | 1532 | ControlCommandLogger.log(toCommandString(command)); |
afe13e7a BH |
1533 | } |
1534 | ||
b732adaa | 1535 | ICommandResult result = fCommandShell.executeCommand(command, monitor); |
cfdb727a | 1536 | |
afe13e7a | 1537 | if (ControlPreferences.getInstance().isLoggingEnabled()) { |
13729cbc | 1538 | ControlCommandLogger.log(result.toString()); |
afe13e7a BH |
1539 | } |
1540 | ||
a07c7629 | 1541 | if (checkForError && isError(result)) { |
cfdb727a | 1542 | throw new ExecutionException(Messages.TraceControl_CommandError |
13729cbc | 1543 | + " " + toCommandString(command) + "\n" + result.toString()); //$NON-NLS-1$ //$NON-NLS-2$ |
afe13e7a | 1544 | } |
cfdb727a | 1545 | |
afe13e7a BH |
1546 | return result; |
1547 | } | |
eb1bab5b | 1548 | } |