Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: d2f407f2f1b436765d459591af7812bc58eaa623 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
/*******************************************************************************
 * Copyright (c) 2011 Ericsson
 * 
 * All rights reserved. This program and the accompanying materials are
 * made available under the terms of the Eclipse Public License v1.0 which
 * accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *   Polytechnique Montréal - Initial API and implementation
 *   Bernd Hufmann - Productification, enhancements and fixes
 *   
 *******************************************************************************/
package org.eclipse.linuxtools.internal.lttng.core.tracecontrol.model;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import org.eclipse.linuxtools.internal.lttng.core.tracecontrol.Messages;
import org.eclipse.linuxtools.internal.lttng.core.tracecontrol.model.config.TraceConfig;
import org.eclipse.linuxtools.internal.lttng.core.tracecontrol.service.ILttControllerService;
import org.eclipse.rse.core.subsystems.AbstractResource;
import org.eclipse.rse.core.subsystems.ISubSystem;
import org.eclipse.tm.tcf.protocol.IToken;
import org.eclipse.tm.tcf.util.TCFTask;

/**
 * <b><u>ProviderResource</u></b>
 * <p>
 * This models a remote resource representing a trace defined on a particular system.
 * </p>
 */
public class TraceResource extends AbstractResource implements Comparable<TraceResource> {

    
    public static enum TraceState { CREATED, CONFIGURED, STARTED, PAUSED, STOPPED };
    
    public static final String Ltt_Trace_Property_TracePath = "trace_path"; //$NON-NLS-1$
    public static final String Ltt_Trace_Property_TraceNumberOfChannels = "num_threads"; //$NON-NLS-1$
    public static final String Ltt_Trace_Property_FlightRecorderMode = "flight_only"; //$NON-NLS-1$
    public static final String Ltt_Trace_Property_NormalMode = "normal_only"; //$NON-NLS-1$
    public static final String Ltt_Trace_Property_NetworkTrace = "isNetwork"; //$NON-NLS-1$
    public static final String Ltt_Trace_Property_TraceTransport = "transport"; //$NON-NLS-1$
    
    public static final int DEFAULT_TCF_TASK_TIMEOUT = 10;

    private static final Map<String, PropertyInfo> fPropertyInfo = new HashMap<String, PropertyInfo>();
    
    static {
        fPropertyInfo.put(Ltt_Trace_Property_TracePath, new PropertyInfo(Messages.Ltt_Trace_Property_TracePathName, Messages.Ltt_Trace_Property_TracePathDescription));
        fPropertyInfo.put(Ltt_Trace_Property_TraceNumberOfChannels, new PropertyInfo(Messages.Ltt_Trace_Property_NumberOfChannelsName, Messages.Ltt_Trace_Property_NumberOfChannelsDescr));
        fPropertyInfo.put(Ltt_Trace_Property_FlightRecorderMode, new PropertyInfo(Messages.Ltt_Trace_Property_FlighRecorderModeName, Messages.Ltt_Trace_Property_FlighRecorderModeDesc));
        fPropertyInfo.put(Ltt_Trace_Property_NormalMode, new PropertyInfo(Messages.Ltt_Trace_Property_NormalModeName, Messages.Ltt_Trace_Property_NormalModeDesc));
        fPropertyInfo.put(Ltt_Trace_Property_NetworkTrace, new PropertyInfo(Messages.Ltt_Trace_Property_NetworkTraceName, Messages.Ltt_Trace_Property_NetWorkTraceDescr));
        fPropertyInfo.put(Ltt_Trace_Property_TraceTransport, new PropertyInfo(Messages.Ltt_Trace_Property_TraceTransportName, Messages.Ltt_Trace_Property_TraceTransportDesc));
    }

    public static class PropertyInfo {
        private final String name;
        private final String description;
        PropertyInfo(String name, String description) {
            this.name = name;
            this.description = description;
        }
        public String getName() {
            return name;
        }
        public String getDescription() {
            return description;
        }
    }

    // ------------------------------------------------------------------------
    // Attributes
    // ------------------------------------------------------------------------
    
    private String fName;
    private String fId;
    private TargetResource fParent;
    private TraceState fTraceState;
    private TraceConfig fTraceConfig;
    private ILttControllerService fService;
    
    // ------------------------------------------------------------------------
    // Constructors
    // ------------------------------------------------------------------------
    /**
     * Constructor for TraceResource when given fParent subsystem.
     */
    public TraceResource(ISubSystem parentSubSystem, ILttControllerService service) {
        super(parentSubSystem);
        fService = service;
    }
    
    // ------------------------------------------------------------------------
    // Operations
    // ------------------------------------------------------------------------

    /**
     * Returns the trace state.
     */
    public TraceState getTraceState() {
    	return fTraceState;
    }
    
    /**
     * Sets the trace state.
     * 
     * @param traceState The new state.
     */
    public void setTraceState(TraceState traceState) {
    	fTraceState = traceState;
    }

    /**
     * Returns the trace configuration for this trace.
     * 
     * @return traceConfig
     */
    public TraceConfig getTraceConfig() {
    	return fTraceConfig;
    }

    /**
     * Sets the trace configuration for this trace.
     * 
     * @param traceConfig
     */
    public void setTraceConfig(TraceConfig traceConfig) {
    	fTraceConfig = traceConfig;
    }
    
    /**
     * Returns the name of the trace resource.
     * 
     * @return String
     */
    public String getName() {
        return fName;
    }

    /**
     * Sets the name of the trace resource.
     * 
     * @param fName The fName to set
     */
    public void setName(String name) {
        fName = name;
    }

    /**
     * Returns the ID of the trace resource.
     * 
     * @return String
     */
    public String getId() {
        return fId;
    }

    /**
     * Sets the ID of the trace resource.
     * 
     * @param fId The fId to set
     */
    public void setId(String id) {
        fId = id;
    }

    /**
     * Returns the parent target resource.
     * @return
     */
    public TargetResource getParent() {
        return fParent;
    }

    /**
     * Sets the parent target resource.
     * 
     * @param target
     */
    public void setParent(TargetResource target) {
        fParent = target;
    }
    
    /**
     * Returns the property information for this trace.
     * 
     * @return the value
     */
    public Map<String,PropertyInfo> getPropertyInfo() {
        return fPropertyInfo;
    }

    /**
     * Gets the property information for a given property name. 
     *  
     * @param property the property to get
     * 
     * @return the value
     */
    public String getProperty(String property) {
        if ((fTraceConfig != null) && (fPropertyInfo.containsKey(property))) {
            if (Ltt_Trace_Property_TracePath.equals(property)) {
                return fTraceConfig.getTracePath();
            }
            else if (Ltt_Trace_Property_TraceNumberOfChannels.equals(property)) {
                return String.valueOf(fTraceConfig.getNumChannel());
            }
            else if (Ltt_Trace_Property_FlightRecorderMode.equals(property)) {
                return String.valueOf(fTraceConfig.getMode() == TraceConfig.FLIGHT_RECORDER_MODE);
            }
            else if (Ltt_Trace_Property_NormalMode.equals(property)) {
                return String.valueOf(fTraceConfig.getMode() == TraceConfig.NORMAL_MODE);
            }
            else if (Ltt_Trace_Property_NetworkTrace.equals(property)) {
                return String.valueOf(fTraceConfig.isNetworkTrace());
            }
            else if (Ltt_Trace_Property_TraceTransport.equals(property)) {
                return String.valueOf(fTraceConfig.getTraceTransport());
            }
        }
        return ""; //$NON-NLS-1$
    }
    
    /**
     * @return true if the trace is a network trace and has been already started.
     */
    public boolean isNetworkTraceAndStarted () {
        // for network traces, if trace path is available and if state is started
        return (fTraceConfig != null) && fTraceConfig.isNetworkTrace() && 
               !(TraceConfig.InvalidTracePath.equals(fTraceConfig.getTracePath())) &&
               (fTraceState == TraceState.STARTED);
    }
    
    /**
     * Returns whether the trace is a UST or kernel trace. 
     * 
     * @return true if UST, false for kernel 
     */
    public boolean isUst() {
        return fParent.isUst(); 
    }
    
    /*
     * (non-Javadoc)
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals(Object other) {
        
        if (this == other) {
            return true;
        }

        // We only check the name because the trace name has to be unique
        if (other instanceof TraceResource) {
            TraceResource otherTrace = (TraceResource) other;
            if (fName != null) {
                return fName.equals(otherTrace.fName);    
            }
        }
        return false;        
    }
    
    /*
     * (non-Javadoc)
     * @see java.lang.Object#hashCode()
     */
    @Override 
    public int hashCode() {
        // We only use the name because the trace name has to be unique
        return fName.hashCode();
    }
    
    /*
     * (non-Javadoc)
     * @see java.lang.Comparable#compareTo(java.lang.Object)
     */
    @Override
    public int compareTo(TraceResource o) {
        // We only check the name because the trace name has to be unique
        return fName.toLowerCase().compareTo(o.fName.toLowerCase());
    }

    /*
     * (non-Javadoc)
     * @see java.lang.Object#toString()
     */
    @Override
    @SuppressWarnings("nls")
    public String toString() {
        return "[TraceResource (" + fName + ")]";
    }

    /*
     * Setup trace on the remote system. 
     */
    public void setupTrace() throws Exception {
        // Create future task
        new TCFTask<Boolean>() {
            @Override
            public void run() {

                // Setup trace using Lttng controller service proxy
                fService.setupTrace(fParent.getParent().getName(),
                        fParent.getName(), 
                        fName, 
                        new ILttControllerService.DoneSetupTrace() {

                    @Override
                    public void doneSetupTrace(IToken token, Exception error, Object str) {
                        if (error != null) {
                            // Notify with error
                            error(error);
                            return;
                        }

                        // Notify about success
                        done(Boolean.valueOf(true));
                    }
                });
            }}.get(DEFAULT_TCF_TASK_TIMEOUT, TimeUnit.SECONDS);
    }

    /*
     * Enable or disable a channel on the remote system. 
     */
    public void setChannelEnable(final String channelName, final boolean enabled) throws Exception {
        // Create future task
        new TCFTask<Boolean>() {
            @Override
            public void run() {

                // Set marker enable using Lttng controller service proxy
                fService.setChannelEnable(fParent.getParent().getName(),
                        fParent.getName(), 
                        fName, 
                        channelName, 
                        enabled,  
                        new ILttControllerService.DoneSetChannelEnable() {

                    @Override
                    public void doneSetChannelEnable(IToken token, Exception error, Object str) {
                        if (error != null) {
                            // Notify with error
                            error(error);
                            return;
                        }

                        // Notify about success
                        done(Boolean.valueOf(true));
                    }
                });
            }}.get(DEFAULT_TCF_TASK_TIMEOUT, TimeUnit.SECONDS);
    }

    /*
     * Set channel overwrite on the remote system. 
     */
    public void setChannelOverwrite(final String channelName, final boolean overwrite) throws Exception {
        // Create future task
       new TCFTask<Boolean>() {
            @Override
            public void run() {

                // Set marker overwrite using Lttng controller service proxy
                fService.setChannelOverwrite(fParent.getParent().getName(),
                        fParent.getName(), 
                        fName, 
                        channelName, 
                        overwrite,  
                        new ILttControllerService.DoneSetChannelOverwrite() {

                    @Override
                    public void doneSetChannelOverwrite(IToken token, Exception error, Object str) {
                        if (error != null) {
                            // Notify with error
                            error(error);
                            return;
                        }

                        // Notify about success
                        done(Boolean.valueOf(true));
                    }
                });
            }}.get(DEFAULT_TCF_TASK_TIMEOUT, TimeUnit.SECONDS);
    }

    /*
     * Set channel timer on the remote system. 
     */
    public void setChannelTimer(final String channelName, final long timer) throws Exception {
        // Create future task
       new TCFTask<Boolean>() {
            @Override
            public void run() {

                // Set marker switch_timer using Lttng controller service proxy
                fService.setChannelTimer(fParent.getParent().getName(),
                        fParent.getName(), 
                        fName, 
                        channelName, 
                        timer,  
                        new ILttControllerService.DoneSetChannelTimer() {

                    @Override
                    public void doneSetChannelTimer(IToken token, Exception error, Object str) {
                        if (error != null) {
                            // Notify with error
                            error(error);
                            return;
                        }

                        // Notify about success
                        done(Boolean.valueOf(true));
                    }
                });
            }}.get(DEFAULT_TCF_TASK_TIMEOUT, TimeUnit.SECONDS);
    }

    /*
     * Setup the size of the sub-buffer on the remote system.
     */
    public void setChannelSubbufNum(final String channelName, final long subbufNum) throws Exception {
        // Create future task
        new TCFTask<Boolean>() {
            @Override
            public void run() {

                // Set marker enable using Lttng controller service proxy
                fService.setChannelSubbufNum(fParent.getParent().getName(),
                        fParent.getName(),
                        fName,
                        channelName,
                        subbufNum,
                        new ILttControllerService.DoneSetChannelSubbufNum() {

                    @Override
                    public void doneSetChannelSubbufNum(IToken token, Exception error, Object str) {
                        if (error != null) {
                            // Notify with error
                            error(error);
                            return;
                        }

                        // Notify about success
                        done(Boolean.valueOf(true));
                    }
                });
            }}.get(DEFAULT_TCF_TASK_TIMEOUT, TimeUnit.SECONDS);
    }

    /*
     * Setup the size of the sub-buffer on the remote system.
     */
    public void setChannelSubbufSize(final String channelName, final long subbufSize) throws Exception {
        // Create future task
        new TCFTask<Boolean>() {
            @Override
            public void run() {

                // Set marker enable using Lttng controller service proxy
                fService.setChannelSubbufSize(fParent.getParent().getName(),
                        fParent.getName(), 
                        fName, 
                        channelName, 
                        subbufSize,  
                        new ILttControllerService.DoneSetChannelSubbufSize() {

                    @Override
                    public void doneSetChannelSubbufSize(IToken token, Exception error, Object str) {
                        if (error != null) {
                            // Notify with error
                            error(error);
                            return;
                        }

                        // Notify about success
                        done(Boolean.valueOf(true));
                    }
                });
            }}.get(DEFAULT_TCF_TASK_TIMEOUT, TimeUnit.SECONDS);
    }


}

Back to the top