1 /*******************************************************************************
2 * Copyright (c) 2011 Ericsson
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
10 * Polytechnique Montréal - Initial API and implementation
11 * Bernd Hufmann - Productification, enhancements and fixes
13 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.lttng
.ui
.tracecontrol
.actions
;
16 import java
.util
.Iterator
;
17 import java
.util
.concurrent
.TimeUnit
;
19 import org
.eclipse
.jface
.action
.IAction
;
20 import org
.eclipse
.jface
.viewers
.ISelection
;
21 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
22 import org
.eclipse
.jface
.window
.Window
;
23 import org
.eclipse
.jface
.wizard
.WizardDialog
;
24 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.tracecontrol
.model
.TraceResource
;
25 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.tracecontrol
.model
.TraceResource
.TraceState
;
26 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.tracecontrol
.model
.config
.TraceChannel
;
27 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.tracecontrol
.model
.config
.TraceChannels
;
28 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.tracecontrol
.model
.config
.TraceConfig
;
29 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.tracecontrol
.service
.ILttControllerService
;
30 import org
.eclipse
.linuxtools
.lttng
.ui
.LTTngUiPlugin
;
31 import org
.eclipse
.linuxtools
.lttng
.ui
.tracecontrol
.Messages
;
32 import org
.eclipse
.linuxtools
.lttng
.ui
.tracecontrol
.TraceControlConstants
;
33 import org
.eclipse
.linuxtools
.lttng
.ui
.tracecontrol
.subsystems
.TraceSubSystem
;
34 import org
.eclipse
.linuxtools
.lttng
.ui
.tracecontrol
.wizards
.ConfigureTraceWizard
;
35 import org
.eclipse
.rse
.core
.events
.ISystemRemoteChangeEvents
;
36 import org
.eclipse
.rse
.core
.model
.ISystemRegistry
;
37 import org
.eclipse
.rse
.core
.model
.SystemStartHere
;
38 import org
.eclipse
.rse
.services
.clientserver
.messages
.SystemMessageException
;
39 import org
.eclipse
.rse
.ui
.SystemBasePlugin
;
40 import org
.eclipse
.swt
.widgets
.Shell
;
41 import org
.eclipse
.tm
.tcf
.protocol
.IToken
;
42 import org
.eclipse
.tm
.tcf
.util
.TCFTask
;
43 import org
.eclipse
.ui
.IObjectActionDelegate
;
44 import org
.eclipse
.ui
.IViewActionDelegate
;
45 import org
.eclipse
.ui
.IViewPart
;
46 import org
.eclipse
.ui
.IWorkbenchPart
;
47 import org
.eclipse
.ui
.IWorkbenchWindow
;
48 import org
.eclipse
.ui
.IWorkbenchWindowActionDelegate
;
51 * <b><u>ConfigureTrace</u></b>
53 * Action implementation to configure a trace.
56 public class ConfigureTrace
implements IObjectActionDelegate
, IWorkbenchWindowActionDelegate
, IViewActionDelegate
{
58 // ------------------------------------------------------------------------
60 // ------------------------------------------------------------------------
61 private TraceResource fSelectedTrace
= null;
62 private IStructuredSelection fSelection
= null;
64 // ------------------------------------------------------------------------
66 // ------------------------------------------------------------------------
68 public ConfigureTrace() {
71 // ------------------------------------------------------------------------
73 // ------------------------------------------------------------------------
77 * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart)
80 public void setActivePart(IAction arg0
, IWorkbenchPart arg1
) {
85 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
88 public void run(IAction arg0
) {
89 ConfigureTraceWizard wizard
= new ConfigureTraceWizard();
90 wizard
.init(SystemBasePlugin
.getActiveWorkbenchWindow().getWorkbench(), fSelection
);
91 WizardDialog wDialog
= new WizardDialog(getShell(), wizard
);
93 if (wDialog
.getReturnCode() != Window
.OK
) {
97 final TraceConfig result
= wizard
.getTraceConfig();
102 // Update channel settings
103 TraceChannels channels
= result
.getTraceChannels();
105 for (Iterator
<String
> iterator
= channels
.keySet().iterator(); iterator
.hasNext();) {
106 String chanName
= (String
) iterator
.next();
107 TraceChannel chan
= channels
.get(chanName
);
109 boolean doIt
= false;
111 // If we channel settings have been updated send the relevant command to the agent
112 TraceChannel other
= new TraceChannel(chan
.getName());
114 if (fSelectedTrace
.getTraceConfig() == null || fSelectedTrace
.getTraceConfig().getTraceChannels() == null) {
115 // Do the update since channels haven't been configured previously (or we re-connected to the agent)
117 } else if (fSelectedTrace
.getTraceConfig() != null && fSelectedTrace
.getTraceConfig().getTraceChannels() != null) {
118 // Channels has been configured previously, compare new settings with old. Do the update if necessary
119 TraceChannel other2
= fSelectedTrace
.getTraceConfig().getTraceChannels().get(chanName
);
120 if (other2
!= null) {
124 doIt
= !(chan
.equals(other
));
127 // Please note that currently, the agent doesn't support the retrieval of channel settings.
128 // Therefore, the current settings might not be known!
131 if (!fSelectedTrace
.isUst()) {
132 // Update kernel tracing related parameters (not applicable for UST)
134 if (chan
.isEnabledStatusKnown()) {
135 if(!other
.isEnabledStatusKnown() || (chan
.isEnabled() != other
.isEnabled()) ) {
136 setChannelEnable(chan
.getName(), chan
.isEnabled());
140 if (chan
.isChannelOverrideStatusKnown()) {
141 if(!other
.isChannelOverrideStatusKnown() || (chan
.isChannelOverride() != other
.isChannelOverride())) {
142 setChannelOverwrite(chanName
, chan
.isChannelOverride());
146 if (chan
.getSubbufNum() != other
.getSubbufNum()) {
147 setChannelSubbufNum(chanName
, chan
.getSubbufNum());
150 if (chan
.getSubbufSize() != other
.getSubbufSize()) {
151 setChannelSubbufSize(chanName
, chan
.getSubbufSize());
155 if (chan
.getTimer() != other
.getTimer()) {
156 setChannelTimer(chanName
, chan
.getTimer());
160 // Update state of trace
161 if (fSelectedTrace
.getTraceState() == TraceState
.CREATED
) {
162 fSelectedTrace
.setTraceState(TraceState
.CONFIGURED
);
165 fSelectedTrace
.setTraceConfig(result
);
167 ISystemRegistry registry
= SystemStartHere
.getSystemRegistry();
168 registry
.fireRemoteResourceChangeEvent(ISystemRemoteChangeEvents
.SYSTEM_REMOTE_RESOURCE_CHANGED
, fSelectedTrace
, fSelectedTrace
.getParent(), fSelectedTrace
.getSubSystem(), null);
170 // } catch (SystemMessageException e) {
171 // SystemMessageException sysExp;
172 // if (e instanceof SystemMessageException) {
173 // sysExp = (SystemMessageException)e;
175 // sysExp = new SystemMessageException(LTTngUiPlugin.getDefault().getMessage(e));
178 // SystemBasePlugin.logError(Messages.Lttng_Control_ErrorConfigureTrace + " (" + //$NON-NLS-1$
179 // Messages.Lttng_Resource_Trace + ": " + fSelectedTrace.getName() + ")", sysExp); //$NON-NLS-1$ //$NON-NLS-2$
187 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
189 @SuppressWarnings("unchecked")
191 public void selectionChanged(IAction action
, ISelection selection
) {
192 if (selection
instanceof IStructuredSelection
) {
193 // store the selected targets to be used when running
194 Iterator
<IStructuredSelection
> theSet
= ((IStructuredSelection
) selection
).iterator();
195 fSelection
= (IStructuredSelection
) selection
;
196 while (theSet
.hasNext()) {
197 Object obj
= theSet
.next();
198 if (obj
instanceof TraceResource
) {
199 fSelectedTrace
= (TraceResource
)obj
;
211 * Returns the active workbench shell of this plug-in.
213 * @return active workbench shell.
215 protected Shell
getShell() {
216 return SystemBasePlugin
.getActiveWorkbenchShell();
221 * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
224 public void init(IWorkbenchWindow window
) {
230 * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
233 public void dispose() {
238 * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart)
241 public void init(IViewPart view
) {
245 * Enable or disable a channel on the remote system.
247 private void setChannelEnable(final String channelName
, final boolean enabled
) {
249 final ILttControllerService service
= ((TraceSubSystem
)fSelectedTrace
.getSubSystem()).getControllerService();
251 // Create future task
252 new TCFTask
<Boolean
>() {
256 // Set marker enable using Lttng controller service proxy
257 service
.setChannelEnable(fSelectedTrace
.getParent().getParent().getName(),
258 fSelectedTrace
.getParent().getName(),
259 fSelectedTrace
.getName(),
262 new ILttControllerService
.DoneSetChannelEnable() {
265 public void doneSetChannelEnable(IToken token
, Exception error
, Object str
) {
272 // Notify about success
273 done(Boolean
.valueOf(true));
276 }}.get(TraceControlConstants
.DEFAULT_TCF_TASK_TIMEOUT
, TimeUnit
.SECONDS
);
277 } catch (Exception e
) {
278 SystemMessageException sysExp
;
279 if (e
instanceof SystemMessageException
) {
280 sysExp
= (SystemMessageException
)e
;
282 sysExp
= new SystemMessageException(LTTngUiPlugin
.getDefault().getMessage(e
));
284 SystemBasePlugin
.logError(Messages
.Lttng_Control_ErrorSetChannelEnable
+ " (" + //$NON-NLS-1$
285 Messages
.Lttng_Resource_Trace
+ ": " + fSelectedTrace
.getName() + ", " + //$NON-NLS-1$ //$NON-NLS-2$
286 Messages
.Lttng_Resource_Channel
+ ": " + channelName
+ ")", sysExp
); //$NON-NLS-1$ //$NON-NLS-2$
290 // setChannelOverwrite* provider target trace channel enable
291 private void setChannelOverwrite(final String channelName
, final boolean override
) {
293 final ILttControllerService service
= ((TraceSubSystem
)fSelectedTrace
.getSubSystem()).getControllerService();
295 // Create future task
296 new TCFTask
<Boolean
>() {
300 // Set marker enable using Lttng controller service proxy
301 service
.setChannelOverwrite(fSelectedTrace
.getParent().getParent().getName(),
302 fSelectedTrace
.getParent().getName(),
303 fSelectedTrace
.getName(),
306 new ILttControllerService
.DoneSetChannelOverwrite() {
309 public void doneSetChannelOverwrite(IToken token
, Exception error
, Object str
) {
316 // Notify about success
317 done(Boolean
.valueOf(true));
320 }}.get(TraceControlConstants
.DEFAULT_TCF_TASK_TIMEOUT
, TimeUnit
.SECONDS
);
321 } catch (Exception e
) {
322 SystemMessageException sysExp
;
323 if (e
instanceof SystemMessageException
) {
324 sysExp
= (SystemMessageException
)e
;
326 sysExp
= new SystemMessageException(LTTngUiPlugin
.getDefault().getMessage(e
));
328 SystemBasePlugin
.logError(Messages
.Lttng_Control_ErrorSetChannelOverwrite
+ " (" + //$NON-NLS-1$
329 Messages
.Lttng_Resource_Trace
+ ": " + fSelectedTrace
.getName() + ", " + //$NON-NLS-1$ //$NON-NLS-2$
330 Messages
.Lttng_Resource_Channel
+ ": " + channelName
+ ")", sysExp
); //$NON-NLS-1$ //$NON-NLS-2$
335 * Setup the number of sub-buffers on the remote system.
337 private void setChannelSubbufNum(final String channelName
, final long numSubBuf
) {
339 final ILttControllerService service
= ((TraceSubSystem
)fSelectedTrace
.getSubSystem()).getControllerService();
341 // Create future task
342 new TCFTask
<Boolean
>() {
346 // Set marker enable using Lttng controller service proxy
347 service
.setChannelSubbufNum(fSelectedTrace
.getParent().getParent().getName(),
348 fSelectedTrace
.getParent().getName(),
349 fSelectedTrace
.getName(),
352 new ILttControllerService
.DoneSetChannelSubbufNum() {
355 public void doneSetChannelSubbufNum(IToken token
, Exception error
, Object str
) {
362 // Notify about success
363 done(Boolean
.valueOf(true));
366 }}.get(TraceControlConstants
.DEFAULT_TCF_TASK_TIMEOUT
, TimeUnit
.SECONDS
);
367 } catch (Exception e
) {
368 SystemMessageException sysExp
;
369 if (e
instanceof SystemMessageException
) {
370 sysExp
= (SystemMessageException
)e
;
372 sysExp
= new SystemMessageException(LTTngUiPlugin
.getDefault().getMessage(e
));
374 SystemBasePlugin
.logError(Messages
.Lttng_Control_ErrorSetSubbufNum
+ " (" + //$NON-NLS-1$
375 Messages
.Lttng_Resource_Trace
+ ": " + fSelectedTrace
.getName() + ", " + //$NON-NLS-1$ //$NON-NLS-2$
376 Messages
.Lttng_Resource_Channel
+ ": " + channelName
+ ")", sysExp
); //$NON-NLS-1$ //$NON-NLS-2$
381 * Setup the size of the sub-buffer on the remote system.
383 private void setChannelSubbufSize(final String channelName
, final long subBufSize
) {
385 final ILttControllerService service
= ((TraceSubSystem
)fSelectedTrace
.getSubSystem()).getControllerService();
387 // Create future task
388 new TCFTask
<Boolean
>() {
392 // Set marker enable using Lttng controller service proxy
393 service
.setChannelSubbufSize(fSelectedTrace
.getParent().getParent().getName(),
394 fSelectedTrace
.getParent().getName(),
395 fSelectedTrace
.getName(),
398 new ILttControllerService
.DoneSetChannelSubbufSize() {
401 public void doneSetChannelSubbufSize(IToken token
, Exception error
, Object str
) {
408 // Notify about success
409 done(Boolean
.valueOf(true));
412 }}.get(TraceControlConstants
.DEFAULT_TCF_TASK_TIMEOUT
, TimeUnit
.SECONDS
);
413 } catch (Exception e
) {
414 SystemMessageException sysExp
;
415 if (e
instanceof SystemMessageException
) {
416 sysExp
= (SystemMessageException
)e
;
418 sysExp
= new SystemMessageException(LTTngUiPlugin
.getDefault().getMessage(e
));
420 SystemBasePlugin
.logError(Messages
.Lttng_Control_ErrorSetSubbufSize
+ " (" + //$NON-NLS-1$
421 Messages
.Lttng_Resource_Trace
+ ": " + fSelectedTrace
.getName() + ", " + //$NON-NLS-1$ //$NON-NLS-2$
422 Messages
.Lttng_Resource_Channel
+ ": " + channelName
+ ")", sysExp
); //$NON-NLS-1$ //$NON-NLS-2$
427 * Setup up the channel timer on the remote system.
429 private void setChannelTimer(final String channelName
, final long timer
) {
431 final ILttControllerService service
= ((TraceSubSystem
)fSelectedTrace
.getSubSystem()).getControllerService();
433 // Create future task
434 new TCFTask
<Boolean
>() {
438 // Set marker enable using Lttng controller service proxy
439 service
.setChannelTimer(fSelectedTrace
.getParent().getParent().getName(),
440 fSelectedTrace
.getParent().getName(),
441 fSelectedTrace
.getName(),
444 new ILttControllerService
.DoneSetChannelTimer() {
447 public void doneSetChannelTimer(IToken token
, Exception error
, Object str
) {
454 // Notify about success
455 done(Boolean
.valueOf(true));
458 }}.get(TraceControlConstants
.DEFAULT_TCF_TASK_TIMEOUT
, TimeUnit
.SECONDS
);
459 } catch (Exception e
) {
460 SystemMessageException sysExp
;
461 if (e
instanceof SystemMessageException
) {
462 sysExp
= (SystemMessageException
)e
;
464 sysExp
= new SystemMessageException(LTTngUiPlugin
.getDefault().getMessage(e
));
466 SystemBasePlugin
.logError(Messages
.Lttng_Control_ErrorSetChannelTimer
+ " (" + //$NON-NLS-1$
467 Messages
.Lttng_Resource_Trace
+ ": " + fSelectedTrace
.getName() + ", " + //$NON-NLS-1$ //$NON-NLS-2$
468 Messages
.Lttng_Resource_Channel
+ ": " + channelName
+ ")", sysExp
); //$NON-NLS-1$ //$NON-NLS-2$