32de99024f45ef65d8a0c4f7a6aff3cb6a2cb027
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.control.ui / src / org / eclipse / tracecompass / internal / lttng2 / control / ui / views / model / impl / TraceSessionComponent.java
1 /**********************************************************************
2 * Copyright (c) 2012, 2014 Ericsson
3 *
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
8 *
9 * Contributors:
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;
15
16 import java.util.List;
17
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;
34
35 /**
36 * <p>
37 * Implementation of the trace session component.
38 * </p>
39 *
40 * @author Bernd Hufmann
41 */
42 public class TraceSessionComponent extends TraceControlComponent {
43
44 // ------------------------------------------------------------------------
45 // Constants
46 // ------------------------------------------------------------------------
47 /**
48 * Path to icon file for this component (inactive state).
49 */
50 public static final String TRACE_SESSION_ICON_FILE_INACTIVE = "icons/obj16/session_inactive.gif"; //$NON-NLS-1$
51 /**
52 * Path to icon file for this component (active state).
53 */
54 public static final String TRACE_SESSION_ICON_FILE_ACTIVE = "icons/obj16/session_active.gif"; //$NON-NLS-1$
55 /**
56 * Path to icon file for this component (destroyed state).
57 */
58 public static final String TRACE_SESSION_ICON_FILE_DESTROYED = "icons/obj16/session_destroyed.gif"; //$NON-NLS-1$
59
60 // ------------------------------------------------------------------------
61 // Attributes
62 // ------------------------------------------------------------------------
63 /**
64 * The session information.
65 */
66 private ISessionInfo fSessionInfo = null;
67 /**
68 * A flag to indicate if session has been destroyed.
69 */
70 private boolean fIsDestroyed = false;
71 /**
72 * The image to be displayed in state active.
73 */
74 private Image fActiveImage = null;
75 /**
76 * The image to be displayed in state destroyed
77 */
78 private Image fDestroyedImage = null;
79
80 // ------------------------------------------------------------------------
81 // Constructors
82 // ------------------------------------------------------------------------
83 /**
84 * Constructor
85 * @param name - the name of the component.
86 * @param parent - the parent of this component.
87 */
88 public TraceSessionComponent(String name, ITraceControlComponent parent) {
89 super(name, 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);
95 }
96
97 /**
98 * Constructor
99 *
100 * @param sessionInfo
101 * the session information used to create the session
102 * @param parent
103 * the parent of this component.
104 */
105 public TraceSessionComponent(ISessionInfo sessionInfo, ITraceControlComponent parent) {
106 this(sessionInfo.getName(), parent);
107 copyLiveInfo(sessionInfo);
108 }
109
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());
114 }
115 if (sessionInfo.getLiveUrl() != null) {
116 fSessionInfo.setLiveUrl(sessionInfo.getLiveUrl());
117 }
118 }
119
120 // ------------------------------------------------------------------------
121 // Accessors
122 // ------------------------------------------------------------------------
123
124 @Override
125 public Image getImage() {
126 if (fIsDestroyed) {
127 return fDestroyedImage;
128 }
129
130 if (fSessionInfo.getSessionState() == TraceSessionState.INACTIVE) {
131 return super.getImage();
132 }
133
134 return fActiveImage;
135 }
136
137 /**
138 * @return the whether the session is destroyed or not.
139 */
140 public boolean isDestroyed() {
141 return fIsDestroyed;
142 }
143
144 /**
145 * Sets the session destroyed state to the given value.
146 * @param destroyed - value to set.
147 */
148 public void setDestroyed(boolean destroyed) {
149 fIsDestroyed = destroyed;
150 }
151
152 /**
153 * @return the session state state (active or inactive).
154 */
155 public TraceSessionState getSessionState() {
156 return fSessionInfo.getSessionState();
157 }
158
159 /**
160 * Sets the session state to the given value.
161 * @param state - state to set.
162 */
163 public void setSessionState(TraceSessionState state) {
164 fSessionInfo.setSessionState(state);
165 }
166
167 /**
168 * Sets the event state to the value specified by the given name.
169 * @param stateName - state to set.
170 */
171 public void setSessionState(String stateName) {
172 fSessionInfo.setSessionState(stateName);
173 }
174
175 /**
176 * @return path string where session is located.
177 */
178 public String getSessionPath() {
179 return fSessionInfo.getSessionPath();
180 }
181
182 /**
183 * Sets the path string (where session is located) to the given value.
184 * @param sessionPath - session path to set.
185 */
186 public void setSessionPath(String sessionPath) {
187 fSessionInfo.setSessionPath(sessionPath);
188 }
189
190 /**
191 * Returns if session is streamed over network
192 * @return <code>true</code> if streamed over network else <code>false</code>
193 */
194 public boolean isStreamedTrace() {
195 return fSessionInfo.isStreamedTrace();
196 }
197
198 /**
199 * Sets whether the trace is streamed or not
200 * @param isStreamedTrace <code>true</code> if streamed over network else <code>false</code>
201 */
202 public void setIsStreamedTrace(boolean isStreamedTrace) {
203 fSessionInfo.setStreamedTrace(isStreamedTrace);
204 }
205
206 /**
207 * Returns whether the session is snapshot session or not
208 * @return <code>true</code> if it is snapshot session else <code>false</code>
209 */
210 public boolean isSnapshotSession() {
211 return fSessionInfo.isSnapshotSession();
212 }
213
214 /**
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
217 */
218 public ISnapshotInfo getSnapshotInfo() {
219 return fSessionInfo.getSnapshotInfo();
220 }
221
222 @Override
223 public <T> T getAdapter(Class<T> adapter) {
224 if (adapter == IPropertySource.class) {
225 return adapter.cast(new TraceSessionPropertySource(this));
226 }
227 return null;
228 }
229
230 /**
231 * @return all available domains of this session.
232 */
233 public TraceDomainComponent[] getDomains() {
234 List<ITraceControlComponent> sessions = getChildren(TraceDomainComponent.class);
235 return sessions.toArray(new TraceDomainComponent[sessions.size()]);
236 }
237
238 /**
239 * @return the parent target node
240 */
241 public TargetNodeComponent getTargetNode() {
242 return ((TraceSessionGroup)getParent()).getTargetNode();
243 }
244
245 /**
246 * Returns whether the kernel provider is available or not
247 * @return <code>true</code> if kernel provide is available or <code>false</code>
248 */
249 public boolean hasKernelProvider() {
250 List<ITraceControlComponent> providerGroups = getTargetNode().getChildren(TraceProviderGroup.class);
251 return (!providerGroups.isEmpty() ? ((TraceProviderGroup) providerGroups.get(0)).hasKernelProvider() : false);
252 }
253
254 /**
255 * Returns if node supports filtering of events
256 * @param isKernel - <code>true</code> for kernel provider else <code>false</code>
257 * @return <code>true</code> if node supports filtering else <code>false</code>
258 */
259 public boolean isEventFilteringSupported(boolean isKernel) {
260 return ((TargetNodeComponent)getParent().getParent()).isEventFilteringSupported(isKernel);
261 }
262
263 /**
264 * Returns if node supports snapshots or not
265 * @return <code>true</code> if it supports snapshots else <code>false</code>
266 *
267 */
268 public boolean isSnapshotSupported() {
269 return ((TargetNodeComponent)getParent().getParent()).isSnapshotSupported();
270 }
271
272 // ------------------------------------------------------------------------
273 // Operations
274 // ------------------------------------------------------------------------
275
276 /**
277 * Retrieves the session configuration from the node.
278 *
279 * @param monitor
280 * - a progress monitor
281 * @throws ExecutionException
282 * If the command fails
283 */
284 public void getConfigurationFromNode(IProgressMonitor monitor)
285 throws ExecutionException {
286 removeAllChildren();
287 ISessionInfo newInfo = getControlService().getSession(getName(), monitor);
288 if (newInfo != null) {
289 ISessionInfo oldSessionInfo = fSessionInfo;
290 fSessionInfo = newInfo;
291 copyLiveInfo(oldSessionInfo);
292
293 IDomainInfo[] domains = fSessionInfo.getDomains();
294 for (int i = 0; i < domains.length; i++) {
295 TraceDomainComponent domainComponent = new TraceDomainComponent(
296 domains[i].getName(), this);
297 addChild(domainComponent);
298 domainComponent.setDomainInfo(domains[i]);
299 }
300 }
301 }
302
303 /**
304 * Starts the session.
305 *
306 * @param monitor
307 * - a progress monitor
308 * @throws ExecutionException
309 * If the command fails
310 */
311 public void startSession(IProgressMonitor monitor)
312 throws ExecutionException {
313 getControlService().startSession(getName(), monitor);
314 }
315
316 /**
317 * Starts the session.
318 *
319 * @param monitor
320 * - a progress monitor
321 * @throws ExecutionException
322 * If the command fails
323 */
324 public void stopSession(IProgressMonitor monitor) throws ExecutionException {
325 getControlService().stopSession(getName(), monitor);
326 }
327
328 /**
329 * Enables channels with given names which are part of this domain. If a
330 * given channel doesn't exists it creates a new channel with the given
331 * parameters (or default values if given parameter is null).
332 *
333 * @param channelNames
334 * - a list of channel names to enable on this domain
335 * @param info
336 * - channel information to set for the channel (use null for
337 * default)
338 * @param isKernel
339 * - a flag for indicating kernel or UST.
340 * @param monitor
341 * - a progress monitor
342 * @throws ExecutionException
343 * If the command fails
344 */
345 public void enableChannels(List<String> channelNames, IChannelInfo info,
346 boolean isKernel, IProgressMonitor monitor)
347 throws ExecutionException {
348 getControlService().enableChannels(getName(), channelNames, isKernel,
349 info, monitor);
350 }
351
352 /**
353 * Enables a list of events with no additional parameters.
354 *
355 * @param eventNames
356 * - a list of event names to enabled.
357 * @param isKernel
358 * - a flag for indicating kernel or UST.
359 * @param filterExpression
360 * - a filter expression
361 * @param monitor
362 * - a progress monitor
363 * @throws ExecutionException
364 * If the command fails
365 */
366 public void enableEvents(List<String> eventNames, boolean isKernel,
367 String filterExpression, IProgressMonitor monitor) throws ExecutionException {
368 getControlService().enableEvents(getName(), null, eventNames, isKernel,
369 filterExpression, monitor);
370 }
371
372 /**
373 * Enables all syscalls (for kernel domain)
374 *
375 * @param monitor
376 * - a progress monitor
377 * @throws ExecutionException
378 * If the command fails
379 */
380 public void enableSyscalls(IProgressMonitor monitor)
381 throws ExecutionException {
382 getControlService().enableSyscalls(getName(), null, monitor);
383 }
384
385 /**
386 * Enables a dynamic probe (for kernel domain)
387 *
388 * @param eventName
389 * - event name for probe
390 * @param isFunction
391 * - true for dynamic function entry/return probe else false
392 * @param probe
393 * - the actual probe
394 * @param monitor
395 * - a progress monitor
396 * @throws ExecutionException
397 * If the command fails
398 */
399 public void enableProbe(String eventName, boolean isFunction, String probe,
400 IProgressMonitor monitor) throws ExecutionException {
401 getControlService().enableProbe(getName(), null, eventName, isFunction,
402 probe, monitor);
403 }
404
405 /**
406 * Enables events using log level.
407 *
408 * @param eventName
409 * - a event name
410 * @param logLevelType
411 * - a log level type
412 * @param level
413 * - a log level
414 * @param filterExpression
415 * - a filter expression
416 * @param monitor
417 * - a progress monitor
418 * @throws ExecutionException
419 * If the command fails
420 */
421 public void enableLogLevel(String eventName, LogLevelType logLevelType,
422 TraceLogLevel level, String filterExpression, IProgressMonitor monitor)
423 throws ExecutionException {
424 getControlService().enableLogLevel(getName(), null, eventName,
425 logLevelType, level, null, monitor);
426 }
427
428 /**
429 * Gets all available contexts to be added to channels/events.
430 *
431 * @param monitor
432 * The monitor that will indicate the progress
433 * @return the list of available contexts
434 * @throws ExecutionException
435 * If the command fails
436 */
437 public List<String> getContextList(IProgressMonitor monitor)
438 throws ExecutionException {
439 return getControlService().getContextList(monitor);
440 }
441
442 /**
443 * Records a snapshot.
444 *
445 * @param monitor
446 * - a progress monitor
447 * @throws ExecutionException
448 * If the command fails
449 */
450 public void recordSnapshot(IProgressMonitor monitor) throws ExecutionException {
451 getControlService().recordSnapshot(getName(), monitor);
452 }
453
454 /**
455 * Save all or a given session.
456 *
457 * @param session
458 * a session name to save or null for all
459 * @param outputPath
460 * a path to save session or null for default location
461 * @param isForce
462 * flag whether to overwrite existing or not
463 * @param monitor
464 * a progress monitor
465 * @throws ExecutionException
466 * If the command fails
467 */
468 public void saveSession(String session, String outputPath, boolean isForce, IProgressMonitor monitor) throws ExecutionException {
469 getControlService().saveSession(session, outputPath, isForce, monitor);
470 }
471
472 /**
473 * Returns if session is live.
474 * @return <code>true</code> if session if live else <code>false</code>
475 */
476 public boolean isLiveTrace() {
477 return fSessionInfo.isLive();
478 }
479
480 /**
481 * Get the live URL.
482 *
483 * @return the live URL
484 */
485 public String getLiveUrl() {
486 return fSessionInfo.getLiveUrl();
487 }
488
489 /**
490 * Get the live port.
491 *
492 * @return the live port
493 */
494 public Integer getLivePort() {
495 return fSessionInfo.getLivePort();
496 }
497 }
This page took 0.044934 seconds and 5 git commands to generate.