| 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.model.impl; |
| 13 | |
| 14 | import java.util.ArrayList; |
| 15 | import java.util.List; |
| 16 | |
| 17 | import org.eclipse.core.commands.ExecutionException; |
| 18 | import org.eclipse.core.runtime.IProgressMonitor; |
| 19 | import org.eclipse.core.runtime.NullProgressMonitor; |
| 20 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.IChannelInfo; |
| 21 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.IEventInfo; |
| 22 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.LogLevelType; |
| 23 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceEnablement; |
| 24 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceLogLevel; |
| 25 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.ChannelInfo; |
| 26 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.ProbeEventInfo; |
| 27 | import org.eclipse.linuxtools.internal.lttng2.ui.Activator; |
| 28 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.messages.Messages; |
| 29 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent; |
| 30 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.property.TraceChannelPropertySource; |
| 31 | import org.eclipse.swt.graphics.Image; |
| 32 | import org.eclipse.ui.views.properties.IPropertySource; |
| 33 | |
| 34 | |
| 35 | /** |
| 36 | * <p> |
| 37 | * Implementation of the trace channel component. |
| 38 | * </p> |
| 39 | * |
| 40 | * @author Bernd Hufmann |
| 41 | */ |
| 42 | public class TraceChannelComponent extends TraceControlComponent { |
| 43 | // ------------------------------------------------------------------------ |
| 44 | // Constants |
| 45 | // ------------------------------------------------------------------------ |
| 46 | /** |
| 47 | * Path to icon file for this component (state enabled). |
| 48 | */ |
| 49 | public static final String TRACE_CHANNEL_ICON_FILE_ENABLED = "icons/obj16/channel.gif"; //$NON-NLS-1$ |
| 50 | /** |
| 51 | * Path to icon file for this component (state disabled). |
| 52 | */ |
| 53 | public static final String TRACE_CHANNEL_ICON_FILE_DISABLED = "icons/obj16/channel_disabled.gif"; //$NON-NLS-1$ |
| 54 | |
| 55 | // ------------------------------------------------------------------------ |
| 56 | // Attributes |
| 57 | // ------------------------------------------------------------------------ |
| 58 | /** |
| 59 | * The channel information. |
| 60 | */ |
| 61 | private IChannelInfo fChannelInfo = null; |
| 62 | /** |
| 63 | * The image to be displayed in disabled state. |
| 64 | */ |
| 65 | private Image fDisabledImage = null; |
| 66 | |
| 67 | // ------------------------------------------------------------------------ |
| 68 | // Constructors |
| 69 | // ------------------------------------------------------------------------ |
| 70 | /** |
| 71 | * Constructor |
| 72 | * @param name - the name of the component. |
| 73 | * @param parent - the parent of this component. |
| 74 | */ |
| 75 | public TraceChannelComponent(String name, ITraceControlComponent parent) { |
| 76 | super(name, parent); |
| 77 | setImage(TRACE_CHANNEL_ICON_FILE_ENABLED); |
| 78 | setToolTip(Messages.TraceControl_ChannelDisplayName); |
| 79 | fChannelInfo = new ChannelInfo(name); |
| 80 | fDisabledImage = Activator.getDefault().loadIcon(TRACE_CHANNEL_ICON_FILE_DISABLED); |
| 81 | } |
| 82 | |
| 83 | // ------------------------------------------------------------------------ |
| 84 | // Accessors |
| 85 | // ------------------------------------------------------------------------ |
| 86 | /* |
| 87 | * (non-Javadoc) |
| 88 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getImage() |
| 89 | */ |
| 90 | @Override |
| 91 | public Image getImage() { |
| 92 | if (fChannelInfo.getState() == TraceEnablement.DISABLED) { |
| 93 | return fDisabledImage; |
| 94 | } |
| 95 | return super.getImage(); |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Sets the channel information. |
| 100 | * |
| 101 | * @param channelInfo |
| 102 | * The channel info to assign to this component |
| 103 | */ |
| 104 | public void setChannelInfo(IChannelInfo channelInfo) { |
| 105 | fChannelInfo = channelInfo; |
| 106 | IEventInfo[] events = fChannelInfo.getEvents(); |
| 107 | List<ITraceControlComponent> eventComponents = new ArrayList<ITraceControlComponent>(); |
| 108 | for (int i = 0; i < events.length; i++) { |
| 109 | TraceEventComponent event = null; |
| 110 | if (events[i].getClass() == ProbeEventInfo.class) { |
| 111 | event = new TraceProbeEventComponent(events[i].getName(), this); |
| 112 | } else { |
| 113 | event = new TraceEventComponent(events[i].getName(), this); |
| 114 | } |
| 115 | |
| 116 | eventComponents.add(event); |
| 117 | event.setEventInfo(events[i]); |
| 118 | // addChild(event); |
| 119 | } |
| 120 | if (!eventComponents.isEmpty()) { |
| 121 | setChildren(eventComponents); |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * @return the overwrite mode value. |
| 127 | */ |
| 128 | public boolean isOverwriteMode() { |
| 129 | return fChannelInfo.isOverwriteMode(); |
| 130 | } |
| 131 | /** |
| 132 | * Sets the overwrite mode value to the given mode. |
| 133 | * @param mode - mode to set. |
| 134 | */ |
| 135 | public void setOverwriteMode(boolean mode){ |
| 136 | fChannelInfo.setOverwriteMode(mode); |
| 137 | } |
| 138 | /** |
| 139 | * @return the sub-buffer size. |
| 140 | */ |
| 141 | public long getSubBufferSize() { |
| 142 | return fChannelInfo.getSubBufferSize(); |
| 143 | } |
| 144 | /** |
| 145 | * Sets the sub-buffer size to the given value. |
| 146 | * @param bufferSize - size to set to set. |
| 147 | */ |
| 148 | public void setSubBufferSize(long bufferSize) { |
| 149 | fChannelInfo.setSubBufferSize(bufferSize); |
| 150 | } |
| 151 | /** |
| 152 | * @return the number of sub-buffers. |
| 153 | */ |
| 154 | public int getNumberOfSubBuffers() { |
| 155 | return fChannelInfo.getNumberOfSubBuffers(); |
| 156 | } |
| 157 | /** |
| 158 | * Sets the number of sub-buffers to the given value. |
| 159 | * @param numberOfSubBuffers - value to set. |
| 160 | */ |
| 161 | public void setNumberOfSubBuffers(int numberOfSubBuffers) { |
| 162 | fChannelInfo.setNumberOfSubBuffers(numberOfSubBuffers); |
| 163 | } |
| 164 | /** |
| 165 | * @return the switch timer interval. |
| 166 | */ |
| 167 | public long getSwitchTimer() { |
| 168 | return fChannelInfo.getSwitchTimer(); |
| 169 | } |
| 170 | /** |
| 171 | * Sets the switch timer interval to the given value. |
| 172 | * @param timer - timer value to set. |
| 173 | */ |
| 174 | public void setSwitchTimer(long timer) { |
| 175 | fChannelInfo.setSwitchTimer(timer); |
| 176 | } |
| 177 | /** |
| 178 | * @return the read timer interval. |
| 179 | */ |
| 180 | public long getReadTimer() { |
| 181 | return fChannelInfo.getReadTimer(); |
| 182 | } |
| 183 | /** |
| 184 | * Sets the read timer interval to the given value. |
| 185 | * @param timer - timer value to set.. |
| 186 | */ |
| 187 | public void setReadTimer(long timer) { |
| 188 | fChannelInfo.setReadTimer(timer); |
| 189 | } |
| 190 | /** |
| 191 | * @return the output type. |
| 192 | */ |
| 193 | public String getOutputType() { |
| 194 | return fChannelInfo.getOutputType(); |
| 195 | } |
| 196 | /** |
| 197 | * Sets the output type to the given value. |
| 198 | * @param type - type to set. |
| 199 | */ |
| 200 | public void setOutputType(String type) { |
| 201 | fChannelInfo.setOutputType(type); |
| 202 | } |
| 203 | /** |
| 204 | * @return the channel state (enabled or disabled). |
| 205 | */ |
| 206 | public TraceEnablement getState() { |
| 207 | return fChannelInfo.getState(); |
| 208 | } |
| 209 | /** |
| 210 | * Sets the channel state (enablement) to the given value. |
| 211 | * @param state - state to set. |
| 212 | */ |
| 213 | public void setState(TraceEnablement state) { |
| 214 | fChannelInfo.setState(state); |
| 215 | } |
| 216 | /** |
| 217 | * Sets the channel state (enablement) to the value specified by the given name. |
| 218 | * @param stateName - state to set. |
| 219 | */ |
| 220 | public void setState(String stateName) { |
| 221 | fChannelInfo.setState(stateName); |
| 222 | } |
| 223 | /* |
| 224 | * (non-Javadoc) |
| 225 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getAdapter(java.lang.Class) |
| 226 | */ |
| 227 | @Override |
| 228 | public Object getAdapter(Class adapter) { |
| 229 | if (adapter == IPropertySource.class) { |
| 230 | return new TraceChannelPropertySource(this); |
| 231 | } |
| 232 | return null; |
| 233 | } |
| 234 | |
| 235 | /** |
| 236 | * @return session name from parent |
| 237 | */ |
| 238 | public String getSessionName() { |
| 239 | return ((TraceDomainComponent)getParent()).getSessionName(); |
| 240 | } |
| 241 | |
| 242 | /** |
| 243 | * @return session from parent |
| 244 | */ |
| 245 | public TraceSessionComponent getSession() { |
| 246 | return ((TraceDomainComponent)getParent()).getSession(); |
| 247 | } |
| 248 | |
| 249 | /** |
| 250 | * @return if domain is kernel or UST |
| 251 | */ |
| 252 | public boolean isKernel() { |
| 253 | return ((TraceDomainComponent)getParent()).isKernel(); |
| 254 | } |
| 255 | |
| 256 | /** |
| 257 | * @return the parent target node |
| 258 | */ |
| 259 | public TargetNodeComponent getTargetNode() { |
| 260 | return ((TraceDomainComponent)getParent()).getTargetNode(); |
| 261 | } |
| 262 | |
| 263 | // ------------------------------------------------------------------------ |
| 264 | // Operations |
| 265 | // ------------------------------------------------------------------------ |
| 266 | /** |
| 267 | * Enables a list of events with no additional parameters. |
| 268 | * |
| 269 | * @param eventNames |
| 270 | * - a list of event names to enabled. |
| 271 | * @throws ExecutionException |
| 272 | * If the command fails |
| 273 | */ |
| 274 | public void enableEvents(List<String> eventNames) throws ExecutionException { |
| 275 | enableEvents(eventNames, new NullProgressMonitor()); |
| 276 | } |
| 277 | |
| 278 | /** |
| 279 | * Enables a list of events with no additional parameters. |
| 280 | * |
| 281 | * @param eventNames |
| 282 | * - a list of event names to enabled. |
| 283 | * @param monitor |
| 284 | * - a progress monitor |
| 285 | * @throws ExecutionException |
| 286 | * If the command fails |
| 287 | */ |
| 288 | public void enableEvents(List<String> eventNames, IProgressMonitor monitor) throws ExecutionException { |
| 289 | enableEvents(eventNames, null, monitor); |
| 290 | } |
| 291 | |
| 292 | /** |
| 293 | * Enables a list of events with no additional parameters. |
| 294 | * |
| 295 | * @param eventNames |
| 296 | * - a list of event names to enabled. |
| 297 | * @param filterExpression |
| 298 | * - a filter expression |
| 299 | * @param monitor |
| 300 | * - a progress monitor |
| 301 | * @throws ExecutionException |
| 302 | * If the command fails |
| 303 | */ |
| 304 | public void enableEvents(List<String> eventNames, String filterExpression, IProgressMonitor monitor) throws ExecutionException { |
| 305 | getControlService().enableEvents(getSessionName(), getName(), eventNames, isKernel(), filterExpression, monitor); |
| 306 | } |
| 307 | |
| 308 | /** |
| 309 | * Enables all syscalls (for kernel domain) |
| 310 | * |
| 311 | * @throws ExecutionException |
| 312 | * If the command fails |
| 313 | */ |
| 314 | public void enableSyscalls() throws ExecutionException { |
| 315 | enableSyscalls(new NullProgressMonitor()); |
| 316 | } |
| 317 | |
| 318 | /** |
| 319 | * Enables all syscalls (for kernel domain) |
| 320 | * |
| 321 | * @param monitor |
| 322 | * - a progress monitor |
| 323 | * @throws ExecutionException |
| 324 | * If the command fails |
| 325 | */ |
| 326 | public void enableSyscalls(IProgressMonitor monitor) throws ExecutionException { |
| 327 | getControlService().enableSyscalls(getSessionName(), getName(), monitor); |
| 328 | } |
| 329 | |
| 330 | /** |
| 331 | * Enables a dynamic probe (for kernel domain) |
| 332 | * |
| 333 | * @param eventName |
| 334 | * - event name for probe |
| 335 | * @param isFunction |
| 336 | * - true for dynamic function entry/return probe else false |
| 337 | * @param probe |
| 338 | * - the actual probe |
| 339 | * @throws ExecutionException |
| 340 | * If the command fails |
| 341 | */ |
| 342 | public void enableProbe(String eventName, boolean isFunction, String probe) |
| 343 | throws ExecutionException { |
| 344 | enableProbe(eventName, isFunction, probe, new NullProgressMonitor()); |
| 345 | } |
| 346 | |
| 347 | /** |
| 348 | * Enables a dynamic probe (for kernel domain) |
| 349 | * |
| 350 | * @param eventName |
| 351 | * - event name for probe |
| 352 | * @param isFunction |
| 353 | * - true for dynamic function entry/return probe else false |
| 354 | * @param probe |
| 355 | * - the actual probe |
| 356 | * @param monitor |
| 357 | * - a progress monitor |
| 358 | * @throws ExecutionException |
| 359 | * If the command fails |
| 360 | */ |
| 361 | public void enableProbe(String eventName, boolean isFunction, String probe, |
| 362 | IProgressMonitor monitor) throws ExecutionException { |
| 363 | getControlService().enableProbe(getSessionName(), getName(), eventName, isFunction, probe, monitor); |
| 364 | } |
| 365 | |
| 366 | /** |
| 367 | * Enables events using log level. |
| 368 | * |
| 369 | * @param eventName |
| 370 | * - a event name |
| 371 | * @param logLevelType |
| 372 | * - a log level type |
| 373 | * @param level |
| 374 | * - a log level |
| 375 | * @param filterExpression |
| 376 | * - a filter expression |
| 377 | * @throws ExecutionException |
| 378 | * If the command fails |
| 379 | */ |
| 380 | public void enableLogLevel(String eventName, LogLevelType logLevelType, |
| 381 | TraceLogLevel level, String filterExpression) throws ExecutionException { |
| 382 | enableLogLevel(eventName, logLevelType, level, filterExpression, new NullProgressMonitor()); |
| 383 | } |
| 384 | |
| 385 | /** |
| 386 | * Enables events using log level. |
| 387 | * |
| 388 | * @param eventName |
| 389 | * - a event name |
| 390 | * @param logLevelType |
| 391 | * - a log level type |
| 392 | * @param level |
| 393 | * - a log level |
| 394 | * @param filterExpression |
| 395 | * - a filter expression |
| 396 | * @param monitor |
| 397 | * - a progress monitor |
| 398 | * @throws ExecutionException |
| 399 | * If the command fails |
| 400 | */ |
| 401 | public void enableLogLevel(String eventName, LogLevelType logLevelType, |
| 402 | TraceLogLevel level, String filterExpression, IProgressMonitor monitor) |
| 403 | throws ExecutionException { |
| 404 | getControlService().enableLogLevel(getSessionName(), getName(), eventName, logLevelType, level, filterExpression, monitor); |
| 405 | } |
| 406 | |
| 407 | /** |
| 408 | * Enables a list of events with no additional parameters. |
| 409 | * |
| 410 | * @param eventNames |
| 411 | * - a list of event names to enabled. |
| 412 | * @throws ExecutionException |
| 413 | * If the command fails |
| 414 | */ |
| 415 | public void disableEvent(List<String> eventNames) throws ExecutionException { |
| 416 | disableEvent(eventNames, new NullProgressMonitor()); |
| 417 | } |
| 418 | |
| 419 | /** |
| 420 | * Enables a list of events with no additional parameters. |
| 421 | * |
| 422 | * @param eventNames |
| 423 | * - a list of event names to enabled. |
| 424 | * @param monitor |
| 425 | * - a progress monitor |
| 426 | * @throws ExecutionException |
| 427 | * If the command fails |
| 428 | */ |
| 429 | public void disableEvent(List<String> eventNames, IProgressMonitor monitor) |
| 430 | throws ExecutionException { |
| 431 | getControlService().disableEvent(getParent().getParent().getName(), |
| 432 | getName(), eventNames, isKernel(), monitor); |
| 433 | } |
| 434 | |
| 435 | /** |
| 436 | * Add contexts to given channels and or events |
| 437 | * |
| 438 | * @param contexts |
| 439 | * - a list of contexts to add |
| 440 | * @throws ExecutionException |
| 441 | * If the command fails |
| 442 | */ |
| 443 | public void addContexts(List<String> contexts) throws ExecutionException { |
| 444 | addContexts(contexts, new NullProgressMonitor()); |
| 445 | } |
| 446 | |
| 447 | /** |
| 448 | * Add contexts to given channels and or events |
| 449 | * |
| 450 | * @param contexts |
| 451 | * - a list of contexts to add |
| 452 | * @param monitor |
| 453 | * - a progress monitor |
| 454 | * @throws ExecutionException |
| 455 | * If the command fails |
| 456 | */ |
| 457 | public void addContexts(List<String> contexts, IProgressMonitor monitor) |
| 458 | throws ExecutionException { |
| 459 | getControlService().addContexts(getSessionName(), getName(), null, |
| 460 | isKernel(), contexts, monitor); |
| 461 | } |
| 462 | } |