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