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 if (sessionInfo
.getLivePort() != null) {
113 fSessionInfo
.setLivePort(sessionInfo
.getLivePort());
115 if (sessionInfo
.getLiveUrl() != null) {
116 fSessionInfo
.setLiveUrl(sessionInfo
.getLiveUrl());
120 // ------------------------------------------------------------------------
122 // ------------------------------------------------------------------------
125 public Image
getImage() {
127 return fDestroyedImage
;
130 if (fSessionInfo
.getSessionState() == TraceSessionState
.INACTIVE
) {
131 return super.getImage();
138 * @return the whether the session is destroyed or not.
140 public boolean isDestroyed() {
145 * Sets the session destroyed state to the given value.
146 * @param destroyed - value to set.
148 public void setDestroyed(boolean destroyed
) {
149 fIsDestroyed
= destroyed
;
153 * @return the session state state (active or inactive).
155 public TraceSessionState
getSessionState() {
156 return fSessionInfo
.getSessionState();
160 * Sets the session state to the given value.
161 * @param state - state to set.
163 public void setSessionState(TraceSessionState state
) {
164 fSessionInfo
.setSessionState(state
);
168 * Sets the event state to the value specified by the given name.
169 * @param stateName - state to set.
171 public void setSessionState(String stateName
) {
172 fSessionInfo
.setSessionState(stateName
);
176 * @return path string where session is located.
178 public String
getSessionPath() {
179 return fSessionInfo
.getSessionPath();
183 * Sets the path string (where session is located) to the given value.
184 * @param sessionPath - session path to set.
186 public void setSessionPath(String sessionPath
) {
187 fSessionInfo
.setSessionPath(sessionPath
);
191 * Returns if session is streamed over network
192 * @return <code>true</code> if streamed over network else <code>false</code>
194 public boolean isStreamedTrace() {
195 return fSessionInfo
.isStreamedTrace();
199 * Sets whether the trace is streamed or not
200 * @param isStreamedTrace <code>true</code> if streamed over network else <code>false</code>
202 public void setIsStreamedTrace(boolean isStreamedTrace
) {
203 fSessionInfo
.setStreamedTrace(isStreamedTrace
);
207 * Returns whether the session is snapshot session or not
208 * @return <code>true</code> if it is snapshot session else <code>false</code>
210 public boolean isSnapshotSession() {
211 return fSessionInfo
.isSnapshotSession();
215 * Gets the snapshot information if available whether the session is a snapshot session or not
216 * @return the snapshot information or null if it is not a snapshot session
218 public ISnapshotInfo
getSnapshotInfo() {
219 return fSessionInfo
.getSnapshotInfo();
223 public <T
> T
getAdapter(Class
<T
> adapter
) {
224 if (adapter
== IPropertySource
.class) {
225 return adapter
.cast(new TraceSessionPropertySource(this));
231 * @return all available domains of this session.
233 public TraceDomainComponent
[] getDomains() {
234 List
<ITraceControlComponent
> sessions
= getChildren(TraceDomainComponent
.class);
235 return sessions
.toArray(new TraceDomainComponent
[sessions
.size()]);
239 * @return the parent target node
241 public TargetNodeComponent
getTargetNode() {
242 return ((TraceSessionGroup
)getParent()).getTargetNode();
246 * Returns whether the kernel provider is available or not
247 * @return <code>true</code> if kernel provide is available or <code>false</code>
249 public boolean hasKernelProvider() {
250 List
<ITraceControlComponent
> providerGroups
= getTargetNode().getChildren(TraceProviderGroup
.class);
251 return (!providerGroups
.isEmpty() ?
((TraceProviderGroup
) providerGroups
.get(0)).hasKernelProvider() : false);
255 * Returns if node supports filtering of events
256 * @return <code>true</code> if node supports filtering else <code>false</code>
258 public boolean isEventFilteringSupported() {
259 return ((TargetNodeComponent
)getParent().getParent()).isEventFilteringSupported();
263 * Returns if node supports snapshots or not
264 * @return <code>true</code> if it supports snapshots else <code>false</code>
267 public boolean isSnapshotSupported() {
268 return ((TargetNodeComponent
)getParent().getParent()).isSnapshotSupported();
271 // ------------------------------------------------------------------------
273 // ------------------------------------------------------------------------
276 * Retrieves the session configuration from the node.
279 * - a progress monitor
280 * @throws ExecutionException
281 * If the command fails
283 public void getConfigurationFromNode(IProgressMonitor monitor
)
284 throws ExecutionException
{
286 ISessionInfo newInfo
= getControlService().getSession(getName(), monitor
);
287 if (newInfo
!= null) {
288 ISessionInfo oldSessionInfo
= fSessionInfo
;
289 fSessionInfo
= newInfo
;
290 copyLiveInfo(oldSessionInfo
);
292 IDomainInfo
[] domains
= fSessionInfo
.getDomains();
293 for (int i
= 0; i
< domains
.length
; i
++) {
294 TraceDomainComponent domainComponent
= new TraceDomainComponent(
295 domains
[i
].getName(), this);
296 addChild(domainComponent
);
297 domainComponent
.setDomainInfo(domains
[i
]);
303 * Starts the session.
306 * - a progress monitor
307 * @throws ExecutionException
308 * If the command fails
310 public void startSession(IProgressMonitor monitor
)
311 throws ExecutionException
{
312 getControlService().startSession(getName(), monitor
);
316 * Starts the session.
319 * - a progress monitor
320 * @throws ExecutionException
321 * If the command fails
323 public void stopSession(IProgressMonitor monitor
) throws ExecutionException
{
324 getControlService().stopSession(getName(), monitor
);
328 * Enables channels with given names which are part of this domain. If a
329 * given channel doesn't exists it creates a new channel with the given
330 * parameters (or default values if given parameter is null).
332 * @param channelNames
333 * - a list of channel names to enable on this domain
335 * - channel information to set for the channel (use null for
338 * - a flag for indicating kernel or UST.
340 * - a progress monitor
341 * @throws ExecutionException
342 * If the command fails
344 public void enableChannels(List
<String
> channelNames
, IChannelInfo info
,
345 boolean isKernel
, IProgressMonitor monitor
)
346 throws ExecutionException
{
347 getControlService().enableChannels(getName(), channelNames
, isKernel
,
352 * Enables a list of events with no additional parameters.
355 * - a list of event names to enabled.
357 * - a flag for indicating kernel or UST.
358 * @param filterExpression
359 * - a filter expression
361 * - a progress monitor
362 * @throws ExecutionException
363 * If the command fails
365 public void enableEvents(List
<String
> eventNames
, boolean isKernel
,
366 String filterExpression
, IProgressMonitor monitor
) throws ExecutionException
{
367 getControlService().enableEvents(getName(), null, eventNames
, isKernel
,
368 filterExpression
, monitor
);
372 * Enables all syscalls (for kernel domain)
375 * - a progress monitor
376 * @throws ExecutionException
377 * If the command fails
379 public void enableSyscalls(IProgressMonitor monitor
)
380 throws ExecutionException
{
381 getControlService().enableSyscalls(getName(), null, monitor
);
385 * Enables a dynamic probe (for kernel domain)
388 * - event name for probe
390 * - true for dynamic function entry/return probe else false
394 * - a progress monitor
395 * @throws ExecutionException
396 * If the command fails
398 public void enableProbe(String eventName
, boolean isFunction
, String probe
,
399 IProgressMonitor monitor
) throws ExecutionException
{
400 getControlService().enableProbe(getName(), null, eventName
, isFunction
,
405 * Enables events using log level.
409 * @param logLevelType
413 * @param filterExpression
414 * - a filter expression
416 * - a progress monitor
417 * @throws ExecutionException
418 * If the command fails
420 public void enableLogLevel(String eventName
, LogLevelType logLevelType
,
421 TraceLogLevel level
, String filterExpression
, IProgressMonitor monitor
)
422 throws ExecutionException
{
423 getControlService().enableLogLevel(getName(), null, eventName
,
424 logLevelType
, level
, null, monitor
);
428 * Gets all available contexts to be added to channels/events.
431 * The monitor that will indicate the progress
432 * @return the list of available contexts
433 * @throws ExecutionException
434 * If the command fails
436 public List
<String
> getContextList(IProgressMonitor monitor
)
437 throws ExecutionException
{
438 return getControlService().getContextList(monitor
);
442 * Records a snapshot.
445 * - a progress monitor
446 * @throws ExecutionException
447 * If the command fails
449 public void recordSnapshot(IProgressMonitor monitor
) throws ExecutionException
{
450 getControlService().recordSnapshot(getName(), monitor
);
454 * Save all or a given session.
457 * a session name to save or null for all
459 * a path to save session or null for default location
461 * flag whether to overwrite existing or not
464 * @throws ExecutionException
465 * If the command fails
467 public void saveSession(String session
, String outputPath
, boolean isForce
, IProgressMonitor monitor
) throws ExecutionException
{
468 getControlService().saveSession(session
, outputPath
, isForce
, monitor
);
472 * Returns if session is live.
473 * @return <code>true</code> if session if live else <code>false</code>
475 public boolean isLiveTrace() {
476 return fSessionInfo
.isLive();
482 * @return the live URL
484 public String
getLiveUrl() {
485 return fSessionInfo
.getLiveUrl();
491 * @return the live port
493 public Integer
getLivePort() {
494 return fSessionInfo
.getLivePort();