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
.tracecontrol
.model
;
16 import java
.util
.HashMap
;
18 import java
.util
.concurrent
.TimeUnit
;
20 import org
.eclipse
.linuxtools
.lttng
.tracecontrol
.Messages
;
21 import org
.eclipse
.linuxtools
.lttng
.tracecontrol
.model
.config
.TraceConfig
;
22 import org
.eclipse
.linuxtools
.lttng
.tracecontrol
.service
.ILttControllerService
;
23 import org
.eclipse
.rse
.core
.subsystems
.AbstractResource
;
24 import org
.eclipse
.rse
.core
.subsystems
.ISubSystem
;
25 import org
.eclipse
.tm
.tcf
.protocol
.IToken
;
26 import org
.eclipse
.tm
.tcf
.util
.TCFTask
;
29 * <b><u>ProviderResource</u></b>
31 * This models a remote resource representing a trace defined on a particular system.
34 public class TraceResource
extends AbstractResource
implements Comparable
<TraceResource
> {
37 public static enum TraceState
{ CREATED
, CONFIGURED
, STARTED
, PAUSED
, STOPPED
};
39 public static final String Ltt_Trace_Property_TracePath
= "trace_path"; //$NON-NLS-1$
40 public static final String Ltt_Trace_Property_TraceNumberOfChannels
= "num_threads"; //$NON-NLS-1$
41 public static final String Ltt_Trace_Property_FlightRecorderMode
= "flight_only"; //$NON-NLS-1$
42 public static final String Ltt_Trace_Property_NormalMode
= "normal_only"; //$NON-NLS-1$
43 public static final String Ltt_Trace_Property_NetworkTrace
= "isNetwork"; //$NON-NLS-1$
44 public static final String Ltt_Trace_Property_TraceTransport
= "transport"; //$NON-NLS-1$
46 public static final int DEFAULT_TCF_TASK_TIMEOUT
= 10;
48 private static final Map
<String
, PropertyInfo
> fPropertyInfo
= new HashMap
<String
, PropertyInfo
>();
51 fPropertyInfo
.put(Ltt_Trace_Property_TracePath
, new PropertyInfo(Messages
.Ltt_Trace_Property_TracePathName
, Messages
.Ltt_Trace_Property_TracePathDescription
));
52 fPropertyInfo
.put(Ltt_Trace_Property_TraceNumberOfChannels
, new PropertyInfo(Messages
.Ltt_Trace_Property_NumberOfChannelsName
, Messages
.Ltt_Trace_Property_NumberOfChannelsDescr
));
53 fPropertyInfo
.put(Ltt_Trace_Property_FlightRecorderMode
, new PropertyInfo(Messages
.Ltt_Trace_Property_FlighRecorderModeName
, Messages
.Ltt_Trace_Property_FlighRecorderModeDesc
));
54 fPropertyInfo
.put(Ltt_Trace_Property_NormalMode
, new PropertyInfo(Messages
.Ltt_Trace_Property_NormalModeName
, Messages
.Ltt_Trace_Property_NormalModeDesc
));
55 fPropertyInfo
.put(Ltt_Trace_Property_NetworkTrace
, new PropertyInfo(Messages
.Ltt_Trace_Property_NetworkTraceName
, Messages
.Ltt_Trace_Property_NetWorkTraceDescr
));
56 fPropertyInfo
.put(Ltt_Trace_Property_TraceTransport
, new PropertyInfo(Messages
.Ltt_Trace_Property_TraceTransportName
, Messages
.Ltt_Trace_Property_TraceTransportDesc
));
59 public static class PropertyInfo
{
60 private final String name
;
61 private final String description
;
62 PropertyInfo(String name
, String description
) {
64 this.description
= description
;
66 public String
getName() {
69 public String
getDescription() {
74 // ------------------------------------------------------------------------
76 // ------------------------------------------------------------------------
80 private TargetResource fParent
;
81 private TraceState fTraceState
;
82 private TraceConfig fTraceConfig
;
83 private ILttControllerService fService
;
85 // ------------------------------------------------------------------------
87 // ------------------------------------------------------------------------
89 * Constructor for TraceResource when given fParent subsystem.
91 public TraceResource(ISubSystem parentSubSystem
, ILttControllerService service
) {
92 super(parentSubSystem
);
96 // ------------------------------------------------------------------------
98 // ------------------------------------------------------------------------
101 * Returns the trace state.
103 public TraceState
getTraceState() {
108 * Sets the trace state.
110 * @param traceState The new state.
112 public void setTraceState(TraceState traceState
) {
113 fTraceState
= traceState
;
117 * Returns the trace configuration for this trace.
119 * @return traceConfig
121 public TraceConfig
getTraceConfig() {
126 * Sets the trace configuration for this trace.
130 public void setTraceConfig(TraceConfig traceConfig
) {
131 fTraceConfig
= traceConfig
;
135 * Returns the name of the trace resource.
139 public String
getName() {
144 * Sets the name of the trace resource.
146 * @param fName The fName to set
148 public void setName(String name
) {
153 * Returns the ID of the trace resource.
157 public String
getId() {
162 * Sets the ID of the trace resource.
164 * @param fId The fId to set
166 public void setId(String id
) {
171 * Returns the parent target resource.
174 public TargetResource
getParent() {
179 * Sets the parent target resource.
183 public void setParent(TargetResource target
) {
188 * Returns the property information for this trace.
192 public Map
<String
,PropertyInfo
> getPropertyInfo() {
193 return fPropertyInfo
;
197 * Gets the property information for a given property name.
199 * @param property the property to get
203 public String
getProperty(String property
) {
204 if ((fTraceConfig
!= null) && (fPropertyInfo
.containsKey(property
))) {
205 if (Ltt_Trace_Property_TracePath
.equals(property
)) {
206 return fTraceConfig
.getTracePath();
208 else if (Ltt_Trace_Property_TraceNumberOfChannels
.equals(property
)) {
209 return String
.valueOf(fTraceConfig
.getNumChannel());
211 else if (Ltt_Trace_Property_FlightRecorderMode
.equals(property
)) {
212 return String
.valueOf(fTraceConfig
.getMode() == TraceConfig
.FLIGHT_RECORDER_MODE
);
214 else if (Ltt_Trace_Property_NormalMode
.equals(property
)) {
215 return String
.valueOf(fTraceConfig
.getMode() == TraceConfig
.NORMAL_MODE
);
217 else if (Ltt_Trace_Property_NetworkTrace
.equals(property
)) {
218 return String
.valueOf(fTraceConfig
.isNetworkTrace());
220 else if (Ltt_Trace_Property_TraceTransport
.equals(property
)) {
221 return String
.valueOf(fTraceConfig
.getTraceTransport());
224 return ""; //$NON-NLS-1$
228 * @return true if the trace is a network trace and has been already started.
230 public boolean isNetworkTraceAndStarted () {
231 // for network traces, if trace path is available and if state is started
232 return (fTraceConfig
!= null) && fTraceConfig
.isNetworkTrace() &&
233 !(TraceConfig
.InvalidTracePath
.equals(fTraceConfig
.getTracePath())) &&
234 (fTraceState
== TraceState
.STARTED
);
238 * Returns whether the trace is a UST or kernel trace.
240 * @return true if UST, false for kernel
242 public boolean isUst() {
243 return fParent
.isUst();
248 * @see java.lang.Object#equals(java.lang.Object)
251 public boolean equals(Object other
) {
257 // We only check the name because the trace name has to be unique
258 if (other
instanceof TraceResource
) {
259 TraceResource otherTrace
= (TraceResource
) other
;
261 if ((fName
== null) && (otherTrace
.fName
== null)) {
263 } else if ((fName
== null) && (otherTrace
.fName
!= null)) {
266 else if ((fName
!= null) && (otherTrace
.fName
== null)) {
270 return fName
.equals(otherTrace
.fName
);
278 * @see java.lang.Object#hashCode()
281 public int hashCode() {
282 // We only use the name because the trace name has to be unique
283 return fName
.hashCode();
288 * @see java.lang.Comparable#compareTo(java.lang.Object)
291 public int compareTo(TraceResource o
) {
292 // We only check the name because the trace name has to be unique
293 return fName
.toLowerCase().compareTo(o
.fName
.toLowerCase());
298 * @see java.lang.Object#toString()
301 @SuppressWarnings("nls")
302 public String
toString() {
303 return "[TraceResource (" + fName
+ ")]";
307 * Setup trace on the remote system.
309 public void setupTrace() throws Exception
{
310 // Create future task
311 new TCFTask
<Boolean
>() {
315 // Setup trace using Lttng controller service proxy
316 fService
.setupTrace(fParent
.getParent().getName(),
319 new ILttControllerService
.DoneSetupTrace() {
322 public void doneSetupTrace(IToken token
, Exception error
, Object str
) {
329 // Notify about success
330 done(Boolean
.valueOf(true));
333 }}.get(DEFAULT_TCF_TASK_TIMEOUT
, TimeUnit
.SECONDS
);
337 * Enable or disable a channel on the remote system.
339 public void setChannelEnable(final String channelName
, final boolean enabled
) throws Exception
{
340 // Create future task
341 new TCFTask
<Boolean
>() {
345 // Set marker enable using Lttng controller service proxy
346 fService
.setChannelEnable(fParent
.getParent().getName(),
351 new ILttControllerService
.DoneSetChannelEnable() {
354 public void doneSetChannelEnable(IToken token
, Exception error
, Object str
) {
361 // Notify about success
362 done(Boolean
.valueOf(true));
365 }}.get(DEFAULT_TCF_TASK_TIMEOUT
, TimeUnit
.SECONDS
);
369 * Set channel overwrite on the remote system.
371 public void setChannelOverwrite(final String channelName
, final boolean overwrite
) throws Exception
{
372 // Create future task
373 new TCFTask
<Boolean
>() {
377 // Set marker overwrite using Lttng controller service proxy
378 fService
.setChannelOverwrite(fParent
.getParent().getName(),
383 new ILttControllerService
.DoneSetChannelOverwrite() {
386 public void doneSetChannelOverwrite(IToken token
, Exception error
, Object str
) {
393 // Notify about success
394 done(Boolean
.valueOf(true));
397 }}.get(DEFAULT_TCF_TASK_TIMEOUT
, TimeUnit
.SECONDS
);
401 * Set channel timer on the remote system.
403 public void setChannelTimer(final String channelName
, final long timer
) throws Exception
{
404 // Create future task
405 new TCFTask
<Boolean
>() {
409 // Set marker switch_timer using Lttng controller service proxy
410 fService
.setChannelTimer(fParent
.getParent().getName(),
415 new ILttControllerService
.DoneSetChannelTimer() {
418 public void doneSetChannelTimer(IToken token
, Exception error
, Object str
) {
425 // Notify about success
426 done(Boolean
.valueOf(true));
429 }}.get(DEFAULT_TCF_TASK_TIMEOUT
, TimeUnit
.SECONDS
);
433 * Setup the size of the sub-buffer on the remote system.
435 public void setChannelSubbufNum(final String channelName
, final long subbufNum
) throws Exception
{
436 // Create future task
437 new TCFTask
<Boolean
>() {
441 // Set marker enable using Lttng controller service proxy
442 fService
.setChannelSubbufNum(fParent
.getParent().getName(),
447 new ILttControllerService
.DoneSetChannelSubbufNum() {
450 public void doneSetChannelSubbufNum(IToken token
, Exception error
, Object str
) {
457 // Notify about success
458 done(Boolean
.valueOf(true));
461 }}.get(DEFAULT_TCF_TASK_TIMEOUT
, TimeUnit
.SECONDS
);
465 * Setup the size of the sub-buffer on the remote system.
467 public void setChannelSubbufSize(final String channelName
, final long subbufSize
) throws Exception
{
468 // Create future task
469 new TCFTask
<Boolean
>() {
473 // Set marker enable using Lttng controller service proxy
474 fService
.setChannelSubbufSize(fParent
.getParent().getName(),
479 new ILttControllerService
.DoneSetChannelSubbufSize() {
482 public void doneSetChannelSubbufSize(IToken token
, Exception error
, Object str
) {
489 // Notify about success
490 done(Boolean
.valueOf(true));
493 }}.get(DEFAULT_TCF_TASK_TIMEOUT
, TimeUnit
.SECONDS
);