Commit | Line | Data |
---|---|---|
e8d771d5 BH |
1 | /******************************************************************************* |
2 | * Copyright (c) 2011 Ericsson | |
3 | * | |
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 | |
8 | * | |
9 | * Contributors: | |
10 | * Polytechnique Montréal - Initial API and implementation | |
11 | * Bernd Hufmann - Productification, enhancements and fixes | |
12 | * | |
13 | *******************************************************************************/ | |
5945cec9 | 14 | package org.eclipse.linuxtools.internal.lttng.core.tracecontrol.model; |
e8d771d5 BH |
15 | |
16 | import java.util.HashMap; | |
17 | import java.util.Map; | |
a79913eb | 18 | import java.util.concurrent.TimeUnit; |
e8d771d5 | 19 | |
5945cec9 FC |
20 | import org.eclipse.linuxtools.internal.lttng.core.tracecontrol.Messages; |
21 | import org.eclipse.linuxtools.internal.lttng.core.tracecontrol.model.config.TraceConfig; | |
22 | import org.eclipse.linuxtools.internal.lttng.core.tracecontrol.service.ILttControllerService; | |
e8d771d5 BH |
23 | import org.eclipse.rse.core.subsystems.AbstractResource; |
24 | import org.eclipse.rse.core.subsystems.ISubSystem; | |
04a934f0 PT |
25 | import org.eclipse.tcf.protocol.IToken; |
26 | import org.eclipse.tcf.util.TCFTask; | |
e8d771d5 BH |
27 | |
28 | /** | |
29 | * <b><u>ProviderResource</u></b> | |
30 | * <p> | |
31 | * This models a remote resource representing a trace defined on a particular system. | |
32 | * </p> | |
33 | */ | |
34 | public class TraceResource extends AbstractResource implements Comparable<TraceResource> { | |
35 | ||
36 | ||
37 | public static enum TraceState { CREATED, CONFIGURED, STARTED, PAUSED, STOPPED }; | |
38 | ||
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$ | |
45 | ||
a79913eb FC |
46 | public static final int DEFAULT_TCF_TASK_TIMEOUT = 10; |
47 | ||
e8d771d5 BH |
48 | private static final Map<String, PropertyInfo> fPropertyInfo = new HashMap<String, PropertyInfo>(); |
49 | ||
50 | static { | |
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)); | |
57 | } | |
58 | ||
59 | public static class PropertyInfo { | |
60 | private final String name; | |
61 | private final String description; | |
62 | PropertyInfo(String name, String description) { | |
63 | this.name = name; | |
64 | this.description = description; | |
65 | } | |
66 | public String getName() { | |
67 | return name; | |
68 | } | |
69 | public String getDescription() { | |
70 | return description; | |
71 | } | |
72 | } | |
73 | ||
74 | // ------------------------------------------------------------------------ | |
75 | // Attributes | |
76 | // ------------------------------------------------------------------------ | |
77 | ||
78 | private String fName; | |
79 | private String fId; | |
80 | private TargetResource fParent; | |
81 | private TraceState fTraceState; | |
82 | private TraceConfig fTraceConfig; | |
a79913eb | 83 | private ILttControllerService fService; |
e8d771d5 BH |
84 | |
85 | // ------------------------------------------------------------------------ | |
86 | // Constructors | |
87 | // ------------------------------------------------------------------------ | |
88 | /** | |
89 | * Constructor for TraceResource when given fParent subsystem. | |
90 | */ | |
a79913eb | 91 | public TraceResource(ISubSystem parentSubSystem, ILttControllerService service) { |
e8d771d5 | 92 | super(parentSubSystem); |
a79913eb | 93 | fService = service; |
e8d771d5 BH |
94 | } |
95 | ||
96 | // ------------------------------------------------------------------------ | |
97 | // Operations | |
98 | // ------------------------------------------------------------------------ | |
99 | ||
100 | /** | |
101 | * Returns the trace state. | |
102 | */ | |
103 | public TraceState getTraceState() { | |
104 | return fTraceState; | |
105 | } | |
106 | ||
107 | /** | |
108 | * Sets the trace state. | |
109 | * | |
110 | * @param traceState The new state. | |
111 | */ | |
112 | public void setTraceState(TraceState traceState) { | |
113 | fTraceState = traceState; | |
114 | } | |
115 | ||
116 | /** | |
117 | * Returns the trace configuration for this trace. | |
118 | * | |
119 | * @return traceConfig | |
120 | */ | |
121 | public TraceConfig getTraceConfig() { | |
122 | return fTraceConfig; | |
123 | } | |
124 | ||
125 | /** | |
126 | * Sets the trace configuration for this trace. | |
127 | * | |
128 | * @param traceConfig | |
129 | */ | |
130 | public void setTraceConfig(TraceConfig traceConfig) { | |
131 | fTraceConfig = traceConfig; | |
132 | } | |
133 | ||
134 | /** | |
135 | * Returns the name of the trace resource. | |
136 | * | |
137 | * @return String | |
138 | */ | |
139 | public String getName() { | |
140 | return fName; | |
141 | } | |
142 | ||
143 | /** | |
144 | * Sets the name of the trace resource. | |
145 | * | |
146 | * @param fName The fName to set | |
147 | */ | |
148 | public void setName(String name) { | |
149 | fName = name; | |
150 | } | |
151 | ||
152 | /** | |
153 | * Returns the ID of the trace resource. | |
154 | * | |
155 | * @return String | |
156 | */ | |
157 | public String getId() { | |
158 | return fId; | |
159 | } | |
160 | ||
161 | /** | |
162 | * Sets the ID of the trace resource. | |
163 | * | |
164 | * @param fId The fId to set | |
165 | */ | |
166 | public void setId(String id) { | |
167 | fId = id; | |
168 | } | |
169 | ||
170 | /** | |
171 | * Returns the parent target resource. | |
172 | * @return | |
173 | */ | |
174 | public TargetResource getParent() { | |
175 | return fParent; | |
176 | } | |
177 | ||
178 | /** | |
179 | * Sets the parent target resource. | |
180 | * | |
181 | * @param target | |
182 | */ | |
183 | public void setParent(TargetResource target) { | |
184 | fParent = target; | |
185 | } | |
186 | ||
187 | /** | |
188 | * Returns the property information for this trace. | |
189 | * | |
190 | * @return the value | |
191 | */ | |
192 | public Map<String,PropertyInfo> getPropertyInfo() { | |
193 | return fPropertyInfo; | |
194 | } | |
195 | ||
196 | /** | |
197 | * Gets the property information for a given property name. | |
198 | * | |
199 | * @param property the property to get | |
200 | * | |
201 | * @return the value | |
202 | */ | |
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(); | |
207 | } | |
208 | else if (Ltt_Trace_Property_TraceNumberOfChannels.equals(property)) { | |
209 | return String.valueOf(fTraceConfig.getNumChannel()); | |
210 | } | |
211 | else if (Ltt_Trace_Property_FlightRecorderMode.equals(property)) { | |
212 | return String.valueOf(fTraceConfig.getMode() == TraceConfig.FLIGHT_RECORDER_MODE); | |
213 | } | |
214 | else if (Ltt_Trace_Property_NormalMode.equals(property)) { | |
215 | return String.valueOf(fTraceConfig.getMode() == TraceConfig.NORMAL_MODE); | |
216 | } | |
217 | else if (Ltt_Trace_Property_NetworkTrace.equals(property)) { | |
218 | return String.valueOf(fTraceConfig.isNetworkTrace()); | |
219 | } | |
220 | else if (Ltt_Trace_Property_TraceTransport.equals(property)) { | |
221 | return String.valueOf(fTraceConfig.getTraceTransport()); | |
222 | } | |
223 | } | |
224 | return ""; //$NON-NLS-1$ | |
225 | } | |
226 | ||
227 | /** | |
228 | * @return true if the trace is a network trace and has been already started. | |
229 | */ | |
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); | |
235 | } | |
236 | ||
237 | /** | |
238 | * Returns whether the trace is a UST or kernel trace. | |
239 | * | |
240 | * @return true if UST, false for kernel | |
241 | */ | |
242 | public boolean isUst() { | |
243 | return fParent.isUst(); | |
244 | } | |
245 | ||
246 | /* | |
247 | * (non-Javadoc) | |
248 | * @see java.lang.Object#equals(java.lang.Object) | |
249 | */ | |
250 | @Override | |
251 | public boolean equals(Object other) { | |
252 | ||
253 | if (this == other) { | |
254 | return true; | |
255 | } | |
256 | ||
257 | // We only check the name because the trace name has to be unique | |
258 | if (other instanceof TraceResource) { | |
259 | TraceResource otherTrace = (TraceResource) other; | |
f9a8715c | 260 | if (fName != null) { |
e8d771d5 BH |
261 | return fName.equals(otherTrace.fName); |
262 | } | |
263 | } | |
264 | return false; | |
265 | } | |
266 | ||
267 | /* | |
268 | * (non-Javadoc) | |
269 | * @see java.lang.Object#hashCode() | |
270 | */ | |
271 | @Override | |
272 | public int hashCode() { | |
273 | // We only use the name because the trace name has to be unique | |
274 | return fName.hashCode(); | |
275 | } | |
276 | ||
277 | /* | |
278 | * (non-Javadoc) | |
279 | * @see java.lang.Comparable#compareTo(java.lang.Object) | |
280 | */ | |
281 | @Override | |
282 | public int compareTo(TraceResource o) { | |
283 | // We only check the name because the trace name has to be unique | |
284 | return fName.toLowerCase().compareTo(o.fName.toLowerCase()); | |
285 | } | |
286 | ||
287 | /* | |
288 | * (non-Javadoc) | |
289 | * @see java.lang.Object#toString() | |
290 | */ | |
291 | @Override | |
292 | @SuppressWarnings("nls") | |
293 | public String toString() { | |
294 | return "[TraceResource (" + fName + ")]"; | |
295 | } | |
a79913eb FC |
296 | |
297 | /* | |
298 | * Setup trace on the remote system. | |
299 | */ | |
300 | public void setupTrace() throws Exception { | |
301 | // Create future task | |
302 | new TCFTask<Boolean>() { | |
303 | @Override | |
304 | public void run() { | |
305 | ||
306 | // Setup trace using Lttng controller service proxy | |
307 | fService.setupTrace(fParent.getParent().getName(), | |
308 | fParent.getName(), | |
309 | fName, | |
310 | new ILttControllerService.DoneSetupTrace() { | |
311 | ||
312 | @Override | |
313 | public void doneSetupTrace(IToken token, Exception error, Object str) { | |
314 | if (error != null) { | |
315 | // Notify with error | |
316 | error(error); | |
317 | return; | |
318 | } | |
319 | ||
320 | // Notify about success | |
321 | done(Boolean.valueOf(true)); | |
322 | } | |
323 | }); | |
324 | }}.get(DEFAULT_TCF_TASK_TIMEOUT, TimeUnit.SECONDS); | |
325 | } | |
326 | ||
327 | /* | |
328 | * Enable or disable a channel on the remote system. | |
329 | */ | |
330 | public void setChannelEnable(final String channelName, final boolean enabled) throws Exception { | |
331 | // Create future task | |
332 | new TCFTask<Boolean>() { | |
333 | @Override | |
334 | public void run() { | |
335 | ||
336 | // Set marker enable using Lttng controller service proxy | |
337 | fService.setChannelEnable(fParent.getParent().getName(), | |
338 | fParent.getName(), | |
339 | fName, | |
340 | channelName, | |
341 | enabled, | |
342 | new ILttControllerService.DoneSetChannelEnable() { | |
343 | ||
344 | @Override | |
345 | public void doneSetChannelEnable(IToken token, Exception error, Object str) { | |
346 | if (error != null) { | |
347 | // Notify with error | |
348 | error(error); | |
349 | return; | |
350 | } | |
351 | ||
352 | // Notify about success | |
353 | done(Boolean.valueOf(true)); | |
354 | } | |
355 | }); | |
356 | }}.get(DEFAULT_TCF_TASK_TIMEOUT, TimeUnit.SECONDS); | |
357 | } | |
358 | ||
359 | /* | |
360 | * Set channel overwrite on the remote system. | |
361 | */ | |
362 | public void setChannelOverwrite(final String channelName, final boolean overwrite) throws Exception { | |
363 | // Create future task | |
364 | new TCFTask<Boolean>() { | |
365 | @Override | |
366 | public void run() { | |
367 | ||
368 | // Set marker overwrite using Lttng controller service proxy | |
369 | fService.setChannelOverwrite(fParent.getParent().getName(), | |
370 | fParent.getName(), | |
371 | fName, | |
372 | channelName, | |
373 | overwrite, | |
374 | new ILttControllerService.DoneSetChannelOverwrite() { | |
375 | ||
376 | @Override | |
377 | public void doneSetChannelOverwrite(IToken token, Exception error, Object str) { | |
378 | if (error != null) { | |
379 | // Notify with error | |
380 | error(error); | |
381 | return; | |
382 | } | |
383 | ||
384 | // Notify about success | |
385 | done(Boolean.valueOf(true)); | |
386 | } | |
387 | }); | |
388 | }}.get(DEFAULT_TCF_TASK_TIMEOUT, TimeUnit.SECONDS); | |
389 | } | |
390 | ||
391 | /* | |
392 | * Set channel timer on the remote system. | |
393 | */ | |
394 | public void setChannelTimer(final String channelName, final long timer) throws Exception { | |
395 | // Create future task | |
396 | new TCFTask<Boolean>() { | |
397 | @Override | |
398 | public void run() { | |
399 | ||
400 | // Set marker switch_timer using Lttng controller service proxy | |
401 | fService.setChannelTimer(fParent.getParent().getName(), | |
402 | fParent.getName(), | |
403 | fName, | |
404 | channelName, | |
405 | timer, | |
406 | new ILttControllerService.DoneSetChannelTimer() { | |
407 | ||
408 | @Override | |
409 | public void doneSetChannelTimer(IToken token, Exception error, Object str) { | |
410 | if (error != null) { | |
411 | // Notify with error | |
412 | error(error); | |
413 | return; | |
414 | } | |
415 | ||
416 | // Notify about success | |
417 | done(Boolean.valueOf(true)); | |
418 | } | |
419 | }); | |
420 | }}.get(DEFAULT_TCF_TASK_TIMEOUT, TimeUnit.SECONDS); | |
421 | } | |
422 | ||
423 | /* | |
424 | * Setup the size of the sub-buffer on the remote system. | |
425 | */ | |
426 | public void setChannelSubbufNum(final String channelName, final long subbufNum) throws Exception { | |
427 | // Create future task | |
428 | new TCFTask<Boolean>() { | |
429 | @Override | |
430 | public void run() { | |
431 | ||
432 | // Set marker enable using Lttng controller service proxy | |
433 | fService.setChannelSubbufNum(fParent.getParent().getName(), | |
434 | fParent.getName(), | |
435 | fName, | |
436 | channelName, | |
437 | subbufNum, | |
438 | new ILttControllerService.DoneSetChannelSubbufNum() { | |
439 | ||
440 | @Override | |
441 | public void doneSetChannelSubbufNum(IToken token, Exception error, Object str) { | |
442 | if (error != null) { | |
443 | // Notify with error | |
444 | error(error); | |
445 | return; | |
446 | } | |
447 | ||
448 | // Notify about success | |
449 | done(Boolean.valueOf(true)); | |
450 | } | |
451 | }); | |
452 | }}.get(DEFAULT_TCF_TASK_TIMEOUT, TimeUnit.SECONDS); | |
453 | } | |
454 | ||
455 | /* | |
456 | * Setup the size of the sub-buffer on the remote system. | |
457 | */ | |
458 | public void setChannelSubbufSize(final String channelName, final long subbufSize) throws Exception { | |
459 | // Create future task | |
460 | new TCFTask<Boolean>() { | |
461 | @Override | |
462 | public void run() { | |
463 | ||
464 | // Set marker enable using Lttng controller service proxy | |
465 | fService.setChannelSubbufSize(fParent.getParent().getName(), | |
466 | fParent.getName(), | |
467 | fName, | |
468 | channelName, | |
469 | subbufSize, | |
470 | new ILttControllerService.DoneSetChannelSubbufSize() { | |
471 | ||
472 | @Override | |
473 | public void doneSetChannelSubbufSize(IToken token, Exception error, Object str) { | |
474 | if (error != null) { | |
475 | // Notify with error | |
476 | error(error); | |
477 | return; | |
478 | } | |
479 | ||
480 | // Notify about success | |
481 | done(Boolean.valueOf(true)); | |
482 | } | |
483 | }); | |
484 | }}.get(DEFAULT_TCF_TASK_TIMEOUT, TimeUnit.SECONDS); | |
485 | } | |
486 | ||
487 | ||
e8d771d5 | 488 | } |