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