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