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