| 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 | **********************************************************************/ |
| 12 | package org.eclipse.linuxtools.internal.lttng2.ui.views.control.service; |
| 13 | |
| 14 | import java.util.ArrayList; |
| 15 | import java.util.Iterator; |
| 16 | import java.util.List; |
| 17 | import java.util.regex.Matcher; |
| 18 | |
| 19 | import org.eclipse.core.commands.ExecutionException; |
| 20 | import org.eclipse.core.runtime.IProgressMonitor; |
| 21 | import org.eclipse.core.runtime.NullProgressMonitor; |
| 22 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.Messages; |
| 23 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.logging.ControlCommandLogger; |
| 24 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IBaseEventInfo; |
| 25 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo; |
| 26 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IDomainInfo; |
| 27 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IEventInfo; |
| 28 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IProbeEventInfo; |
| 29 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ISessionInfo; |
| 30 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IUstProviderInfo; |
| 31 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.LogLevelType; |
| 32 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceEventType; |
| 33 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceLogLevel; |
| 34 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.BaseEventInfo; |
| 35 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.ChannelInfo; |
| 36 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.DomainInfo; |
| 37 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.EventInfo; |
| 38 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.ProbeEventInfo; |
| 39 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.SessionInfo; |
| 40 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.UstProviderInfo; |
| 41 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.preferences.ControlPreferences; |
| 42 | |
| 43 | /** |
| 44 | * <b><u>LTTngControlService</u></b> |
| 45 | * <p> |
| 46 | * Service for sending LTTng trace control commands to remote host. |
| 47 | * </p> |
| 48 | */ |
| 49 | public class LTTngControlService implements ILttngControlService { |
| 50 | |
| 51 | |
| 52 | // ------------------------------------------------------------------------ |
| 53 | // Attributes |
| 54 | // ------------------------------------------------------------------------ |
| 55 | /** |
| 56 | * The command shell implementation |
| 57 | */ |
| 58 | protected ICommandShell fCommandShell = null; |
| 59 | |
| 60 | protected String fVersion = "Unknown"; //$NON-NLS-1$ |
| 61 | |
| 62 | // ------------------------------------------------------------------------ |
| 63 | // Constructors |
| 64 | // ------------------------------------------------------------------------ |
| 65 | |
| 66 | /** |
| 67 | * Constructor |
| 68 | * |
| 69 | * @param shell |
| 70 | * - the command shell implementation to use |
| 71 | */ |
| 72 | public LTTngControlService(ICommandShell shell) { |
| 73 | fCommandShell = shell; |
| 74 | } |
| 75 | |
| 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 | } |
| 91 | // ------------------------------------------------------------------------ |
| 92 | // Operations |
| 93 | // ------------------------------------------------------------------------ |
| 94 | |
| 95 | /* |
| 96 | * (non-Javadoc) |
| 97 | * |
| 98 | * @see |
| 99 | * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService |
| 100 | * #getSessionNames(org.eclipse.core.runtime.IProgressMonitor) |
| 101 | */ |
| 102 | @Override |
| 103 | public String[] getSessionNames(IProgressMonitor monitor) throws ExecutionException { |
| 104 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_LIST); |
| 105 | |
| 106 | ICommandResult result = executeCommand(command.toString(), monitor); |
| 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]; |
| 121 | Matcher matcher = LTTngControlServiceConstants.SESSION_PATTERN.matcher(line); |
| 122 | if (matcher.matches()) { |
| 123 | retArray.add(matcher.group(2).trim()); |
| 124 | } |
| 125 | index++; |
| 126 | } |
| 127 | return retArray.toArray(new String[retArray.size()]); |
| 128 | } |
| 129 | |
| 130 | /* |
| 131 | * (non-Javadoc) |
| 132 | * |
| 133 | * @see |
| 134 | * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService |
| 135 | * #getSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor) |
| 136 | */ |
| 137 | @Override |
| 138 | public ISessionInfo getSession(String sessionName, IProgressMonitor monitor) throws ExecutionException { |
| 139 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_LIST, sessionName); |
| 140 | ICommandResult result = executeCommand(command.toString(), monitor); |
| 141 | |
| 142 | int index = 0; |
| 143 | |
| 144 | // Output: |
| 145 | // Tracing session mysession2: [inactive] |
| 146 | // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330 |
| 147 | ISessionInfo sessionInfo = new SessionInfo(sessionName); |
| 148 | |
| 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]; |
| 156 | Matcher matcher = LTTngControlServiceConstants.TRACE_SESSION_PATTERN.matcher(line); |
| 157 | if (matcher.matches()) { |
| 158 | sessionInfo.setSessionState(matcher.group(2)); |
| 159 | index++; |
| 160 | continue; |
| 161 | } |
| 162 | |
| 163 | matcher = LTTngControlServiceConstants.TRACE_SESSION_PATH_PATTERN.matcher(line); |
| 164 | if (matcher.matches()) { |
| 165 | sessionInfo.setSessionPath(matcher.group(1).trim()); |
| 166 | index++; |
| 167 | continue; |
| 168 | } |
| 169 | |
| 170 | matcher = LTTngControlServiceConstants.DOMAIN_KERNEL_PATTERN.matcher(line); |
| 171 | if (matcher.matches()) { |
| 172 | // Create Domain |
| 173 | IDomainInfo domainInfo = new DomainInfo(Messages.TraceControl_KernelDomainDisplayName); |
| 174 | sessionInfo.addDomain(domainInfo); |
| 175 | |
| 176 | // in domain kernel |
| 177 | ArrayList<IChannelInfo> channels = new ArrayList<IChannelInfo>(); |
| 178 | index = parseDomain(result.getOutput(), index, channels); |
| 179 | |
| 180 | // set channels |
| 181 | domainInfo.setChannels(channels); |
| 182 | |
| 183 | // set kernel flag |
| 184 | domainInfo.setIsKernel(true); |
| 185 | continue; |
| 186 | } |
| 187 | |
| 188 | matcher = LTTngControlServiceConstants.DOMAIN_UST_GLOBAL_PATTERN.matcher(line); |
| 189 | if (matcher.matches()) { |
| 190 | IDomainInfo domainInfo = new DomainInfo(Messages.TraceControl_UstGlobalDomainDisplayName); |
| 191 | sessionInfo.addDomain(domainInfo); |
| 192 | |
| 193 | // in domain UST |
| 194 | ArrayList<IChannelInfo> channels = new ArrayList<IChannelInfo>(); |
| 195 | index = parseDomain(result.getOutput(), index, channels); |
| 196 | |
| 197 | // set channels |
| 198 | domainInfo.setChannels(channels); |
| 199 | |
| 200 | // set kernel flag |
| 201 | domainInfo.setIsKernel(false); |
| 202 | continue; |
| 203 | } |
| 204 | index++; |
| 205 | } |
| 206 | return sessionInfo; |
| 207 | } |
| 208 | |
| 209 | /* |
| 210 | * (non-Javadoc) |
| 211 | * |
| 212 | * @see |
| 213 | * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService |
| 214 | * #getKernelProvider(org.eclipse.core.runtime.IProgressMonitor) |
| 215 | */ |
| 216 | @Override |
| 217 | public List<IBaseEventInfo> getKernelProvider(IProgressMonitor monitor) throws ExecutionException { |
| 218 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_LIST_KERNEL); |
| 219 | ICommandResult result = executeCommand(command.toString(), monitor); |
| 220 | |
| 221 | // Kernel events: |
| 222 | // ------------- |
| 223 | // sched_kthread_stop (type: tracepoint) |
| 224 | List<IBaseEventInfo> events = new ArrayList<IBaseEventInfo>(); |
| 225 | getProviderEventInfo(result.getOutput(), 0, events); |
| 226 | return events; |
| 227 | } |
| 228 | |
| 229 | /* |
| 230 | * (non-Javadoc) |
| 231 | * |
| 232 | * @see |
| 233 | * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService |
| 234 | * #getUstProvider() |
| 235 | */ |
| 236 | @Override |
| 237 | public List<IUstProviderInfo> getUstProvider() throws ExecutionException { |
| 238 | return getUstProvider(new NullProgressMonitor()); |
| 239 | } |
| 240 | |
| 241 | /* |
| 242 | * (non-Javadoc) |
| 243 | * |
| 244 | * @see |
| 245 | * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService |
| 246 | * #getUstProvider(org.eclipse.core.runtime.IProgressMonitor) |
| 247 | */ |
| 248 | @Override |
| 249 | public List<IUstProviderInfo> getUstProvider(IProgressMonitor monitor) throws ExecutionException { |
| 250 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_LIST_UST); |
| 251 | |
| 252 | ICommandResult result = executeCommand(command.toString(), monitor); |
| 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) |
| 268 | |
| 269 | List<IUstProviderInfo> allProviders = new ArrayList<IUstProviderInfo>(); |
| 270 | IUstProviderInfo provider = null; |
| 271 | |
| 272 | int index = 0; |
| 273 | while (index < result.getOutput().length) { |
| 274 | String line = result.getOutput()[index]; |
| 275 | Matcher matcher = LTTngControlServiceConstants.UST_PROVIDER_PATTERN.matcher(line); |
| 276 | if (matcher.matches()) { |
| 277 | |
| 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); |
| 284 | |
| 285 | } else { |
| 286 | index++; |
| 287 | } |
| 288 | |
| 289 | } |
| 290 | return allProviders; |
| 291 | } |
| 292 | |
| 293 | /* |
| 294 | * (non-Javadoc) |
| 295 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#createSession(java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor) |
| 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 | |
| 303 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_CREATE_SESSION, newName); |
| 304 | |
| 305 | if (newPath != null && !"".equals(newPath)) { //$NON-NLS-1$ |
| 306 | command.append(LTTngControlServiceConstants.OPTION_OUTPUT_PATH); |
| 307 | command.append(newPath); |
| 308 | } |
| 309 | |
| 310 | ICommandResult result = executeCommand(command.toString(), monitor); |
| 311 | |
| 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 |
| 317 | Matcher matcher = LTTngControlServiceConstants.CREATE_SESSION_NAME_PATTERN.matcher(output[0]); |
| 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$ |
| 325 | Messages.TraceControl_UnexpectedCommandOutputFormat + ":\n" + //$NON-NLS-1$ |
| 326 | formatOutput(result)); |
| 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 |
| 336 | matcher = LTTngControlServiceConstants.CREATE_SESSION_PATH_PATTERN.matcher(output[1]); |
| 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$ |
| 344 | Messages.TraceControl_UnexpectedCommandOutputFormat + ":\n" + //$NON-NLS-1$ |
| 345 | formatOutput(result)); |
| 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); |
| 363 | |
| 364 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_DESTROY_SESSION, newName); |
| 365 | |
| 366 | ICommandResult result = executeCommand(command.toString(), monitor, false); |
| 367 | String[] output = result.getOutput(); |
| 368 | |
| 369 | if (isError(result) && ((output == null) || (!LTTngControlServiceConstants.SESSION_NOT_FOUND_ERROR_PATTERN.matcher(output[0]).matches()))) { |
| 370 | throw new ExecutionException(Messages.TraceControl_CommandError + " " + command.toString() + "\n" + formatOutput(result)); //$NON-NLS-1$ //$NON-NLS-2$ |
| 371 | } |
| 372 | //Session <sessionName> destroyed |
| 373 | } |
| 374 | |
| 375 | /* |
| 376 | * (non-Javadoc) |
| 377 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#startSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor) |
| 378 | */ |
| 379 | @Override |
| 380 | public void startSession(String sessionName, IProgressMonitor monitor) throws ExecutionException { |
| 381 | |
| 382 | String newSessionName = formatParameter(sessionName); |
| 383 | |
| 384 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_START_SESSION, newSessionName); |
| 385 | |
| 386 | executeCommand(command.toString(), monitor); |
| 387 | |
| 388 | //Session <sessionName> started |
| 389 | } |
| 390 | |
| 391 | /* |
| 392 | * (non-Javadoc) |
| 393 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#stopSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor) |
| 394 | */ |
| 395 | @Override |
| 396 | public void stopSession(String sessionName, IProgressMonitor monitor) throws ExecutionException { |
| 397 | String newSessionName = formatParameter(sessionName); |
| 398 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_STOP_SESSION, newSessionName); |
| 399 | |
| 400 | executeCommand(command.toString(), monitor); |
| 401 | |
| 402 | //Session <sessionName> stopped |
| 403 | |
| 404 | } |
| 405 | |
| 406 | /* |
| 407 | * (non-Javadoc) |
| 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) |
| 409 | */ |
| 410 | @Override |
| 411 | public void enableChannels(String sessionName, List<String> channelNames, boolean isKernel, IChannelInfo info, IProgressMonitor monitor) throws ExecutionException { |
| 412 | |
| 413 | // no channels to enable |
| 414 | if (channelNames.isEmpty()) { |
| 415 | return; |
| 416 | } |
| 417 | |
| 418 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_ENABLE_CHANNEL); |
| 419 | |
| 420 | for (Iterator<String> iterator = channelNames.iterator(); iterator.hasNext();) { |
| 421 | String channel = (String) iterator.next(); |
| 422 | command.append(channel); |
| 423 | if (iterator.hasNext()) { |
| 424 | command.append(','); |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | if (isKernel) { |
| 429 | command.append(LTTngControlServiceConstants.OPTION_KERNEL); |
| 430 | } else { |
| 431 | command.append(LTTngControlServiceConstants.OPTION_UST); |
| 432 | } |
| 433 | |
| 434 | String newSessionName = formatParameter(sessionName); |
| 435 | command.append(LTTngControlServiceConstants.OPTION_SESSION); |
| 436 | command.append(newSessionName); |
| 437 | |
| 438 | if (info != null) { |
| 439 | // --discard Discard event when buffers are full (default) |
| 440 | |
| 441 | // --overwrite Flight recorder mode |
| 442 | if (info.isOverwriteMode()) { |
| 443 | command.append(LTTngControlServiceConstants.OPTION_OVERWRITE); |
| 444 | } |
| 445 | // --subbuf-size SIZE Subbuffer size in bytes |
| 446 | // (default: 4096, kernel default: 262144) |
| 447 | command.append(LTTngControlServiceConstants.OPTION_SUB_BUFFER_SIZE); |
| 448 | command.append(String.valueOf(info.getSubBufferSize())); |
| 449 | |
| 450 | // --num-subbuf NUM Number of subbufers |
| 451 | // (default: 8, kernel default: 4) |
| 452 | command.append(LTTngControlServiceConstants.OPTION_NUM_SUB_BUFFERS); |
| 453 | command.append(String.valueOf(info.getNumberOfSubBuffers())); |
| 454 | |
| 455 | // --switch-timer USEC Switch timer interval in usec (default: 0) |
| 456 | command.append(LTTngControlServiceConstants.OPTION_SWITCH_TIMER); |
| 457 | command.append(String.valueOf(info.getSwitchTimer())); |
| 458 | |
| 459 | // --read-timer USEC Read timer interval in usec (default: 200) |
| 460 | command.append(LTTngControlServiceConstants.OPTION_READ_TIMER); |
| 461 | command.append(String.valueOf(info.getReadTimer())); |
| 462 | } |
| 463 | |
| 464 | executeCommand(command.toString(), monitor); |
| 465 | |
| 466 | } |
| 467 | |
| 468 | /* |
| 469 | * (non-Javadoc) |
| 470 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#disableChannel(java.lang.String, java.util.List, org.eclipse.core.runtime.IProgressMonitor) |
| 471 | */ |
| 472 | @Override |
| 473 | public void disableChannels(String sessionName, List<String> channelNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException { |
| 474 | |
| 475 | // no channels to enable |
| 476 | if (channelNames.isEmpty()) { |
| 477 | return; |
| 478 | } |
| 479 | |
| 480 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_DISABLE_CHANNEL); |
| 481 | |
| 482 | for (Iterator<String> iterator = channelNames.iterator(); iterator.hasNext();) { |
| 483 | String channel = (String) iterator.next(); |
| 484 | command.append(channel); |
| 485 | if (iterator.hasNext()) { |
| 486 | command.append(','); |
| 487 | } |
| 488 | } |
| 489 | |
| 490 | if (isKernel) { |
| 491 | command.append(LTTngControlServiceConstants.OPTION_KERNEL); |
| 492 | } else { |
| 493 | command.append(LTTngControlServiceConstants.OPTION_UST); |
| 494 | } |
| 495 | |
| 496 | String newSessionName = formatParameter(sessionName); |
| 497 | command.append(LTTngControlServiceConstants.OPTION_SESSION); |
| 498 | command.append(newSessionName); |
| 499 | |
| 500 | executeCommand(command.toString(), monitor); |
| 501 | } |
| 502 | |
| 503 | /* |
| 504 | * (non-Javadoc) |
| 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) |
| 506 | */ |
| 507 | @Override |
| 508 | public void enableEvents(String sessionName, String channelName, List<String> eventNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException { |
| 509 | |
| 510 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_ENABLE_EVENT); |
| 511 | |
| 512 | if (eventNames == null || eventNames.isEmpty()) { |
| 513 | command.append(LTTngControlServiceConstants.OPTION_ALL); |
| 514 | } else { |
| 515 | |
| 516 | for (Iterator<String> iterator = eventNames.iterator(); iterator.hasNext();) { |
| 517 | String event = (String) iterator.next(); |
| 518 | command.append(event); |
| 519 | if (iterator.hasNext()) { |
| 520 | command.append(','); |
| 521 | } |
| 522 | } |
| 523 | } |
| 524 | |
| 525 | if (isKernel) { |
| 526 | command.append(LTTngControlServiceConstants.OPTION_KERNEL); |
| 527 | } else { |
| 528 | command.append(LTTngControlServiceConstants.OPTION_UST); |
| 529 | } |
| 530 | |
| 531 | String newSessionName = formatParameter(sessionName); |
| 532 | |
| 533 | command.append(LTTngControlServiceConstants.OPTION_SESSION); |
| 534 | command.append(newSessionName); |
| 535 | |
| 536 | if (channelName != null) { |
| 537 | command.append(LTTngControlServiceConstants.OPTION_CHANNEL); |
| 538 | command.append(channelName); |
| 539 | } |
| 540 | |
| 541 | command.append(LTTngControlServiceConstants.OPTION_TRACEPOINT); |
| 542 | |
| 543 | executeCommand(command.toString(), monitor); |
| 544 | |
| 545 | } |
| 546 | |
| 547 | /* |
| 548 | * (non-Javadoc) |
| 549 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#enableSyscalls(java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor) |
| 550 | */ |
| 551 | @Override |
| 552 | public void enableSyscalls(String sessionName, String channelName, IProgressMonitor monitor) throws ExecutionException { |
| 553 | |
| 554 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_ENABLE_EVENT); |
| 555 | |
| 556 | command.append(LTTngControlServiceConstants.OPTION_ALL); |
| 557 | command.append(LTTngControlServiceConstants.OPTION_KERNEL); |
| 558 | |
| 559 | String newSessionName = formatParameter(sessionName); |
| 560 | |
| 561 | command.append(LTTngControlServiceConstants.OPTION_SESSION); |
| 562 | command.append(newSessionName); |
| 563 | |
| 564 | if (channelName != null) { |
| 565 | command.append(LTTngControlServiceConstants.OPTION_CHANNEL); |
| 566 | command.append(channelName); |
| 567 | } |
| 568 | |
| 569 | command.append(LTTngControlServiceConstants.OPTION_SYSCALL); |
| 570 | |
| 571 | executeCommand(command.toString(), monitor); |
| 572 | } |
| 573 | |
| 574 | /* |
| 575 | * (non-Javadoc) |
| 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) |
| 577 | */ |
| 578 | @Override |
| 579 | public void enableProbe(String sessionName, String channelName, String eventName, boolean isFunction, String probe, IProgressMonitor monitor) throws ExecutionException { |
| 580 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_ENABLE_EVENT); |
| 581 | |
| 582 | command.append(eventName); |
| 583 | command.append(LTTngControlServiceConstants.OPTION_KERNEL); |
| 584 | |
| 585 | String newSessionName = formatParameter(sessionName); |
| 586 | command.append(LTTngControlServiceConstants.OPTION_SESSION); |
| 587 | command.append(newSessionName); |
| 588 | |
| 589 | if (channelName != null) { |
| 590 | command.append(LTTngControlServiceConstants.OPTION_CHANNEL); |
| 591 | command.append(channelName); |
| 592 | } |
| 593 | if (isFunction) { |
| 594 | command.append(LTTngControlServiceConstants.OPTION_FUNCTION_PROBE); |
| 595 | } else { |
| 596 | command.append(LTTngControlServiceConstants.OPTION_PROBE); |
| 597 | } |
| 598 | |
| 599 | command.append(probe); |
| 600 | |
| 601 | executeCommand(command.toString(), monitor); |
| 602 | } |
| 603 | |
| 604 | /* |
| 605 | * (non-Javadoc) |
| 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) |
| 607 | */ |
| 608 | @Override |
| 609 | public void enableLogLevel(String sessionName, String channelName, String eventName, LogLevelType logLevelType, TraceLogLevel level, IProgressMonitor monitor) throws ExecutionException { |
| 610 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_ENABLE_EVENT); |
| 611 | |
| 612 | command.append(eventName); |
| 613 | command.append(LTTngControlServiceConstants.OPTION_UST); |
| 614 | |
| 615 | String newSessionName = formatParameter(sessionName); |
| 616 | command.append(LTTngControlServiceConstants.OPTION_SESSION); |
| 617 | command.append(newSessionName); |
| 618 | |
| 619 | if (channelName != null) { |
| 620 | command.append(LTTngControlServiceConstants.OPTION_CHANNEL); |
| 621 | command.append(channelName); |
| 622 | } |
| 623 | |
| 624 | if (logLevelType == LogLevelType.LOGLEVEL) { |
| 625 | command.append(LTTngControlServiceConstants.OPTION_LOGLEVEL); |
| 626 | } else if (logLevelType == LogLevelType.LOGLEVEL_ONLY) { |
| 627 | command.append(LTTngControlServiceConstants.OPTION_LOGLEVEL_ONLY); |
| 628 | |
| 629 | } else { |
| 630 | return; |
| 631 | } |
| 632 | command.append(level.getInName()); |
| 633 | |
| 634 | executeCommand(command.toString(), monitor); |
| 635 | |
| 636 | } |
| 637 | |
| 638 | /* |
| 639 | * (non-Javadoc) |
| 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) |
| 641 | */ |
| 642 | @Override |
| 643 | public void disableEvent(String sessionName, String channelName, List<String> eventNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException { |
| 644 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_DISABLE_EVENT); |
| 645 | |
| 646 | if (eventNames == null) { |
| 647 | command.append(LTTngControlServiceConstants.OPTION_ALL); |
| 648 | } else { |
| 649 | // no events to enable |
| 650 | if (eventNames.isEmpty()) { |
| 651 | return; |
| 652 | } |
| 653 | |
| 654 | for (Iterator<String> iterator = eventNames.iterator(); iterator.hasNext();) { |
| 655 | String event = (String) iterator.next(); |
| 656 | command.append(event); |
| 657 | if (iterator.hasNext()) { |
| 658 | command.append(','); |
| 659 | } |
| 660 | } |
| 661 | } |
| 662 | |
| 663 | if (isKernel) { |
| 664 | command.append(LTTngControlServiceConstants.OPTION_KERNEL); |
| 665 | } else { |
| 666 | command.append(LTTngControlServiceConstants.OPTION_UST); |
| 667 | } |
| 668 | |
| 669 | String newSessionName = formatParameter(sessionName); |
| 670 | command.append(LTTngControlServiceConstants.OPTION_SESSION); |
| 671 | command.append(newSessionName); |
| 672 | |
| 673 | if (channelName != null) { |
| 674 | command.append(LTTngControlServiceConstants.OPTION_CHANNEL); |
| 675 | command.append(channelName); |
| 676 | } |
| 677 | |
| 678 | executeCommand(command.toString(), monitor); |
| 679 | } |
| 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 | |
| 688 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_ADD_CONTEXT, LTTngControlServiceConstants.OPTION_HELP); |
| 689 | |
| 690 | ICommandResult result = executeCommand(command.toString(), monitor); |
| 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 | |
| 701 | Matcher startMatcher = LTTngControlServiceConstants.ADD_CONTEXT_HELP_CONTEXTS_INTRO.matcher(line); |
| 702 | Matcher endMatcher = LTTngControlServiceConstants.ADD_CONTEXT_HELP_CONTEXTS_END_LINE.matcher(line); |
| 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 { |
| 725 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_ADD_CONTEXT); |
| 726 | |
| 727 | String newSessionName = formatParameter(sessionName); |
| 728 | command.append(LTTngControlServiceConstants.OPTION_SESSION); |
| 729 | command.append(newSessionName); |
| 730 | |
| 731 | if (channelName != null) { |
| 732 | command.append(LTTngControlServiceConstants.OPTION_CHANNEL); |
| 733 | command.append(channelName); |
| 734 | } |
| 735 | |
| 736 | if (eventName != null) { |
| 737 | command.append(LTTngControlServiceConstants.OPTION_EVENT); |
| 738 | command.append(eventName); |
| 739 | } |
| 740 | |
| 741 | if (isKernel) { |
| 742 | command.append(LTTngControlServiceConstants.OPTION_KERNEL); |
| 743 | } else { |
| 744 | command.append(LTTngControlServiceConstants.OPTION_UST); |
| 745 | } |
| 746 | |
| 747 | for (Iterator<String> iterator = contextNames.iterator(); iterator.hasNext();) { |
| 748 | String context = (String) iterator.next(); |
| 749 | command.append(LTTngControlServiceConstants.OPTION_CONTEXT_TYPE); |
| 750 | command.append(context); |
| 751 | } |
| 752 | |
| 753 | executeCommand(command.toString(), monitor); |
| 754 | |
| 755 | } |
| 756 | |
| 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); |
| 764 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_CALIBRATE); |
| 765 | // |
| 766 | // command.append(OPTION_SESSION); |
| 767 | // command.append(newSessionName); |
| 768 | |
| 769 | if (isKernel) { |
| 770 | command.append(LTTngControlServiceConstants.OPTION_KERNEL); |
| 771 | } else { |
| 772 | command.append(LTTngControlServiceConstants.OPTION_UST); |
| 773 | } |
| 774 | |
| 775 | command.append(LTTngControlServiceConstants.OPTION_FUNCTION_PROBE); |
| 776 | |
| 777 | executeCommand(command.toString(), monitor); |
| 778 | } |
| 779 | |
| 780 | // ------------------------------------------------------------------------ |
| 781 | // Helper methods |
| 782 | // ------------------------------------------------------------------------ |
| 783 | /** |
| 784 | * Checks if command result is an error result. |
| 785 | * |
| 786 | * @param result |
| 787 | * - the command result to check |
| 788 | * @return true if error else false |
| 789 | */ |
| 790 | protected boolean isError(ICommandResult result) { |
| 791 | if ((result.getResult()) != 0 || (result.getOutput().length < 1 || LTTngControlServiceConstants.ERROR_PATTERN.matcher(result.getOutput()[0]).matches())) { |
| 792 | return true; |
| 793 | } |
| 794 | return false; |
| 795 | } |
| 796 | |
| 797 | /** |
| 798 | * Formats the output string as single string. |
| 799 | * |
| 800 | * @param output |
| 801 | * - output array |
| 802 | * @return - the formatted output |
| 803 | */ |
| 804 | protected String formatOutput(ICommandResult result) { |
| 805 | if ((result == null) || result.getOutput() == null || result.getOutput().length == 0) { |
| 806 | return ""; //$NON-NLS-1$ |
| 807 | } |
| 808 | String[] output = result.getOutput(); |
| 809 | StringBuffer ret = new StringBuffer(); |
| 810 | ret.append("Return Value: "); //$NON-NLS-1$ |
| 811 | ret.append(result.getResult()); |
| 812 | ret.append("\n"); //$NON-NLS-1$ |
| 813 | for (int i = 0; i < output.length; i++) { |
| 814 | ret.append(output[i] + "\n"); //$NON-NLS-1$ |
| 815 | } |
| 816 | return ret.toString(); |
| 817 | } |
| 818 | |
| 819 | /** |
| 820 | * Parses the domain information. |
| 821 | * |
| 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 |
| 829 | */ |
| 830 | protected int parseDomain(String[] output, int currentIndex, List<IChannelInfo> channels) { |
| 831 | int index = currentIndex; |
| 832 | |
| 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 | |
| 845 | while (index < output.length) { |
| 846 | String line = output[index]; |
| 847 | |
| 848 | Matcher outerMatcher = LTTngControlServiceConstants.CHANNELS_SECTION_PATTERN.matcher(line); |
| 849 | if (outerMatcher.matches()) { |
| 850 | IChannelInfo channelInfo = null; |
| 851 | while (index < output.length) { |
| 852 | String subLine = output[index]; |
| 853 | |
| 854 | Matcher innerMatcher = LTTngControlServiceConstants.CHANNEL_PATTERN.matcher(subLine); |
| 855 | if (innerMatcher.matches()) { |
| 856 | channelInfo = new ChannelInfo(""); //$NON-NLS-1$ |
| 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 | |
| 866 | } else if (LTTngControlServiceConstants.OVERWRITE_MODE_ATTRIBUTE.matcher(subLine).matches()) { |
| 867 | String value = getAttributeValue(subLine); |
| 868 | channelInfo.setOverwriteMode(!LTTngControlServiceConstants.OVERWRITE_MODE_ATTRIBUTE_FALSE.equals(value)); |
| 869 | } else if (LTTngControlServiceConstants.SUBBUFFER_SIZE_ATTRIBUTE.matcher(subLine).matches()) { |
| 870 | channelInfo.setSubBufferSize(Long.valueOf(getAttributeValue(subLine))); |
| 871 | |
| 872 | } else if (LTTngControlServiceConstants.NUM_SUBBUFFERS_ATTRIBUTE.matcher(subLine).matches()) { |
| 873 | channelInfo.setNumberOfSubBuffers(Integer.valueOf(getAttributeValue(subLine))); |
| 874 | |
| 875 | } else if (LTTngControlServiceConstants.SWITCH_TIMER_ATTRIBUTE.matcher(subLine).matches()) { |
| 876 | channelInfo.setSwitchTimer(Long.valueOf(getAttributeValue(subLine))); |
| 877 | |
| 878 | } else if (LTTngControlServiceConstants.READ_TIMER_ATTRIBUTE.matcher(subLine).matches()) { |
| 879 | channelInfo.setReadTimer(Long.valueOf(getAttributeValue(subLine))); |
| 880 | |
| 881 | } else if (LTTngControlServiceConstants.OUTPUT_ATTRIBUTE.matcher(subLine).matches()) { |
| 882 | channelInfo.setOutputType(getAttributeValue(subLine)); |
| 883 | |
| 884 | } else if (LTTngControlServiceConstants.EVENT_SECTION_PATTERN.matcher(subLine).matches()) { |
| 885 | List<IEventInfo> events = new ArrayList<IEventInfo>(); |
| 886 | index = parseEvents(output, index, events); |
| 887 | channelInfo.setEvents(events); |
| 888 | // we want to stay at the current index to be able to |
| 889 | // exit the domain |
| 890 | continue; |
| 891 | } else if (LTTngControlServiceConstants.DOMAIN_KERNEL_PATTERN.matcher(subLine).matches()) { |
| 892 | return index; |
| 893 | |
| 894 | } else if (LTTngControlServiceConstants.DOMAIN_UST_GLOBAL_PATTERN.matcher(subLine).matches()) { |
| 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 | * |
| 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 |
| 914 | * @return the new current index in command output array |
| 915 | */ |
| 916 | protected int parseEvents(String[] output, int currentIndex, List<IEventInfo> events) { |
| 917 | int index = currentIndex; |
| 918 | |
| 919 | while (index < output.length) { |
| 920 | String line = output[index]; |
| 921 | if (LTTngControlServiceConstants.CHANNEL_PATTERN.matcher(line).matches()) { |
| 922 | // end of channel |
| 923 | return index; |
| 924 | } else if (LTTngControlServiceConstants.DOMAIN_KERNEL_PATTERN.matcher(line).matches()) { |
| 925 | // end of domain |
| 926 | return index; |
| 927 | } else if (LTTngControlServiceConstants.DOMAIN_UST_GLOBAL_PATTERN.matcher(line).matches()) { |
| 928 | // end of domain |
| 929 | return index; |
| 930 | } |
| 931 | |
| 932 | Matcher matcher = LTTngControlServiceConstants.EVENT_PATTERN.matcher(line); |
| 933 | Matcher matcher2 = LTTngControlServiceConstants.WILDCARD_EVENT_PATTERN.matcher(line); |
| 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); |
| 941 | index++; |
| 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)); |
| 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 |
| 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); |
| 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); |
| 978 | } else if ((LTTngControlServiceConstants.EVENT_PATTERN.matcher(probeLine).matches()) || (LTTngControlServiceConstants.WILDCARD_EVENT_PATTERN.matcher(probeLine).matches())) { |
| 979 | break; |
| 980 | } else if (LTTngControlServiceConstants.CHANNEL_PATTERN.matcher(probeLine).matches()) { |
| 981 | break; |
| 982 | } else if (LTTngControlServiceConstants.DOMAIN_KERNEL_PATTERN.matcher(probeLine).matches()) { |
| 983 | // end of domain |
| 984 | break; |
| 985 | } else if (LTTngControlServiceConstants.DOMAIN_UST_GLOBAL_PATTERN.matcher(probeLine).matches()) { |
| 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++; |
| 999 | } |
| 1000 | // else if (line.matches(EVENT_NONE_PATTERN)) { |
| 1001 | // do nothing |
| 1002 | // } else |
| 1003 | |
| 1004 | } |
| 1005 | |
| 1006 | return index; |
| 1007 | } |
| 1008 | |
| 1009 | /** |
| 1010 | * Parses a line with attributes: <attribute Name>: <attribute value> |
| 1011 | * |
| 1012 | * @param line |
| 1013 | * - attribute line to parse |
| 1014 | * @return the attribute value as string |
| 1015 | */ |
| 1016 | protected String getAttributeValue(String line) { |
| 1017 | String[] temp = line.split("\\: "); //$NON-NLS-1$ |
| 1018 | return temp[1]; |
| 1019 | } |
| 1020 | |
| 1021 | /** |
| 1022 | * Parses the event information within a provider. |
| 1023 | * |
| 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 |
| 1030 | * @return the new current index in command output array |
| 1031 | */ |
| 1032 | protected int getProviderEventInfo(String[] output, int currentIndex, List<IBaseEventInfo> events) { |
| 1033 | int index = currentIndex; |
| 1034 | while (index < output.length) { |
| 1035 | String line = output[index]; |
| 1036 | Matcher matcher = LTTngControlServiceConstants.PROVIDER_EVENT_PATTERN.matcher(line); |
| 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); |
| 1044 | } else if (LTTngControlServiceConstants.UST_PROVIDER_PATTERN.matcher(line).matches()) { |
| 1045 | return index; |
| 1046 | } |
| 1047 | index++; |
| 1048 | } |
| 1049 | return index; |
| 1050 | } |
| 1051 | |
| 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 | */ |
| 1058 | protected String formatParameter(String parameter) { |
| 1059 | if (parameter != null) { |
| 1060 | StringBuffer newString = new StringBuffer(); |
| 1061 | newString.append(parameter); |
| 1062 | |
| 1063 | if (parameter.contains(" ")) { //$NON-NLS-1$ |
| 1064 | newString.insert(0, "\""); //$NON-NLS-1$ |
| 1065 | newString.append("\""); //$NON-NLS-1$ |
| 1066 | } |
| 1067 | return newString.toString(); |
| 1068 | } |
| 1069 | return null; |
| 1070 | } |
| 1071 | |
| 1072 | /** |
| 1073 | * @param strings array of string that makes up a command line |
| 1074 | * @return string buffer with created command line |
| 1075 | */ |
| 1076 | protected StringBuffer createCommand(String... strings) { |
| 1077 | StringBuffer command = new StringBuffer(); |
| 1078 | command.append(LTTngControlServiceConstants.CONTROL_COMMAND); |
| 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 | */ |
| 1090 | protected String getTracingGroupOption() { |
| 1091 | if (!ControlPreferences.getInstance().isDefaultTracingGroup() && !ControlPreferences.getInstance().getTracingGroup().equals("")) { //$NON-NLS-1$ |
| 1092 | return LTTngControlServiceConstants.OPTION_TRACING_GROUP + ControlPreferences.getInstance().getTracingGroup(); |
| 1093 | } |
| 1094 | return ""; //$NON-NLS-1$ |
| 1095 | } |
| 1096 | |
| 1097 | /** |
| 1098 | * @return the verbose option as configured in the preferences |
| 1099 | */ |
| 1100 | protected String getVerboseOption() { |
| 1101 | if (ControlPreferences.getInstance().isLoggingEnabled()) { |
| 1102 | String level = ControlPreferences.getInstance().getVerboseLevel(); |
| 1103 | if (ControlPreferences.TRACE_CONTROL_VERBOSE_LEVEL_VERBOSE.equals(level)) { |
| 1104 | return LTTngControlServiceConstants.OPTION_VERBOSE; |
| 1105 | } |
| 1106 | if (ControlPreferences.TRACE_CONTROL_VERBOSE_LEVEL_V_VERBOSE.equals(level)) { |
| 1107 | return LTTngControlServiceConstants.OPTION_VERY_VERBOSE; |
| 1108 | } |
| 1109 | if (ControlPreferences.TRACE_CONTROL_VERBOSE_LEVEL_V_V_VERBOSE.equals(level)) { |
| 1110 | return LTTngControlServiceConstants.OPTION_VERY_VERY_VERBOSE; |
| 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 | */ |
| 1124 | protected ICommandResult executeCommand(String command, IProgressMonitor monitor) throws ExecutionException { |
| 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 | */ |
| 1137 | protected ICommandResult executeCommand(String command, IProgressMonitor monitor, boolean checkForError) throws ExecutionException { |
| 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 | } |
| 1154 | } |