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