| 1 | /********************************************************************** |
| 2 | * Copyright (c) 2012, 2014 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 | * Bernd Hufmann - Updated for support of LTTng Tools 2.1 |
| 12 | * Simon Delisle - Updated for support of LTTng Tools 2.2 |
| 13 | **********************************************************************/ |
| 14 | package org.eclipse.linuxtools.internal.lttng2.ui.views.control.service; |
| 15 | |
| 16 | import java.util.ArrayList; |
| 17 | import java.util.Iterator; |
| 18 | import java.util.List; |
| 19 | import java.util.regex.Matcher; |
| 20 | |
| 21 | import org.eclipse.core.commands.ExecutionException; |
| 22 | import org.eclipse.core.runtime.IProgressMonitor; |
| 23 | import org.eclipse.core.runtime.NullProgressMonitor; |
| 24 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.IBaseEventInfo; |
| 25 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.IChannelInfo; |
| 26 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.IDomainInfo; |
| 27 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.IEventInfo; |
| 28 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.IFieldInfo; |
| 29 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.IProbeEventInfo; |
| 30 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.ISessionInfo; |
| 31 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.ISnapshotInfo; |
| 32 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.IUstProviderInfo; |
| 33 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.LogLevelType; |
| 34 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceEventType; |
| 35 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceLogLevel; |
| 36 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.BaseEventInfo; |
| 37 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.BufferType; |
| 38 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.ChannelInfo; |
| 39 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.DomainInfo; |
| 40 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.EventInfo; |
| 41 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.FieldInfo; |
| 42 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.ProbeEventInfo; |
| 43 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.SessionInfo; |
| 44 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.SnapshotInfo; |
| 45 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.UstProviderInfo; |
| 46 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.logging.ControlCommandLogger; |
| 47 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.messages.Messages; |
| 48 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.preferences.ControlPreferences; |
| 49 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.remote.ICommandResult; |
| 50 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.remote.ICommandShell; |
| 51 | |
| 52 | /** |
| 53 | * <p> |
| 54 | * Service for sending LTTng trace control commands to remote host. |
| 55 | * </p> |
| 56 | * |
| 57 | * @author Bernd Hufmann |
| 58 | */ |
| 59 | public class LTTngControlService implements ILttngControlService { |
| 60 | |
| 61 | // ------------------------------------------------------------------------ |
| 62 | // Attributes |
| 63 | // ------------------------------------------------------------------------ |
| 64 | /** |
| 65 | * The command shell implementation |
| 66 | */ |
| 67 | private final ICommandShell fCommandShell; |
| 68 | |
| 69 | /** |
| 70 | * The version string. |
| 71 | */ |
| 72 | private LttngVersion fVersion = null; |
| 73 | |
| 74 | // ------------------------------------------------------------------------ |
| 75 | // Constructors |
| 76 | // ------------------------------------------------------------------------ |
| 77 | |
| 78 | /** |
| 79 | * Constructor |
| 80 | * |
| 81 | * @param shell |
| 82 | * - the command shell implementation to use |
| 83 | */ |
| 84 | public LTTngControlService(ICommandShell shell) { |
| 85 | fCommandShell = shell; |
| 86 | } |
| 87 | |
| 88 | // ------------------------------------------------------------------------ |
| 89 | // Accessors |
| 90 | // ------------------------------------------------------------------------ |
| 91 | |
| 92 | @Override |
| 93 | public String getVersion() { |
| 94 | if (fVersion == null) { |
| 95 | return "Unknown"; //$NON-NLS-1$ |
| 96 | } |
| 97 | return fVersion.toString(); |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Sets the version of the LTTng 2.0 control service. |
| 102 | * @param version - a version to set |
| 103 | */ |
| 104 | public void setVersion(String version) { |
| 105 | fVersion = new LttngVersion(version); |
| 106 | } |
| 107 | |
| 108 | @Override |
| 109 | public boolean isVersionSupported(String version) { |
| 110 | LttngVersion tmp = new LttngVersion(version); |
| 111 | return (fVersion != null && fVersion.compareTo(tmp) >= 0) ? true : false; |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * Returns the command shell implementation. |
| 116 | * |
| 117 | * @return the command shell implementation |
| 118 | */ |
| 119 | protected ICommandShell getCommandShell() { |
| 120 | return fCommandShell; |
| 121 | } |
| 122 | |
| 123 | // ------------------------------------------------------------------------ |
| 124 | // Operations |
| 125 | // ------------------------------------------------------------------------ |
| 126 | |
| 127 | @Override |
| 128 | public String[] getSessionNames(IProgressMonitor monitor) throws ExecutionException { |
| 129 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_LIST); |
| 130 | |
| 131 | ICommandResult result = executeCommand(command.toString(), monitor); |
| 132 | |
| 133 | // Output: |
| 134 | // Available tracing sessions: |
| 135 | // 1) mysession1 (/home/user/lttng-traces/mysession1-20120123-083928) [inactive] |
| 136 | // 2) mysession (/home/user/lttng-traces/mysession-20120123-083318) [inactive] |
| 137 | // |
| 138 | // Use lttng list <session_name> for more details |
| 139 | |
| 140 | ArrayList<String> retArray = new ArrayList<>(); |
| 141 | int index = 0; |
| 142 | while (index < result.getOutput().length) { |
| 143 | String line = result.getOutput()[index]; |
| 144 | Matcher matcher = LTTngControlServiceConstants.SESSION_PATTERN.matcher(line); |
| 145 | if (matcher.matches()) { |
| 146 | retArray.add(matcher.group(2).trim()); |
| 147 | } |
| 148 | index++; |
| 149 | } |
| 150 | return retArray.toArray(new String[retArray.size()]); |
| 151 | } |
| 152 | |
| 153 | @Override |
| 154 | public ISessionInfo getSession(String sessionName, IProgressMonitor monitor) throws ExecutionException { |
| 155 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_LIST, sessionName); |
| 156 | ICommandResult result = executeCommand(command.toString(), monitor); |
| 157 | |
| 158 | int index = 0; |
| 159 | |
| 160 | // Output: |
| 161 | // Tracing session mysession2: [inactive] |
| 162 | // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330 |
| 163 | ISessionInfo sessionInfo = new SessionInfo(sessionName); |
| 164 | |
| 165 | while (index < result.getOutput().length) { |
| 166 | // Tracing session mysession2: [inactive] |
| 167 | // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330 |
| 168 | // |
| 169 | // === Domain: Kernel === |
| 170 | // |
| 171 | String line = result.getOutput()[index]; |
| 172 | Matcher matcher = LTTngControlServiceConstants.TRACE_SESSION_PATTERN.matcher(line); |
| 173 | if (matcher.matches()) { |
| 174 | sessionInfo.setSessionState(matcher.group(2)); |
| 175 | index++; |
| 176 | continue; |
| 177 | } |
| 178 | |
| 179 | matcher = LTTngControlServiceConstants.TRACE_SNAPSHOT_SESSION_PATTERN.matcher(line); |
| 180 | if (matcher.matches()) { |
| 181 | sessionInfo.setSessionState(matcher.group(2)); |
| 182 | // real name will be set later |
| 183 | ISnapshotInfo snapshotInfo = new SnapshotInfo(""); //$NON-NLS-1$ |
| 184 | sessionInfo.setSnapshotInfo(snapshotInfo); |
| 185 | index++; |
| 186 | continue; |
| 187 | } |
| 188 | |
| 189 | if (!sessionInfo.isSnapshotSession()) { |
| 190 | matcher = LTTngControlServiceConstants.TRACE_NETWORK_PATH_PATTERN.matcher(line); |
| 191 | if (matcher.matches()) { |
| 192 | sessionInfo.setStreamedTrace(true); |
| 193 | } |
| 194 | |
| 195 | matcher = LTTngControlServiceConstants.TRACE_SESSION_PATH_PATTERN.matcher(line); |
| 196 | if (matcher.matches()) { |
| 197 | sessionInfo.setSessionPath(matcher.group(1).trim()); |
| 198 | index++; |
| 199 | continue; |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | matcher = LTTngControlServiceConstants.DOMAIN_KERNEL_PATTERN.matcher(line); |
| 204 | if (matcher.matches()) { |
| 205 | // Create Domain |
| 206 | IDomainInfo domainInfo = new DomainInfo(Messages.TraceControl_KernelDomainDisplayName); |
| 207 | |
| 208 | // set kernel flag |
| 209 | domainInfo.setIsKernel(true); |
| 210 | |
| 211 | // in domain kernel |
| 212 | ArrayList<IChannelInfo> channels = new ArrayList<>(); |
| 213 | index = parseDomain(result.getOutput(), index, channels, domainInfo); |
| 214 | |
| 215 | if (channels.size() > 0) { |
| 216 | // add domain |
| 217 | sessionInfo.addDomain(domainInfo); |
| 218 | |
| 219 | // set channels |
| 220 | domainInfo.setChannels(channels); |
| 221 | } |
| 222 | continue; |
| 223 | } |
| 224 | |
| 225 | matcher = LTTngControlServiceConstants.DOMAIN_UST_GLOBAL_PATTERN.matcher(line); |
| 226 | if (matcher.matches()) { |
| 227 | IDomainInfo domainInfo = new DomainInfo(Messages.TraceControl_UstGlobalDomainDisplayName); |
| 228 | |
| 229 | // set kernel flag |
| 230 | domainInfo.setIsKernel(false); |
| 231 | |
| 232 | // in domain UST |
| 233 | ArrayList<IChannelInfo> channels = new ArrayList<>(); |
| 234 | index = parseDomain(result.getOutput(), index, channels, domainInfo); |
| 235 | |
| 236 | if (channels.size() > 0) { |
| 237 | // add domain |
| 238 | sessionInfo.addDomain(domainInfo); |
| 239 | |
| 240 | // set channels |
| 241 | domainInfo.setChannels(channels); |
| 242 | } |
| 243 | continue; |
| 244 | } |
| 245 | index++; |
| 246 | } |
| 247 | |
| 248 | if (sessionInfo.isSnapshotSession()) { |
| 249 | ISnapshotInfo snapshot = getSnapshotInfo(sessionName, monitor); |
| 250 | sessionInfo.setSnapshotInfo(snapshot); |
| 251 | } |
| 252 | |
| 253 | return sessionInfo; |
| 254 | } |
| 255 | |
| 256 | @Override |
| 257 | public ISnapshotInfo getSnapshotInfo(String sessionName, IProgressMonitor monitor) throws ExecutionException { |
| 258 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_LIST_SNAPSHOT_OUTPUT, LTTngControlServiceConstants.OPTION_SESSION, sessionName); |
| 259 | ICommandResult result = executeCommand(command.toString(), monitor); |
| 260 | |
| 261 | int index = 0; |
| 262 | |
| 263 | // Output: |
| 264 | // [1] snapshot-1: /home/user/lttng-traces/my-20130909-114431 |
| 265 | // or |
| 266 | // [3] snapshot-3: net4://172.0.0.1/ |
| 267 | ISnapshotInfo snapshotInfo = new SnapshotInfo(""); //$NON-NLS-1$ |
| 268 | |
| 269 | while (index < result.getOutput().length) { |
| 270 | String line = result.getOutput()[index]; |
| 271 | Matcher matcher = LTTngControlServiceConstants.LIST_SNAPSHOT_OUTPUT_PATTERN.matcher(line); |
| 272 | if (matcher.matches()) { |
| 273 | snapshotInfo.setId(Integer.valueOf(matcher.group(1))); |
| 274 | snapshotInfo.setName(matcher.group(2)); |
| 275 | snapshotInfo.setSnapshotPath(matcher.group(3)); |
| 276 | |
| 277 | Matcher matcher2 = LTTngControlServiceConstants.SNAPSHOT_NETWORK_PATH_PATTERN.matcher(snapshotInfo.getSnapshotPath()); |
| 278 | if (matcher2.matches()) { |
| 279 | snapshotInfo.setStreamedSnapshot(true); |
| 280 | } |
| 281 | |
| 282 | index++; |
| 283 | break; |
| 284 | } |
| 285 | index++; |
| 286 | } |
| 287 | |
| 288 | return snapshotInfo; |
| 289 | } |
| 290 | |
| 291 | @Override |
| 292 | public List<IBaseEventInfo> getKernelProvider(IProgressMonitor monitor) throws ExecutionException { |
| 293 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_LIST_KERNEL); |
| 294 | ICommandResult result = executeCommand(command.toString(), monitor, false); |
| 295 | |
| 296 | List<IBaseEventInfo> events = new ArrayList<>(); |
| 297 | |
| 298 | if (result.getOutput() != null) { |
| 299 | // Ignore the following 2 cases: |
| 300 | // Spawning a session daemon |
| 301 | // Error: Unable to list kernel events |
| 302 | // or: |
| 303 | // Error: Unable to list kernel events |
| 304 | // |
| 305 | int index = 0; |
| 306 | while (index < result.getOutput().length) { |
| 307 | String line = result.getOutput()[index]; |
| 308 | Matcher matcher = LTTngControlServiceConstants.LIST_KERNEL_NO_KERNEL_PROVIDER_PATTERN.matcher(line); |
| 309 | if (matcher.matches()) { |
| 310 | return events; |
| 311 | } |
| 312 | index++; |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | if (isError(result)) { |
| 317 | throw new ExecutionException(Messages.TraceControl_CommandError + " " + command.toString() + "\n" + formatOutput(result)); //$NON-NLS-1$ //$NON-NLS-2$ |
| 318 | } |
| 319 | |
| 320 | // Kernel events: |
| 321 | // ------------- |
| 322 | // sched_kthread_stop (type: tracepoint) |
| 323 | getProviderEventInfo(result.getOutput(), 0, events); |
| 324 | return events; |
| 325 | } |
| 326 | |
| 327 | @Override |
| 328 | public List<IUstProviderInfo> getUstProvider() throws ExecutionException { |
| 329 | return getUstProvider(new NullProgressMonitor()); |
| 330 | } |
| 331 | |
| 332 | @Override |
| 333 | public List<IUstProviderInfo> getUstProvider(IProgressMonitor monitor) throws ExecutionException { |
| 334 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_LIST_UST); |
| 335 | |
| 336 | if (isVersionSupported("2.1.0")) { //$NON-NLS-1$ |
| 337 | command.append(LTTngControlServiceConstants.OPTION_FIELDS); |
| 338 | } |
| 339 | |
| 340 | ICommandResult result = executeCommand(command.toString(), monitor, false); |
| 341 | List<IUstProviderInfo> allProviders = new ArrayList<>(); |
| 342 | |
| 343 | // Workaround for versions 2.0.x which causes a segmentation fault for this command |
| 344 | // if LTTng Tools is compiled without UST support. |
| 345 | if (!isVersionSupported("2.1.0") && (result.getResult() != 0)) { //$NON-NLS-1$ |
| 346 | return allProviders; |
| 347 | } |
| 348 | |
| 349 | if (result.getOutput() != null) { |
| 350 | // Ignore the following 2 cases: |
| 351 | // Spawning a session daemon |
| 352 | // Error: Unable to list UST events: Listing UST events failed |
| 353 | // or: |
| 354 | // Error: Unable to list UST events: Listing UST events failed |
| 355 | // |
| 356 | int index = 0; |
| 357 | while (index < result.getOutput().length) { |
| 358 | String line = result.getOutput()[index]; |
| 359 | Matcher matcher = LTTngControlServiceConstants.LIST_UST_NO_UST_PROVIDER_PATTERN.matcher(line); |
| 360 | if (matcher.matches()) { |
| 361 | return allProviders; |
| 362 | } |
| 363 | index++; |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | if (isError(result)) { |
| 368 | throw new ExecutionException(Messages.TraceControl_CommandError + " " + command.toString() + "\n" + formatOutput(result)); //$NON-NLS-1$ //$NON-NLS-2$ |
| 369 | } |
| 370 | |
| 371 | // Note that field print-outs exists for version >= 2.1.0 |
| 372 | // |
| 373 | // UST events: |
| 374 | // ------------- |
| 375 | // |
| 376 | // PID: 3635 - Name: |
| 377 | // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello |
| 378 | // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type: |
| 379 | // tracepoint) |
| 380 | // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint) |
| 381 | // field: doublefield (float) |
| 382 | // field: floatfield (float) |
| 383 | // field: stringfield (string) |
| 384 | // |
| 385 | // PID: 6459 - Name: |
| 386 | // /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello |
| 387 | // ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type: |
| 388 | // tracepoint) |
| 389 | // ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint) |
| 390 | // field: doublefield (float) |
| 391 | // field: floatfield (float) |
| 392 | // field: stringfield (string) |
| 393 | |
| 394 | IUstProviderInfo provider = null; |
| 395 | |
| 396 | int index = 0; |
| 397 | while (index < result.getOutput().length) { |
| 398 | String line = result.getOutput()[index]; |
| 399 | Matcher matcher = LTTngControlServiceConstants.UST_PROVIDER_PATTERN.matcher(line); |
| 400 | if (matcher.matches()) { |
| 401 | provider = new UstProviderInfo(matcher.group(2).trim()); |
| 402 | provider.setPid(Integer.valueOf(matcher.group(1).trim())); |
| 403 | List<IBaseEventInfo> events = new ArrayList<>(); |
| 404 | index = getProviderEventInfo(result.getOutput(), ++index, events); |
| 405 | provider.setEvents(events); |
| 406 | allProviders.add(provider); |
| 407 | } else { |
| 408 | index++; |
| 409 | } |
| 410 | } |
| 411 | return allProviders; |
| 412 | } |
| 413 | |
| 414 | @Override |
| 415 | public ISessionInfo createSession(String sessionName, String sessionPath, boolean isSnapshot, IProgressMonitor monitor) throws ExecutionException { |
| 416 | |
| 417 | String newName = formatParameter(sessionName); |
| 418 | String newPath = formatParameter(sessionPath); |
| 419 | |
| 420 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_CREATE_SESSION, newName); |
| 421 | |
| 422 | if (newPath != null && !"".equals(newPath)) { //$NON-NLS-1$ |
| 423 | command.append(LTTngControlServiceConstants.OPTION_OUTPUT_PATH); |
| 424 | command.append(newPath); |
| 425 | } |
| 426 | |
| 427 | if (isSnapshot) { |
| 428 | command.append(LTTngControlServiceConstants.OPTION_SNAPSHOT); |
| 429 | } |
| 430 | |
| 431 | ICommandResult result = executeCommand(command.toString(), monitor); |
| 432 | |
| 433 | //Session myssession2 created. |
| 434 | //Traces will be written in /home/user/lttng-traces/myssession2-20120209-095418 |
| 435 | String[] output = result.getOutput(); |
| 436 | |
| 437 | // Get and session name and path |
| 438 | String name = null; |
| 439 | String path = null; |
| 440 | |
| 441 | int index = 0; |
| 442 | while (index < output.length) { |
| 443 | String line = output[index]; |
| 444 | Matcher nameMatcher = LTTngControlServiceConstants.CREATE_SESSION_NAME_PATTERN.matcher(line); |
| 445 | Matcher pathMatcher = LTTngControlServiceConstants.CREATE_SESSION_PATH_PATTERN.matcher(line); |
| 446 | if (nameMatcher.matches()) { |
| 447 | name = String.valueOf(nameMatcher.group(1).trim()); |
| 448 | } else if (pathMatcher.matches()) { |
| 449 | path = String.valueOf(pathMatcher.group(1).trim()); |
| 450 | } |
| 451 | index++; |
| 452 | } |
| 453 | |
| 454 | // Verify session name |
| 455 | if ((name == null) || (!"".equals(sessionName) && !name.equals(sessionName))) { //$NON-NLS-1$ |
| 456 | // Unexpected name returned |
| 457 | throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$ |
| 458 | Messages.TraceControl_UnexpectedNameError + ": " + name); //$NON-NLS-1$ |
| 459 | } |
| 460 | |
| 461 | SessionInfo sessionInfo = new SessionInfo(name); |
| 462 | |
| 463 | // Verify session path |
| 464 | if (!isSnapshot && |
| 465 | ((path == null) || ((sessionPath != null) && (!path.contains(sessionPath))))) { |
| 466 | // Unexpected path |
| 467 | throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$ |
| 468 | Messages.TraceControl_UnexpectedPathError + ": " + name); //$NON-NLS-1$ |
| 469 | } |
| 470 | |
| 471 | if (isSnapshot) { |
| 472 | // Make it a snapshot session - content of snapshot info need to |
| 473 | // set afterwards using getSession() or getSnapshotInfo() |
| 474 | sessionInfo.setSnapshotInfo(new SnapshotInfo("")); //$NON-NLS-1$ |
| 475 | } else { |
| 476 | sessionInfo.setSessionPath(path); |
| 477 | } |
| 478 | |
| 479 | return sessionInfo; |
| 480 | |
| 481 | } |
| 482 | |
| 483 | @Override |
| 484 | public ISessionInfo createSession(String sessionName, String networkUrl, String controlUrl, String dataUrl, boolean isSnapshot, IProgressMonitor monitor) throws ExecutionException { |
| 485 | |
| 486 | String newName = formatParameter(sessionName); |
| 487 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_CREATE_SESSION, newName); |
| 488 | |
| 489 | if (isSnapshot) { |
| 490 | command.append(LTTngControlServiceConstants.OPTION_SNAPSHOT); |
| 491 | } |
| 492 | |
| 493 | if (networkUrl != null) { |
| 494 | command.append(LTTngControlServiceConstants.OPTION_NETWORK_URL); |
| 495 | command.append(networkUrl); |
| 496 | } else { |
| 497 | command.append(LTTngControlServiceConstants.OPTION_CONTROL_URL); |
| 498 | command.append(controlUrl); |
| 499 | |
| 500 | command.append(LTTngControlServiceConstants.OPTION_DATA_URL); |
| 501 | command.append(dataUrl); |
| 502 | } |
| 503 | |
| 504 | ICommandResult result = executeCommand(command.toString(), monitor); |
| 505 | |
| 506 | // Verify output |
| 507 | String[] output = result.getOutput(); |
| 508 | |
| 509 | // Get and session name and path |
| 510 | String name = null; |
| 511 | String path = null; |
| 512 | |
| 513 | int index = 0; |
| 514 | while (index < output.length) { |
| 515 | String line = output[index]; |
| 516 | Matcher nameMatcher = LTTngControlServiceConstants.CREATE_SESSION_NAME_PATTERN.matcher(line); |
| 517 | Matcher pathMatcher = LTTngControlServiceConstants.CREATE_SESSION_PATH_PATTERN.matcher(line); |
| 518 | |
| 519 | if (nameMatcher.matches()) { |
| 520 | name = String.valueOf(nameMatcher.group(1).trim()); |
| 521 | } else if (pathMatcher.matches() && (networkUrl != null)) { |
| 522 | path = String.valueOf(pathMatcher.group(1).trim()); |
| 523 | } |
| 524 | index++; |
| 525 | } |
| 526 | |
| 527 | // Verify session name |
| 528 | if ((name == null) || (!"".equals(sessionName) && !name.equals(sessionName))) { //$NON-NLS-1$ |
| 529 | // Unexpected name returned |
| 530 | throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$ |
| 531 | Messages.TraceControl_UnexpectedNameError + ": " + name); //$NON-NLS-1$ |
| 532 | } |
| 533 | |
| 534 | SessionInfo sessionInfo = new SessionInfo(name); |
| 535 | |
| 536 | sessionInfo.setStreamedTrace(true); |
| 537 | |
| 538 | // Verify session path |
| 539 | if (networkUrl != null) { |
| 540 | if (!isSnapshot && (path == null)) { |
| 541 | // Unexpected path |
| 542 | throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$ |
| 543 | Messages.TraceControl_UnexpectedPathError + ": " + name); //$NON-NLS-1$ |
| 544 | } |
| 545 | |
| 546 | if (isSnapshot) { |
| 547 | sessionInfo.setStreamedTrace(false); |
| 548 | } else { |
| 549 | sessionInfo.setSessionPath(path); |
| 550 | // Check file protocol |
| 551 | Matcher matcher = LTTngControlServiceConstants.TRACE_FILE_PROTOCOL_PATTERN.matcher(path); |
| 552 | if (matcher.matches()) { |
| 553 | sessionInfo.setStreamedTrace(false); |
| 554 | } |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | // When using controlUrl and dataUrl the full session path is not known yet |
| 559 | // and will be set later on when listing the session |
| 560 | |
| 561 | return sessionInfo; |
| 562 | } |
| 563 | |
| 564 | @Override |
| 565 | public void destroySession(String sessionName, IProgressMonitor monitor) throws ExecutionException { |
| 566 | String newName = formatParameter(sessionName); |
| 567 | |
| 568 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_DESTROY_SESSION, newName); |
| 569 | |
| 570 | ICommandResult result = executeCommand(command.toString(), monitor, false); |
| 571 | String[] output = result.getOutput(); |
| 572 | |
| 573 | boolean isError = isError(result); |
| 574 | if (isError && (output != null)) { |
| 575 | int index = 0; |
| 576 | while (index < output.length) { |
| 577 | String line = output[index]; |
| 578 | Matcher matcher = LTTngControlServiceConstants.SESSION_NOT_FOUND_ERROR_PATTERN.matcher(line); |
| 579 | if (matcher.matches()) { |
| 580 | // Don't treat this as an error |
| 581 | isError = false; |
| 582 | } |
| 583 | index++; |
| 584 | } |
| 585 | } |
| 586 | |
| 587 | if (isError) { |
| 588 | throw new ExecutionException(Messages.TraceControl_CommandError + " " + command.toString() + "\n" + formatOutput(result)); //$NON-NLS-1$ //$NON-NLS-2$ |
| 589 | } |
| 590 | |
| 591 | //Session <sessionName> destroyed |
| 592 | } |
| 593 | |
| 594 | @Override |
| 595 | public void startSession(String sessionName, IProgressMonitor monitor) throws ExecutionException { |
| 596 | |
| 597 | String newSessionName = formatParameter(sessionName); |
| 598 | |
| 599 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_START_SESSION, newSessionName); |
| 600 | |
| 601 | executeCommand(command.toString(), monitor); |
| 602 | |
| 603 | //Session <sessionName> started |
| 604 | } |
| 605 | |
| 606 | @Override |
| 607 | public void stopSession(String sessionName, IProgressMonitor monitor) throws ExecutionException { |
| 608 | String newSessionName = formatParameter(sessionName); |
| 609 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_STOP_SESSION, newSessionName); |
| 610 | |
| 611 | executeCommand(command.toString(), monitor); |
| 612 | |
| 613 | //Session <sessionName> stopped |
| 614 | |
| 615 | } |
| 616 | |
| 617 | @Override |
| 618 | public void enableChannels(String sessionName, List<String> channelNames, boolean isKernel, IChannelInfo info, IProgressMonitor monitor) throws ExecutionException { |
| 619 | |
| 620 | // no channels to enable |
| 621 | if (channelNames.isEmpty()) { |
| 622 | return; |
| 623 | } |
| 624 | |
| 625 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_ENABLE_CHANNEL); |
| 626 | |
| 627 | for (Iterator<String> iterator = channelNames.iterator(); iterator.hasNext();) { |
| 628 | String channel = iterator.next(); |
| 629 | command.append(channel); |
| 630 | if (iterator.hasNext()) { |
| 631 | command.append(','); |
| 632 | } |
| 633 | } |
| 634 | |
| 635 | if (isKernel) { |
| 636 | command.append(LTTngControlServiceConstants.OPTION_KERNEL); |
| 637 | } else { |
| 638 | command.append(LTTngControlServiceConstants.OPTION_UST); |
| 639 | } |
| 640 | |
| 641 | String newSessionName = formatParameter(sessionName); |
| 642 | command.append(LTTngControlServiceConstants.OPTION_SESSION); |
| 643 | command.append(newSessionName); |
| 644 | |
| 645 | if (info != null) { |
| 646 | // --discard Discard event when buffers are full (default) |
| 647 | |
| 648 | // --overwrite Flight recorder mode |
| 649 | if (info.isOverwriteMode()) { |
| 650 | command.append(LTTngControlServiceConstants.OPTION_OVERWRITE); |
| 651 | } |
| 652 | // --subbuf-size SIZE Subbuffer size in bytes |
| 653 | // (default: 4096, kernel default: 262144) |
| 654 | if (info.getSubBufferSize() != LTTngControlServiceConstants.UNUSED_VALUE) { |
| 655 | command.append(LTTngControlServiceConstants.OPTION_SUB_BUFFER_SIZE); |
| 656 | command.append(String.valueOf(info.getSubBufferSize())); |
| 657 | } |
| 658 | |
| 659 | // --num-subbuf NUM Number of subbufers |
| 660 | if (info.getNumberOfSubBuffers() != LTTngControlServiceConstants.UNUSED_VALUE) { |
| 661 | command.append(LTTngControlServiceConstants.OPTION_NUM_SUB_BUFFERS); |
| 662 | command.append(String.valueOf(info.getNumberOfSubBuffers())); |
| 663 | } |
| 664 | |
| 665 | // --switch-timer USEC Switch timer interval in usec |
| 666 | if (info.getSwitchTimer() != LTTngControlServiceConstants.UNUSED_VALUE) { |
| 667 | command.append(LTTngControlServiceConstants.OPTION_SWITCH_TIMER); |
| 668 | command.append(String.valueOf(info.getSwitchTimer())); |
| 669 | } |
| 670 | |
| 671 | // --read-timer USEC Read timer interval in usec |
| 672 | if (info.getReadTimer() != LTTngControlServiceConstants.UNUSED_VALUE) { |
| 673 | command.append(LTTngControlServiceConstants.OPTION_READ_TIMER); |
| 674 | command.append(String.valueOf(info.getReadTimer())); |
| 675 | } |
| 676 | |
| 677 | if (isVersionSupported("2.2.0")) { //$NON-NLS-1$ |
| 678 | // --buffers-uid Every application sharing the same UID use the same buffers |
| 679 | // --buffers-pid Buffers are allocated per PID |
| 680 | if (!isKernel) { |
| 681 | if (info.getBufferType() == BufferType.BUFFER_PER_PID) { |
| 682 | command.append(LTTngControlServiceConstants.OPTION_PER_PID_BUFFERS); |
| 683 | |
| 684 | } else if (info.getBufferType() == BufferType.BUFFER_PER_UID) { |
| 685 | command.append(LTTngControlServiceConstants.OPTION_PER_UID_BUFFERS); |
| 686 | } |
| 687 | } |
| 688 | |
| 689 | // -C SIZE Maximum size of trace files in bytes |
| 690 | if (info.getMaxSizeTraceFiles() != LTTngControlServiceConstants.UNUSED_VALUE) { |
| 691 | command.append(LTTngControlServiceConstants.OPTION_MAX_SIZE_TRACE_FILES); |
| 692 | command.append(String.valueOf(info.getMaxSizeTraceFiles())); |
| 693 | } |
| 694 | |
| 695 | // -W NUM Maximum number of trace files |
| 696 | if (info.getMaxNumberTraceFiles() != LTTngControlServiceConstants.UNUSED_VALUE) { |
| 697 | command.append(LTTngControlServiceConstants.OPTION_MAX_TRACE_FILES); |
| 698 | command.append(String.valueOf(info.getMaxNumberTraceFiles())); |
| 699 | } |
| 700 | } |
| 701 | } |
| 702 | |
| 703 | executeCommand(command.toString(), monitor); |
| 704 | |
| 705 | } |
| 706 | |
| 707 | @Override |
| 708 | public void disableChannels(String sessionName, List<String> channelNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException { |
| 709 | |
| 710 | // no channels to enable |
| 711 | if (channelNames.isEmpty()) { |
| 712 | return; |
| 713 | } |
| 714 | |
| 715 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_DISABLE_CHANNEL); |
| 716 | |
| 717 | for (Iterator<String> iterator = channelNames.iterator(); iterator.hasNext();) { |
| 718 | String channel = iterator.next(); |
| 719 | command.append(channel); |
| 720 | if (iterator.hasNext()) { |
| 721 | command.append(','); |
| 722 | } |
| 723 | } |
| 724 | |
| 725 | if (isKernel) { |
| 726 | command.append(LTTngControlServiceConstants.OPTION_KERNEL); |
| 727 | } else { |
| 728 | command.append(LTTngControlServiceConstants.OPTION_UST); |
| 729 | } |
| 730 | |
| 731 | String newSessionName = formatParameter(sessionName); |
| 732 | command.append(LTTngControlServiceConstants.OPTION_SESSION); |
| 733 | command.append(newSessionName); |
| 734 | |
| 735 | executeCommand(command.toString(), monitor); |
| 736 | } |
| 737 | |
| 738 | @Override |
| 739 | public void enableEvents(String sessionName, String channelName, List<String> eventNames, boolean isKernel, String filterExpression, IProgressMonitor monitor) throws ExecutionException { |
| 740 | |
| 741 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_ENABLE_EVENT); |
| 742 | |
| 743 | if (eventNames == null || eventNames.isEmpty()) { |
| 744 | command.append(LTTngControlServiceConstants.OPTION_ALL); |
| 745 | } else { |
| 746 | |
| 747 | StringBuffer eventNameParameter = new StringBuffer(); |
| 748 | for (Iterator<String> iterator = eventNames.iterator(); iterator.hasNext();) { |
| 749 | String event = iterator.next(); |
| 750 | eventNameParameter.append(event); |
| 751 | if (iterator.hasNext()) { |
| 752 | eventNameParameter.append(','); |
| 753 | } |
| 754 | } |
| 755 | command.append(formatParameter(eventNameParameter.toString())); |
| 756 | } |
| 757 | |
| 758 | if (isKernel) { |
| 759 | command.append(LTTngControlServiceConstants.OPTION_KERNEL); |
| 760 | } else { |
| 761 | command.append(LTTngControlServiceConstants.OPTION_UST); |
| 762 | } |
| 763 | |
| 764 | String newSessionName = formatParameter(sessionName); |
| 765 | |
| 766 | command.append(LTTngControlServiceConstants.OPTION_SESSION); |
| 767 | command.append(newSessionName); |
| 768 | |
| 769 | if (channelName != null) { |
| 770 | command.append(LTTngControlServiceConstants.OPTION_CHANNEL); |
| 771 | command.append(channelName); |
| 772 | } |
| 773 | |
| 774 | command.append(LTTngControlServiceConstants.OPTION_TRACEPOINT); |
| 775 | |
| 776 | if (filterExpression != null) { |
| 777 | command.append(LTTngControlServiceConstants.OPTION_FILTER); |
| 778 | command.append('\''); |
| 779 | command.append(filterExpression); |
| 780 | command.append('\''); |
| 781 | } |
| 782 | |
| 783 | executeCommand(command.toString(), monitor); |
| 784 | |
| 785 | } |
| 786 | |
| 787 | @Override |
| 788 | public void enableSyscalls(String sessionName, String channelName, IProgressMonitor monitor) throws ExecutionException { |
| 789 | |
| 790 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_ENABLE_EVENT); |
| 791 | |
| 792 | command.append(LTTngControlServiceConstants.OPTION_ALL); |
| 793 | command.append(LTTngControlServiceConstants.OPTION_KERNEL); |
| 794 | |
| 795 | String newSessionName = formatParameter(sessionName); |
| 796 | |
| 797 | command.append(LTTngControlServiceConstants.OPTION_SESSION); |
| 798 | command.append(newSessionName); |
| 799 | |
| 800 | if (channelName != null) { |
| 801 | command.append(LTTngControlServiceConstants.OPTION_CHANNEL); |
| 802 | command.append(channelName); |
| 803 | } |
| 804 | |
| 805 | command.append(LTTngControlServiceConstants.OPTION_SYSCALL); |
| 806 | |
| 807 | executeCommand(command.toString(), monitor); |
| 808 | } |
| 809 | |
| 810 | @Override |
| 811 | public void enableProbe(String sessionName, String channelName, String eventName, boolean isFunction, String probe, IProgressMonitor monitor) throws ExecutionException { |
| 812 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_ENABLE_EVENT); |
| 813 | |
| 814 | command.append(eventName); |
| 815 | command.append(LTTngControlServiceConstants.OPTION_KERNEL); |
| 816 | |
| 817 | String newSessionName = formatParameter(sessionName); |
| 818 | command.append(LTTngControlServiceConstants.OPTION_SESSION); |
| 819 | command.append(newSessionName); |
| 820 | |
| 821 | if (channelName != null) { |
| 822 | command.append(LTTngControlServiceConstants.OPTION_CHANNEL); |
| 823 | command.append(channelName); |
| 824 | } |
| 825 | if (isFunction) { |
| 826 | command.append(LTTngControlServiceConstants.OPTION_FUNCTION_PROBE); |
| 827 | } else { |
| 828 | command.append(LTTngControlServiceConstants.OPTION_PROBE); |
| 829 | } |
| 830 | |
| 831 | command.append(probe); |
| 832 | |
| 833 | executeCommand(command.toString(), monitor); |
| 834 | } |
| 835 | |
| 836 | @Override |
| 837 | public void enableLogLevel(String sessionName, String channelName, String eventName, LogLevelType logLevelType, TraceLogLevel level, String filterExpression, IProgressMonitor monitor) throws ExecutionException { |
| 838 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_ENABLE_EVENT); |
| 839 | |
| 840 | command.append(eventName); |
| 841 | command.append(LTTngControlServiceConstants.OPTION_UST); |
| 842 | |
| 843 | String newSessionName = formatParameter(sessionName); |
| 844 | command.append(LTTngControlServiceConstants.OPTION_SESSION); |
| 845 | command.append(newSessionName); |
| 846 | |
| 847 | if (channelName != null) { |
| 848 | command.append(LTTngControlServiceConstants.OPTION_CHANNEL); |
| 849 | command.append(channelName); |
| 850 | } |
| 851 | |
| 852 | if (logLevelType == LogLevelType.LOGLEVEL) { |
| 853 | command.append(LTTngControlServiceConstants.OPTION_LOGLEVEL); |
| 854 | } else if (logLevelType == LogLevelType.LOGLEVEL_ONLY) { |
| 855 | command.append(LTTngControlServiceConstants.OPTION_LOGLEVEL_ONLY); |
| 856 | |
| 857 | } else { |
| 858 | return; |
| 859 | } |
| 860 | command.append(level.getInName()); |
| 861 | |
| 862 | executeCommand(command.toString(), monitor); |
| 863 | } |
| 864 | |
| 865 | @Override |
| 866 | public void disableEvent(String sessionName, String channelName, List<String> eventNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException { |
| 867 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_DISABLE_EVENT); |
| 868 | |
| 869 | if (eventNames == null) { |
| 870 | command.append(LTTngControlServiceConstants.OPTION_ALL); |
| 871 | } else { |
| 872 | // no events to disable |
| 873 | if (eventNames.isEmpty()) { |
| 874 | return; |
| 875 | } |
| 876 | |
| 877 | StringBuffer eventNameParameter = new StringBuffer(); |
| 878 | for (Iterator<String> iterator = eventNames.iterator(); iterator.hasNext();) { |
| 879 | String event = iterator.next(); |
| 880 | eventNameParameter.append(event); |
| 881 | if (iterator.hasNext()) { |
| 882 | eventNameParameter.append(','); |
| 883 | } |
| 884 | } |
| 885 | command.append(formatParameter(eventNameParameter.toString())); |
| 886 | } |
| 887 | |
| 888 | if (isKernel) { |
| 889 | command.append(LTTngControlServiceConstants.OPTION_KERNEL); |
| 890 | } else { |
| 891 | command.append(LTTngControlServiceConstants.OPTION_UST); |
| 892 | } |
| 893 | |
| 894 | String newSessionName = formatParameter(sessionName); |
| 895 | command.append(LTTngControlServiceConstants.OPTION_SESSION); |
| 896 | command.append(newSessionName); |
| 897 | |
| 898 | if (channelName != null) { |
| 899 | command.append(LTTngControlServiceConstants.OPTION_CHANNEL); |
| 900 | command.append(channelName); |
| 901 | } |
| 902 | |
| 903 | executeCommand(command.toString(), monitor); |
| 904 | } |
| 905 | |
| 906 | @Override |
| 907 | public List<String> getContextList(IProgressMonitor monitor) throws ExecutionException { |
| 908 | |
| 909 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_ADD_CONTEXT, LTTngControlServiceConstants.OPTION_HELP); |
| 910 | |
| 911 | ICommandResult result = executeCommand(command.toString(), monitor); |
| 912 | |
| 913 | String[] output = result.getOutput(); |
| 914 | |
| 915 | List<String> contexts = new ArrayList<>(0); |
| 916 | |
| 917 | int index = 0; |
| 918 | boolean inList = false; |
| 919 | while (index < output.length) { |
| 920 | String line = result.getOutput()[index]; |
| 921 | |
| 922 | Matcher startMatcher = LTTngControlServiceConstants.ADD_CONTEXT_HELP_CONTEXTS_INTRO.matcher(line); |
| 923 | Matcher endMatcher = LTTngControlServiceConstants.ADD_CONTEXT_HELP_CONTEXTS_END_LINE.matcher(line); |
| 924 | |
| 925 | if (startMatcher.matches()) { |
| 926 | inList = true; |
| 927 | } else if (endMatcher.matches()) { |
| 928 | break; |
| 929 | } else if (inList == true) { |
| 930 | String[] tmp = line.split(","); //$NON-NLS-1$ |
| 931 | for (int i = 0; i < tmp.length; i++) { |
| 932 | contexts.add(tmp[i].trim()); |
| 933 | } |
| 934 | } |
| 935 | index++; |
| 936 | } |
| 937 | return contexts; |
| 938 | } |
| 939 | |
| 940 | @Override |
| 941 | public void addContexts(String sessionName, String channelName, String eventName, boolean isKernel, List<String> contextNames, IProgressMonitor monitor) throws ExecutionException { |
| 942 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_ADD_CONTEXT); |
| 943 | |
| 944 | String newSessionName = formatParameter(sessionName); |
| 945 | command.append(LTTngControlServiceConstants.OPTION_SESSION); |
| 946 | command.append(newSessionName); |
| 947 | |
| 948 | if (channelName != null) { |
| 949 | command.append(LTTngControlServiceConstants.OPTION_CHANNEL); |
| 950 | command.append(channelName); |
| 951 | } |
| 952 | |
| 953 | if (eventName != null) { |
| 954 | command.append(LTTngControlServiceConstants.OPTION_EVENT); |
| 955 | command.append(eventName); |
| 956 | } |
| 957 | |
| 958 | if (isKernel) { |
| 959 | command.append(LTTngControlServiceConstants.OPTION_KERNEL); |
| 960 | } else { |
| 961 | command.append(LTTngControlServiceConstants.OPTION_UST); |
| 962 | } |
| 963 | |
| 964 | for (Iterator<String> iterator = contextNames.iterator(); iterator.hasNext();) { |
| 965 | String context = iterator.next(); |
| 966 | command.append(LTTngControlServiceConstants.OPTION_CONTEXT_TYPE); |
| 967 | command.append(context); |
| 968 | } |
| 969 | |
| 970 | executeCommand(command.toString(), monitor); |
| 971 | |
| 972 | } |
| 973 | |
| 974 | @Override |
| 975 | public void calibrate(boolean isKernel, IProgressMonitor monitor) throws ExecutionException { |
| 976 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_CALIBRATE); |
| 977 | |
| 978 | if (isKernel) { |
| 979 | command.append(LTTngControlServiceConstants.OPTION_KERNEL); |
| 980 | } else { |
| 981 | command.append(LTTngControlServiceConstants.OPTION_UST); |
| 982 | } |
| 983 | |
| 984 | command.append(LTTngControlServiceConstants.OPTION_FUNCTION_PROBE); |
| 985 | |
| 986 | executeCommand(command.toString(), monitor); |
| 987 | } |
| 988 | |
| 989 | @Override |
| 990 | public void recordSnapshot(String sessionName, IProgressMonitor monitor) |
| 991 | throws ExecutionException { |
| 992 | StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_RECORD_SNAPSHOT); |
| 993 | |
| 994 | String newSessionName = formatParameter(sessionName); |
| 995 | command.append(LTTngControlServiceConstants.OPTION_SESSION); |
| 996 | command.append(newSessionName); |
| 997 | |
| 998 | executeCommand(command.toString(), monitor); |
| 999 | } |
| 1000 | |
| 1001 | // ------------------------------------------------------------------------ |
| 1002 | // Helper methods |
| 1003 | // ------------------------------------------------------------------------ |
| 1004 | |
| 1005 | /** |
| 1006 | * Checks if command result is an error result. |
| 1007 | * |
| 1008 | * @param result |
| 1009 | * - the command result to check |
| 1010 | * @return true if error else false |
| 1011 | */ |
| 1012 | protected boolean isError(ICommandResult result) { |
| 1013 | // Check return code and length of returned strings |
| 1014 | if ((result.getResult()) != 0 || (result.getOutput().length < 1)) { |
| 1015 | return true; |
| 1016 | } |
| 1017 | |
| 1018 | // Look for error pattern |
| 1019 | int index = 0; |
| 1020 | while (index < result.getOutput().length) { |
| 1021 | String line = result.getOutput()[index]; |
| 1022 | Matcher matcher = LTTngControlServiceConstants.ERROR_PATTERN.matcher(line); |
| 1023 | if (matcher.matches()) { |
| 1024 | return true; |
| 1025 | } |
| 1026 | index++; |
| 1027 | } |
| 1028 | |
| 1029 | return false; |
| 1030 | } |
| 1031 | |
| 1032 | /** |
| 1033 | * Formats the output string as single string. |
| 1034 | * |
| 1035 | * @param result |
| 1036 | * - output array |
| 1037 | * @return - the formatted output |
| 1038 | */ |
| 1039 | public static String formatOutput(ICommandResult result) { |
| 1040 | if ((result == null) || result.getOutput() == null || result.getOutput().length == 0) { |
| 1041 | return ""; //$NON-NLS-1$ |
| 1042 | } |
| 1043 | String[] output = result.getOutput(); |
| 1044 | StringBuffer ret = new StringBuffer(); |
| 1045 | ret.append("Return Value: "); //$NON-NLS-1$ |
| 1046 | ret.append(result.getResult()); |
| 1047 | ret.append("\n"); //$NON-NLS-1$ |
| 1048 | for (int i = 0; i < output.length; i++) { |
| 1049 | ret.append(output[i]).append("\n"); //$NON-NLS-1$ |
| 1050 | } |
| 1051 | return ret.toString(); |
| 1052 | } |
| 1053 | |
| 1054 | /** |
| 1055 | * Parses the domain information. |
| 1056 | * |
| 1057 | * @param output |
| 1058 | * - a command output array |
| 1059 | * @param currentIndex |
| 1060 | * - current index in command output array |
| 1061 | * @param channels |
| 1062 | * - list for returning channel information |
| 1063 | * @param domainInfo |
| 1064 | * - The domain information |
| 1065 | * @return the new current index in command output array |
| 1066 | */ |
| 1067 | protected int parseDomain(String[] output, int currentIndex, List<IChannelInfo> channels, IDomainInfo domainInfo) { |
| 1068 | int index = currentIndex; |
| 1069 | |
| 1070 | // if kernel set the buffer type to shared |
| 1071 | if (domainInfo.isKernel()) { |
| 1072 | domainInfo.setBufferType(BufferType.BUFFER_SHARED); |
| 1073 | } |
| 1074 | |
| 1075 | // Channels: |
| 1076 | // ------------- |
| 1077 | // - channnel1: [enabled] |
| 1078 | // |
| 1079 | // Attributes: |
| 1080 | // overwrite mode: 0 |
| 1081 | // subbufers size: 262144 |
| 1082 | // number of subbufers: 4 |
| 1083 | // switch timer interval: 0 |
| 1084 | // read timer interval: 200 |
| 1085 | // output: splice() |
| 1086 | |
| 1087 | while (index < output.length) { |
| 1088 | String line = output[index]; |
| 1089 | |
| 1090 | if (isVersionSupported("2.2.0")) { //$NON-NLS-1$ |
| 1091 | Matcher bufferTypeMatcher = LTTngControlServiceConstants.BUFFER_TYPE_PATTERN.matcher(line); |
| 1092 | if (bufferTypeMatcher.matches()) { |
| 1093 | String bufferTypeString = getAttributeValue(line); |
| 1094 | if (BufferType.BUFFER_PER_PID.getInName().equals(bufferTypeString)) { |
| 1095 | domainInfo.setBufferType(BufferType.BUFFER_PER_PID); |
| 1096 | } else if (BufferType.BUFFER_PER_UID.getInName().equals(bufferTypeString)) { |
| 1097 | domainInfo.setBufferType(BufferType.BUFFER_PER_UID); |
| 1098 | } else { |
| 1099 | domainInfo.setBufferType(BufferType.BUFFER_TYPE_UNKNOWN); |
| 1100 | } |
| 1101 | } |
| 1102 | } else { |
| 1103 | domainInfo.setBufferType(BufferType.BUFFER_TYPE_UNKNOWN); |
| 1104 | } |
| 1105 | Matcher outerMatcher = LTTngControlServiceConstants.CHANNELS_SECTION_PATTERN.matcher(line); |
| 1106 | Matcher noKernelChannelMatcher = LTTngControlServiceConstants.DOMAIN_NO_KERNEL_CHANNEL_PATTERN.matcher(line); |
| 1107 | Matcher noUstChannelMatcher = LTTngControlServiceConstants.DOMAIN_NO_UST_CHANNEL_PATTERN.matcher(line); |
| 1108 | if (outerMatcher.matches()) { |
| 1109 | IChannelInfo channelInfo = null; |
| 1110 | while (index < output.length) { |
| 1111 | String subLine = output[index]; |
| 1112 | |
| 1113 | Matcher innerMatcher = LTTngControlServiceConstants.CHANNEL_PATTERN.matcher(subLine); |
| 1114 | if (innerMatcher.matches()) { |
| 1115 | channelInfo = new ChannelInfo(""); //$NON-NLS-1$ |
| 1116 | // get channel name |
| 1117 | channelInfo.setName(innerMatcher.group(1)); |
| 1118 | |
| 1119 | // get channel enablement |
| 1120 | channelInfo.setState(innerMatcher.group(2)); |
| 1121 | |
| 1122 | // set BufferType |
| 1123 | channelInfo.setBufferType(domainInfo.getBufferType()); |
| 1124 | |
| 1125 | // add channel |
| 1126 | channels.add(channelInfo); |
| 1127 | |
| 1128 | } else if (LTTngControlServiceConstants.OVERWRITE_MODE_ATTRIBUTE.matcher(subLine).matches()) { |
| 1129 | String value = getAttributeValue(subLine); |
| 1130 | if (channelInfo != null) { |
| 1131 | channelInfo.setOverwriteMode(!LTTngControlServiceConstants.OVERWRITE_MODE_ATTRIBUTE_FALSE.equals(value)); |
| 1132 | } |
| 1133 | } else if (LTTngControlServiceConstants.SUBBUFFER_SIZE_ATTRIBUTE.matcher(subLine).matches()) { |
| 1134 | if (channelInfo != null) { |
| 1135 | channelInfo.setSubBufferSize(Long.valueOf(getAttributeValue(subLine))); |
| 1136 | } |
| 1137 | |
| 1138 | } else if (LTTngControlServiceConstants.NUM_SUBBUFFERS_ATTRIBUTE.matcher(subLine).matches()) { |
| 1139 | if (channelInfo != null) { |
| 1140 | channelInfo.setNumberOfSubBuffers(Integer.valueOf(getAttributeValue(subLine))); |
| 1141 | } |
| 1142 | |
| 1143 | } else if (LTTngControlServiceConstants.SWITCH_TIMER_ATTRIBUTE.matcher(subLine).matches()) { |
| 1144 | if (channelInfo != null) { |
| 1145 | channelInfo.setSwitchTimer(Long.valueOf(getAttributeValue(subLine))); |
| 1146 | } |
| 1147 | |
| 1148 | } else if (LTTngControlServiceConstants.READ_TIMER_ATTRIBUTE.matcher(subLine).matches()) { |
| 1149 | if (channelInfo != null) { |
| 1150 | channelInfo.setReadTimer(Long.valueOf(getAttributeValue(subLine))); |
| 1151 | } |
| 1152 | |
| 1153 | } else if (LTTngControlServiceConstants.OUTPUT_ATTRIBUTE.matcher(subLine).matches()) { |
| 1154 | if (channelInfo != null) { |
| 1155 | channelInfo.setOutputType(getAttributeValue(subLine)); |
| 1156 | } |
| 1157 | |
| 1158 | } else if (LTTngControlServiceConstants.EVENT_SECTION_PATTERN.matcher(subLine).matches()) { |
| 1159 | List<IEventInfo> events = new ArrayList<>(); |
| 1160 | index = parseEvents(output, index, events); |
| 1161 | if (channelInfo != null) { |
| 1162 | channelInfo.setEvents(events); |
| 1163 | } |
| 1164 | // we want to stay at the current index to be able to |
| 1165 | // exit the domain |
| 1166 | continue; |
| 1167 | } else if (LTTngControlServiceConstants.DOMAIN_KERNEL_PATTERN.matcher(subLine).matches()) { |
| 1168 | return index; |
| 1169 | |
| 1170 | } else if (LTTngControlServiceConstants.DOMAIN_UST_GLOBAL_PATTERN.matcher(subLine).matches()) { |
| 1171 | return index; |
| 1172 | } |
| 1173 | index++; |
| 1174 | } |
| 1175 | } else if (noKernelChannelMatcher.matches() || noUstChannelMatcher.matches()) { |
| 1176 | // domain indicates that no channels were found -> return |
| 1177 | index++; |
| 1178 | return index; |
| 1179 | } |
| 1180 | index++; |
| 1181 | } |
| 1182 | return index; |
| 1183 | } |
| 1184 | |
| 1185 | /** |
| 1186 | * Parses the event information within a domain. |
| 1187 | * |
| 1188 | * @param output |
| 1189 | * - a command output array |
| 1190 | * @param currentIndex |
| 1191 | * - current index in command output array |
| 1192 | * @param events |
| 1193 | * - list for returning event information |
| 1194 | * @return the new current index in command output array |
| 1195 | */ |
| 1196 | protected int parseEvents(String[] output, int currentIndex, List<IEventInfo> events) { |
| 1197 | int index = currentIndex; |
| 1198 | |
| 1199 | while (index < output.length) { |
| 1200 | String line = output[index]; |
| 1201 | if (LTTngControlServiceConstants.CHANNEL_PATTERN.matcher(line).matches()) { |
| 1202 | // end of channel |
| 1203 | return index; |
| 1204 | } else if (LTTngControlServiceConstants.DOMAIN_KERNEL_PATTERN.matcher(line).matches()) { |
| 1205 | // end of domain |
| 1206 | return index; |
| 1207 | } else if (LTTngControlServiceConstants.DOMAIN_UST_GLOBAL_PATTERN.matcher(line).matches()) { |
| 1208 | // end of domain |
| 1209 | return index; |
| 1210 | } |
| 1211 | |
| 1212 | Matcher matcher = LTTngControlServiceConstants.EVENT_PATTERN.matcher(line); |
| 1213 | Matcher matcher2 = LTTngControlServiceConstants.WILDCARD_EVENT_PATTERN.matcher(line); |
| 1214 | |
| 1215 | if (matcher.matches()) { |
| 1216 | IEventInfo eventInfo = new EventInfo(matcher.group(1).trim()); |
| 1217 | eventInfo.setLogLevel(matcher.group(2).trim()); |
| 1218 | eventInfo.setEventType(matcher.group(3).trim()); |
| 1219 | eventInfo.setState(matcher.group(4)); |
| 1220 | String filter = matcher.group(5); |
| 1221 | if (filter != null) { |
| 1222 | filter = filter.substring(1, filter.length() - 1); // remove '[' and ']' |
| 1223 | eventInfo.setFilterExpression(filter); |
| 1224 | } |
| 1225 | events.add(eventInfo); |
| 1226 | index++; |
| 1227 | } else if (matcher2.matches()) { |
| 1228 | IEventInfo eventInfo = new EventInfo(matcher2.group(1).trim()); |
| 1229 | eventInfo.setLogLevel(TraceLogLevel.LEVEL_UNKNOWN); |
| 1230 | eventInfo.setEventType(matcher2.group(2).trim()); |
| 1231 | eventInfo.setState(matcher2.group(3)); |
| 1232 | String filter = matcher2.group(4); |
| 1233 | if (filter != null) { |
| 1234 | filter = filter.substring(1, filter.length() - 1); // remove '[' and ']' |
| 1235 | eventInfo.setFilterExpression(filter); |
| 1236 | } |
| 1237 | |
| 1238 | if ((eventInfo.getEventType() == TraceEventType.PROBE) || |
| 1239 | (eventInfo.getEventType() == TraceEventType.FUNCTION)){ |
| 1240 | IProbeEventInfo probeEvent = new ProbeEventInfo(eventInfo.getName()); |
| 1241 | probeEvent.setLogLevel(eventInfo.getLogLevel()); |
| 1242 | probeEvent.setEventType(eventInfo.getEventType()); |
| 1243 | probeEvent.setState(eventInfo.getState()); |
| 1244 | |
| 1245 | // Overwrite eventinfo |
| 1246 | eventInfo = probeEvent; |
| 1247 | |
| 1248 | // myevent2 (type: probe) [enabled] |
| 1249 | // addr: 0xc0101340 |
| 1250 | // myevent0 (type: function) [enabled] |
| 1251 | // offset: 0x0 |
| 1252 | // symbol: init_post |
| 1253 | index++; |
| 1254 | while (index < output.length) { |
| 1255 | String probeLine = output[index]; |
| 1256 | // parse probe |
| 1257 | Matcher addrMatcher = LTTngControlServiceConstants.PROBE_ADDRESS_PATTERN.matcher(probeLine); |
| 1258 | Matcher offsetMatcher = LTTngControlServiceConstants.PROBE_OFFSET_PATTERN.matcher(probeLine); |
| 1259 | Matcher symbolMatcher = LTTngControlServiceConstants.PROBE_SYMBOL_PATTERN.matcher(probeLine); |
| 1260 | if (addrMatcher.matches()) { |
| 1261 | String addr = addrMatcher.group(2).trim(); |
| 1262 | probeEvent.setAddress(addr); |
| 1263 | } else if (offsetMatcher.matches()) { |
| 1264 | String offset = offsetMatcher.group(2).trim(); |
| 1265 | probeEvent.setOffset(offset); |
| 1266 | } else if (symbolMatcher.matches()) { |
| 1267 | String symbol = symbolMatcher.group(2).trim(); |
| 1268 | probeEvent.setSymbol(symbol); |
| 1269 | } else if ((LTTngControlServiceConstants.EVENT_PATTERN.matcher(probeLine).matches()) || (LTTngControlServiceConstants.WILDCARD_EVENT_PATTERN.matcher(probeLine).matches())) { |
| 1270 | break; |
| 1271 | } else if (LTTngControlServiceConstants.CHANNEL_PATTERN.matcher(probeLine).matches()) { |
| 1272 | break; |
| 1273 | } else if (LTTngControlServiceConstants.DOMAIN_KERNEL_PATTERN.matcher(probeLine).matches()) { |
| 1274 | // end of domain |
| 1275 | break; |
| 1276 | } else if (LTTngControlServiceConstants.DOMAIN_UST_GLOBAL_PATTERN.matcher(probeLine).matches()) { |
| 1277 | // end of domain |
| 1278 | break; |
| 1279 | } |
| 1280 | index++; |
| 1281 | } |
| 1282 | events.add(eventInfo); |
| 1283 | } else { |
| 1284 | events.add(eventInfo); |
| 1285 | index++; |
| 1286 | continue; |
| 1287 | } |
| 1288 | } else { |
| 1289 | index++; |
| 1290 | } |
| 1291 | } |
| 1292 | |
| 1293 | return index; |
| 1294 | } |
| 1295 | |
| 1296 | /** |
| 1297 | * Parses a line with attributes: <attribute Name>: <attribute value> |
| 1298 | * |
| 1299 | * @param line |
| 1300 | * - attribute line to parse |
| 1301 | * @return the attribute value as string |
| 1302 | */ |
| 1303 | protected String getAttributeValue(String line) { |
| 1304 | String[] temp = line.split("\\: "); //$NON-NLS-1$ |
| 1305 | return temp[1]; |
| 1306 | } |
| 1307 | |
| 1308 | /** |
| 1309 | * Parses the event information within a provider. |
| 1310 | * |
| 1311 | * @param output |
| 1312 | * - a command output array |
| 1313 | * @param currentIndex |
| 1314 | * - current index in command output array |
| 1315 | * @param events |
| 1316 | * - list for returning event information |
| 1317 | * @return the new current index in command output array |
| 1318 | */ |
| 1319 | protected int getProviderEventInfo(String[] output, int currentIndex, List<IBaseEventInfo> events) { |
| 1320 | int index = currentIndex; |
| 1321 | IBaseEventInfo eventInfo = null; |
| 1322 | while (index < output.length) { |
| 1323 | String line = output[index]; |
| 1324 | Matcher matcher = LTTngControlServiceConstants.PROVIDER_EVENT_PATTERN.matcher(line); |
| 1325 | if (matcher.matches()) { |
| 1326 | // sched_kthread_stop (loglevel: TRACE_EMERG0) (type: tracepoint) |
| 1327 | eventInfo = new BaseEventInfo(matcher.group(1).trim()); |
| 1328 | eventInfo.setLogLevel(matcher.group(2).trim()); |
| 1329 | eventInfo.setEventType(matcher.group(3).trim()); |
| 1330 | events.add(eventInfo); |
| 1331 | index++; |
| 1332 | } else if (LTTngControlServiceConstants.EVENT_FIELD_PATTERN.matcher(line).matches()) { |
| 1333 | if (eventInfo != null) { |
| 1334 | List<IFieldInfo> fields = new ArrayList<>(); |
| 1335 | index = getFieldInfo(output, index, fields); |
| 1336 | eventInfo.setFields(fields); |
| 1337 | } else { |
| 1338 | index++; |
| 1339 | } |
| 1340 | } |
| 1341 | else if (LTTngControlServiceConstants.UST_PROVIDER_PATTERN.matcher(line).matches()) { |
| 1342 | return index; |
| 1343 | } else { |
| 1344 | index++; |
| 1345 | } |
| 1346 | } |
| 1347 | return index; |
| 1348 | } |
| 1349 | |
| 1350 | |
| 1351 | /** |
| 1352 | * Parse a field's information. |
| 1353 | * |
| 1354 | * @param output |
| 1355 | * A command output array |
| 1356 | * @param currentIndex |
| 1357 | * The current index in the command output array |
| 1358 | * @param fields |
| 1359 | * List for returning the field information |
| 1360 | * @return The new current index in the command output array |
| 1361 | */ |
| 1362 | protected int getFieldInfo(String[] output, int currentIndex, List<IFieldInfo> fields) { |
| 1363 | int index = currentIndex; |
| 1364 | IFieldInfo fieldInfo = null; |
| 1365 | while (index < output.length) { |
| 1366 | String line = output[index]; |
| 1367 | Matcher matcher = LTTngControlServiceConstants.EVENT_FIELD_PATTERN.matcher(line); |
| 1368 | if (matcher.matches()) { |
| 1369 | // field: content (string) |
| 1370 | fieldInfo = new FieldInfo(matcher.group(2).trim()); |
| 1371 | fieldInfo.setFieldType(matcher.group(3).trim()); |
| 1372 | fields.add(fieldInfo); |
| 1373 | } else if (LTTngControlServiceConstants.PROVIDER_EVENT_PATTERN.matcher(line).matches()) { |
| 1374 | return index; |
| 1375 | } else if (LTTngControlServiceConstants.UST_PROVIDER_PATTERN.matcher(line).matches()) { |
| 1376 | return index; |
| 1377 | } |
| 1378 | index++; |
| 1379 | } |
| 1380 | return index; |
| 1381 | } |
| 1382 | |
| 1383 | /** |
| 1384 | * Formats a command parameter for the command execution i.e. adds quotes |
| 1385 | * at the beginning and end if necessary. |
| 1386 | * @param parameter - parameter to format |
| 1387 | * @return formated parameter |
| 1388 | */ |
| 1389 | protected String formatParameter(String parameter) { |
| 1390 | if (parameter != null) { |
| 1391 | StringBuffer newString = new StringBuffer(); |
| 1392 | newString.append(parameter); |
| 1393 | |
| 1394 | if (parameter.contains(" ") || parameter.contains("*")) { //$NON-NLS-1$ //$NON-NLS-2$ |
| 1395 | newString.insert(0, "\""); //$NON-NLS-1$ |
| 1396 | newString.append("\""); //$NON-NLS-1$ |
| 1397 | } |
| 1398 | return newString.toString(); |
| 1399 | } |
| 1400 | return null; |
| 1401 | } |
| 1402 | |
| 1403 | /** |
| 1404 | * @param strings array of string that makes up a command line |
| 1405 | * @return string buffer with created command line |
| 1406 | */ |
| 1407 | protected StringBuffer createCommand(String... strings) { |
| 1408 | StringBuffer command = new StringBuffer(); |
| 1409 | command.append(LTTngControlServiceConstants.CONTROL_COMMAND); |
| 1410 | command.append(getTracingGroupOption()); |
| 1411 | command.append(getVerboseOption()); |
| 1412 | for (String string : strings) { |
| 1413 | command.append(string); |
| 1414 | } |
| 1415 | return command; |
| 1416 | } |
| 1417 | |
| 1418 | /** |
| 1419 | * @return the tracing group option if configured in the preferences |
| 1420 | */ |
| 1421 | protected String getTracingGroupOption() { |
| 1422 | if (!ControlPreferences.getInstance().isDefaultTracingGroup() && !ControlPreferences.getInstance().getTracingGroup().equals("")) { //$NON-NLS-1$ |
| 1423 | return LTTngControlServiceConstants.OPTION_TRACING_GROUP + ControlPreferences.getInstance().getTracingGroup(); |
| 1424 | } |
| 1425 | return ""; //$NON-NLS-1$ |
| 1426 | } |
| 1427 | |
| 1428 | /** |
| 1429 | * @return the verbose option as configured in the preferences |
| 1430 | */ |
| 1431 | protected String getVerboseOption() { |
| 1432 | if (ControlPreferences.getInstance().isLoggingEnabled()) { |
| 1433 | String level = ControlPreferences.getInstance().getVerboseLevel(); |
| 1434 | if (ControlPreferences.TRACE_CONTROL_VERBOSE_LEVEL_VERBOSE.equals(level)) { |
| 1435 | return LTTngControlServiceConstants.OPTION_VERBOSE; |
| 1436 | } |
| 1437 | if (ControlPreferences.TRACE_CONTROL_VERBOSE_LEVEL_V_VERBOSE.equals(level)) { |
| 1438 | return LTTngControlServiceConstants.OPTION_VERY_VERBOSE; |
| 1439 | } |
| 1440 | if (ControlPreferences.TRACE_CONTROL_VERBOSE_LEVEL_V_V_VERBOSE.equals(level)) { |
| 1441 | return LTTngControlServiceConstants.OPTION_VERY_VERY_VERBOSE; |
| 1442 | } |
| 1443 | } |
| 1444 | return ""; //$NON-NLS-1$ |
| 1445 | } |
| 1446 | |
| 1447 | /** |
| 1448 | * Method that logs the command and command result if logging is enabled as |
| 1449 | * well as forwards the command execution to the shell. |
| 1450 | * |
| 1451 | * @param command |
| 1452 | * - the command to execute |
| 1453 | * @param monitor |
| 1454 | * - a progress monitor |
| 1455 | * @return the command result |
| 1456 | * @throws ExecutionException |
| 1457 | * If the command fails |
| 1458 | */ |
| 1459 | protected ICommandResult executeCommand(String command, |
| 1460 | IProgressMonitor monitor) throws ExecutionException { |
| 1461 | return executeCommand(command, monitor, true); |
| 1462 | } |
| 1463 | |
| 1464 | /** |
| 1465 | * Method that logs the command and command result if logging is enabled as |
| 1466 | * well as forwards the command execution to the shell. |
| 1467 | * |
| 1468 | * @param command |
| 1469 | * - the command to execute |
| 1470 | * @param monitor |
| 1471 | * - a progress monitor |
| 1472 | * @param checkForError |
| 1473 | * - true to verify command result, else false |
| 1474 | * @return the command result |
| 1475 | * @throws ExecutionException |
| 1476 | * in case of error result |
| 1477 | */ |
| 1478 | protected ICommandResult executeCommand(String command, |
| 1479 | IProgressMonitor monitor, boolean checkForError) |
| 1480 | throws ExecutionException { |
| 1481 | if (ControlPreferences.getInstance().isLoggingEnabled()) { |
| 1482 | ControlCommandLogger.log(command); |
| 1483 | } |
| 1484 | |
| 1485 | ICommandResult result = fCommandShell.executeCommand( |
| 1486 | command.toString(), monitor); |
| 1487 | |
| 1488 | if (ControlPreferences.getInstance().isLoggingEnabled()) { |
| 1489 | ControlCommandLogger.log(formatOutput(result)); |
| 1490 | } |
| 1491 | |
| 1492 | if (checkForError && isError(result)) { |
| 1493 | throw new ExecutionException(Messages.TraceControl_CommandError |
| 1494 | + " " + command.toString() + "\n" + formatOutput(result)); //$NON-NLS-1$ //$NON-NLS-2$ |
| 1495 | } |
| 1496 | |
| 1497 | return result; |
| 1498 | } |
| 1499 | } |