1 /**********************************************************************
2 * Copyright (c) 2012, 2013 Ericsson
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
10 * Bernd Hufmann - Initial API and implementation
11 * Bernd Hufmann - Updated for support of LTTng Tools 2.1
12 **********************************************************************/
13 package org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.model
.impl
;
15 import java
.util
.List
;
17 import org
.eclipse
.core
.commands
.ExecutionException
;
18 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
19 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.IChannelInfo
;
20 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.IDomainInfo
;
21 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.ISessionInfo
;
22 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.ISnapshotInfo
;
23 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.LogLevelType
;
24 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.TraceLogLevel
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.TraceSessionState
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.impl
.SessionInfo
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.Activator
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.messages
.Messages
;
29 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.model
.ITraceControlComponent
;
30 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.property
.TraceSessionPropertySource
;
31 import org
.eclipse
.swt
.graphics
.Image
;
32 import org
.eclipse
.ui
.views
.properties
.IPropertySource
;
36 * Implementation of the trace session component.
39 * @author Bernd Hufmann
41 public class TraceSessionComponent
extends TraceControlComponent
{
43 // ------------------------------------------------------------------------
45 // ------------------------------------------------------------------------
47 * Path to icon file for this component (inactive state).
49 public static final String TRACE_SESSION_ICON_FILE_INACTIVE
= "icons/obj16/session_inactive.gif"; //$NON-NLS-1$
51 * Path to icon file for this component (active state).
53 public static final String TRACE_SESSION_ICON_FILE_ACTIVE
= "icons/obj16/session_active.gif"; //$NON-NLS-1$
55 * Path to icon file for this component (destroyed state).
57 public static final String TRACE_SESSION_ICON_FILE_DESTROYED
= "icons/obj16/session_destroyed.gif"; //$NON-NLS-1$
59 // ------------------------------------------------------------------------
61 // ------------------------------------------------------------------------
63 * The session information.
65 private ISessionInfo fSessionInfo
= null;
67 * A flag to indicate if session has been destroyed.
69 private boolean fIsDestroyed
= false;
71 * The image to be displayed in state active.
73 private Image fActiveImage
= null;
75 * The image to be displayed in state destroyed
77 private Image fDestroyedImage
= null;
79 // ------------------------------------------------------------------------
81 // ------------------------------------------------------------------------
84 * @param name - the name of the component.
85 * @param parent - the parent of this component.
87 public TraceSessionComponent(String name
, ITraceControlComponent parent
) {
89 setImage(TRACE_SESSION_ICON_FILE_INACTIVE
);
90 setToolTip(Messages
.TraceControl_SessionDisplayName
);
91 fSessionInfo
= new SessionInfo(name
);
92 fActiveImage
= Activator
.getDefault().loadIcon(TRACE_SESSION_ICON_FILE_ACTIVE
);
93 fDestroyedImage
= Activator
.getDefault().loadIcon(TRACE_SESSION_ICON_FILE_DESTROYED
);
96 // ------------------------------------------------------------------------
98 // ------------------------------------------------------------------------
101 public Image
getImage() {
103 return fDestroyedImage
;
106 if (fSessionInfo
.getSessionState() == TraceSessionState
.INACTIVE
) {
107 return super.getImage();
114 * @return the whether the session is destroyed or not.
116 public boolean isDestroyed() {
121 * Sets the session destroyed state to the given value.
122 * @param destroyed - value to set.
124 public void setDestroyed(boolean destroyed
) {
125 fIsDestroyed
= destroyed
;
129 * @return the session state state (active or inactive).
131 public TraceSessionState
getSessionState() {
132 return fSessionInfo
.getSessionState();
136 * Sets the session state to the given value.
137 * @param state - state to set.
139 public void setSessionState(TraceSessionState state
) {
140 fSessionInfo
.setSessionState(state
);
144 * Sets the event state to the value specified by the given name.
145 * @param stateName - state to set.
147 public void setSessionState(String stateName
) {
148 fSessionInfo
.setSessionState(stateName
);
152 * @return path string where session is located.
154 public String
getSessionPath() {
155 return fSessionInfo
.getSessionPath();
159 * Sets the path string (where session is located) to the given value.
160 * @param sessionPath - session path to set.
162 public void setSessionPath(String sessionPath
) {
163 fSessionInfo
.setSessionPath(sessionPath
);
167 * Returns if session is streamed over network
168 * @return <code>true</code> if streamed over network else <code>false</code>
170 public boolean isStreamedTrace() {
171 return fSessionInfo
.isStreamedTrace();
175 * Sets whether the trace is streamed or not
176 * @param isStreamedTrace <code>true</code> if streamed over network else <code>false</code>
178 public void setIsStreamedTrace(boolean isStreamedTrace
) {
179 fSessionInfo
.setStreamedTrace(isStreamedTrace
);
183 * Returns whether the session is snapshot session or not
184 * @return <code>true</code> if it is snapshot session else <code>false</code>
186 public boolean isSnapshotSession() {
187 return fSessionInfo
.isSnapshotSession();
191 * Gets the snapshot information if available whether the session is a snapshot session or not
192 * @return the snapshot information or null if it is not a snapshot session
194 public ISnapshotInfo
getSnapshotInfo() {
195 return fSessionInfo
.getSnapshotInfo();
199 public Object
getAdapter(Class adapter
) {
200 if (adapter
== IPropertySource
.class) {
201 return new TraceSessionPropertySource(this);
207 * @return all available domains of this session.
209 public TraceDomainComponent
[] getDomains() {
210 List
<ITraceControlComponent
> sessions
= getChildren(TraceDomainComponent
.class);
211 return sessions
.toArray(new TraceDomainComponent
[sessions
.size()]);
215 * @return the parent target node
217 public TargetNodeComponent
getTargetNode() {
218 return ((TraceSessionGroup
)getParent()).getTargetNode();
222 * Returns whether the kernel provider is available or not
223 * @return <code>true</code> if kernel provide is available or <code>false</code>
225 public boolean hasKernelProvider() {
226 List
<ITraceControlComponent
> providerGroups
= getTargetNode().getChildren(TraceProviderGroup
.class);
227 return (!providerGroups
.isEmpty() ?
((TraceProviderGroup
) providerGroups
.get(0)).hasKernelProvider() : false);
231 * Returns if node supports filtering of events
232 * @return <code>true</code> if node supports filtering else <code>false</code>
234 public boolean isEventFilteringSupported() {
235 return ((TargetNodeComponent
)getParent().getParent()).isEventFilteringSupported();
239 * Returns if node supports snapshots or not
240 * @return <code>true</code> if it supports snapshots else <code>false</code>
243 public boolean isSnapshotSupported() {
244 return ((TargetNodeComponent
)getParent().getParent()).isSnapshotSupported();
247 // ------------------------------------------------------------------------
249 // ------------------------------------------------------------------------
252 * Retrieves the session configuration from the node.
255 * - a progress monitor
256 * @throws ExecutionException
257 * If the command fails
259 public void getConfigurationFromNode(IProgressMonitor monitor
)
260 throws ExecutionException
{
262 fSessionInfo
= getControlService().getSession(getName(), monitor
);
264 IDomainInfo
[] domains
= fSessionInfo
.getDomains();
265 for (int i
= 0; i
< domains
.length
; i
++) {
266 TraceDomainComponent domainComponent
= new TraceDomainComponent(
267 domains
[i
].getName(), this);
268 addChild(domainComponent
);
269 domainComponent
.setDomainInfo(domains
[i
]);
274 * Starts the session.
277 * - a progress monitor
278 * @throws ExecutionException
279 * If the command fails
281 public void startSession(IProgressMonitor monitor
)
282 throws ExecutionException
{
283 getControlService().startSession(getName(), monitor
);
287 * Starts the session.
290 * - a progress monitor
291 * @throws ExecutionException
292 * If the command fails
294 public void stopSession(IProgressMonitor monitor
) throws ExecutionException
{
295 getControlService().stopSession(getName(), monitor
);
299 * Enables channels with given names which are part of this domain. If a
300 * given channel doesn't exists it creates a new channel with the given
301 * parameters (or default values if given parameter is null).
303 * @param channelNames
304 * - a list of channel names to enable on this domain
306 * - channel information to set for the channel (use null for
309 * - a flag for indicating kernel or UST.
311 * - a progress monitor
312 * @throws ExecutionException
313 * If the command fails
315 public void enableChannels(List
<String
> channelNames
, IChannelInfo info
,
316 boolean isKernel
, IProgressMonitor monitor
)
317 throws ExecutionException
{
318 getControlService().enableChannels(getName(), channelNames
, isKernel
,
323 * Enables a list of events with no additional parameters.
326 * - a list of event names to enabled.
328 * - a flag for indicating kernel or UST.
329 * @param filterExpression
330 * - a filter expression
332 * - a progress monitor
333 * @throws ExecutionException
334 * If the command fails
336 public void enableEvents(List
<String
> eventNames
, boolean isKernel
,
337 String filterExpression
, IProgressMonitor monitor
) throws ExecutionException
{
338 getControlService().enableEvents(getName(), null, eventNames
, isKernel
,
339 filterExpression
, monitor
);
343 * Enables all syscalls (for kernel domain)
346 * - a progress monitor
347 * @throws ExecutionException
348 * If the command fails
350 public void enableSyscalls(IProgressMonitor monitor
)
351 throws ExecutionException
{
352 getControlService().enableSyscalls(getName(), null, monitor
);
356 * Enables a dynamic probe (for kernel domain)
359 * - event name for probe
361 * - true for dynamic function entry/return probe else false
365 * - a progress monitor
366 * @throws ExecutionException
367 * If the command fails
369 public void enableProbe(String eventName
, boolean isFunction
, String probe
,
370 IProgressMonitor monitor
) throws ExecutionException
{
371 getControlService().enableProbe(getName(), null, eventName
, isFunction
,
376 * Enables events using log level.
380 * @param logLevelType
384 * @param filterExpression
385 * - a filter expression
387 * - a progress monitor
388 * @throws ExecutionException
389 * If the command fails
391 public void enableLogLevel(String eventName
, LogLevelType logLevelType
,
392 TraceLogLevel level
, String filterExpression
, IProgressMonitor monitor
)
393 throws ExecutionException
{
394 getControlService().enableLogLevel(getName(), null, eventName
,
395 logLevelType
, level
, null, monitor
);
399 * Gets all available contexts to be added to channels/events.
402 * The monitor that will indicate the progress
403 * @return the list of available contexts
404 * @throws ExecutionException
405 * If the command fails
407 public List
<String
> getContextList(IProgressMonitor monitor
)
408 throws ExecutionException
{
409 return getControlService().getContextList(monitor
);
413 * Records a snapshot.
416 * - a progress monitor
417 * @throws ExecutionException
418 * If the command fails
420 public void recordSnapshot(IProgressMonitor monitor
) throws ExecutionException
{
421 getControlService().recordSnapshot(getName(), monitor
);