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