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