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
.ui
.views
.control
.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
.core
.runtime
.NullProgressMonitor
;
20 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.IChannelInfo
;
21 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.IDomainInfo
;
22 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.ISessionInfo
;
23 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.LogLevelType
;
24 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.TraceLogLevel
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.TraceSessionState
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.SessionInfo
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.Activator
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.messages
.Messages
;
29 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.ITraceControlComponent
;
30 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.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 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getImage()
104 public Image
getImage() {
106 return fDestroyedImage
;
109 if (fSessionInfo
.getSessionState() == TraceSessionState
.INACTIVE
) {
110 return super.getImage();
117 * @return the whether the session is destroyed or not.
119 public boolean isDestroyed() {
124 * Sets the session destroyed state to the given value.
125 * @param destroyed - value to set.
127 public void setDestroyed(boolean destroyed
) {
128 fIsDestroyed
= destroyed
;
132 * @return the session state state (active or inactive).
134 public TraceSessionState
getSessionState() {
135 return fSessionInfo
.getSessionState();
139 * Sets the session state to the given value.
140 * @param state - state to set.
142 public void setSessionState(TraceSessionState state
) {
143 fSessionInfo
.setSessionState(state
);
147 * Sets the event state to the value specified by the given name.
148 * @param stateName - state to set.
150 public void setSessionState(String stateName
) {
151 fSessionInfo
.setSessionState(stateName
);
155 * @return path string where session is located.
157 public String
getSessionPath() {
158 return fSessionInfo
.getSessionPath();
162 * Sets the path string (where session is located) to the given value.
163 * @param sessionPath - session path to set.
165 public void setSessionPath(String sessionPath
) {
166 fSessionInfo
.setSessionPath(sessionPath
);
170 * Returns if session is streamed over network
171 * @return <code>true</code> if streamed over network else <code>false</code>
173 public boolean isStreamedTrace() {
174 return fSessionInfo
.isStreamedTrace();
178 * Sets whether the trace is streamed or not
179 * @param isStreamedTrace <code>true</code> if streamed over network else <code>false</code>
181 public void setIsStreamedTrace(boolean isStreamedTrace
) {
182 fSessionInfo
.setStreamedTrace(isStreamedTrace
);
187 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getAdapter(java.lang.Class)
190 public Object
getAdapter(Class adapter
) {
191 if (adapter
== IPropertySource
.class) {
192 return new TraceSessionPropertySource(this);
198 * @return all available domains of this session.
200 public TraceDomainComponent
[] getDomains() {
201 List
<ITraceControlComponent
> sessions
= getChildren(TraceDomainComponent
.class);
202 return sessions
.toArray(new TraceDomainComponent
[sessions
.size()]);
206 * @return the parent target node
208 public TargetNodeComponent
getTargetNode() {
209 return ((TraceSessionGroup
)getParent()).getTargetNode();
213 * Returns whether the kernel provider is available or not
214 * @return <code>true</code> if kernel provide is available or <code>false</code>
216 public boolean hasKernelProvider() {
217 List
<ITraceControlComponent
> providerGroups
= getTargetNode().getChildren(TraceProviderGroup
.class);
218 return (!providerGroups
.isEmpty() ?
((TraceProviderGroup
) providerGroups
.get(0)).hasKernelProvider() : false);
222 * Returns if node supports filtering of events
223 * @return <code>true</code> if node supports filtering else <code>false</code>
225 public boolean isEventFilteringSupported() {
226 return ((TargetNodeComponent
)getParent().getParent()).isEventFilteringSupported();
229 // ------------------------------------------------------------------------
231 // ------------------------------------------------------------------------
234 * Retrieves the session configuration from the node.
236 * @throws ExecutionException
237 * If the command fails
239 public void getConfigurationFromNode() throws ExecutionException
{
240 getConfigurationFromNode(new NullProgressMonitor());
244 * Retrieves the session configuration from the node.
247 * - a progress monitor
248 * @throws ExecutionException
249 * If the command fails
251 public void getConfigurationFromNode(IProgressMonitor monitor
)
252 throws ExecutionException
{
254 fSessionInfo
= getControlService().getSession(getName(), monitor
);
255 IDomainInfo
[] domains
= fSessionInfo
.getDomains();
256 for (int i
= 0; i
< domains
.length
; i
++) {
257 TraceDomainComponent domainComponent
= new TraceDomainComponent(
258 domains
[i
].getName(), this);
259 addChild(domainComponent
);
260 domainComponent
.setDomainInfo(domains
[i
]);
265 * Starts the session.
267 * @throws ExecutionException
268 * If the command fails
270 public void startSession() throws ExecutionException
{
271 startSession(new NullProgressMonitor());
275 * Starts the session.
278 * - a progress monitor
279 * @throws ExecutionException
280 * If the command fails
282 public void startSession(IProgressMonitor monitor
)
283 throws ExecutionException
{
284 getControlService().startSession(getName(), monitor
);
288 * Starts the session.
290 * @throws ExecutionException
291 * If the command fails
293 public void stopSession() throws ExecutionException
{
294 startSession(new NullProgressMonitor());
298 * Starts the session.
301 * - a progress monitor
302 * @throws ExecutionException
303 * If the command fails
305 public void stopSession(IProgressMonitor monitor
) throws ExecutionException
{
306 getControlService().stopSession(getName(), monitor
);
310 * Enables channels with given names which are part of this domain. If a
311 * given channel doesn't exists it creates a new channel with the given
312 * parameters (or default values if given parameter is null).
314 * @param channelNames
315 * - a list of channel names to enable on this domain
317 * - channel information to set for the channel (use null for
320 * - a flag for indicating kernel or UST.
321 * @throws ExecutionException
322 * If the command fails
324 public void enableChannels(List
<String
> channelNames
, IChannelInfo info
,
325 boolean isKernel
) throws ExecutionException
{
326 enableChannels(channelNames
, info
, isKernel
, new NullProgressMonitor());
330 * Enables channels with given names which are part of this domain. If a
331 * given channel doesn't exists it creates a new channel with the given
332 * parameters (or default values if given parameter is null).
334 * @param channelNames
335 * - a list of channel names to enable on this domain
337 * - channel information to set for the channel (use null for
340 * - a flag for indicating kernel or UST.
342 * - a progress monitor
343 * @throws ExecutionException
344 * If the command fails
346 public void enableChannels(List
<String
> channelNames
, IChannelInfo info
,
347 boolean isKernel
, IProgressMonitor monitor
)
348 throws ExecutionException
{
349 getControlService().enableChannels(getName(), channelNames
, isKernel
,
354 * Enables a list of events with no additional parameters.
357 * - a list of event names to enabled.
359 * - a flag for indicating kernel or UST.
360 * @param filterExpression
361 * - a filter expression
362 * @throws ExecutionException
363 * If the command fails
365 public void enableEvent(List
<String
> eventNames
, boolean isKernel
, String filterExpression
)
366 throws ExecutionException
{
367 enableEvents(eventNames
, isKernel
, filterExpression
, new NullProgressMonitor());
371 * Enables a list of events with no additional parameters.
374 * - a list of event names to enabled.
376 * - a flag for indicating kernel or UST.
377 * @param filterExpression
378 * - a filter expression
380 * - a progress monitor
381 * @throws ExecutionException
382 * If the command fails
384 public void enableEvents(List
<String
> eventNames
, boolean isKernel
,
385 String filterExpression
, IProgressMonitor monitor
) throws ExecutionException
{
386 getControlService().enableEvents(getName(), null, eventNames
, isKernel
,
387 filterExpression
, monitor
);
391 * Enables all syscalls (for kernel domain)
393 * @throws ExecutionException
394 * If the command fails
396 public void enableSyscalls() throws ExecutionException
{
397 enableSyscalls(new NullProgressMonitor());
401 * Enables all syscalls (for kernel domain)
404 * - a progress monitor
405 * @throws ExecutionException
406 * If the command fails
408 public void enableSyscalls(IProgressMonitor monitor
)
409 throws ExecutionException
{
410 getControlService().enableSyscalls(getName(), null, monitor
);
414 * Enables a dynamic probe (for kernel domain)
417 * - event name for probe
419 * - true for dynamic function entry/return probe else false
422 * @throws ExecutionException
423 * If the command fails
425 public void enableProbe(String eventName
, boolean isFunction
, String probe
)
426 throws ExecutionException
{
427 enableProbe(eventName
, isFunction
, probe
, new NullProgressMonitor());
431 * Enables a dynamic probe (for kernel domain)
434 * - event name for probe
436 * - true for dynamic function entry/return probe else false
440 * - a progress monitor
441 * @throws ExecutionException
442 * If the command fails
444 public void enableProbe(String eventName
, boolean isFunction
, String probe
,
445 IProgressMonitor monitor
) throws ExecutionException
{
446 getControlService().enableProbe(getName(), null, eventName
, isFunction
,
451 * Enables events using log level.
455 * @param logLevelType
459 * @param filterExpression
460 * - a filter expression
461 * @throws ExecutionException
462 * If the command fails
464 public void enableLogLevel(String eventName
, LogLevelType logLevelType
,
465 TraceLogLevel level
, String filterExpression
) throws ExecutionException
{
466 enableLogLevel(eventName
, logLevelType
, level
, filterExpression
,
467 new NullProgressMonitor());
471 * Enables events using log level.
475 * @param logLevelType
479 * @param filterExpression
480 * - a filter expression
482 * - a progress monitor
483 * @throws ExecutionException
484 * If the command fails
486 public void enableLogLevel(String eventName
, LogLevelType logLevelType
,
487 TraceLogLevel level
, String filterExpression
, IProgressMonitor monitor
)
488 throws ExecutionException
{
489 getControlService().enableLogLevel(getName(), null, eventName
,
490 logLevelType
, level
, null, monitor
);
494 * Gets all available contexts to be added to channels/events.
496 * @return the list of available contexts
497 * @throws ExecutionException
498 * If the command fails
500 public List
<String
> getContextList() throws ExecutionException
{
501 return getContextList(new NullProgressMonitor());
505 * Gets all available contexts to be added to channels/events.
508 * The monitor that will indicate the progress
509 * @return the list of available contexts
510 * @throws ExecutionException
511 * If the command fails
513 public List
<String
> getContextList(IProgressMonitor monitor
)
514 throws ExecutionException
{
515 return getControlService().getContextList(monitor
);