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