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
.ITraceLogLevel
;
26 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.LogLevelType
;
27 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TraceDomainType
;
28 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TraceSessionState
;
29 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.SessionInfo
;
30 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.Activator
;
31 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.messages
.Messages
;
32 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.ITraceControlComponent
;
33 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.property
.TraceSessionPropertySource
;
34 import org
.eclipse
.ui
.views
.properties
.IPropertySource
;
38 * Implementation of the trace session component.
41 * @author Bernd Hufmann
43 public class TraceSessionComponent
extends TraceControlComponent
{
45 // ------------------------------------------------------------------------
47 // ------------------------------------------------------------------------
49 * Path to icon file for this component (inactive state).
51 public static final String TRACE_SESSION_ICON_FILE_INACTIVE
= "icons/obj16/session_inactive.gif"; //$NON-NLS-1$
53 * Path to icon file for this component (active state).
55 public static final String TRACE_SESSION_ICON_FILE_ACTIVE
= "icons/obj16/session_active.gif"; //$NON-NLS-1$
57 * Path to icon file for this component (destroyed state).
59 public static final String TRACE_SESSION_ICON_FILE_DESTROYED
= "icons/obj16/session_destroyed.gif"; //$NON-NLS-1$
61 // ------------------------------------------------------------------------
63 // ------------------------------------------------------------------------
65 * The session information.
67 private ISessionInfo fSessionInfo
= null;
69 * A flag to indicate if session has been destroyed.
71 private boolean fIsDestroyed
= false;
73 * The image to be displayed in state active.
75 private Image fActiveImage
= null;
77 * The image to be displayed in state destroyed
79 private Image fDestroyedImage
= null;
81 // ------------------------------------------------------------------------
83 // ------------------------------------------------------------------------
86 * @param name - the name of the component.
87 * @param parent - the parent of this component.
89 public TraceSessionComponent(String name
, ITraceControlComponent parent
) {
91 setImage(TRACE_SESSION_ICON_FILE_INACTIVE
);
92 setToolTip(Messages
.TraceControl_SessionDisplayName
);
93 fSessionInfo
= new SessionInfo(name
);
94 fActiveImage
= Activator
.getDefault().loadIcon(TRACE_SESSION_ICON_FILE_ACTIVE
);
95 fDestroyedImage
= Activator
.getDefault().loadIcon(TRACE_SESSION_ICON_FILE_DESTROYED
);
102 * the session information used to create the session
104 * the parent of this component.
106 public TraceSessionComponent(ISessionInfo sessionInfo
, ITraceControlComponent parent
) {
107 this(sessionInfo
.getName(), parent
);
108 copyLiveInfo(sessionInfo
);
111 private void copyLiveInfo(ISessionInfo sessionInfo
) {
113 * Since we can't retrieve this live port and URL from the node, we
114 * copy it over. Note that this information gets lost when the user
115 * presses the refresh button or restarts or Trace Compass.
117 if (sessionInfo
.getLivePort() != null) {
118 fSessionInfo
.setLivePort(sessionInfo
.getLivePort());
120 if (sessionInfo
.getLiveUrl() != null) {
121 fSessionInfo
.setLiveUrl(sessionInfo
.getLiveUrl());
125 * Live streaming has been added in 2.4.x. Since we can't retrieve
126 * whether a session is live or not from a 2.4.x node, we copy it over.
127 * Note that this information gets lost when the user presses the
128 * refresh button or restarts or Trace Compass.
130 * For LTTng 2.5.0 and later it's possible to retrieve this information.
131 * So we don't need to copy this over be set here. This will make sure
132 * that the session is recognized as live after a Trace Compass restart
135 if (!getTargetNode().isVersionSupported("2.5.0")) { //$NON-NLS-1$
136 fSessionInfo
.setLive(sessionInfo
.isLive());
140 // ------------------------------------------------------------------------
142 // ------------------------------------------------------------------------
145 public Image
getImage() {
147 return fDestroyedImage
;
150 if (fSessionInfo
.getSessionState() == TraceSessionState
.INACTIVE
) {
151 return super.getImage();
158 * @return the whether the session is destroyed or not.
160 public boolean isDestroyed() {
165 * Sets the session destroyed state to the given value.
166 * @param destroyed - value to set.
168 public void setDestroyed(boolean destroyed
) {
169 fIsDestroyed
= destroyed
;
173 * @return the session state state (active or inactive).
175 public TraceSessionState
getSessionState() {
176 return fSessionInfo
.getSessionState();
180 * Sets the session state to the given value.
181 * @param state - state to set.
183 public void setSessionState(TraceSessionState state
) {
184 fSessionInfo
.setSessionState(state
);
188 * Sets the event state to the value specified by the given name.
189 * @param stateName - state to set.
191 public void setSessionState(String stateName
) {
192 fSessionInfo
.setSessionState(stateName
);
196 * @return path string where session is located.
198 public String
getSessionPath() {
199 return fSessionInfo
.getSessionPath();
203 * Sets the path string (where session is located) to the given value.
204 * @param sessionPath - session path to set.
206 public void setSessionPath(String sessionPath
) {
207 fSessionInfo
.setSessionPath(sessionPath
);
211 * Returns if session is streamed over network
212 * @return <code>true</code> if streamed over network else <code>false</code>
214 public boolean isStreamedTrace() {
215 return fSessionInfo
.isStreamedTrace();
219 * Sets whether the trace is streamed or not
220 * @param isStreamedTrace <code>true</code> if streamed over network else <code>false</code>
222 public void setIsStreamedTrace(boolean isStreamedTrace
) {
223 fSessionInfo
.setStreamedTrace(isStreamedTrace
);
227 * Returns whether the session is snapshot session or not
228 * @return <code>true</code> if it is snapshot session else <code>false</code>
230 public boolean isSnapshotSession() {
231 return fSessionInfo
.isSnapshotSession();
235 * Gets the snapshot information if available whether the session is a snapshot session or not
236 * @return the snapshot information or null if it is not a snapshot session
238 public ISnapshotInfo
getSnapshotInfo() {
239 return fSessionInfo
.getSnapshotInfo();
243 public <T
> T
getAdapter(Class
<T
> adapter
) {
244 if (adapter
== IPropertySource
.class) {
245 return adapter
.cast(new TraceSessionPropertySource(this));
251 * @return all available domains of this session.
253 public TraceDomainComponent
[] getDomains() {
254 List
<ITraceControlComponent
> sessions
= getChildren(TraceDomainComponent
.class);
255 return sessions
.toArray(new TraceDomainComponent
[sessions
.size()]);
259 * @return the parent target node
261 public TargetNodeComponent
getTargetNode() {
262 return ((TraceSessionGroup
)getParent()).getTargetNode();
266 * Returns whether the kernel provider is available or not
267 * @return <code>true</code> if kernel provide is available or <code>false</code>
269 public boolean hasKernelProvider() {
270 List
<ITraceControlComponent
> providerGroups
= getTargetNode().getChildren(TraceProviderGroup
.class);
271 return (!providerGroups
.isEmpty() ?
((TraceProviderGroup
) providerGroups
.get(0)).hasKernelProvider() : false);
275 * Returns if node supports filtering of events
276 * @param domain - the domain type ({@link TraceDomainType})
277 * @return <code>true</code> if node supports filtering else <code>false</code>
279 public boolean isEventFilteringSupported(TraceDomainType domain
) {
280 return ((TargetNodeComponent
)getParent().getParent()).isEventFilteringSupported(domain
);
284 * Returns if node supports snapshots or not
285 * @return <code>true</code> if it supports snapshots else <code>false</code>
288 public boolean isSnapshotSupported() {
289 return ((TargetNodeComponent
)getParent().getParent()).isSnapshotSupported();
292 // ------------------------------------------------------------------------
294 // ------------------------------------------------------------------------
297 * Retrieves the session configuration from the node.
300 * - a progress monitor
301 * @throws ExecutionException
302 * If the command fails
304 public void getConfigurationFromNode(IProgressMonitor monitor
)
305 throws ExecutionException
{
307 ISessionInfo newInfo
= getControlService().getSession(getName(), monitor
);
308 if (newInfo
!= null) {
309 ISessionInfo oldSessionInfo
= fSessionInfo
;
310 fSessionInfo
= newInfo
;
311 copyLiveInfo(oldSessionInfo
);
313 IDomainInfo
[] domains
= fSessionInfo
.getDomains();
314 for (int i
= 0; i
< domains
.length
; i
++) {
315 TraceDomainComponent domainComponent
= new TraceDomainComponent(domains
[i
].getName(), this);
316 addChild(domainComponent
);
317 domainComponent
.setDomainInfo(domains
[i
]);
323 * Starts the session.
326 * - a progress monitor
327 * @throws ExecutionException
328 * If the command fails
330 public void startSession(IProgressMonitor monitor
)
331 throws ExecutionException
{
332 getControlService().startSession(getName(), monitor
);
336 * Starts the session.
339 * - a progress monitor
340 * @throws ExecutionException
341 * If the command fails
343 public void stopSession(IProgressMonitor monitor
) throws ExecutionException
{
344 getControlService().stopSession(getName(), monitor
);
348 * Enables channels with given names which are part of this domain. If a
349 * given channel doesn't exists it creates a new channel with the given
350 * parameters (or default values if given parameter is null).
352 * @param channelNames
353 * - a list of channel names to enable on this domain
355 * - channel information to set for the channel (use null for
358 * - indicate the domain type ({@link TraceDomainType})
360 * - a progress monitor
361 * @throws ExecutionException
362 * If the command fails
364 public void enableChannels(List
<String
> channelNames
, IChannelInfo info
,
365 TraceDomainType domain
, IProgressMonitor monitor
)
366 throws ExecutionException
{
367 getControlService().enableChannels(getName(), channelNames
, domain
,
372 * Enables a list of events with no additional parameters.
375 * - a list of event names to enabled.
377 * - the type of the domain type ({@link TraceDomainType})
378 * @param filterExpression
379 * - a filter expression
380 * @param excludedEvents
381 * - a list of events to exclude.
383 * - a progress monitor
384 * @throws ExecutionException
385 * If the command fails
387 public void enableEvents(List
<String
> eventNames
, TraceDomainType domain
,
388 String filterExpression
, List
<String
> excludedEvents
, IProgressMonitor monitor
) throws ExecutionException
{
389 getControlService().enableEvents(getName(), null, eventNames
, domain
,
390 filterExpression
, excludedEvents
, monitor
);
394 * Enables all syscalls (for kernel domain)
396 * @param syscallNames
397 * - a list of syscall names to be enabled
399 * - a progress monitor
400 * @throws ExecutionException
401 * If the command fails
403 public void enableSyscalls(List
<String
> syscallNames
, IProgressMonitor monitor
)
404 throws ExecutionException
{
405 getControlService().enableSyscalls(getName(), null, syscallNames
, monitor
);
409 * Enables a dynamic probe (for kernel domain)
412 * - event name for probe
414 * - true for dynamic function entry/return probe else false
418 * - a progress monitor
419 * @throws ExecutionException
420 * If the command fails
422 public void enableProbe(String eventName
, boolean isFunction
, String probe
,
423 IProgressMonitor monitor
) throws ExecutionException
{
424 getControlService().enableProbe(getName(), null, eventName
, isFunction
,
429 * Enables events using log level.
432 * - a list of event names
433 * @param logLevelType
437 * @param filterExpression
438 * - a filter expression
440 * - the domain type ({@link TraceDomainType})
442 * - a progress monitor
443 * @throws ExecutionException
444 * If the command fails
446 public void enableLogLevel(List
<String
> eventNames
, LogLevelType logLevelType
,
447 ITraceLogLevel level
, String filterExpression
,
448 TraceDomainType domain
, IProgressMonitor monitor
)
449 throws ExecutionException
{
450 getControlService().enableLogLevel(getName(), null, eventNames
,
451 logLevelType
, level
, null, domain
, monitor
);
455 * Gets all available contexts to be added to channels/events.
458 * The monitor that will indicate the progress
459 * @return the list of available contexts
460 * @throws ExecutionException
461 * If the command fails
463 public List
<String
> getContextList(IProgressMonitor monitor
)
464 throws ExecutionException
{
465 return getControlService().getContextList(monitor
);
469 * Records a snapshot.
472 * - a progress monitor
473 * @throws ExecutionException
474 * If the command fails
476 public void recordSnapshot(IProgressMonitor monitor
) throws ExecutionException
{
477 getControlService().recordSnapshot(getName(), monitor
);
481 * Save all or a given session.
484 * a session name to save or null for all
486 * a path to save session or null for default location
488 * flag whether to overwrite existing or not
491 * @throws ExecutionException
492 * If the command fails
494 public void saveSession(String session
, String outputPath
, boolean isForce
, IProgressMonitor monitor
) throws ExecutionException
{
495 getControlService().saveSession(session
, outputPath
, isForce
, monitor
);
499 * Returns if session is live.
500 * @return <code>true</code> if session if live else <code>false</code>
502 public boolean isLiveTrace() {
503 return fSessionInfo
.isLive();
509 * @return the live URL
511 public String
getLiveUrl() {
512 return fSessionInfo
.getLiveUrl();
518 * @return the live port
520 public Integer
getLivePort() {
521 return fSessionInfo
.getLivePort();