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