Commit | Line | Data |
---|---|---|
eb1bab5b | 1 | /********************************************************************** |
6fd3c6e9 | 2 | * Copyright (c) 2012, 2014 Ericsson |
cfdb727a | 3 | * |
eb1bab5b BH |
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 | |
cfdb727a AM |
8 | * |
9 | * Contributors: | |
eb1bab5b | 10 | * Bernd Hufmann - Initial API and implementation |
ba3a9bd2 | 11 | * Bernd Hufmann - Updated for support of LTTng Tools 2.1 |
6fd3c6e9 | 12 | * Marc-Andre Laperle - Support for opening a live session |
eb1bab5b | 13 | **********************************************************************/ |
8e8c0226 | 14 | package org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl; |
eb1bab5b | 15 | |
6503ae0f BH |
16 | import java.util.List; |
17 | ||
eb1bab5b BH |
18 | import org.eclipse.core.commands.ExecutionException; |
19 | import org.eclipse.core.runtime.IProgressMonitor; | |
8e8c0226 AM |
20 | import org.eclipse.linuxtools.internal.lttng2.control.core.model.IChannelInfo; |
21 | import org.eclipse.linuxtools.internal.lttng2.control.core.model.IDomainInfo; | |
22 | import org.eclipse.linuxtools.internal.lttng2.control.core.model.ISessionInfo; | |
23 | import org.eclipse.linuxtools.internal.lttng2.control.core.model.ISnapshotInfo; | |
24 | import org.eclipse.linuxtools.internal.lttng2.control.core.model.LogLevelType; | |
25 | import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceLogLevel; | |
26 | import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceSessionState; | |
27 | import org.eclipse.linuxtools.internal.lttng2.control.core.model.impl.SessionInfo; | |
28 | import org.eclipse.linuxtools.internal.lttng2.control.ui.Activator; | |
29 | import org.eclipse.linuxtools.internal.lttng2.control.ui.views.messages.Messages; | |
30 | import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.ITraceControlComponent; | |
31 | import org.eclipse.linuxtools.internal.lttng2.control.ui.views.property.TraceSessionPropertySource; | |
eb1bab5b | 32 | import org.eclipse.swt.graphics.Image; |
06b9339e | 33 | import org.eclipse.ui.views.properties.IPropertySource; |
eb1bab5b BH |
34 | |
35 | /** | |
eb1bab5b BH |
36 | * <p> |
37 | * Implementation of the trace session component. | |
38 | * </p> | |
cfdb727a | 39 | * |
dbd4432d | 40 | * @author Bernd Hufmann |
eb1bab5b BH |
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 | /** | |
cfdb727a | 84 | * Constructor |
eb1bab5b BH |
85 | * @param name - the name of the component. |
86 | * @param parent - the parent of this component. | |
cfdb727a | 87 | */ |
eb1bab5b BH |
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); | |
31a6a4e4 BH |
93 | fActiveImage = Activator.getDefault().loadIcon(TRACE_SESSION_ICON_FILE_ACTIVE); |
94 | fDestroyedImage = Activator.getDefault().loadIcon(TRACE_SESSION_ICON_FILE_DESTROYED); | |
eb1bab5b BH |
95 | } |
96 | ||
6fd3c6e9 MAL |
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 | fSessionInfo.setLive(sessionInfo.isLive()); | |
113 | fSessionInfo.setLiveDelay(sessionInfo.getLiveDelay()); | |
114 | fSessionInfo.setLivePort(sessionInfo.getLivePort()); | |
115 | fSessionInfo.setLiveUrl(sessionInfo.getLiveUrl()); | |
116 | } | |
117 | ||
eb1bab5b BH |
118 | // ------------------------------------------------------------------------ |
119 | // Accessors | |
120 | // ------------------------------------------------------------------------ | |
11252342 | 121 | |
eb1bab5b BH |
122 | @Override |
123 | public Image getImage() { | |
124 | if (fIsDestroyed) { | |
125 | return fDestroyedImage; | |
126 | } | |
127 | ||
128 | if (fSessionInfo.getSessionState() == TraceSessionState.INACTIVE) { | |
129 | return super.getImage(); | |
130 | } | |
cfdb727a | 131 | |
eb1bab5b BH |
132 | return fActiveImage; |
133 | } | |
134 | ||
eb1bab5b BH |
135 | /** |
136 | * @return the whether the session is destroyed or not. | |
137 | */ | |
138 | public boolean isDestroyed() { | |
139 | return fIsDestroyed; | |
140 | } | |
bbb3538a | 141 | |
eb1bab5b BH |
142 | /** |
143 | * Sets the session destroyed state to the given value. | |
144 | * @param destroyed - value to set. | |
145 | */ | |
146 | public void setDestroyed(boolean destroyed) { | |
147 | fIsDestroyed = destroyed; | |
148 | } | |
bbb3538a | 149 | |
eb1bab5b BH |
150 | /** |
151 | * @return the session state state (active or inactive). | |
152 | */ | |
153 | public TraceSessionState getSessionState() { | |
154 | return fSessionInfo.getSessionState(); | |
155 | } | |
156 | ||
157 | /** | |
158 | * Sets the session state to the given value. | |
159 | * @param state - state to set. | |
160 | */ | |
161 | public void setSessionState(TraceSessionState state) { | |
162 | fSessionInfo.setSessionState(state); | |
163 | } | |
bbb3538a | 164 | |
eb1bab5b BH |
165 | /** |
166 | * Sets the event state to the value specified by the given name. | |
167 | * @param stateName - state to set. | |
168 | */ | |
169 | public void setSessionState(String stateName) { | |
170 | fSessionInfo.setSessionState(stateName); | |
171 | } | |
172 | ||
173 | /** | |
174 | * @return path string where session is located. | |
175 | */ | |
176 | public String getSessionPath() { | |
177 | return fSessionInfo.getSessionPath(); | |
178 | } | |
179 | ||
180 | /** | |
181 | * Sets the path string (where session is located) to the given value. | |
cfdb727a | 182 | * @param sessionPath - session path to set. |
eb1bab5b BH |
183 | */ |
184 | public void setSessionPath(String sessionPath) { | |
185 | fSessionInfo.setSessionPath(sessionPath); | |
186 | } | |
187 | ||
f3b33d40 BH |
188 | /** |
189 | * Returns if session is streamed over network | |
190 | * @return <code>true</code> if streamed over network else <code>false</code> | |
191 | */ | |
192 | public boolean isStreamedTrace() { | |
193 | return fSessionInfo.isStreamedTrace(); | |
194 | } | |
195 | ||
196 | /** | |
197 | * Sets whether the trace is streamed or not | |
198 | * @param isStreamedTrace <code>true</code> if streamed over network else <code>false</code> | |
199 | */ | |
200 | public void setIsStreamedTrace(boolean isStreamedTrace) { | |
201 | fSessionInfo.setStreamedTrace(isStreamedTrace); | |
202 | } | |
203 | ||
589d0d33 BH |
204 | /** |
205 | * Returns whether the session is snapshot session or not | |
206 | * @return <code>true</code> if it is snapshot session else <code>false</code> | |
207 | */ | |
208 | public boolean isSnapshotSession() { | |
209 | return fSessionInfo.isSnapshotSession(); | |
210 | } | |
211 | ||
212 | /** | |
213 | * Gets the snapshot information if available whether the session is a snapshot session or not | |
214 | * @return the snapshot information or null if it is not a snapshot session | |
215 | */ | |
216 | public ISnapshotInfo getSnapshotInfo() { | |
217 | return fSessionInfo.getSnapshotInfo(); | |
218 | } | |
219 | ||
06b9339e BH |
220 | @Override |
221 | public Object getAdapter(Class adapter) { | |
222 | if (adapter == IPropertySource.class) { | |
223 | return new TraceSessionPropertySource(this); | |
224 | } | |
225 | return null; | |
cfdb727a | 226 | } |
bbb3538a | 227 | |
6503ae0f BH |
228 | /** |
229 | * @return all available domains of this session. | |
230 | */ | |
231 | public TraceDomainComponent[] getDomains() { | |
232 | List<ITraceControlComponent> sessions = getChildren(TraceDomainComponent.class); | |
cfdb727a | 233 | return sessions.toArray(new TraceDomainComponent[sessions.size()]); |
6503ae0f | 234 | } |
cfdb727a | 235 | |
498704b3 BH |
236 | /** |
237 | * @return the parent target node | |
238 | */ | |
239 | public TargetNodeComponent getTargetNode() { | |
240 | return ((TraceSessionGroup)getParent()).getTargetNode(); | |
241 | } | |
cfdb727a | 242 | |
a07c7629 BH |
243 | /** |
244 | * Returns whether the kernel provider is available or not | |
245 | * @return <code>true</code> if kernel provide is available or <code>false</code> | |
246 | */ | |
247 | public boolean hasKernelProvider() { | |
248 | List<ITraceControlComponent> providerGroups = getTargetNode().getChildren(TraceProviderGroup.class); | |
249 | return (!providerGroups.isEmpty() ? ((TraceProviderGroup) providerGroups.get(0)).hasKernelProvider() : false); | |
250 | } | |
251 | ||
d4514365 BH |
252 | /** |
253 | * Returns if node supports filtering of events | |
254 | * @return <code>true</code> if node supports filtering else <code>false</code> | |
255 | */ | |
256 | public boolean isEventFilteringSupported() { | |
257 | return ((TargetNodeComponent)getParent().getParent()).isEventFilteringSupported(); | |
258 | } | |
259 | ||
589d0d33 BH |
260 | /** |
261 | * Returns if node supports snapshots or not | |
262 | * @return <code>true</code> if it supports snapshots else <code>false</code> | |
263 | * | |
264 | */ | |
265 | public boolean isSnapshotSupported() { | |
266 | return ((TargetNodeComponent)getParent().getParent()).isSnapshotSupported(); | |
267 | } | |
268 | ||
eb1bab5b BH |
269 | // ------------------------------------------------------------------------ |
270 | // Operations | |
271 | // ------------------------------------------------------------------------ | |
cfdb727a | 272 | |
eb1bab5b | 273 | /** |
cfdb727a AM |
274 | * Retrieves the session configuration from the node. |
275 | * | |
276 | * @param monitor | |
277 | * - a progress monitor | |
eb1bab5b | 278 | * @throws ExecutionException |
cfdb727a | 279 | * If the command fails |
eb1bab5b | 280 | */ |
cfdb727a AM |
281 | public void getConfigurationFromNode(IProgressMonitor monitor) |
282 | throws ExecutionException { | |
bbb3538a | 283 | removeAllChildren(); |
6fd3c6e9 | 284 | ISessionInfo oldSessionInfo = fSessionInfo; |
eb1bab5b | 285 | fSessionInfo = getControlService().getSession(getName(), monitor); |
6fd3c6e9 | 286 | copyLiveInfo(oldSessionInfo); |
589d0d33 | 287 | |
eb1bab5b BH |
288 | IDomainInfo[] domains = fSessionInfo.getDomains(); |
289 | for (int i = 0; i < domains.length; i++) { | |
cfdb727a AM |
290 | TraceDomainComponent domainComponent = new TraceDomainComponent( |
291 | domains[i].getName(), this); | |
bbb3538a BH |
292 | addChild(domainComponent); |
293 | domainComponent.setDomainInfo(domains[i]); | |
eb1bab5b BH |
294 | } |
295 | } | |
cfdb727a | 296 | |
bbb3538a BH |
297 | /** |
298 | * Starts the session. | |
cfdb727a AM |
299 | * |
300 | * @param monitor | |
301 | * - a progress monitor | |
302 | * @throws ExecutionException | |
303 | * If the command fails | |
bbb3538a | 304 | */ |
cfdb727a AM |
305 | public void startSession(IProgressMonitor monitor) |
306 | throws ExecutionException { | |
bbb3538a BH |
307 | getControlService().startSession(getName(), monitor); |
308 | } | |
cfdb727a | 309 | |
bbb3538a BH |
310 | /** |
311 | * Starts the session. | |
cfdb727a AM |
312 | * |
313 | * @param monitor | |
314 | * - a progress monitor | |
315 | * @throws ExecutionException | |
316 | * If the command fails | |
bbb3538a BH |
317 | */ |
318 | public void stopSession(IProgressMonitor monitor) throws ExecutionException { | |
319 | getControlService().stopSession(getName(), monitor); | |
320 | } | |
321 | ||
c56972bb | 322 | /** |
cfdb727a AM |
323 | * Enables channels with given names which are part of this domain. If a |
324 | * given channel doesn't exists it creates a new channel with the given | |
325 | * parameters (or default values if given parameter is null). | |
326 | * | |
327 | * @param channelNames | |
328 | * - a list of channel names to enable on this domain | |
329 | * @param info | |
330 | * - channel information to set for the channel (use null for | |
331 | * default) | |
332 | * @param isKernel | |
333 | * - a flag for indicating kernel or UST. | |
334 | * @param monitor | |
335 | * - a progress monitor | |
c56972bb | 336 | * @throws ExecutionException |
cfdb727a | 337 | * If the command fails |
c56972bb | 338 | */ |
cfdb727a AM |
339 | public void enableChannels(List<String> channelNames, IChannelInfo info, |
340 | boolean isKernel, IProgressMonitor monitor) | |
341 | throws ExecutionException { | |
342 | getControlService().enableChannels(getName(), channelNames, isKernel, | |
343 | info, monitor); | |
c56972bb | 344 | } |
cfdb727a | 345 | |
6503ae0f BH |
346 | /** |
347 | * Enables a list of events with no additional parameters. | |
cfdb727a AM |
348 | * |
349 | * @param eventNames | |
350 | * - a list of event names to enabled. | |
351 | * @param isKernel | |
352 | * - a flag for indicating kernel or UST. | |
d4514365 BH |
353 | * @param filterExpression |
354 | * - a filter expression | |
cfdb727a AM |
355 | * @param monitor |
356 | * - a progress monitor | |
6503ae0f | 357 | * @throws ExecutionException |
cfdb727a | 358 | * If the command fails |
6503ae0f | 359 | */ |
cfdb727a | 360 | public void enableEvents(List<String> eventNames, boolean isKernel, |
d4514365 | 361 | String filterExpression, IProgressMonitor monitor) throws ExecutionException { |
cfdb727a | 362 | getControlService().enableEvents(getName(), null, eventNames, isKernel, |
d4514365 | 363 | filterExpression, monitor); |
498704b3 BH |
364 | } |
365 | ||
498704b3 BH |
366 | /** |
367 | * Enables all syscalls (for kernel domain) | |
cfdb727a AM |
368 | * |
369 | * @param monitor | |
370 | * - a progress monitor | |
498704b3 | 371 | * @throws ExecutionException |
cfdb727a | 372 | * If the command fails |
498704b3 | 373 | */ |
cfdb727a AM |
374 | public void enableSyscalls(IProgressMonitor monitor) |
375 | throws ExecutionException { | |
498704b3 BH |
376 | getControlService().enableSyscalls(getName(), null, monitor); |
377 | } | |
378 | ||
498704b3 BH |
379 | /** |
380 | * Enables a dynamic probe (for kernel domain) | |
cfdb727a AM |
381 | * |
382 | * @param eventName | |
383 | * - event name for probe | |
384 | * @param isFunction | |
385 | * - true for dynamic function entry/return probe else false | |
386 | * @param probe | |
387 | * - the actual probe | |
388 | * @param monitor | |
389 | * - a progress monitor | |
498704b3 | 390 | * @throws ExecutionException |
cfdb727a | 391 | * If the command fails |
498704b3 | 392 | */ |
cfdb727a AM |
393 | public void enableProbe(String eventName, boolean isFunction, String probe, |
394 | IProgressMonitor monitor) throws ExecutionException { | |
395 | getControlService().enableProbe(getName(), null, eventName, isFunction, | |
396 | probe, monitor); | |
6503ae0f | 397 | } |
cfdb727a | 398 | |
ccc66d01 BH |
399 | /** |
400 | * Enables events using log level. | |
cfdb727a AM |
401 | * |
402 | * @param eventName | |
403 | * - a event name | |
404 | * @param logLevelType | |
405 | * - a log level type | |
406 | * @param level | |
407 | * - a log level | |
d4514365 BH |
408 | * @param filterExpression |
409 | * - a filter expression | |
cfdb727a AM |
410 | * @param monitor |
411 | * - a progress monitor | |
ccc66d01 | 412 | * @throws ExecutionException |
cfdb727a | 413 | * If the command fails |
ccc66d01 | 414 | */ |
cfdb727a | 415 | public void enableLogLevel(String eventName, LogLevelType logLevelType, |
d4514365 | 416 | TraceLogLevel level, String filterExpression, IProgressMonitor monitor) |
cfdb727a AM |
417 | throws ExecutionException { |
418 | getControlService().enableLogLevel(getName(), null, eventName, | |
d4514365 | 419 | logLevelType, level, null, monitor); |
ccc66d01 | 420 | } |
cfdb727a | 421 | |
b793fbe1 BH |
422 | /** |
423 | * Gets all available contexts to be added to channels/events. | |
cfdb727a | 424 | * |
b793fbe1 | 425 | * @param monitor |
cfdb727a | 426 | * The monitor that will indicate the progress |
b793fbe1 | 427 | * @return the list of available contexts |
cfdb727a AM |
428 | * @throws ExecutionException |
429 | * If the command fails | |
b793fbe1 | 430 | */ |
cfdb727a AM |
431 | public List<String> getContextList(IProgressMonitor monitor) |
432 | throws ExecutionException { | |
b793fbe1 BH |
433 | return getControlService().getContextList(monitor); |
434 | } | |
589d0d33 BH |
435 | |
436 | /** | |
437 | * Records a snapshot. | |
438 | * | |
439 | * @param monitor | |
440 | * - a progress monitor | |
441 | * @throws ExecutionException | |
442 | * If the command fails | |
443 | */ | |
444 | public void recordSnapshot(IProgressMonitor monitor) throws ExecutionException { | |
445 | getControlService().recordSnapshot(getName(), monitor); | |
446 | } | |
6fd3c6e9 MAL |
447 | |
448 | /** | |
449 | * Returns if session is live. | |
450 | * @return <code>true</code> if session if live else <code>false</code> | |
451 | */ | |
452 | public boolean isLiveTrace() { | |
453 | return fSessionInfo.isLive(); | |
454 | } | |
455 | ||
456 | /** | |
457 | * Get the live URL. | |
458 | * | |
459 | * @return the live URL | |
460 | */ | |
461 | public String getLiveUrl() { | |
462 | return fSessionInfo.getLiveUrl(); | |
463 | } | |
464 | ||
465 | /** | |
466 | * Get the live port. | |
467 | * | |
468 | * @return the live port | |
469 | */ | |
470 | public Integer getLivePort() { | |
471 | return fSessionInfo.getLivePort(); | |
472 | } | |
eb1bab5b | 473 | } |