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