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