Commit | Line | Data |
---|---|---|
eb1bab5b | 1 | /********************************************************************** |
ba3a9bd2 | 2 | * Copyright (c) 2012, 2013 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 |
589d0d33 | 415 | public ISessionInfo createSession(String sessionName, String sessionPath, boolean isSnapshot, IProgressMonitor monitor) throws ExecutionException { |
bbb3538a BH |
416 | |
417 | String newName = formatParameter(sessionName); | |
418 | String newPath = formatParameter(sessionPath); | |
419 | ||
276c17e7 | 420 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_CREATE_SESSION, newName); |
c56972bb | 421 | |
bbb3538a | 422 | if (newPath != null && !"".equals(newPath)) { //$NON-NLS-1$ |
276c17e7 | 423 | command.append(LTTngControlServiceConstants.OPTION_OUTPUT_PATH); |
c56972bb | 424 | command.append(newPath); |
bbb3538a BH |
425 | } |
426 | ||
589d0d33 BH |
427 | if (isSnapshot) { |
428 | command.append(LTTngControlServiceConstants.OPTION_SNAPSHOT); | |
429 | } | |
430 | ||
afe13e7a BH |
431 | ICommandResult result = executeCommand(command.toString(), monitor); |
432 | ||
bbb3538a BH |
433 | //Session myssession2 created. |
434 | //Traces will be written in /home/user/lttng-traces/myssession2-20120209-095418 | |
435 | String[] output = result.getOutput(); | |
cfdb727a | 436 | |
d128c979 | 437 | // Get and session name and path |
bbb3538a | 438 | String name = null; |
d128c979 | 439 | String path = null; |
bbb3538a | 440 | |
d128c979 BH |
441 | int index = 0; |
442 | while (index < output.length) { | |
443 | String line = output[index]; | |
444 | Matcher nameMatcher = LTTngControlServiceConstants.CREATE_SESSION_NAME_PATTERN.matcher(line); | |
445 | Matcher pathMatcher = LTTngControlServiceConstants.CREATE_SESSION_PATH_PATTERN.matcher(line); | |
446 | if (nameMatcher.matches()) { | |
447 | name = String.valueOf(nameMatcher.group(1).trim()); | |
448 | } else if (pathMatcher.matches()) { | |
449 | path = String.valueOf(pathMatcher.group(1).trim()); | |
450 | } | |
451 | index++; | |
bbb3538a BH |
452 | } |
453 | ||
d128c979 | 454 | // Verify session name |
f3b33d40 | 455 | if ((name == null) || (!"".equals(sessionName) && !name.equals(sessionName))) { //$NON-NLS-1$ |
bbb3538a | 456 | // Unexpected name returned |
cfdb727a AM |
457 | throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$ |
458 | Messages.TraceControl_UnexpectedNameError + ": " + name); //$NON-NLS-1$ | |
bbb3538a | 459 | } |
cfdb727a | 460 | |
f3b33d40 BH |
461 | SessionInfo sessionInfo = new SessionInfo(name); |
462 | ||
d128c979 | 463 | // Verify session path |
589d0d33 BH |
464 | if (!isSnapshot && |
465 | ((path == null) || ((sessionPath != null) && (!path.contains(sessionPath))))) { | |
a30e79fe BH |
466 | // Unexpected path |
467 | throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$ | |
468 | Messages.TraceControl_UnexpectedPathError + ": " + name); //$NON-NLS-1$ | |
f3b33d40 | 469 | } |
d128c979 | 470 | |
589d0d33 BH |
471 | if (isSnapshot) { |
472 | // Make it a snapshot session - content of snapshot info need to | |
473 | // set afterwards using getSession() or getSnapshotInfo() | |
474 | sessionInfo.setSnapshotInfo(new SnapshotInfo("")); //$NON-NLS-1$ | |
475 | } else { | |
476 | sessionInfo.setSessionPath(path); | |
477 | } | |
f3b33d40 BH |
478 | |
479 | return sessionInfo; | |
480 | ||
481 | } | |
482 | ||
f3b33d40 | 483 | @Override |
589d0d33 | 484 | public ISessionInfo createSession(String sessionName, String networkUrl, String controlUrl, String dataUrl, boolean isSnapshot, IProgressMonitor monitor) throws ExecutionException { |
f3b33d40 BH |
485 | |
486 | String newName = formatParameter(sessionName); | |
487 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_CREATE_SESSION, newName); | |
488 | ||
589d0d33 BH |
489 | if (isSnapshot) { |
490 | command.append(LTTngControlServiceConstants.OPTION_SNAPSHOT); | |
491 | } | |
492 | ||
f3b33d40 BH |
493 | if (networkUrl != null) { |
494 | command.append(LTTngControlServiceConstants.OPTION_NETWORK_URL); | |
495 | command.append(networkUrl); | |
496 | } else { | |
497 | command.append(LTTngControlServiceConstants.OPTION_CONTROL_URL); | |
498 | command.append(controlUrl); | |
499 | ||
500 | command.append(LTTngControlServiceConstants.OPTION_DATA_URL); | |
501 | command.append(dataUrl); | |
502 | } | |
503 | ||
f3b33d40 BH |
504 | ICommandResult result = executeCommand(command.toString(), monitor); |
505 | ||
d128c979 | 506 | // Verify output |
f3b33d40 BH |
507 | String[] output = result.getOutput(); |
508 | ||
d128c979 | 509 | // Get and session name and path |
f3b33d40 | 510 | String name = null; |
d128c979 | 511 | String path = null; |
cfdb727a | 512 | |
d128c979 BH |
513 | int index = 0; |
514 | while (index < output.length) { | |
515 | String line = output[index]; | |
516 | Matcher nameMatcher = LTTngControlServiceConstants.CREATE_SESSION_NAME_PATTERN.matcher(line); | |
517 | Matcher pathMatcher = LTTngControlServiceConstants.CREATE_SESSION_PATH_PATTERN.matcher(line); | |
518 | ||
519 | if (nameMatcher.matches()) { | |
520 | name = String.valueOf(nameMatcher.group(1).trim()); | |
521 | } else if (pathMatcher.matches() && (networkUrl != null)) { | |
522 | path = String.valueOf(pathMatcher.group(1).trim()); | |
523 | } | |
524 | index++; | |
525 | } | |
526 | ||
527 | // Verify session name | |
528 | if ((name == null) || (!"".equals(sessionName) && !name.equals(sessionName))) { //$NON-NLS-1$ | |
529 | // Unexpected name returned | |
cfdb727a | 530 | throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$ |
d128c979 | 531 | Messages.TraceControl_UnexpectedNameError + ": " + name); //$NON-NLS-1$ |
bbb3538a | 532 | } |
cfdb727a | 533 | |
bbb3538a | 534 | SessionInfo sessionInfo = new SessionInfo(name); |
f3b33d40 | 535 | |
d128c979 BH |
536 | sessionInfo.setStreamedTrace(true); |
537 | ||
538 | // Verify session path | |
539 | if (networkUrl != null) { | |
589d0d33 | 540 | if (!isSnapshot && (path == null)) { |
f3b33d40 BH |
541 | // Unexpected path |
542 | throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$ | |
543 | Messages.TraceControl_UnexpectedPathError + ": " + name); //$NON-NLS-1$ | |
544 | } | |
d128c979 | 545 | |
589d0d33 | 546 | if (isSnapshot) { |
d128c979 | 547 | sessionInfo.setStreamedTrace(false); |
589d0d33 BH |
548 | } else { |
549 | sessionInfo.setSessionPath(path); | |
550 | // Check file protocol | |
551 | Matcher matcher = LTTngControlServiceConstants.TRACE_FILE_PROTOCOL_PATTERN.matcher(path); | |
552 | if (matcher.matches()) { | |
553 | sessionInfo.setStreamedTrace(false); | |
554 | } | |
d128c979 | 555 | } |
f3b33d40 | 556 | } |
589d0d33 | 557 | |
d128c979 BH |
558 | // When using controlUrl and dataUrl the full session path is not known yet |
559 | // and will be set later on when listing the session | |
bbb3538a BH |
560 | |
561 | return sessionInfo; | |
562 | } | |
cfdb727a | 563 | |
bbb3538a BH |
564 | @Override |
565 | public void destroySession(String sessionName, IProgressMonitor monitor) throws ExecutionException { | |
566 | String newName = formatParameter(sessionName); | |
bbb3538a | 567 | |
276c17e7 | 568 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_DESTROY_SESSION, newName); |
afe13e7a BH |
569 | |
570 | ICommandResult result = executeCommand(command.toString(), monitor, false); | |
bbb3538a | 571 | String[] output = result.getOutput(); |
cfdb727a | 572 | |
d128c979 BH |
573 | boolean isError = isError(result); |
574 | if (isError && (output != null)) { | |
575 | int index = 0; | |
576 | while (index < output.length) { | |
577 | String line = output[index]; | |
578 | Matcher matcher = LTTngControlServiceConstants.SESSION_NOT_FOUND_ERROR_PATTERN.matcher(line); | |
579 | if (matcher.matches()) { | |
580 | // Don't treat this as an error | |
581 | isError = false; | |
582 | } | |
583 | index++; | |
584 | } | |
585 | } | |
586 | ||
587 | if (isError) { | |
588 | throw new ExecutionException(Messages.TraceControl_CommandError + " " + command.toString() + "\n" + formatOutput(result)); //$NON-NLS-1$ //$NON-NLS-2$ | |
589 | } | |
590 | ||
bbb3538a BH |
591 | //Session <sessionName> destroyed |
592 | } | |
cfdb727a | 593 | |
bbb3538a BH |
594 | @Override |
595 | public void startSession(String sessionName, IProgressMonitor monitor) throws ExecutionException { | |
596 | ||
597 | String newSessionName = formatParameter(sessionName); | |
598 | ||
276c17e7 | 599 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_START_SESSION, newSessionName); |
bbb3538a | 600 | |
afe13e7a | 601 | executeCommand(command.toString(), monitor); |
bbb3538a | 602 | |
bbb3538a BH |
603 | //Session <sessionName> started |
604 | } | |
605 | ||
bbb3538a BH |
606 | @Override |
607 | public void stopSession(String sessionName, IProgressMonitor monitor) throws ExecutionException { | |
608 | String newSessionName = formatParameter(sessionName); | |
276c17e7 | 609 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_STOP_SESSION, newSessionName); |
bbb3538a | 610 | |
afe13e7a | 611 | executeCommand(command.toString(), monitor); |
bbb3538a | 612 | |
bbb3538a | 613 | //Session <sessionName> stopped |
cfdb727a | 614 | |
bbb3538a | 615 | } |
cfdb727a | 616 | |
bbb3538a | 617 | @Override |
498704b3 | 618 | public void enableChannels(String sessionName, List<String> channelNames, boolean isKernel, IChannelInfo info, IProgressMonitor monitor) throws ExecutionException { |
bbb3538a BH |
619 | |
620 | // no channels to enable | |
c56972bb | 621 | if (channelNames.isEmpty()) { |
bbb3538a BH |
622 | return; |
623 | } | |
624 | ||
276c17e7 | 625 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_ENABLE_CHANNEL); |
bbb3538a BH |
626 | |
627 | for (Iterator<String> iterator = channelNames.iterator(); iterator.hasNext();) { | |
cfdb727a | 628 | String channel = iterator.next(); |
bbb3538a BH |
629 | command.append(channel); |
630 | if (iterator.hasNext()) { | |
c56972bb | 631 | command.append(','); |
bbb3538a BH |
632 | } |
633 | } | |
634 | ||
635 | if (isKernel) { | |
276c17e7 | 636 | command.append(LTTngControlServiceConstants.OPTION_KERNEL); |
bbb3538a | 637 | } else { |
276c17e7 | 638 | command.append(LTTngControlServiceConstants.OPTION_UST); |
bbb3538a BH |
639 | } |
640 | ||
afe13e7a | 641 | String newSessionName = formatParameter(sessionName); |
276c17e7 | 642 | command.append(LTTngControlServiceConstants.OPTION_SESSION); |
bbb3538a BH |
643 | command.append(newSessionName); |
644 | ||
645 | if (info != null) { | |
646 | // --discard Discard event when buffers are full (default) | |
bbb3538a BH |
647 | |
648 | // --overwrite Flight recorder mode | |
649 | if (info.isOverwriteMode()) { | |
276c17e7 | 650 | command.append(LTTngControlServiceConstants.OPTION_OVERWRITE); |
bbb3538a BH |
651 | } |
652 | // --subbuf-size SIZE Subbuffer size in bytes | |
653 | // (default: 4096, kernel default: 262144) | |
e799e5f3 SD |
654 | if (info.getSubBufferSize() != LTTngControlServiceConstants.UNUSED_VALUE) { |
655 | command.append(LTTngControlServiceConstants.OPTION_SUB_BUFFER_SIZE); | |
656 | command.append(String.valueOf(info.getSubBufferSize())); | |
657 | } | |
bbb3538a BH |
658 | |
659 | // --num-subbuf NUM Number of subbufers | |
e799e5f3 SD |
660 | if (info.getNumberOfSubBuffers() != LTTngControlServiceConstants.UNUSED_VALUE) { |
661 | command.append(LTTngControlServiceConstants.OPTION_NUM_SUB_BUFFERS); | |
662 | command.append(String.valueOf(info.getNumberOfSubBuffers())); | |
663 | } | |
664 | ||
665 | // --switch-timer USEC Switch timer interval in usec | |
666 | if (info.getSwitchTimer() != LTTngControlServiceConstants.UNUSED_VALUE) { | |
667 | command.append(LTTngControlServiceConstants.OPTION_SWITCH_TIMER); | |
668 | command.append(String.valueOf(info.getSwitchTimer())); | |
669 | } | |
cfdb727a | 670 | |
e799e5f3 SD |
671 | // --read-timer USEC Read timer interval in usec |
672 | if (info.getReadTimer() != LTTngControlServiceConstants.UNUSED_VALUE) { | |
673 | command.append(LTTngControlServiceConstants.OPTION_READ_TIMER); | |
674 | command.append(String.valueOf(info.getReadTimer())); | |
675 | } | |
bbb3538a | 676 | |
e799e5f3 | 677 | if (isVersionSupported("2.2.0")) { //$NON-NLS-1$ |
83051fc3 BH |
678 | // --buffers-uid Every application sharing the same UID use the same buffers |
679 | // --buffers-pid Buffers are allocated per PID | |
680 | if (!isKernel) { | |
681 | if (info.getBufferType() == BufferType.BUFFER_PER_PID) { | |
682 | command.append(LTTngControlServiceConstants.OPTION_PER_PID_BUFFERS); | |
683 | ||
684 | } else if (info.getBufferType() == BufferType.BUFFER_PER_UID) { | |
685 | command.append(LTTngControlServiceConstants.OPTION_PER_UID_BUFFERS); | |
686 | } | |
e799e5f3 SD |
687 | } |
688 | ||
689 | // -C SIZE Maximum size of trace files in bytes | |
690 | if (info.getMaxSizeTraceFiles() != LTTngControlServiceConstants.UNUSED_VALUE) { | |
691 | command.append(LTTngControlServiceConstants.OPTION_MAX_SIZE_TRACE_FILES); | |
692 | command.append(String.valueOf(info.getMaxSizeTraceFiles())); | |
693 | } | |
694 | ||
695 | // -W NUM Maximum number of trace files | |
696 | if (info.getMaxNumberTraceFiles() != LTTngControlServiceConstants.UNUSED_VALUE) { | |
697 | command.append(LTTngControlServiceConstants.OPTION_MAX_TRACE_FILES); | |
698 | command.append(String.valueOf(info.getMaxNumberTraceFiles())); | |
699 | } | |
700 | } | |
cfdb727a | 701 | } |
bbb3538a | 702 | |
afe13e7a | 703 | executeCommand(command.toString(), monitor); |
cfdb727a | 704 | |
bbb3538a BH |
705 | } |
706 | ||
bbb3538a | 707 | @Override |
498704b3 | 708 | public void disableChannels(String sessionName, List<String> channelNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException { |
cfdb727a | 709 | |
bbb3538a | 710 | // no channels to enable |
c56972bb | 711 | if (channelNames.isEmpty()) { |
bbb3538a BH |
712 | return; |
713 | } | |
714 | ||
276c17e7 | 715 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_DISABLE_CHANNEL); |
bbb3538a BH |
716 | |
717 | for (Iterator<String> iterator = channelNames.iterator(); iterator.hasNext();) { | |
cfdb727a | 718 | String channel = iterator.next(); |
bbb3538a BH |
719 | command.append(channel); |
720 | if (iterator.hasNext()) { | |
c56972bb | 721 | command.append(','); |
bbb3538a BH |
722 | } |
723 | } | |
724 | ||
725 | if (isKernel) { | |
276c17e7 | 726 | command.append(LTTngControlServiceConstants.OPTION_KERNEL); |
6503ae0f | 727 | } else { |
276c17e7 | 728 | command.append(LTTngControlServiceConstants.OPTION_UST); |
6503ae0f BH |
729 | } |
730 | ||
afe13e7a | 731 | String newSessionName = formatParameter(sessionName); |
276c17e7 | 732 | command.append(LTTngControlServiceConstants.OPTION_SESSION); |
6503ae0f BH |
733 | command.append(newSessionName); |
734 | ||
afe13e7a | 735 | executeCommand(command.toString(), monitor); |
6503ae0f | 736 | } |
cfdb727a | 737 | |
6503ae0f | 738 | @Override |
d4514365 | 739 | public void enableEvents(String sessionName, String channelName, List<String> eventNames, boolean isKernel, String filterExpression, IProgressMonitor monitor) throws ExecutionException { |
6503ae0f | 740 | |
276c17e7 | 741 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_ENABLE_EVENT); |
6503ae0f | 742 | |
c56972bb | 743 | if (eventNames == null || eventNames.isEmpty()) { |
276c17e7 | 744 | command.append(LTTngControlServiceConstants.OPTION_ALL); |
3e91c9c0 | 745 | } else { |
3e91c9c0 | 746 | |
7a6e4bfd | 747 | StringBuffer eventNameParameter = new StringBuffer(); |
3e91c9c0 | 748 | for (Iterator<String> iterator = eventNames.iterator(); iterator.hasNext();) { |
cfdb727a | 749 | String event = iterator.next(); |
7a6e4bfd | 750 | eventNameParameter.append(event); |
3e91c9c0 | 751 | if (iterator.hasNext()) { |
7a6e4bfd | 752 | eventNameParameter.append(','); |
3e91c9c0 | 753 | } |
6503ae0f | 754 | } |
7a6e4bfd | 755 | command.append(formatParameter(eventNameParameter.toString())); |
6503ae0f BH |
756 | } |
757 | ||
758 | if (isKernel) { | |
276c17e7 | 759 | command.append(LTTngControlServiceConstants.OPTION_KERNEL); |
bbb3538a | 760 | } else { |
276c17e7 | 761 | command.append(LTTngControlServiceConstants.OPTION_UST); |
bbb3538a BH |
762 | } |
763 | ||
afe13e7a BH |
764 | String newSessionName = formatParameter(sessionName); |
765 | ||
276c17e7 | 766 | command.append(LTTngControlServiceConstants.OPTION_SESSION); |
bbb3538a BH |
767 | command.append(newSessionName); |
768 | ||
6503ae0f | 769 | if (channelName != null) { |
276c17e7 | 770 | command.append(LTTngControlServiceConstants.OPTION_CHANNEL); |
6503ae0f BH |
771 | command.append(channelName); |
772 | } | |
cfdb727a | 773 | |
276c17e7 | 774 | command.append(LTTngControlServiceConstants.OPTION_TRACEPOINT); |
cfdb727a | 775 | |
d4514365 BH |
776 | if (filterExpression != null) { |
777 | command.append(LTTngControlServiceConstants.OPTION_FILTER); | |
778 | command.append('\''); | |
779 | command.append(filterExpression); | |
780 | command.append('\''); | |
781 | } | |
782 | ||
afe13e7a | 783 | executeCommand(command.toString(), monitor); |
cfdb727a | 784 | |
498704b3 | 785 | } |
6503ae0f | 786 | |
498704b3 BH |
787 | @Override |
788 | public void enableSyscalls(String sessionName, String channelName, IProgressMonitor monitor) throws ExecutionException { | |
afe13e7a | 789 | |
276c17e7 | 790 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_ENABLE_EVENT); |
498704b3 | 791 | |
276c17e7 BH |
792 | command.append(LTTngControlServiceConstants.OPTION_ALL); |
793 | command.append(LTTngControlServiceConstants.OPTION_KERNEL); | |
498704b3 | 794 | |
afe13e7a BH |
795 | String newSessionName = formatParameter(sessionName); |
796 | ||
276c17e7 | 797 | command.append(LTTngControlServiceConstants.OPTION_SESSION); |
498704b3 BH |
798 | command.append(newSessionName); |
799 | ||
800 | if (channelName != null) { | |
276c17e7 | 801 | command.append(LTTngControlServiceConstants.OPTION_CHANNEL); |
498704b3 BH |
802 | command.append(channelName); |
803 | } | |
cfdb727a | 804 | |
276c17e7 | 805 | command.append(LTTngControlServiceConstants.OPTION_SYSCALL); |
cfdb727a | 806 | |
afe13e7a | 807 | executeCommand(command.toString(), monitor); |
498704b3 | 808 | } |
cfdb727a | 809 | |
498704b3 | 810 | @Override |
d132bcc7 | 811 | public void enableProbe(String sessionName, String channelName, String eventName, boolean isFunction, String probe, IProgressMonitor monitor) throws ExecutionException { |
276c17e7 | 812 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_ENABLE_EVENT); |
498704b3 BH |
813 | |
814 | command.append(eventName); | |
276c17e7 | 815 | command.append(LTTngControlServiceConstants.OPTION_KERNEL); |
498704b3 | 816 | |
afe13e7a | 817 | String newSessionName = formatParameter(sessionName); |
276c17e7 | 818 | command.append(LTTngControlServiceConstants.OPTION_SESSION); |
498704b3 BH |
819 | command.append(newSessionName); |
820 | ||
821 | if (channelName != null) { | |
276c17e7 | 822 | command.append(LTTngControlServiceConstants.OPTION_CHANNEL); |
498704b3 | 823 | command.append(channelName); |
bbb3538a | 824 | } |
d132bcc7 | 825 | if (isFunction) { |
276c17e7 | 826 | command.append(LTTngControlServiceConstants.OPTION_FUNCTION_PROBE); |
d132bcc7 | 827 | } else { |
276c17e7 | 828 | command.append(LTTngControlServiceConstants.OPTION_PROBE); |
498704b3 | 829 | } |
cfdb727a | 830 | |
498704b3 | 831 | command.append(probe); |
cfdb727a | 832 | |
afe13e7a | 833 | executeCommand(command.toString(), monitor); |
498704b3 | 834 | } |
ccc66d01 | 835 | |
ccc66d01 | 836 | @Override |
d4514365 | 837 | public void enableLogLevel(String sessionName, String channelName, String eventName, LogLevelType logLevelType, TraceLogLevel level, String filterExpression, IProgressMonitor monitor) throws ExecutionException { |
276c17e7 | 838 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_ENABLE_EVENT); |
ccc66d01 BH |
839 | |
840 | command.append(eventName); | |
276c17e7 | 841 | command.append(LTTngControlServiceConstants.OPTION_UST); |
ccc66d01 | 842 | |
afe13e7a | 843 | String newSessionName = formatParameter(sessionName); |
276c17e7 | 844 | command.append(LTTngControlServiceConstants.OPTION_SESSION); |
ccc66d01 BH |
845 | command.append(newSessionName); |
846 | ||
847 | if (channelName != null) { | |
276c17e7 | 848 | command.append(LTTngControlServiceConstants.OPTION_CHANNEL); |
ccc66d01 BH |
849 | command.append(channelName); |
850 | } | |
cfdb727a | 851 | |
ccc66d01 | 852 | if (logLevelType == LogLevelType.LOGLEVEL) { |
276c17e7 | 853 | command.append(LTTngControlServiceConstants.OPTION_LOGLEVEL); |
ccc66d01 | 854 | } else if (logLevelType == LogLevelType.LOGLEVEL_ONLY) { |
276c17e7 | 855 | command.append(LTTngControlServiceConstants.OPTION_LOGLEVEL_ONLY); |
cfdb727a | 856 | |
ccc66d01 BH |
857 | } else { |
858 | return; | |
859 | } | |
860 | command.append(level.getInName()); | |
cfdb727a | 861 | |
afe13e7a | 862 | executeCommand(command.toString(), monitor); |
ccc66d01 BH |
863 | } |
864 | ||
6503ae0f BH |
865 | @Override |
866 | public void disableEvent(String sessionName, String channelName, List<String> eventNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException { | |
276c17e7 | 867 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_DISABLE_EVENT); |
6503ae0f | 868 | |
3e91c9c0 | 869 | if (eventNames == null) { |
276c17e7 | 870 | command.append(LTTngControlServiceConstants.OPTION_ALL); |
3e91c9c0 | 871 | } else { |
7a6e4bfd | 872 | // no events to disable |
c56972bb | 873 | if (eventNames.isEmpty()) { |
3e91c9c0 BH |
874 | return; |
875 | } | |
6503ae0f | 876 | |
7a6e4bfd | 877 | StringBuffer eventNameParameter = new StringBuffer(); |
3e91c9c0 | 878 | for (Iterator<String> iterator = eventNames.iterator(); iterator.hasNext();) { |
cfdb727a | 879 | String event = iterator.next(); |
7a6e4bfd | 880 | eventNameParameter.append(event); |
3e91c9c0 | 881 | if (iterator.hasNext()) { |
7a6e4bfd | 882 | eventNameParameter.append(','); |
3e91c9c0 | 883 | } |
6503ae0f | 884 | } |
7a6e4bfd | 885 | command.append(formatParameter(eventNameParameter.toString())); |
6503ae0f BH |
886 | } |
887 | ||
888 | if (isKernel) { | |
276c17e7 | 889 | command.append(LTTngControlServiceConstants.OPTION_KERNEL); |
6503ae0f | 890 | } else { |
276c17e7 | 891 | command.append(LTTngControlServiceConstants.OPTION_UST); |
6503ae0f BH |
892 | } |
893 | ||
afe13e7a | 894 | String newSessionName = formatParameter(sessionName); |
276c17e7 | 895 | command.append(LTTngControlServiceConstants.OPTION_SESSION); |
6503ae0f BH |
896 | command.append(newSessionName); |
897 | ||
898 | if (channelName != null) { | |
276c17e7 | 899 | command.append(LTTngControlServiceConstants.OPTION_CHANNEL); |
6503ae0f BH |
900 | command.append(channelName); |
901 | } | |
902 | ||
afe13e7a | 903 | executeCommand(command.toString(), monitor); |
6503ae0f | 904 | } |
b793fbe1 | 905 | |
b793fbe1 BH |
906 | @Override |
907 | public List<String> getContextList(IProgressMonitor monitor) throws ExecutionException { | |
908 | ||
276c17e7 | 909 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_ADD_CONTEXT, LTTngControlServiceConstants.OPTION_HELP); |
b793fbe1 | 910 | |
afe13e7a | 911 | ICommandResult result = executeCommand(command.toString(), monitor); |
b793fbe1 | 912 | |
cfdb727a AM |
913 | String[] output = result.getOutput(); |
914 | ||
e0838ca1 | 915 | List<String> contexts = new ArrayList<>(0); |
cfdb727a | 916 | |
b793fbe1 BH |
917 | int index = 0; |
918 | boolean inList = false; | |
919 | while (index < output.length) { | |
920 | String line = result.getOutput()[index]; | |
cfdb727a | 921 | |
276c17e7 BH |
922 | Matcher startMatcher = LTTngControlServiceConstants.ADD_CONTEXT_HELP_CONTEXTS_INTRO.matcher(line); |
923 | Matcher endMatcher = LTTngControlServiceConstants.ADD_CONTEXT_HELP_CONTEXTS_END_LINE.matcher(line); | |
b793fbe1 BH |
924 | |
925 | if (startMatcher.matches()) { | |
926 | inList = true; | |
927 | } else if (endMatcher.matches()) { | |
928 | break; | |
929 | } else if (inList == true) { | |
930 | String[] tmp = line.split(","); //$NON-NLS-1$ | |
931 | for (int i = 0; i < tmp.length; i++) { | |
932 | contexts.add(tmp[i].trim()); | |
933 | } | |
934 | } | |
935 | index++; | |
936 | } | |
937 | return contexts; | |
938 | } | |
939 | ||
b793fbe1 BH |
940 | @Override |
941 | public void addContexts(String sessionName, String channelName, String eventName, boolean isKernel, List<String> contextNames, IProgressMonitor monitor) throws ExecutionException { | |
276c17e7 | 942 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_ADD_CONTEXT); |
b793fbe1 | 943 | |
afe13e7a | 944 | String newSessionName = formatParameter(sessionName); |
276c17e7 | 945 | command.append(LTTngControlServiceConstants.OPTION_SESSION); |
b793fbe1 | 946 | command.append(newSessionName); |
cfdb727a | 947 | |
b793fbe1 | 948 | if (channelName != null) { |
276c17e7 | 949 | command.append(LTTngControlServiceConstants.OPTION_CHANNEL); |
b793fbe1 BH |
950 | command.append(channelName); |
951 | } | |
952 | ||
953 | if (eventName != null) { | |
276c17e7 | 954 | command.append(LTTngControlServiceConstants.OPTION_EVENT); |
b793fbe1 BH |
955 | command.append(eventName); |
956 | } | |
957 | ||
958 | if (isKernel) { | |
276c17e7 | 959 | command.append(LTTngControlServiceConstants.OPTION_KERNEL); |
b793fbe1 | 960 | } else { |
276c17e7 | 961 | command.append(LTTngControlServiceConstants.OPTION_UST); |
b793fbe1 | 962 | } |
cfdb727a | 963 | |
b793fbe1 | 964 | for (Iterator<String> iterator = contextNames.iterator(); iterator.hasNext();) { |
cfdb727a | 965 | String context = iterator.next(); |
276c17e7 | 966 | command.append(LTTngControlServiceConstants.OPTION_CONTEXT_TYPE); |
b793fbe1 BH |
967 | command.append(context); |
968 | } | |
969 | ||
afe13e7a | 970 | executeCommand(command.toString(), monitor); |
cfdb727a | 971 | |
b793fbe1 BH |
972 | } |
973 | ||
b720ac44 BH |
974 | @Override |
975 | public void calibrate(boolean isKernel, IProgressMonitor monitor) throws ExecutionException { | |
276c17e7 | 976 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_CALIBRATE); |
b720ac44 BH |
977 | |
978 | if (isKernel) { | |
276c17e7 | 979 | command.append(LTTngControlServiceConstants.OPTION_KERNEL); |
b720ac44 | 980 | } else { |
276c17e7 | 981 | command.append(LTTngControlServiceConstants.OPTION_UST); |
b720ac44 BH |
982 | } |
983 | ||
276c17e7 | 984 | command.append(LTTngControlServiceConstants.OPTION_FUNCTION_PROBE); |
b720ac44 | 985 | |
afe13e7a | 986 | executeCommand(command.toString(), monitor); |
b720ac44 | 987 | } |
cfdb727a | 988 | |
589d0d33 BH |
989 | @Override |
990 | public void recordSnapshot(String sessionName, IProgressMonitor monitor) | |
991 | throws ExecutionException { | |
992 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_RECORD_SNAPSHOT); | |
993 | ||
994 | String newSessionName = formatParameter(sessionName); | |
995 | command.append(LTTngControlServiceConstants.OPTION_SESSION); | |
996 | command.append(newSessionName); | |
997 | ||
998 | executeCommand(command.toString(), monitor); | |
999 | } | |
1000 | ||
eb1bab5b BH |
1001 | // ------------------------------------------------------------------------ |
1002 | // Helper methods | |
1003 | // ------------------------------------------------------------------------ | |
11252342 | 1004 | |
eb1bab5b BH |
1005 | /** |
1006 | * Checks if command result is an error result. | |
cfdb727a | 1007 | * |
4775bcbf BH |
1008 | * @param result |
1009 | * - the command result to check | |
eb1bab5b BH |
1010 | * @return true if error else false |
1011 | */ | |
276c17e7 | 1012 | protected boolean isError(ICommandResult result) { |
d128c979 BH |
1013 | // Check return code and length of returned strings |
1014 | if ((result.getResult()) != 0 || (result.getOutput().length < 1)) { | |
eb1bab5b BH |
1015 | return true; |
1016 | } | |
d128c979 BH |
1017 | |
1018 | // Look for error pattern | |
1019 | int index = 0; | |
1020 | while (index < result.getOutput().length) { | |
1021 | String line = result.getOutput()[index]; | |
1022 | Matcher matcher = LTTngControlServiceConstants.ERROR_PATTERN.matcher(line); | |
1023 | if (matcher.matches()) { | |
1024 | return true; | |
1025 | } | |
1026 | index++; | |
1027 | } | |
1028 | ||
eb1bab5b BH |
1029 | return false; |
1030 | } | |
4775bcbf | 1031 | |
eb1bab5b BH |
1032 | /** |
1033 | * Formats the output string as single string. | |
cfdb727a | 1034 | * |
ea21cd65 | 1035 | * @param result |
4775bcbf | 1036 | * - output array |
eb1bab5b BH |
1037 | * @return - the formatted output |
1038 | */ | |
7a6e4bfd | 1039 | public static String formatOutput(ICommandResult result) { |
afe13e7a | 1040 | if ((result == null) || result.getOutput() == null || result.getOutput().length == 0) { |
eb1bab5b BH |
1041 | return ""; //$NON-NLS-1$ |
1042 | } | |
afe13e7a | 1043 | String[] output = result.getOutput(); |
eb1bab5b | 1044 | StringBuffer ret = new StringBuffer(); |
afe13e7a BH |
1045 | ret.append("Return Value: "); //$NON-NLS-1$ |
1046 | ret.append(result.getResult()); | |
1047 | ret.append("\n"); //$NON-NLS-1$ | |
eb1bab5b | 1048 | for (int i = 0; i < output.length; i++) { |
046b6849 | 1049 | ret.append(output[i]).append("\n"); //$NON-NLS-1$ |
eb1bab5b BH |
1050 | } |
1051 | return ret.toString(); | |
1052 | } | |
4775bcbf | 1053 | |
eb1bab5b BH |
1054 | /** |
1055 | * Parses the domain information. | |
cfdb727a | 1056 | * |
4775bcbf BH |
1057 | * @param output |
1058 | * - a command output array | |
1059 | * @param currentIndex | |
1060 | * - current index in command output array | |
1061 | * @param channels | |
1062 | * - list for returning channel information | |
ca8c54b3 SD |
1063 | * @param domainInfo |
1064 | * - The domain information | |
4775bcbf | 1065 | * @return the new current index in command output array |
eb1bab5b | 1066 | */ |
ca8c54b3 | 1067 | protected int parseDomain(String[] output, int currentIndex, List<IChannelInfo> channels, IDomainInfo domainInfo) { |
eb1bab5b BH |
1068 | int index = currentIndex; |
1069 | ||
83051fc3 BH |
1070 | // if kernel set the buffer type to shared |
1071 | if (domainInfo.isKernel()) { | |
1072 | domainInfo.setBufferType(BufferType.BUFFER_SHARED); | |
1073 | } | |
1074 | ||
4775bcbf BH |
1075 | // Channels: |
1076 | // ------------- | |
1077 | // - channnel1: [enabled] | |
1078 | // | |
1079 | // Attributes: | |
1080 | // overwrite mode: 0 | |
1081 | // subbufers size: 262144 | |
1082 | // number of subbufers: 4 | |
1083 | // switch timer interval: 0 | |
1084 | // read timer interval: 200 | |
1085 | // output: splice() | |
1086 | ||
eb1bab5b BH |
1087 | while (index < output.length) { |
1088 | String line = output[index]; | |
4775bcbf | 1089 | |
ca8c54b3 SD |
1090 | if (isVersionSupported("2.2.0")) { //$NON-NLS-1$ |
1091 | Matcher bufferTypeMatcher = LTTngControlServiceConstants.BUFFER_TYPE_PATTERN.matcher(line); | |
1092 | if (bufferTypeMatcher.matches()) { | |
83051fc3 BH |
1093 | String bufferTypeString = getAttributeValue(line); |
1094 | if (BufferType.BUFFER_PER_PID.getInName().equals(bufferTypeString)) { | |
1095 | domainInfo.setBufferType(BufferType.BUFFER_PER_PID); | |
1096 | } else if (BufferType.BUFFER_PER_UID.getInName().equals(bufferTypeString)) { | |
1097 | domainInfo.setBufferType(BufferType.BUFFER_PER_UID); | |
1098 | } else { | |
1099 | domainInfo.setBufferType(BufferType.BUFFER_TYPE_UNKNOWN); | |
1100 | } | |
ca8c54b3 SD |
1101 | } |
1102 | } else { | |
83051fc3 | 1103 | domainInfo.setBufferType(BufferType.BUFFER_TYPE_UNKNOWN); |
ca8c54b3 | 1104 | } |
276c17e7 | 1105 | Matcher outerMatcher = LTTngControlServiceConstants.CHANNELS_SECTION_PATTERN.matcher(line); |
a30e79fe BH |
1106 | Matcher noKernelChannelMatcher = LTTngControlServiceConstants.DOMAIN_NO_KERNEL_CHANNEL_PATTERN.matcher(line); |
1107 | Matcher noUstChannelMatcher = LTTngControlServiceConstants.DOMAIN_NO_UST_CHANNEL_PATTERN.matcher(line); | |
4775bcbf | 1108 | if (outerMatcher.matches()) { |
eb1bab5b BH |
1109 | IChannelInfo channelInfo = null; |
1110 | while (index < output.length) { | |
1111 | String subLine = output[index]; | |
4775bcbf | 1112 | |
276c17e7 | 1113 | Matcher innerMatcher = LTTngControlServiceConstants.CHANNEL_PATTERN.matcher(subLine); |
4775bcbf | 1114 | if (innerMatcher.matches()) { |
eb1bab5b | 1115 | channelInfo = new ChannelInfo(""); //$NON-NLS-1$ |
4775bcbf BH |
1116 | // get channel name |
1117 | channelInfo.setName(innerMatcher.group(1)); | |
1118 | ||
1119 | // get channel enablement | |
1120 | channelInfo.setState(innerMatcher.group(2)); | |
1121 | ||
83051fc3 BH |
1122 | // set BufferType |
1123 | channelInfo.setBufferType(domainInfo.getBufferType()); | |
1124 | ||
4775bcbf BH |
1125 | // add channel |
1126 | channels.add(channelInfo); | |
1127 | ||
276c17e7 | 1128 | } else if (LTTngControlServiceConstants.OVERWRITE_MODE_ATTRIBUTE.matcher(subLine).matches()) { |
eb1bab5b | 1129 | String value = getAttributeValue(subLine); |
64636df8 BH |
1130 | if (channelInfo != null) { |
1131 | channelInfo.setOverwriteMode(!LTTngControlServiceConstants.OVERWRITE_MODE_ATTRIBUTE_FALSE.equals(value)); | |
1132 | } | |
276c17e7 | 1133 | } else if (LTTngControlServiceConstants.SUBBUFFER_SIZE_ATTRIBUTE.matcher(subLine).matches()) { |
64636df8 BH |
1134 | if (channelInfo != null) { |
1135 | channelInfo.setSubBufferSize(Long.valueOf(getAttributeValue(subLine))); | |
1136 | } | |
4775bcbf | 1137 | |
276c17e7 | 1138 | } else if (LTTngControlServiceConstants.NUM_SUBBUFFERS_ATTRIBUTE.matcher(subLine).matches()) { |
64636df8 BH |
1139 | if (channelInfo != null) { |
1140 | channelInfo.setNumberOfSubBuffers(Integer.valueOf(getAttributeValue(subLine))); | |
1141 | } | |
4775bcbf | 1142 | |
276c17e7 | 1143 | } else if (LTTngControlServiceConstants.SWITCH_TIMER_ATTRIBUTE.matcher(subLine).matches()) { |
64636df8 BH |
1144 | if (channelInfo != null) { |
1145 | channelInfo.setSwitchTimer(Long.valueOf(getAttributeValue(subLine))); | |
1146 | } | |
4775bcbf | 1147 | |
276c17e7 | 1148 | } else if (LTTngControlServiceConstants.READ_TIMER_ATTRIBUTE.matcher(subLine).matches()) { |
64636df8 BH |
1149 | if (channelInfo != null) { |
1150 | channelInfo.setReadTimer(Long.valueOf(getAttributeValue(subLine))); | |
1151 | } | |
4775bcbf | 1152 | |
276c17e7 | 1153 | } else if (LTTngControlServiceConstants.OUTPUT_ATTRIBUTE.matcher(subLine).matches()) { |
64636df8 BH |
1154 | if (channelInfo != null) { |
1155 | channelInfo.setOutputType(getAttributeValue(subLine)); | |
1156 | } | |
4775bcbf | 1157 | |
276c17e7 | 1158 | } else if (LTTngControlServiceConstants.EVENT_SECTION_PATTERN.matcher(subLine).matches()) { |
e0838ca1 | 1159 | List<IEventInfo> events = new ArrayList<>(); |
eb1bab5b | 1160 | index = parseEvents(output, index, events); |
64636df8 BH |
1161 | if (channelInfo != null) { |
1162 | channelInfo.setEvents(events); | |
1163 | } | |
4775bcbf BH |
1164 | // we want to stay at the current index to be able to |
1165 | // exit the domain | |
eb1bab5b | 1166 | continue; |
276c17e7 | 1167 | } else if (LTTngControlServiceConstants.DOMAIN_KERNEL_PATTERN.matcher(subLine).matches()) { |
eb1bab5b BH |
1168 | return index; |
1169 | ||
276c17e7 | 1170 | } else if (LTTngControlServiceConstants.DOMAIN_UST_GLOBAL_PATTERN.matcher(subLine).matches()) { |
eb1bab5b BH |
1171 | return index; |
1172 | } | |
1173 | index++; | |
1174 | } | |
a30e79fe BH |
1175 | } else if (noKernelChannelMatcher.matches() || noUstChannelMatcher.matches()) { |
1176 | // domain indicates that no channels were found -> return | |
1177 | index++; | |
1178 | return index; | |
eb1bab5b BH |
1179 | } |
1180 | index++; | |
1181 | } | |
1182 | return index; | |
1183 | } | |
1184 | ||
1185 | /** | |
1186 | * Parses the event information within a domain. | |
cfdb727a | 1187 | * |
4775bcbf BH |
1188 | * @param output |
1189 | * - a command output array | |
1190 | * @param currentIndex | |
1191 | * - current index in command output array | |
1192 | * @param events | |
1193 | * - list for returning event information | |
eb1bab5b | 1194 | * @return the new current index in command output array |
eb1bab5b | 1195 | */ |
276c17e7 | 1196 | protected int parseEvents(String[] output, int currentIndex, List<IEventInfo> events) { |
eb1bab5b BH |
1197 | int index = currentIndex; |
1198 | ||
1199 | while (index < output.length) { | |
1200 | String line = output[index]; | |
276c17e7 | 1201 | if (LTTngControlServiceConstants.CHANNEL_PATTERN.matcher(line).matches()) { |
eb1bab5b BH |
1202 | // end of channel |
1203 | return index; | |
276c17e7 | 1204 | } else if (LTTngControlServiceConstants.DOMAIN_KERNEL_PATTERN.matcher(line).matches()) { |
eb1bab5b BH |
1205 | // end of domain |
1206 | return index; | |
276c17e7 | 1207 | } else if (LTTngControlServiceConstants.DOMAIN_UST_GLOBAL_PATTERN.matcher(line).matches()) { |
eb1bab5b BH |
1208 | // end of domain |
1209 | return index; | |
cfdb727a | 1210 | } |
4775bcbf | 1211 | |
276c17e7 BH |
1212 | Matcher matcher = LTTngControlServiceConstants.EVENT_PATTERN.matcher(line); |
1213 | Matcher matcher2 = LTTngControlServiceConstants.WILDCARD_EVENT_PATTERN.matcher(line); | |
4775bcbf BH |
1214 | |
1215 | if (matcher.matches()) { | |
1216 | IEventInfo eventInfo = new EventInfo(matcher.group(1).trim()); | |
1217 | eventInfo.setLogLevel(matcher.group(2).trim()); | |
1218 | eventInfo.setEventType(matcher.group(3).trim()); | |
1219 | eventInfo.setState(matcher.group(4)); | |
d4514365 BH |
1220 | String filter = matcher.group(5); |
1221 | if (filter != null) { | |
1222 | filter = filter.substring(1, filter.length() - 1); // remove '[' and ']' | |
1223 | eventInfo.setFilterExpression(filter); | |
1224 | } | |
4775bcbf | 1225 | events.add(eventInfo); |
d132bcc7 | 1226 | index++; |
4775bcbf BH |
1227 | } else if (matcher2.matches()) { |
1228 | IEventInfo eventInfo = new EventInfo(matcher2.group(1).trim()); | |
1229 | eventInfo.setLogLevel(TraceLogLevel.LEVEL_UNKNOWN); | |
1230 | eventInfo.setEventType(matcher2.group(2).trim()); | |
1231 | eventInfo.setState(matcher2.group(3)); | |
d4514365 BH |
1232 | String filter = matcher2.group(4); |
1233 | if (filter != null) { | |
1234 | filter = filter.substring(1, filter.length() - 1); // remove '[' and ']' | |
1235 | eventInfo.setFilterExpression(filter); | |
1236 | } | |
cfdb727a | 1237 | |
1f07c96c BH |
1238 | if ((eventInfo.getEventType() == TraceEventType.PROBE) || |
1239 | (eventInfo.getEventType() == TraceEventType.FUNCTION)){ | |
d132bcc7 BH |
1240 | IProbeEventInfo probeEvent = new ProbeEventInfo(eventInfo.getName()); |
1241 | probeEvent.setLogLevel(eventInfo.getLogLevel()); | |
1242 | probeEvent.setEventType(eventInfo.getEventType()); | |
1243 | probeEvent.setState(eventInfo.getState()); | |
1244 | ||
1245 | // Overwrite eventinfo | |
1246 | eventInfo = probeEvent; | |
1247 | ||
1248 | // myevent2 (type: probe) [enabled] | |
1249 | // addr: 0xc0101340 | |
1f07c96c | 1250 | // myevent0 (type: function) [enabled] |
d132bcc7 BH |
1251 | // offset: 0x0 |
1252 | // symbol: init_post | |
1253 | index++; | |
1254 | while (index < output.length) { | |
1255 | String probeLine = output[index]; | |
1256 | // parse probe | |
276c17e7 BH |
1257 | Matcher addrMatcher = LTTngControlServiceConstants.PROBE_ADDRESS_PATTERN.matcher(probeLine); |
1258 | Matcher offsetMatcher = LTTngControlServiceConstants.PROBE_OFFSET_PATTERN.matcher(probeLine); | |
1259 | Matcher symbolMatcher = LTTngControlServiceConstants.PROBE_SYMBOL_PATTERN.matcher(probeLine); | |
d132bcc7 BH |
1260 | if (addrMatcher.matches()) { |
1261 | String addr = addrMatcher.group(2).trim(); | |
1262 | probeEvent.setAddress(addr); | |
1263 | } else if (offsetMatcher.matches()) { | |
1264 | String offset = offsetMatcher.group(2).trim(); | |
1265 | probeEvent.setOffset(offset); | |
1266 | } else if (symbolMatcher.matches()) { | |
1267 | String symbol = symbolMatcher.group(2).trim(); | |
1268 | probeEvent.setSymbol(symbol); | |
276c17e7 | 1269 | } else if ((LTTngControlServiceConstants.EVENT_PATTERN.matcher(probeLine).matches()) || (LTTngControlServiceConstants.WILDCARD_EVENT_PATTERN.matcher(probeLine).matches())) { |
d132bcc7 | 1270 | break; |
276c17e7 | 1271 | } else if (LTTngControlServiceConstants.CHANNEL_PATTERN.matcher(probeLine).matches()) { |
d132bcc7 | 1272 | break; |
276c17e7 | 1273 | } else if (LTTngControlServiceConstants.DOMAIN_KERNEL_PATTERN.matcher(probeLine).matches()) { |
d132bcc7 BH |
1274 | // end of domain |
1275 | break; | |
276c17e7 | 1276 | } else if (LTTngControlServiceConstants.DOMAIN_UST_GLOBAL_PATTERN.matcher(probeLine).matches()) { |
d132bcc7 BH |
1277 | // end of domain |
1278 | break; | |
1279 | } | |
1280 | index++; | |
1281 | } | |
1282 | events.add(eventInfo); | |
1283 | } else { | |
1284 | events.add(eventInfo); | |
1285 | index++; | |
1286 | continue; | |
1287 | } | |
1288 | } else { | |
1289 | index++; | |
eb1bab5b | 1290 | } |
eb1bab5b BH |
1291 | } |
1292 | ||
1293 | return index; | |
1294 | } | |
1295 | ||
1296 | /** | |
1297 | * Parses a line with attributes: <attribute Name>: <attribute value> | |
cfdb727a | 1298 | * |
4775bcbf BH |
1299 | * @param line |
1300 | * - attribute line to parse | |
eb1bab5b | 1301 | * @return the attribute value as string |
eb1bab5b | 1302 | */ |
276c17e7 | 1303 | protected String getAttributeValue(String line) { |
eb1bab5b BH |
1304 | String[] temp = line.split("\\: "); //$NON-NLS-1$ |
1305 | return temp[1]; | |
1306 | } | |
1307 | ||
1308 | /** | |
4775bcbf | 1309 | * Parses the event information within a provider. |
cfdb727a | 1310 | * |
4775bcbf BH |
1311 | * @param output |
1312 | * - a command output array | |
1313 | * @param currentIndex | |
1314 | * - current index in command output array | |
1315 | * @param events | |
1316 | * - list for returning event information | |
eb1bab5b BH |
1317 | * @return the new current index in command output array |
1318 | */ | |
276c17e7 | 1319 | protected int getProviderEventInfo(String[] output, int currentIndex, List<IBaseEventInfo> events) { |
eb1bab5b | 1320 | int index = currentIndex; |
d4514365 | 1321 | IBaseEventInfo eventInfo = null; |
eb1bab5b BH |
1322 | while (index < output.length) { |
1323 | String line = output[index]; | |
276c17e7 | 1324 | Matcher matcher = LTTngControlServiceConstants.PROVIDER_EVENT_PATTERN.matcher(line); |
4775bcbf | 1325 | if (matcher.matches()) { |
d4514365 BH |
1326 | // sched_kthread_stop (loglevel: TRACE_EMERG0) (type: tracepoint) |
1327 | eventInfo = new BaseEventInfo(matcher.group(1).trim()); | |
4775bcbf BH |
1328 | eventInfo.setLogLevel(matcher.group(2).trim()); |
1329 | eventInfo.setEventType(matcher.group(3).trim()); | |
1330 | events.add(eventInfo); | |
d4514365 BH |
1331 | index++; |
1332 | } else if (LTTngControlServiceConstants.EVENT_FIELD_PATTERN.matcher(line).matches()) { | |
1333 | if (eventInfo != null) { | |
e0838ca1 | 1334 | List<IFieldInfo> fields = new ArrayList<>(); |
d4514365 BH |
1335 | index = getFieldInfo(output, index, fields); |
1336 | eventInfo.setFields(fields); | |
1337 | } else { | |
1338 | index++; | |
1339 | } | |
1340 | } | |
1341 | else if (LTTngControlServiceConstants.UST_PROVIDER_PATTERN.matcher(line).matches()) { | |
1342 | return index; | |
1343 | } else { | |
1344 | index++; | |
1345 | } | |
1346 | } | |
1347 | return index; | |
1348 | } | |
1349 | ||
1350 | ||
7050e327 AM |
1351 | /** |
1352 | * Parse a field's information. | |
1353 | * | |
1354 | * @param output | |
1355 | * A command output array | |
1356 | * @param currentIndex | |
1357 | * The current index in the command output array | |
1358 | * @param fields | |
1359 | * List for returning the field information | |
1360 | * @return The new current index in the command output array | |
1361 | */ | |
d4514365 BH |
1362 | protected int getFieldInfo(String[] output, int currentIndex, List<IFieldInfo> fields) { |
1363 | int index = currentIndex; | |
1364 | IFieldInfo fieldInfo = null; | |
1365 | while (index < output.length) { | |
1366 | String line = output[index]; | |
1367 | Matcher matcher = LTTngControlServiceConstants.EVENT_FIELD_PATTERN.matcher(line); | |
1368 | if (matcher.matches()) { | |
1369 | // field: content (string) | |
1370 | fieldInfo = new FieldInfo(matcher.group(2).trim()); | |
1371 | fieldInfo.setFieldType(matcher.group(3).trim()); | |
1372 | fields.add(fieldInfo); | |
1373 | } else if (LTTngControlServiceConstants.PROVIDER_EVENT_PATTERN.matcher(line).matches()) { | |
1374 | return index; | |
276c17e7 | 1375 | } else if (LTTngControlServiceConstants.UST_PROVIDER_PATTERN.matcher(line).matches()) { |
eb1bab5b BH |
1376 | return index; |
1377 | } | |
1378 | index++; | |
1379 | } | |
1380 | return index; | |
1381 | } | |
1382 | ||
bbb3538a | 1383 | /** |
cfdb727a | 1384 | * Formats a command parameter for the command execution i.e. adds quotes |
bbb3538a BH |
1385 | * at the beginning and end if necessary. |
1386 | * @param parameter - parameter to format | |
1387 | * @return formated parameter | |
1388 | */ | |
276c17e7 | 1389 | protected String formatParameter(String parameter) { |
bbb3538a | 1390 | if (parameter != null) { |
c56972bb BH |
1391 | StringBuffer newString = new StringBuffer(); |
1392 | newString.append(parameter); | |
bbb3538a | 1393 | |
7a6e4bfd | 1394 | if (parameter.contains(" ") || parameter.contains("*")) { //$NON-NLS-1$ //$NON-NLS-2$ |
c56972bb BH |
1395 | newString.insert(0, "\""); //$NON-NLS-1$ |
1396 | newString.append("\""); //$NON-NLS-1$ | |
bbb3538a | 1397 | } |
c56972bb | 1398 | return newString.toString(); |
bbb3538a BH |
1399 | } |
1400 | return null; | |
1401 | } | |
afe13e7a BH |
1402 | |
1403 | /** | |
1404 | * @param strings array of string that makes up a command line | |
1405 | * @return string buffer with created command line | |
1406 | */ | |
276c17e7 | 1407 | protected StringBuffer createCommand(String... strings) { |
afe13e7a | 1408 | StringBuffer command = new StringBuffer(); |
276c17e7 | 1409 | command.append(LTTngControlServiceConstants.CONTROL_COMMAND); |
afe13e7a BH |
1410 | command.append(getTracingGroupOption()); |
1411 | command.append(getVerboseOption()); | |
1412 | for (String string : strings) { | |
1413 | command.append(string); | |
1414 | } | |
1415 | return command; | |
1416 | } | |
1417 | ||
1418 | /** | |
1419 | * @return the tracing group option if configured in the preferences | |
1420 | */ | |
276c17e7 | 1421 | protected String getTracingGroupOption() { |
afe13e7a | 1422 | if (!ControlPreferences.getInstance().isDefaultTracingGroup() && !ControlPreferences.getInstance().getTracingGroup().equals("")) { //$NON-NLS-1$ |
276c17e7 | 1423 | return LTTngControlServiceConstants.OPTION_TRACING_GROUP + ControlPreferences.getInstance().getTracingGroup(); |
afe13e7a BH |
1424 | } |
1425 | return ""; //$NON-NLS-1$ | |
1426 | } | |
1427 | ||
1428 | /** | |
1429 | * @return the verbose option as configured in the preferences | |
1430 | */ | |
276c17e7 | 1431 | protected String getVerboseOption() { |
afe13e7a BH |
1432 | if (ControlPreferences.getInstance().isLoggingEnabled()) { |
1433 | String level = ControlPreferences.getInstance().getVerboseLevel(); | |
1434 | if (ControlPreferences.TRACE_CONTROL_VERBOSE_LEVEL_VERBOSE.equals(level)) { | |
276c17e7 | 1435 | return LTTngControlServiceConstants.OPTION_VERBOSE; |
afe13e7a BH |
1436 | } |
1437 | if (ControlPreferences.TRACE_CONTROL_VERBOSE_LEVEL_V_VERBOSE.equals(level)) { | |
276c17e7 | 1438 | return LTTngControlServiceConstants.OPTION_VERY_VERBOSE; |
cfdb727a | 1439 | } |
afe13e7a | 1440 | if (ControlPreferences.TRACE_CONTROL_VERBOSE_LEVEL_V_V_VERBOSE.equals(level)) { |
276c17e7 | 1441 | return LTTngControlServiceConstants.OPTION_VERY_VERY_VERBOSE; |
afe13e7a BH |
1442 | } |
1443 | } | |
1444 | return ""; //$NON-NLS-1$ | |
1445 | } | |
1446 | ||
1447 | /** | |
cfdb727a AM |
1448 | * Method that logs the command and command result if logging is enabled as |
1449 | * well as forwards the command execution to the shell. | |
1450 | * | |
1451 | * @param command | |
1452 | * - the command to execute | |
1453 | * @param monitor | |
1454 | * - a progress monitor | |
afe13e7a BH |
1455 | * @return the command result |
1456 | * @throws ExecutionException | |
6f4e8ec0 | 1457 | * If the command fails |
afe13e7a | 1458 | */ |
cfdb727a AM |
1459 | protected ICommandResult executeCommand(String command, |
1460 | IProgressMonitor monitor) throws ExecutionException { | |
afe13e7a BH |
1461 | return executeCommand(command, monitor, true); |
1462 | } | |
cfdb727a | 1463 | |
afe13e7a | 1464 | /** |
cfdb727a AM |
1465 | * Method that logs the command and command result if logging is enabled as |
1466 | * well as forwards the command execution to the shell. | |
1467 | * | |
1468 | * @param command | |
1469 | * - the command to execute | |
1470 | * @param monitor | |
1471 | * - a progress monitor | |
1472 | * @param checkForError | |
1473 | * - true to verify command result, else false | |
afe13e7a | 1474 | * @return the command result |
cfdb727a AM |
1475 | * @throws ExecutionException |
1476 | * in case of error result | |
afe13e7a | 1477 | */ |
cfdb727a AM |
1478 | protected ICommandResult executeCommand(String command, |
1479 | IProgressMonitor monitor, boolean checkForError) | |
1480 | throws ExecutionException { | |
afe13e7a BH |
1481 | if (ControlPreferences.getInstance().isLoggingEnabled()) { |
1482 | ControlCommandLogger.log(command); | |
1483 | } | |
1484 | ||
cfdb727a AM |
1485 | ICommandResult result = fCommandShell.executeCommand( |
1486 | command.toString(), monitor); | |
1487 | ||
afe13e7a BH |
1488 | if (ControlPreferences.getInstance().isLoggingEnabled()) { |
1489 | ControlCommandLogger.log(formatOutput(result)); | |
1490 | } | |
1491 | ||
a07c7629 | 1492 | if (checkForError && isError(result)) { |
cfdb727a AM |
1493 | throw new ExecutionException(Messages.TraceControl_CommandError |
1494 | + " " + command.toString() + "\n" + formatOutput(result)); //$NON-NLS-1$ //$NON-NLS-2$ | |
afe13e7a | 1495 | } |
cfdb727a | 1496 | |
afe13e7a BH |
1497 | return result; |
1498 | } | |
eb1bab5b | 1499 | } |