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