1 /**********************************************************************
2 * Copyright (c) 2012, 2014 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 * Marc-Andre Laperle - Support for opening a live session
13 **********************************************************************/
14 package org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
;
16 import java
.util
.List
;
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
.IDomainInfo
;
23 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.ISessionInfo
;
24 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.ISnapshotInfo
;
25 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.LogLevelType
;
26 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TraceLogLevel
;
27 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TraceSessionState
;
28 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.SessionInfo
;
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
.TraceSessionPropertySource
;
33 import org
.eclipse
.ui
.views
.properties
.IPropertySource
;
37 * Implementation of the trace session component.
40 * @author Bernd Hufmann
42 public class TraceSessionComponent
extends TraceControlComponent
{
44 // ------------------------------------------------------------------------
46 // ------------------------------------------------------------------------
48 * Path to icon file for this component (inactive state).
50 public static final String TRACE_SESSION_ICON_FILE_INACTIVE
= "icons/obj16/session_inactive.gif"; //$NON-NLS-1$
52 * Path to icon file for this component (active state).
54 public static final String TRACE_SESSION_ICON_FILE_ACTIVE
= "icons/obj16/session_active.gif"; //$NON-NLS-1$
56 * Path to icon file for this component (destroyed state).
58 public static final String TRACE_SESSION_ICON_FILE_DESTROYED
= "icons/obj16/session_destroyed.gif"; //$NON-NLS-1$
60 // ------------------------------------------------------------------------
62 // ------------------------------------------------------------------------
64 * The session information.
66 private ISessionInfo fSessionInfo
= null;
68 * A flag to indicate if session has been destroyed.
70 private boolean fIsDestroyed
= false;
72 * The image to be displayed in state active.
74 private Image fActiveImage
= null;
76 * The image to be displayed in state destroyed
78 private Image fDestroyedImage
= null;
80 // ------------------------------------------------------------------------
82 // ------------------------------------------------------------------------
85 * @param name - the name of the component.
86 * @param parent - the parent of this component.
88 public TraceSessionComponent(String name
, ITraceControlComponent parent
) {
90 setImage(TRACE_SESSION_ICON_FILE_INACTIVE
);
91 setToolTip(Messages
.TraceControl_SessionDisplayName
);
92 fSessionInfo
= new SessionInfo(name
);
93 fActiveImage
= Activator
.getDefault().loadIcon(TRACE_SESSION_ICON_FILE_ACTIVE
);
94 fDestroyedImage
= Activator
.getDefault().loadIcon(TRACE_SESSION_ICON_FILE_DESTROYED
);
101 * the session information used to create the session
103 * the parent of this component.
105 public TraceSessionComponent(ISessionInfo sessionInfo
, ITraceControlComponent parent
) {
106 this(sessionInfo
.getName(), parent
);
107 copyLiveInfo(sessionInfo
);
110 private void copyLiveInfo(ISessionInfo sessionInfo
) {
111 // Since we can't retrieve this information from the node, we copy it over
112 fSessionInfo
.setLive(sessionInfo
.isLive());
113 fSessionInfo
.setLiveDelay(sessionInfo
.getLiveDelay());
114 fSessionInfo
.setLivePort(sessionInfo
.getLivePort());
115 fSessionInfo
.setLiveUrl(sessionInfo
.getLiveUrl());
118 // ------------------------------------------------------------------------
120 // ------------------------------------------------------------------------
123 public Image
getImage() {
125 return fDestroyedImage
;
128 if (fSessionInfo
.getSessionState() == TraceSessionState
.INACTIVE
) {
129 return super.getImage();
136 * @return the whether the session is destroyed or not.
138 public boolean isDestroyed() {
143 * Sets the session destroyed state to the given value.
144 * @param destroyed - value to set.
146 public void setDestroyed(boolean destroyed
) {
147 fIsDestroyed
= destroyed
;
151 * @return the session state state (active or inactive).
153 public TraceSessionState
getSessionState() {
154 return fSessionInfo
.getSessionState();
158 * Sets the session state to the given value.
159 * @param state - state to set.
161 public void setSessionState(TraceSessionState state
) {
162 fSessionInfo
.setSessionState(state
);
166 * Sets the event state to the value specified by the given name.
167 * @param stateName - state to set.
169 public void setSessionState(String stateName
) {
170 fSessionInfo
.setSessionState(stateName
);
174 * @return path string where session is located.
176 public String
getSessionPath() {
177 return fSessionInfo
.getSessionPath();
181 * Sets the path string (where session is located) to the given value.
182 * @param sessionPath - session path to set.
184 public void setSessionPath(String sessionPath
) {
185 fSessionInfo
.setSessionPath(sessionPath
);
189 * Returns if session is streamed over network
190 * @return <code>true</code> if streamed over network else <code>false</code>
192 public boolean isStreamedTrace() {
193 return fSessionInfo
.isStreamedTrace();
197 * Sets whether the trace is streamed or not
198 * @param isStreamedTrace <code>true</code> if streamed over network else <code>false</code>
200 public void setIsStreamedTrace(boolean isStreamedTrace
) {
201 fSessionInfo
.setStreamedTrace(isStreamedTrace
);
205 * Returns whether the session is snapshot session or not
206 * @return <code>true</code> if it is snapshot session else <code>false</code>
208 public boolean isSnapshotSession() {
209 return fSessionInfo
.isSnapshotSession();
213 * Gets the snapshot information if available whether the session is a snapshot session or not
214 * @return the snapshot information or null if it is not a snapshot session
216 public ISnapshotInfo
getSnapshotInfo() {
217 return fSessionInfo
.getSnapshotInfo();
221 public Object
getAdapter(Class adapter
) {
222 if (adapter
== IPropertySource
.class) {
223 return new TraceSessionPropertySource(this);
229 * @return all available domains of this session.
231 public TraceDomainComponent
[] getDomains() {
232 List
<ITraceControlComponent
> sessions
= getChildren(TraceDomainComponent
.class);
233 return sessions
.toArray(new TraceDomainComponent
[sessions
.size()]);
237 * @return the parent target node
239 public TargetNodeComponent
getTargetNode() {
240 return ((TraceSessionGroup
)getParent()).getTargetNode();
244 * Returns whether the kernel provider is available or not
245 * @return <code>true</code> if kernel provide is available or <code>false</code>
247 public boolean hasKernelProvider() {
248 List
<ITraceControlComponent
> providerGroups
= getTargetNode().getChildren(TraceProviderGroup
.class);
249 return (!providerGroups
.isEmpty() ?
((TraceProviderGroup
) providerGroups
.get(0)).hasKernelProvider() : false);
253 * Returns if node supports filtering of events
254 * @return <code>true</code> if node supports filtering else <code>false</code>
256 public boolean isEventFilteringSupported() {
257 return ((TargetNodeComponent
)getParent().getParent()).isEventFilteringSupported();
261 * Returns if node supports snapshots or not
262 * @return <code>true</code> if it supports snapshots else <code>false</code>
265 public boolean isSnapshotSupported() {
266 return ((TargetNodeComponent
)getParent().getParent()).isSnapshotSupported();
269 // ------------------------------------------------------------------------
271 // ------------------------------------------------------------------------
274 * Retrieves the session configuration from the node.
277 * - a progress monitor
278 * @throws ExecutionException
279 * If the command fails
281 public void getConfigurationFromNode(IProgressMonitor monitor
)
282 throws ExecutionException
{
284 ISessionInfo oldSessionInfo
= fSessionInfo
;
285 fSessionInfo
= getControlService().getSession(getName(), monitor
);
286 copyLiveInfo(oldSessionInfo
);
288 IDomainInfo
[] domains
= fSessionInfo
.getDomains();
289 for (int i
= 0; i
< domains
.length
; i
++) {
290 TraceDomainComponent domainComponent
= new TraceDomainComponent(
291 domains
[i
].getName(), this);
292 addChild(domainComponent
);
293 domainComponent
.setDomainInfo(domains
[i
]);
298 * Starts the session.
301 * - a progress monitor
302 * @throws ExecutionException
303 * If the command fails
305 public void startSession(IProgressMonitor monitor
)
306 throws ExecutionException
{
307 getControlService().startSession(getName(), monitor
);
311 * Starts the session.
314 * - a progress monitor
315 * @throws ExecutionException
316 * If the command fails
318 public void stopSession(IProgressMonitor monitor
) throws ExecutionException
{
319 getControlService().stopSession(getName(), monitor
);
323 * Enables channels with given names which are part of this domain. If a
324 * given channel doesn't exists it creates a new channel with the given
325 * parameters (or default values if given parameter is null).
327 * @param channelNames
328 * - a list of channel names to enable on this domain
330 * - channel information to set for the channel (use null for
333 * - a flag for indicating kernel or UST.
335 * - a progress monitor
336 * @throws ExecutionException
337 * If the command fails
339 public void enableChannels(List
<String
> channelNames
, IChannelInfo info
,
340 boolean isKernel
, IProgressMonitor monitor
)
341 throws ExecutionException
{
342 getControlService().enableChannels(getName(), channelNames
, isKernel
,
347 * Enables a list of events with no additional parameters.
350 * - a list of event names to enabled.
352 * - a flag for indicating kernel or UST.
353 * @param filterExpression
354 * - a filter expression
356 * - a progress monitor
357 * @throws ExecutionException
358 * If the command fails
360 public void enableEvents(List
<String
> eventNames
, boolean isKernel
,
361 String filterExpression
, IProgressMonitor monitor
) throws ExecutionException
{
362 getControlService().enableEvents(getName(), null, eventNames
, isKernel
,
363 filterExpression
, monitor
);
367 * Enables all syscalls (for kernel domain)
370 * - a progress monitor
371 * @throws ExecutionException
372 * If the command fails
374 public void enableSyscalls(IProgressMonitor monitor
)
375 throws ExecutionException
{
376 getControlService().enableSyscalls(getName(), null, monitor
);
380 * Enables a dynamic probe (for kernel domain)
383 * - event name for probe
385 * - true for dynamic function entry/return probe else false
389 * - a progress monitor
390 * @throws ExecutionException
391 * If the command fails
393 public void enableProbe(String eventName
, boolean isFunction
, String probe
,
394 IProgressMonitor monitor
) throws ExecutionException
{
395 getControlService().enableProbe(getName(), null, eventName
, isFunction
,
400 * Enables events using log level.
404 * @param logLevelType
408 * @param filterExpression
409 * - a filter expression
411 * - a progress monitor
412 * @throws ExecutionException
413 * If the command fails
415 public void enableLogLevel(String eventName
, LogLevelType logLevelType
,
416 TraceLogLevel level
, String filterExpression
, IProgressMonitor monitor
)
417 throws ExecutionException
{
418 getControlService().enableLogLevel(getName(), null, eventName
,
419 logLevelType
, level
, null, monitor
);
423 * Gets all available contexts to be added to channels/events.
426 * The monitor that will indicate the progress
427 * @return the list of available contexts
428 * @throws ExecutionException
429 * If the command fails
431 public List
<String
> getContextList(IProgressMonitor monitor
)
432 throws ExecutionException
{
433 return getControlService().getContextList(monitor
);
437 * Records a snapshot.
440 * - a progress monitor
441 * @throws ExecutionException
442 * If the command fails
444 public void recordSnapshot(IProgressMonitor monitor
) throws ExecutionException
{
445 getControlService().recordSnapshot(getName(), monitor
);
449 * Returns if session is live.
450 * @return <code>true</code> if session if live else <code>false</code>
452 public boolean isLiveTrace() {
453 return fSessionInfo
.isLive();
459 * @return the live URL
461 public String
getLiveUrl() {
462 return fSessionInfo
.getLiveUrl();
468 * @return the live port
470 public Integer
getLivePort() {
471 return fSessionInfo
.getLivePort();