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