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