Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 290046
Collapse All | Expand All

(-)META-INF/MANIFEST.MF (+3 lines)
Lines 9-11 Link Here
9
 org.eclipse.linuxtools.tmf;bundle-version="0.0.1"
9
 org.eclipse.linuxtools.tmf;bundle-version="0.0.1"
10
Bundle-RequiredExecutionEnvironment: J2SE-1.5
10
Bundle-RequiredExecutionEnvironment: J2SE-1.5
11
Bundle-ActivationPolicy: lazy
11
Bundle-ActivationPolicy: lazy
12
Export-Package: org.eclipse.linuxtools.lttng,
13
 org.eclipse.linuxtools.lttng.event,
14
 org.eclipse.linuxtools.lttng.trace
(-)src/org/eclipse/linuxtools/lttng/jni/JniException.java (+169 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 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
 *   William Bourque (wbourque@gmail.com) - Initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.linuxtools.lttng.jni;
14
15
/**
16
 * <b><u>JniException</u></b>
17
 * <p>
18
 * Super exception class for JNI
19
 */
20
public class JniException extends Exception {
21
    private static final long serialVersionUID = -6620784221853154537L;
22
23
    JniException(String errMsg) {
24
        super(errMsg);
25
    }
26
}
27
28
/**
29
 * <b><u>JniTraceException</u></b>
30
 * <p>
31
 * Basic exception class for the JniTrace class
32
 */
33
class JniTraceException extends JniException {
34
    private static final long serialVersionUID = -6873007333085268143L;
35
36
    JniTraceException(String errMsg) {
37
        super(errMsg);
38
    }
39
}
40
41
/**
42
 * <b><u>JniOpenTraceFailedException</u></b>
43
 * <p>
44
 * Sub-exception class type for JniTraceException
45
 * This type will get thrown when a trace fail to open
46
 * Most likely to be caused by a bad tracepath
47
 */
48
class JniOpenTraceFailedException extends JniTraceException {
49
    private static final long serialVersionUID = 877769692366394895L;
50
51
    JniOpenTraceFailedException(String errMsg) {
52
        super(errMsg);
53
    }
54
}
55
56
/**
57
 * <b><u>JniNoNextEventInTraceException</u></b>
58
 * <p>
59
 * Sub-exception class type for JniTraceException
60
 * This type will get thrown when we can't find any "next" event
61
 * This should usually mean there is no more event in the trace
62
63
 */
64
class JniNoNextEventInTraceException extends JniTraceException {
65
    private static final long serialVersionUID = -2887528566100063849L;
66
67
    JniNoNextEventInTraceException(String errMsg) {
68
        super(errMsg);
69
    }
70
}
71
72
// 
73
/**
74
 * <b><u>JniTracefileException</u></b>
75
 * <p>
76
 * Basic exception class for the JniTracefile class
77
 */
78
class JniTracefileException extends JniException {
79
    private static final long serialVersionUID = 5081317864491800084L;
80
81
    JniTracefileException(String errMsg) {
82
        super(errMsg);
83
    }
84
}
85
86
/**
87
 * <b><u>JniTracefileWithoutEventException</u></b>
88
 * <p>
89
 * Sub-exception class type for JniTracefileException
90
 * This type will get thrown when a trace file contain no readable events
91
 * The proper course of action would usually be to ignore this useless trace file
92
 */
93
class JniTracefileWithoutEventException extends JniTracefileException {
94
    private static final long serialVersionUID = -8183967479236071261L;
95
96
    JniTracefileWithoutEventException(String errMsg) {
97
        super(errMsg);
98
    }
99
}
100
101
/**
102
 * <b><u>JniEventException</u></b>
103
 * <p>
104
 * Basic exception class for the JniEvent class
105
 */
106
class JniEventException extends JniException {
107
    private static final long serialVersionUID = -5891749130387304519L;
108
109
    JniEventException(String errMsg) {
110
        super(errMsg);
111
    }
112
}
113
114
/**
115
 * <b><u>JniNoSuchEventException</u></b>
116
 * <p>
117
 * Sub-exception type for the JniEventException type
118
 * This exception type will get thrown when an event is unavailable
119
 * This might happen at construction because some events type are not present in
120
 * the trace
121
 */
122
class JniNoSuchEventException extends JniEventException {
123
    private static final long serialVersionUID = -4379712949891538051L;
124
125
    JniNoSuchEventException(String errMsg) {
126
        super(errMsg);
127
    }
128
}
129
130
/**
131
 * <b><u>JniEventOutOfRangeException</u></b>
132
 * <p>
133
 * Sub-exception type for the JniEventException type
134
 * This exception type will get thrown when there is no more event of this type
135
 * available
136
 */
137
class JniEventOutOfRangeException extends JniEventException {
138
    private static final long serialVersionUID = -4645877232795324541L;
139
140
    JniEventOutOfRangeException(String errMsg) {
141
        super(errMsg);
142
    }
143
}
144
145
/**
146
 * <b><u>JniMarkerException</u></b>
147
 * <p>
148
 * Basic Exception class for the JniMarker class
149
 */
150
class JniMarkerException extends JniException {
151
    private static final long serialVersionUID = -4694173610721983794L;
152
153
    JniMarkerException(String errMsg) {
154
        super(errMsg);
155
    }
156
}
157
158
/**
159
 * <b><u>JniMarkerFieldException</u></b>
160
 * <p>
161
 * Basic Exception class for the JniMarkerField class
162
 */
163
class JniMarkerFieldException extends JniException {
164
    private static final long serialVersionUID = 6066381741374806879L;
165
166
    JniMarkerFieldException(String errMsg) {
167
        super(errMsg);
168
    }
169
}
0
  + text/plain
170
  + text/plain
(-)src/org/eclipse/linuxtools/lttng/jni/JniTime.java (+157 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 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
 *   William Bourque (wbourque@gmail.com) - Initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.linuxtools.lttng.jni;
14
15
/**
16
 * <b><u>JniTime</u></b>
17
 * <p>
18
 * JniTime object linked to the LttTime C structure
19
 */
20
public final class JniTime extends Jni_C_Common
21
{
22
    private long time = 0;
23
24
    /**
25
     * Default constructor.
26
     *          
27
     */
28
    JniTime() {
29
        time = 0;
30
    }
31
32
    /**
33
     * Copy constructor.
34
     * 
35
     * @param oldTime A reference to the JniTime you want to copy.           
36
     */
37
    JniTime(JniTime oldTime) {
38
        time = oldTime.getTime();
39
    }
40
41
    /**
42
     * Constructor with parameters
43
     * <br>
44
     * "Ltt style" constructor with Seconds et Nanoseconds
45
     * 
46
     * @param newSec      Seconds of the JniTime
47
     * @param newNanoSec  Nanoseconds of the JniTime
48
     */
49
    JniTime(long newSec, long newNanoSec) {
50
        time = (newSec * NANO) + newNanoSec;
51
    }
52
53
    /**
54
     * Constructor with parameters
55
     * <br>
56
     * Usual "nanosecond only" constructor
57
     * 
58
     * @param newNanoSecTime  JniTime in nanoseconds
59
     */
60
    public JniTime(long newNanoSecTime) {
61
        time = newNanoSecTime;
62
    }
63
64
    /**
65
     * Getter for the second of the time
66
     * <br>
67
     * This only return seconds part, i.e. multiple of 1 000 000, of the stored time
68
     * 
69
     * @return long Second of the time
70
     */
71
    public long getSeconds() {
72
        return (time / NANO);
73
    }
74
75
    /**
76
     * Getter for the nanosecond of the time
77
     * <br>
78
     * This only nanosecondspart , i.e. modulo of 1 000 000, of the stored time
79
     * 
80
     * @return long Nanoseconds of the time
81
     */
82
    public long getNanoSeconds() {
83
        return time % NANO;
84
    }
85
86
    /**
87
     * Getter for the full time, in nanoseconds
88
     * 
89
     * @return The complete time in nanoseconds
90
     */
91
    public long getTime() {
92
        return time;
93
    }
94
     
95
    /**
96
     * Comparaison operator <=
97
     * 
98
     * @param comparedTime  The time we want to compare with this one
99
     * @return boolean true if the compared time is smaller or equal, false otherwise
100
     */
101
    public boolean isGivenTimeSmallerOrEqual(JniTime comparedTime) {
102
103
        // NOTE : We check <= instead of just <
104
        // This mean the RIGHT OPERAND (comparedTime) always prevails
105
        if (comparedTime.getTime() < this.getTime()) {
106
            return true;
107
        } else {
108
            return false;
109
        }
110
    }
111
    
112
    /**
113
     * Integer Comparaison operator
114
     * 
115
     * @param comparedTime  The time we want to compare with this one
116
     * @return int Integer of value -1, 0 or 1, as the pased argument is bigger, equal or smaller than this time
117
     */
118
    public int compare(JniTime comparedTime) {
119
        if ( comparedTime.getTime() < this.getTime() ) {
120
                return 1;
121
        }
122
        else if ( comparedTime.getTime() > this.getTime() ) {
123
                return -1;
124
        }
125
        else {
126
            return 0;
127
        }
128
    }
129
130
    /* 
131
     * Populate this time object
132
     * 
133
     * Note: This function is called from C side.
134
     * 
135
     * @param newTime The time we want to populate
136
     */
137
    @SuppressWarnings("unused")
138
    private void setTimeFromC(long newTime) {
139
        time = newTime;
140
    }
141
    
142
    /**
143
     * toString() method. <u>Intended to debug</u><br>
144
     * <br>
145
     * NOTE : we output the time in the same format as LTT (seconds and nanosecond separatly)
146
     * 
147
     * @return String Attributes of the object concatenated in String
148
     */
149
    public String toString() {
150
        String returnData = "";
151
152
        returnData += "seconds     : " + this.getSeconds() + "\n";
153
        returnData += "nanoSeconds : " + this.getNanoSeconds() + "\n";
154
155
        return returnData;
156
    }
157
}
0
  + text/plain
158
  + text/plain
(-)src/org/eclipse/linuxtools/lttng/jni/JniTrace.java (+741 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 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
 *   William Bourque (wbourque@gmail.com) - Initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.linuxtools.lttng.jni;
14
15
import java.util.Comparator;
16
import java.util.HashMap;
17
import java.util.Iterator;
18
import java.util.PriorityQueue;
19
20
/**
21
 * <b><u>JniTrace</u></b>
22
 * <p>
23
 * This is the top level class in the JNI. It provides access to the 
24
 * LttTrace C structure in java.
25
 * <p>
26
 * Most important fields in the JniTrace are :
27
 * <ul>
28
 * <li>a JniTrace path (a trace <b>directory</b>)
29
 * <li>a HashMap of tracefiles that exists in this trace
30
 * </ul>
31
 */
32
public class JniTrace extends Jni_C_Common {
33
        
34
    // Internal C pointer of the JniTrace used in LTT
35
    private C_Pointer thisTracePtr = new C_Pointer();
36
37
    // Data we should populate from LTT
38
    // Note that all type have been scaled up as there is no "unsigned" in java
39
    // This might be a problem about "unsigned long" as there is no equivalent
40
    // in java
41
42
    private String tracepath = ""; // Path of the trace. Should be a directory (like : /tmp/traceX)
43
    private int    cpuNumber = 0;
44
    private long   archType = 0;
45
    private long   archVariant = 0;
46
    private short  archSize = 0;
47
    private short  lttMajorVersion = 0;
48
    private short  lttMinorVersion = 0;
49
    private short  flightRecorder = 0;
50
    private long   freqScale = 0;
51
    private long   startFreq = 0;
52
    private long   startTimestampCurrentCounter = 0;
53
    private long   startMonotonic = 0;
54
    private JniTime   startTime = null;
55
    private JniTime   startTimeFromTimestampCurrentCounter = null;
56
57
    // This Map holds a reference to the tracefiles owned by this trace
58
    private HashMap<String, JniTracefile> tracefilesMap = null;
59
    // The priority queue (similar to heap) hold events 
60
    private PriorityQueue<JniEvent> eventsHeap = null;
61
    
62
    // This variable will hold the content of the "last" event we read
63
    private JniTime currentEventTimestamp = new JniTime();
64
    
65
    // Comparator we will need for the heap construction
66
    private Comparator<JniEvent> eventComparator = new Comparator<JniEvent>() {
67
    	public int compare(JniEvent left, JniEvent right ){
68
    		return ( left.getEventTime().compare( right.getEventTime() ) );
69
    	}
70
    };
71
    
72
    
73
    // Open/close native functions
74
    private native long ltt_openTrace(String pathname);
75
    private native void ltt_closeTrace(long tracePtr);
76
77
    // Native access functions
78
    private native String ltt_getTracepath(long tracePtr);
79
    private native int    ltt_getCpuNumber(long tracePtr);
80
    private native long   ltt_getArchType(long tracePtr);
81
    private native long   ltt_getArchVariant(long tracePtr);
82
    private native short  ltt_getArchSize(long tracePtr);
83
    private native short  ltt_getLttMajorVersion(long tracePtr);
84
    private native short  ltt_getLttMinorVersion(long tracePtr);
85
    private native short  ltt_getFlightRecorder(long tracePtr);
86
    private native long   ltt_getFreqScale(long tracePtr);
87
    private native long   ltt_getStartFreq(long tracePtr);
88
    private native long   ltt_getStartTimestampCurrentCounter(long tracePtr);
89
    private native long   ltt_getStartMonotonic(long tracePtr);
90
91
    // Native function to fill out startTime
92
    private native void ltt_feedStartTime(long tracePtr, JniTime startTime);
93
94
    // Native function to fill out startTimeFromTimestampCurrentCounter
95
    private native void ltt_feedStartTimeFromTimestampCurrentCounter(long tracePtr, JniTime startTime);
96
97
    // Native function to fill out tracefilesMap
98
    private native void ltt_getAllTracefiles(long tracePtr);
99
100
    // Debug native function, ask LTT to print trace structure
101
    private native void ltt_printTrace(long tracePtr);
102
103
    static {
104
        System.loadLibrary("lttvtraceread");
105
    }
106
        
107
    /**
108
     * Default constructor is forbidden
109
     */
110
    @SuppressWarnings("unused")
111
    private JniTrace() {
112
    }
113
114
    /**
115
     * Copy constructor.
116
     * 
117
     * @param oldTrace
118
     *            A reference to the JniTrace you want to copy.           
119
     */
120
    public JniTrace(JniTrace oldTrace) {
121
        thisTracePtr  = oldTrace.thisTracePtr;
122
        
123
        tracepath       = oldTrace.tracepath;
124
        cpuNumber       = oldTrace.cpuNumber;
125
        archType        = oldTrace.archType;
126
        archVariant     = oldTrace.archVariant;
127
        archSize        = oldTrace.archSize;
128
        lttMajorVersion = oldTrace.lttMajorVersion;
129
        lttMinorVersion = oldTrace.lttMinorVersion;
130
        flightRecorder  = oldTrace.flightRecorder;
131
        freqScale       = oldTrace.freqScale;
132
        startFreq       = oldTrace.startFreq;
133
        startTimestampCurrentCounter = oldTrace.startTimestampCurrentCounter;
134
        startMonotonic  = oldTrace.startMonotonic;
135
        startTime       = oldTrace.startTime;
136
        startTimeFromTimestampCurrentCounter = oldTrace.startTimeFromTimestampCurrentCounter;
137
138
        tracefilesMap = new HashMap<String, JniTracefile>(oldTrace.tracefilesMap.size());
139
        tracefilesMap = oldTrace.tracefilesMap;
140
        
141
        eventsHeap = new PriorityQueue<JniEvent>( oldTrace.eventsHeap.size(), eventComparator );
142
        eventsHeap = oldTrace.eventsHeap;
143
    }        
144
        
145
    /**
146
     * Copy constructor, using pointer.
147
     * 
148
     * @param newPtr The pointer to an already opened LttTrace C structure
149
     *            
150
     * @exception JniException
151
     */
152
    public JniTrace(C_Pointer newPtr) throws JniException {
153
        thisTracePtr = newPtr;
154
        
155
        // Populate our trace
156
        populateTraceInformation();
157
    }
158
        
159
    /**
160
     * Constructor that takes a tracepath parameter
161
     * <br>
162
     * This constructor also opens the trace
163
     * 
164
     * @param newpath The <b>directory</b> of the trace to be opened
165
     * 
166
     * @exception JniException
167
     */
168
    public JniTrace(String newpath) throws JniException {
169
        tracepath = newpath;
170
        thisTracePtr = new C_Pointer();
171
        
172
        openTrace(newpath);
173
    }
174
        
175
    /**
176
     * Open an existing trace<br>
177
     * <br>
178
     * The tracepath is a directory and needs to exist, otherwise
179
     * a JafOpenTraceFailedException is raised.
180
     * 
181
     * @param newPath
182
     *            The <b>directory</b> of the trace to be opened
183
     * @exception JafOpenTraceFailedException
184
     *                Thrown if the open failed
185
     */
186
    public void openTrace(String newPath) throws JniException {
187
        // If open is called while a trace is already opened, we will try to close it first
188
        if (thisTracePtr.getPointer() != NULL) {
189
            closeTrace();
190
        }
191
192
        // Set the tracepath and open it
193
        tracepath = newPath;
194
        openTrace();
195
    }
196
        
197
    /**
198
     * Open an existing trace<br>
199
     * <br>
200
     * The tracepath should have been set already,
201
     * 
202
     * @exception JafOpenTraceFailedException
203
     *                Thrown if the open failed
204
     */
205
    public void openTrace() throws JniException {
206
        
207
        // Raise an exception if the tracepath is empty, otherwise open the trace
208
        if (tracepath == "") {
209
            throw new JniTraceException("Tracepath is not set. (openTrace)");
210
        }
211
        
212
        // If the file is already opened, close it first
213
        if (thisTracePtr.getPointer() != NULL) {
214
            closeTrace();
215
        }
216
217
        // Call the LTT to open the trace
218
        long newPtr = ltt_openTrace(tracepath);
219
        if (newPtr == NULL) {
220
            throw new JniOpenTraceFailedException("Error while opening trace. Is the tracepath correct? (openTrace)");
221
        }
222
223
        // This is OUR pointer
224
        thisTracePtr = new C_Pointer(newPtr);
225
226
        // Populate the trace with LTT information
227
        populateTraceInformation();
228
    }
229
        
230
    /**
231
     * Close a trace
232
     * 
233
     * If the trace is already closed, will silently do nothing.
234
     */
235
    public void closeTrace() {
236
        if (thisTracePtr.getPointer() != NULL) {
237
            ltt_closeTrace(thisTracePtr.getPointer());
238
            thisTracePtr = new C_Pointer(NULL);
239
240
            // Clear the tracefile map
241
            tracefilesMap.clear();
242
            tracefilesMap = null;
243
            
244
            // Clear the eventsHeap and make it points to null
245
            eventsHeap.clear();
246
            eventsHeap = null;
247
248
            // Ask the garbage collector to make a little pass here, as we could
249
            // be left with 100's of unreferenced objects
250
            System.gc();
251
        }
252
    }
253
254
    /* 
255
     * This function populates the trace data with data from LTT
256
     * 
257
     * @throws JafException
258
     */
259
    private void populateTraceInformation() throws JniException {
260
        if (thisTracePtr.getPointer() == NULL) {
261
            throw new JniTraceException("Pointer is NULL, trace not opened/already closed? (populateTraceInformation)");
262
        }
263
264
        // Populate from the LTT library
265
        tracepath   = ltt_getTracepath( thisTracePtr.getPointer() );
266
        cpuNumber   = ltt_getCpuNumber( thisTracePtr.getPointer() );
267
        archType    = ltt_getArchType( thisTracePtr.getPointer() );
268
        archVariant = ltt_getArchVariant( thisTracePtr.getPointer() );
269
        archSize    = ltt_getArchSize( thisTracePtr.getPointer() );
270
        lttMajorVersion = ltt_getLttMajorVersion( thisTracePtr.getPointer() );
271
        lttMinorVersion = ltt_getLttMinorVersion( thisTracePtr.getPointer() );
272
        flightRecorder  = ltt_getFlightRecorder( thisTracePtr.getPointer() );
273
        freqScale   = ltt_getFreqScale( thisTracePtr.getPointer() );
274
        startFreq   = ltt_getStartFreq( thisTracePtr.getPointer() );
275
        startTimestampCurrentCounter = ltt_getStartTimestampCurrentCounter( thisTracePtr.getPointer() );
276
        startMonotonic = ltt_getStartMonotonic( thisTracePtr.getPointer() );
277
278
        // Creation of time is a bit different, we need to pass the object reference to C
279
        startTime = new JniTime();
280
        ltt_feedStartTime( thisTracePtr.getPointer(), startTime );
281
282
        startTimeFromTimestampCurrentCounter = new JniTime();
283
        ltt_feedStartTimeFromTimestampCurrentCounter( thisTracePtr.getPointer(), startTimeFromTimestampCurrentCounter );
284
285
        // Call the fill up function for the tracefiles map
286
        if ( tracefilesMap== null ) {
287
            tracefilesMap = new HashMap<String, JniTracefile>();
288
        }
289
        
290
        ltt_getAllTracefiles( thisTracePtr.getPointer() );
291
        
292
        if (eventsHeap == null) {
293
            eventsHeap = new PriorityQueue<JniEvent>(tracefilesMap.size(), eventComparator);
294
        }
295
        
296
        // Populate the heap with events
297
        populateEventHeap();
298
    }
299
    
300
    /* 
301
     * This function populates the event heap with one event from each tracefile
302
     * It should be called after each seek or when the object is constructed
303
     */
304
    private void populateEventHeap() {
305
        currentEventTimestamp = new JniTime();
306
        eventsHeap.clear();
307
        
308
        Object new_key = null;
309
        JniTracefile tmpTracefile = null;
310
        
311
        Iterator<String> iterator = tracefilesMap.keySet().iterator();
312
        while( iterator.hasNext() ) {
313
            new_key = iterator.next();
314
            
315
            tmpTracefile = tracefilesMap.get(new_key);
316
            if ( tmpTracefile.getCurrentEvent().getEventState() == EOK ) {
317
                eventsHeap.add( tmpTracefile.getCurrentEvent() );
318
            }
319
        }
320
    }
321
322
    /* 
323
     * Fills a map of all the trace files.
324
     * 
325
     * Note: This function is called from C and there is no way to propagate
326
     * exception back to the caller without crashing JNI. Therefore, it MUST
327
     * catch all exceptions.
328
     * 
329
     * @param tracefileName
330
     * @param tracefilePtr
331
     */
332
    @SuppressWarnings("unused")
333
    private void addTracefileFromC(String tracefileName, long tracefilePtr) {
334
        // Create a new tracefile object and insert it in the map
335
        //    the tracefile fill itself with LTT data while being constructed
336
        try {
337
            JniTracefile newTracefile = new JniTracefile( new C_Pointer(tracefilePtr), this );
338
            tracefilesMap.put(tracefileName, newTracefile);
339
        }
340
        catch(JniTracefileWithoutEventException e) {
341
            printlnC("JniTracefile " + tracefileName + " has no event (addTracefileFromC). Ignoring.");
342
        }
343
        catch(Exception e) {
344
            printlnC("Failed to add tracefile " + tracefileName + " to tracefilesMap!(addTracefileFromC)\n\tException raised : " + e.toString() );
345
        }
346
    }
347
        
348
        
349
    /**
350
     * Return the next event, determined by timestamp, among the trace files.
351
     * The event content is populated.
352
     *  
353
     * Returns  null in case of error or if we reach end of trace.
354
     * 
355
     * @return The next event in the trace or null
356
     * @see org.eclipse.linuxtools.lttng.jni.JniEvent
357
     */
358
    public JniEvent readNextEvent() {
359
        // Get the "next" event on the top of the heap but DO NOT remove it
360
        JniEvent tmpEvent = eventsHeap.peek();
361
        
362
        // If the event is null, it was the last one in the trace we can leave the function
363
        if (tmpEvent == null) {
364
            return null;
365
        }
366
        
367
        // Otherwise, we need to make sure the timestamp of the event we got is not the same as the last "NextEvent" we requested 
368
        if (tmpEvent.getEventTime().getTime() == currentEventTimestamp.getTime() ) {
369
            // Remove the event on top as it is the same currentEventTimestamp
370
            eventsHeap.poll();
371
            
372
            // Read the next event for this particular event type
373
            tmpEvent.readNextEvent();
374
            
375
            // If the event state is sane (not Out of Range), put it back in the heap
376
            if ( tmpEvent.getEventState() == EOK ) {
377
                eventsHeap.add(tmpEvent);
378
            }
379
            
380
            // Pick the top event again
381
            tmpEvent = eventsHeap.peek();
382
            
383
            // Save the timestamp if the event is not null (null mean we reached the last event in the trace)
384
            if (tmpEvent != null) {
385
                currentEventTimestamp = tmpEvent.getEventTime();
386
            }
387
        }
388
        // If the event on top has differetn timestamp than the currentTimestamp, just save this timestamp as current
389
        else {
390
            currentEventTimestamp = tmpEvent.getEventTime();
391
        }
392
            
393
        return tmpEvent;
394
    }
395
    
396
    /**
397
     * Return the next event, determined by timestamp, among the trace files.
398
     * The event content is NOT populated (requires a call to readNextEvent()).
399
     *  
400
     * Returns null in case of error or EOF.
401
     * 
402
     * @return The next event, or null if none is available
403
     * @see org.eclipse.linuxtools.lttng.jni.JniEvent
404
     */
405
    public JniEvent findNextEvent() {
406
        return eventsHeap.peek();
407
    }
408
    
409
    /**
410
     * Seek to a certain time and read the next event from that time.<br>
411
     * <br>
412
     * If no more events are available or an error happen, null will be returned
413
     * 
414
     * @param seekTime  The time where we want to seek to
415
     * @return JniEvent    The next event after the seek time or null
416
     * 
417
     * @see org.eclipse.linuxtools.lttng.jni.JniEvent
418
     */
419
     public JniEvent seekAndRead(JniTime seekTime) { 
420
          JniEvent returnedEvent = null;
421
          seekToTime(seekTime);
422
              
423
          // The trace should be correctly positionned, let's get the event
424
          returnedEvent = readNextEvent();
425
               
426
          return returnedEvent;
427
     }
428
    
429
     /**
430
      * Seek to a certain time but <b>do not</b> read the next event.<br>
431
      * <br>
432
      * This only position the trace, it will not return anything.
433
      * 
434
      * @param seekTime     The time where we want to seek to
435
      */
436
      public void seekToTime(JniTime seekTime) {
437
           Object tracefile_name = null;
438
           Iterator<String> iterator = tracefilesMap.keySet().iterator();
439
           
440
           while (iterator.hasNext() ) {
441
               // We seek to the given event for ALL tracefiles
442
               tracefile_name = iterator.next();
443
               tracefilesMap.get(tracefile_name).seekToTime(seekTime);
444
           }
445
           
446
           populateEventHeap();
447
      }
448
     
449
    /**
450
     * Get a certain tracefile from its given name<br>
451
     * 
452
     * @param tracefileName The name of the tracefile
453
     * @return JniTracefile The tracefile found or null if none
454
     * @see org.eclipse.linuxtools.lttng.jni.JniTracefile
455
     */
456
    public JniTracefile requestTracefileByName(String tracefileName) {
457
        return tracefilesMap.get(tracefileName);
458
    }        
459
        
460
    /**
461
     * Get a certain event associated to a trace file from the trace file name<br>
462
     * 
463
     * @param tracefileName The name of the trace file
464
     * @return The JniEvent found or null if none
465
     * @see org.eclipse.linuxtools.lttng.jni.JniEvent
466
     */
467
    public JniEvent requestEventByName(String tracefileName) {
468
        JniEvent returnValue = null;
469
470
        JniTracefile tmpTracefile = tracefilesMap.get(tracefileName);
471
472
        // If the tracefile is found, return the current event
473
        // There should always be an event linked to a tracefile
474
        if (tmpTracefile != null) {
475
            returnValue = tmpTracefile.getCurrentEvent();
476
        }
477
478
        return returnValue;
479
    }   
480
        
481
    // Access to class variable. Most of them doesn't have setter
482
    public String getTracepath() {
483
        return tracepath;
484
    }
485
486
    public int getCpuNumber() {
487
        return cpuNumber;
488
    }
489
490
    public long getArchType() {
491
        return archType;
492
    }
493
494
    public long getArchVariant() {
495
        return archVariant;
496
    }
497
498
    public short getArchSize() {
499
        return archSize;
500
    }
501
502
    public short getLttMajorVersion() {
503
        return lttMajorVersion;
504
    }
505
506
    public short getLttMinorVersion() {
507
        return lttMinorVersion;
508
    }
509
510
    public short getFlightRecorder() {
511
        return flightRecorder;
512
    }
513
514
    public long getFreqScale() {
515
        return freqScale;
516
    }
517
518
    public long getStartFreq() {
519
        return startFreq;
520
    }
521
522
    public long getStartTimestampCurrentCounter() {
523
        return startTimestampCurrentCounter;
524
    }
525
526
    public long getStartMonotonic() {
527
        return startMonotonic;
528
    }
529
530
    public JniTime getStartTime() {
531
        return startTime;
532
    }
533
534
    public JniTime getStartTimeFromTimestampCurrentCounter() {
535
        return startTimeFromTimestampCurrentCounter;
536
    }
537
538
    public HashMap<String, JniTracefile> getTracefilesMap() {
539
        return tracefilesMap;
540
    }        
541
    
542
    /**
543
     * Getter for the last read event timestamp<br>
544
     * 
545
     * @return The time of the last event read
546
     */
547
    public JniTime getCurrentEventTimestamp() {
548
        return currentEventTimestamp;
549
    }
550
    
551
    /**
552
     * Pointer to the LttTrace C structure<br>
553
     * <br>
554
     * The pointer should only be used INTERNALY, do not use these unless you
555
     * know what you are doing.
556
     * 
557
     * @return The actual (long converted) pointer or NULL
558
     */
559
    public C_Pointer getTracePtr() {
560
        return thisTracePtr;
561
    }        
562
        
563
    /**
564
     * Print information for all the tracefiles associated with this trace.
565
     * <u>Intended to debug</u><br>
566
     * 
567
     * This function will call Ltt to print, so information printed will be the
568
     * one from the C structure
569
     * 
570
     * @see org.eclipse.linuxtools.lttng.jni.JniTracefile
571
     */
572
    public void printAllTracefilesInformation() {
573
574
        Object new_key = null;
575
        JniTracefile tracefile;
576
577
        Iterator<String> iterator = tracefilesMap.keySet().iterator();
578
        while (iterator.hasNext()) {
579
            new_key = iterator.next();
580
581
            tracefile = tracefilesMap.get(new_key);
582
583
            tracefile.printTracefileInformation();
584
        }
585
    }        
586
        
587
    /**
588
     * Print information for this trace. <u>Intended to debug</u><br>
589
     * 
590
     * This function will call Ltt to print, so information printed will be the
591
     * one from the C structure<br>
592
     * <br>
593
     * This function will not throw but will complain loudly if pointer is NULL
594
     */
595
    public void printTraceInformation() {
596
597
        // If null pointer, print a warning!
598
        if (thisTracePtr.getPointer() == NULL) {
599
            printlnC("Pointer is NULL, cannot print. (printTraceInformation)");
600
        } else {
601
            ltt_printTrace( thisTracePtr.getPointer() );
602
        }
603
    }
604
        
605
    /**
606
     * toString() method. <u>Intended to debug</u><br>
607
     * 
608
     * @return String Attributes of the object concatenated in String
609
     */
610
    public String toString() {
611
        String returnData = "";
612
        returnData += "tracepath                            : " + tracepath + "\n";
613
        returnData += "cpuNumber                            : " + cpuNumber + "\n";
614
        returnData += "archType                             : " + archType + "\n";
615
        returnData += "archVariant                          : " + archVariant + "\n";
616
        returnData += "archSize                             : " + archSize + "\n";
617
        returnData += "lttMajorVersion                      : " + lttMajorVersion + "\n";
618
        returnData += "lttMinorVersion                      : " + lttMinorVersion + "\n";
619
        returnData += "flightRecorder                       : " + flightRecorder + "\n";
620
        returnData += "freqScale                            : " + freqScale + "\n";
621
        returnData += "startFreq                            : " + startFreq + "\n";
622
        returnData += "startTimestampCurrentCounter         : " + startTimestampCurrentCounter + "\n";
623
        returnData += "startMonotonic                       : " + startMonotonic + "\n";
624
        returnData += "startTime                            : " + startTime.getReferenceToString() + "\n";
625
        returnData += "   seconds                           : " + startTime.getSeconds() + "\n";
626
        returnData += "   nanoSeconds                       : " + startTime.getNanoSeconds() + "\n";
627
        returnData += "startTimeFromTimestampCurrentCounter : " + startTimeFromTimestampCurrentCounter.getReferenceToString() + "\n";
628
        returnData += "   seconds                           : " + startTimeFromTimestampCurrentCounter.getSeconds() + "\n";
629
        returnData += "   nanoSeconds                       : " + startTimeFromTimestampCurrentCounter.getNanoSeconds() + "\n";
630
        returnData += "tracefilesMap                        : " + tracefilesMap.keySet() + "\n";      // Hack to avoid ending up with tracefilesMap.toString()
631
632
        return returnData;
633
    }
634
     
635
     /* 
636
     *  MAIN : For testing only!
637
     */
638
     public static void main(String[] args) {
639
         JniTrace testTrace = null;
640
         JniEvent tmpEvent = null;
641
         
642
         try {
643
             testTrace = new JniTrace("/home/william/trace1");
644
         }
645
         catch (JniException e) {
646
             System.out.println(e.getMessage() );
647
             return;
648
         }
649
         
650
         
651
         testTrace.printlnC( testTrace.toString() );
652
         
653
         long nbEvent = 0;
654
         
655
         testTrace.printlnC("Beginning test run on 600k events");
656
         tmpEvent = testTrace.readNextEvent();
657
         while (tmpEvent != null) {
658
             nbEvent++;
659
             tmpEvent = testTrace.readNextEvent();
660
             
661
             if ( tmpEvent != null ) {
662
                 tmpEvent.parseAllFields();
663
             }
664
         }
665
         testTrace.printlnC("We read " + nbEvent + " total events (JAF)\n");
666
         
667
         
668
         /*
669
         
670
         tmpEvent = testTrace.readNextEvent();
671
         
672
         JniTime test_time = new JniTime(960386633737L);
673
         tmpEvent = testTrace.seekAndRead(test_time);
674
         
675
         testTrace.printlnC(tmpEvent.getParentTracefile().getTracefileName().toString() );
676
         testTrace.printlnC(tmpEvent.toString() );
677
         
678
         
679
         test_time = new JniTime(960386638531L);
680
         tmpEvent = testTrace.seekAndRead(test_time);
681
         
682
         testTrace.printlnC(tmpEvent.getParentTracefile().getTracefileName().toString() );
683
         testTrace.printlnC(tmpEvent.toString() );
684
         
685
         
686
         tmpEvent = testTrace.readNextEvent();
687
         if ( tmpEvent == null ) {
688
             testTrace.printlnC("NULL NULL NULL1");
689
         }
690
         else {
691
             testTrace.printlnC(tmpEvent.getParentTracefile().getTracefileName().toString() );
692
             testTrace.printlnC(tmpEvent.toString() );
693
         }
694
         
695
         tmpEvent = testTrace.readNextEvent();
696
         if ( tmpEvent == null ) {
697
             testTrace.printlnC("NULL NULL NULL2");
698
         }
699
         else {
700
             testTrace.printlnC(tmpEvent.getParentTracefile().getTracefileName().toString() );
701
             testTrace.printlnC(tmpEvent.toString() );
702
         }
703
         */
704
         
705
         
706
         
707
         
708
         
709
         
710
         /*
711
         testTrace.printlnC("Beginning test run seek time");        
712
         JniTime test_time = new JniTime(953, 977711854);
713
         testTrace.seekToTime(test_time);
714
         tmpEvent = testTrace.findNextEvent();
715
         testTrace.printlnC(tmpEvent.toString() );
716
         */
717
         
718
         /*
719
         testTrace.printlnC("Beginning test run parsing event"); 
720
         Object[] parsedName = null;
721
         HashMap<String,Object> parsedData = null;
722
         for ( int x = 0; x<30; x++) {
723
             tmpEvent = testTrace.readNextEvent();
724
                 
725
             testTrace.printlnC(tmpEvent.getParentTracefile().getTracefileName().toString() );
726
             testTrace.printC(tmpEvent.toString() );
727
                 
728
             testTrace.printlnC("Format                  : " + tmpEvent.requestEventMarker().getFormatOverview().toString() );
729
             parsedData = tmpEvent.parse();
730
             parsedName = parsedData.keySet().toArray();
731
             
732
             testTrace.printC("                          ");
733
             for ( int pos=0; pos<parsedName.length; pos++) {
734
                 testTrace.printC( parsedName[pos].toString() + " " + parsedData.get(parsedName[pos]).toString() + " ");
735
             }
736
             testTrace.printlnC("\n");
737
         }*/
738
         
739
     }
740
     
741
}
0
  + text/plain
742
  + text/plain
(-)src/org/eclipse/linuxtools/lttng/jni/JniTracefile.java (+445 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 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
 *   William Bourque (wbourque@gmail.com) - Initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.linuxtools.lttng.jni;
14
15
import java.util.HashMap;
16
17
/**
18
 * <b><u>JniTracefile</u></b>
19
 * <p>
20
 * A tracefile own an event of a certain type
21
 * It provides access to the LttTracefile C structure in java.
22
 * <p>
23
 * Most important fields in the JniTracefile are :
24
 * <ul>
25
 * <li> a JniTracefile path (a tracefile <b>file</b> with a JniTrace directory)
26
 * <li> a name (basically the name without the directory part)
27
 * <li> a reference to a single event object
28
 * <li> a HashMap of marker associated with this tracefile
29
 * </ul>
30
 */
31
public final class JniTracefile extends Jni_C_Common {
32
        
33
    // Internal C pointer of the JniTracefile used in LTT
34
    private C_Pointer thisTracefilePtr = new C_Pointer();
35
    
36
    // Reference to the parent trace
37
    private JniTrace parentTrace = null;
38
    
39
    // Data we should populate from LTT
40
    // Note that all type have been scaled up as there is no "unsigned" in java
41
    // This might be a problem about "unsigned long" as there is no equivalent in java
42
    private boolean isCpuOnline = false;
43
    private String  tracefilePath = "";
44
    private String  tracefileName = "";
45
    private long    cpuNumber = 0;
46
    private long    tid = 0;
47
    private long    pgid = 0;
48
    private long    creation = 0;
49
    private long    tracePtr = 0;
50
    private long    markerDataPtr = 0;
51
    private int     CFileDescriptor = 0;
52
    private long    fileSize = 0;
53
    private long    blocksNumber = 0;
54
    private boolean isBytesOrderReversed = false;
55
    private boolean isFloatWordOrdered = false;
56
    private long    alignement = 0;
57
    private long    bufferHeaderSize = 0;
58
    private int     bitsOfCurrentTimestampCounter = 0;
59
    private int     bitsOfEvent = 0;
60
    private long    currentTimestampCounterMask = 0;
61
    private long    currentTimestampCounterMaskNextBit = 0;
62
    private long    eventsLost = 0;
63
    private long    subBufferCorrupt = 0;
64
    private JniEvent   currentEvent = null;
65
    private long    bufferPtr = NULL;
66
    private long    bufferSize = 0;
67
68
    // This map will hold markers_info owned by this tracefile
69
    private HashMap<Integer, JniMarker> tracefileMarkersMap;        
70
71
    // Native access functions
72
    private native boolean  ltt_getIsCpuOnline(long tracefilePtr);
73
    private native String   ltt_getTracefilepath(long tracefilePtr);
74
    private native String   ltt_getTracefilename(long tracefilePtr);
75
    private native long     ltt_getCpuNumber(long tracefilePtr);
76
    private native long     ltt_getTid(long tracefilePtr);
77
    private native long     ltt_getPgid(long tracefilePtr);
78
    private native long     ltt_getCreation(long tracefilePtr);
79
    private native long     ltt_getTracePtr(long tracefilePtr);
80
    private native long     ltt_getMarkerDataPtr(long tracefilePtr);
81
    private native int      ltt_getCFileDescriptor(long tracefilePtr);
82
    private native long     ltt_getFileSize(long tracefilePtr);
83
    private native long     ltt_getBlockNumber(long tracefilePtr);
84
    private native boolean  ltt_getIsBytesOrderReversed(long tracefilePtr);
85
    private native boolean  ltt_getIsFloatWordOrdered(long tracefilePtr);
86
    private native long     ltt_getAlignement(long tracefilePtr);
87
    private native long     ltt_getBufferHeaderSize(long tracefilePtr);
88
    private native int      ltt_getBitsOfCurrentTimestampCounter(long tracefilePtr);
89
    private native int      ltt_getBitsOfEvent(long tracefilePtr);
90
    private native long     ltt_getCurrentTimestampCounterMask(long tracefilePtr);
91
    private native long     ltt_getCurrentTimestampCounterMaskNextBit(long tracefilePtr);
92
    private native long     ltt_getEventsLost(long tracefilePtr);
93
    private native long     ltt_getSubBufferCorrupt(long tracefilePtr);
94
    private native long     ltt_getEventPtr(long tracefilePtr);
95
    private native long     ltt_getBufferPtr(long tracefilePtr);
96
    private native long     ltt_getBufferSize(long tracefilePtr);
97
98
    // Method to fill a map with marker object
99
    private native void ltt_getAllMarkers(long tracefilePtr);
100
101
    // Debug native function, ask LTT to print tracefile structure
102
    private native void ltt_printTracefile(long tracefilePtr);
103
104
    static {
105
        System.loadLibrary("lttvtraceread");
106
    }
107
        
108
    /**
109
     * Default constructor is forbidden
110
     */
111
    @SuppressWarnings("unused")
112
    private JniTracefile() {
113
    };
114
115
    /**
116
     * Copy constructor.
117
     * 
118
     * @param oldTracefile
119
     *            A reference to the JniTracefile you want to copy. 
120
     */
121
    public JniTracefile(JniTracefile oldTracefile) {
122
        thisTracefilePtr    = oldTracefile.thisTracefilePtr;
123
        parentTrace         = oldTracefile.parentTrace;
124
        tracefileMarkersMap = oldTracefile.tracefileMarkersMap;
125
126
        isCpuOnline         = oldTracefile.isCpuOnline;
127
        tracefilePath       = oldTracefile.tracefilePath;
128
        tracefileName       = oldTracefile.tracefileName;
129
        cpuNumber           = oldTracefile.cpuNumber;
130
        tid                 = oldTracefile.tid;
131
        pgid                = oldTracefile.pgid;
132
        creation            = oldTracefile.creation;
133
        tracePtr            = oldTracefile.tracePtr;
134
        markerDataPtr       = oldTracefile.markerDataPtr;
135
        CFileDescriptor     = oldTracefile.CFileDescriptor;
136
        fileSize            = oldTracefile.fileSize;
137
        blocksNumber        = oldTracefile.blocksNumber;
138
        isBytesOrderReversed = oldTracefile.isBytesOrderReversed;
139
        isFloatWordOrdered  = oldTracefile.isFloatWordOrdered;
140
        alignement          = oldTracefile.alignement;
141
        bufferHeaderSize    = oldTracefile.bufferHeaderSize;
142
        bitsOfCurrentTimestampCounter = oldTracefile.bitsOfCurrentTimestampCounter;
143
        bitsOfEvent         = oldTracefile.bitsOfEvent;
144
        currentTimestampCounterMask = oldTracefile.currentTimestampCounterMask;
145
        currentTimestampCounterMaskNextBit = oldTracefile.currentTimestampCounterMaskNextBit;
146
        eventsLost          = oldTracefile.eventsLost;
147
        subBufferCorrupt    = oldTracefile.subBufferCorrupt;
148
        currentEvent        = oldTracefile.currentEvent;
149
        bufferPtr           = oldTracefile.bufferPtr;
150
        bufferSize          = oldTracefile.bufferSize;
151
    }
152
153
    /**
154
     * Copy constructor, using pointer.
155
     * 
156
     * @param newPtr  The pointer to an already opened LttTracefile C Structure
157
     * 
158
     * @exception JniException
159
     */
160
    public JniTracefile(C_Pointer newPtr, JniTrace newParentTrace) throws JniException {
161
        thisTracefilePtr = newPtr;
162
        parentTrace = newParentTrace;
163
        tracefileMarkersMap = new HashMap<Integer, JniMarker>();
164
165
        // Retrieve the trace file information and load the first event.
166
        try {
167
            populateTracefileInformation();
168
        } catch (JniNoSuchEventException e) {
169
            throw new JniTracefileWithoutEventException(
170
                    "JniEvent constructor reported that no event of this type are usable. (Jaf_Tracefile)");
171
        }
172
    }        
173
174
    /**
175
     * Move the current event to the next one.
176
     * 
177
     * @return The read status, as defined in Jni_C_Common
178
     * @see org.eclipse.linuxtools.lttng.jni.Jni_C_Common
179
     */
180
    public int readNextEvent() {
181
        return currentEvent.readNextEvent();
182
    }        
183
184
    /**
185
     * Move the current event to the time given.<br>
186
     * 
187
     * @param seekTime JniTime where to seek to
188
     * @return The read status, as defined in Jni_C_Common
189
     * @see org.eclipse.linuxtools.lttng.jni.Jni_C_Common
190
     */
191
    public int seekToTime(JniTime seekTime) {
192
        return currentEvent.seekToTime(seekTime);
193
    }
194
195
    /* 
196
     * This function populates the tracefile data with data from LTT
197
     * 
198
     * @throws JafException
199
     */
200
    private void populateTracefileInformation() throws JniException {
201
        if (thisTracefilePtr.getPointer() == NULL) {
202
            throw new JniTracefileException(
203
                    "Pointer is NULL, trace closed? (populateTracefileInformation)");
204
        }
205
206
        isCpuOnline = ltt_getIsCpuOnline( thisTracefilePtr.getPointer() );
207
        tracefilePath = ltt_getTracefilepath( thisTracefilePtr.getPointer() );
208
        tracefileName = ltt_getTracefilename( thisTracefilePtr.getPointer() );
209
        cpuNumber = ltt_getCpuNumber( thisTracefilePtr.getPointer() );
210
        tid = ltt_getTid( thisTracefilePtr.getPointer() );
211
        pgid = ltt_getPgid( thisTracefilePtr.getPointer() );
212
        creation = ltt_getCreation( thisTracefilePtr.getPointer() );
213
        tracePtr = ltt_getTracePtr( thisTracefilePtr.getPointer() );
214
        markerDataPtr = ltt_getMarkerDataPtr( thisTracefilePtr.getPointer() );
215
        CFileDescriptor = ltt_getCFileDescriptor( thisTracefilePtr.getPointer() );
216
        fileSize = ltt_getFileSize( thisTracefilePtr.getPointer() );
217
        blocksNumber = ltt_getBlockNumber( thisTracefilePtr.getPointer() );
218
        isBytesOrderReversed = ltt_getIsBytesOrderReversed( thisTracefilePtr.getPointer() );
219
        isFloatWordOrdered = ltt_getIsFloatWordOrdered( thisTracefilePtr.getPointer() );
220
        alignement = ltt_getAlignement( thisTracefilePtr.getPointer() );
221
        bufferHeaderSize = ltt_getBufferHeaderSize( thisTracefilePtr.getPointer() );
222
        bitsOfCurrentTimestampCounter = ltt_getBitsOfCurrentTimestampCounter( thisTracefilePtr.getPointer() );
223
        bitsOfEvent = ltt_getBitsOfEvent( thisTracefilePtr.getPointer() );
224
        currentTimestampCounterMask = ltt_getCurrentTimestampCounterMask( thisTracefilePtr.getPointer() );
225
        currentTimestampCounterMaskNextBit = ltt_getCurrentTimestampCounterMaskNextBit( thisTracefilePtr.getPointer() );
226
        eventsLost = ltt_getEventsLost( thisTracefilePtr.getPointer() );
227
        subBufferCorrupt = ltt_getSubBufferCorrupt( thisTracefilePtr.getPointer() );
228
        bufferPtr = ltt_getBufferPtr( thisTracefilePtr.getPointer() );
229
        bufferSize = ltt_getBufferSize( thisTracefilePtr.getPointer() );
230
231
        // To fill the map is a bit different
232
        ltt_getAllMarkers( thisTracefilePtr.getPointer() );
233
234
        C_Pointer tmpEventPointer = new C_Pointer(ltt_getEventPtr(thisTracefilePtr.getPointer()));
235
        currentEvent = new JniEvent(tmpEventPointer , tracefileMarkersMap, this);
236
    }        
237
    
238
    /* 
239
     * Fills a map of all the markers associated with this tracefile.
240
     * 
241
     * Note: This function is called from C and there is no way to propagate
242
     * exception back to the caller without crashing JNI. Therefore, it MUST
243
     * catch all exceptions.
244
     * 
245
     * @param markerId          Id of the marker (int)
246
     * @param markerInfoPtr     C Pointer to a marker_info C structure 
247
     */
248
    @SuppressWarnings("unused")
249
    private void addMarkersFromC(int markerId, long markerInfoPtr) {
250
        // Create a new tracefile object and insert it in the map
251
        // the tracefile fill itself with LTT data while being constructed
252
        try {
253
            JniMarker newMarker = new JniMarker( new C_Pointer(markerInfoPtr) );
254
255
            tracefileMarkersMap.put(markerId, newMarker);
256
        } catch (Exception e) {
257
            printlnC("Failed to add marker to tracefileMarkersMap!(addMarkersFromC)\n\tException raised : " + e.toString());
258
        }
259
    }        
260
261
    // Access to class variable. Most of them doesn't have setter
262
    public boolean getIsCpuOnline() {
263
        return isCpuOnline;
264
    }
265
266
    public String getTracefilePath() {
267
        return tracefilePath;
268
    }
269
270
    public String getTracefileName() {
271
        return tracefileName;
272
    }
273
274
    public long getCpuNumber() {
275
        return cpuNumber;
276
    }
277
278
    public long getTid() {
279
        return tid;
280
    }
281
282
    public long getPgid() {
283
        return pgid;
284
    }
285
286
    public long getCreation() {
287
        return creation;
288
    }
289
290
    public long getTracePtr() {
291
        return tracePtr;
292
    }
293
294
    public long getMarkerDataPtr() {
295
        return markerDataPtr;
296
    }
297
298
    public int getCFileDescriptor() {
299
        return CFileDescriptor;
300
    }
301
302
    public long getFileSize() {
303
        return fileSize;
304
    }
305
306
    public long getBlocksNumber() {
307
        return blocksNumber;
308
    }
309
310
    public boolean getIsBytesOrderReversed() {
311
        return isBytesOrderReversed;
312
    }
313
314
    public boolean getIsFloatWordOrdered() {
315
        return isFloatWordOrdered;
316
    }
317
318
    public long getAlignement() {
319
        return alignement;
320
    }
321
322
    public long getBufferHeaderSize() {
323
        return bufferHeaderSize;
324
    }
325
326
    public int getBitsOfCurrentTimestampCounter() {
327
        return bitsOfCurrentTimestampCounter;
328
    }
329
330
    public int getBitsOfEvent() {
331
        return bitsOfEvent;
332
    }
333
334
    public long getCurrentTimestampCounterMask() {
335
        return currentTimestampCounterMask;
336
    }
337
338
    public long getCurrentTimestampCounterMaskNextBit() {
339
        return currentTimestampCounterMaskNextBit;
340
    }
341
342
    public long getEventsLost() {
343
        return eventsLost;
344
    }
345
346
    public long getSubBufferCorrupt() {
347
        return subBufferCorrupt;
348
    }
349
350
    public JniEvent getCurrentEvent() {
351
        return currentEvent;
352
    }
353
354
    public long getBufferPtr() {
355
        return bufferPtr;
356
    }
357
358
    public long getBufferSize() {
359
        return bufferSize;
360
    }
361
362
    public HashMap<Integer, JniMarker> getTracefileMarkersMap() {
363
        return tracefileMarkersMap;
364
    }
365
366
    /**
367
     * Getter to the parent trace for this tracefile.
368
     *
369
     * 
370
     * @return  the parent trace
371
     * @see org.eclipse.linuxtools.lttng.jni.JniTrace
372
     */
373
    public JniTrace getParentTrace() {
374
        return parentTrace;
375
    }
376
    
377
    /**
378
     * Pointer to the LttTracefile C structure<br>
379
     * <br>
380
     * The pointer should only be used INTERNALY, do not use these unless you
381
     * know what you are doing.
382
     * 
383
     * @return The actual (long converted) pointer or NULL
384
     */
385
    public C_Pointer getTracefilePtr() {
386
        return thisTracefilePtr;
387
    }
388
389
    /**
390
     * toString() method. <u>Intended to debug</u><br>
391
     * 
392
     * @return String Attributes of the object concatenated in String
393
     */
394
    public String toString() {
395
        String returnData = "";
396
                
397
        returnData += "isCpuOnline                        : " + isCpuOnline + "\n";
398
        returnData += "tracefilePath                      : " + tracefilePath + "\n";
399
        returnData += "tracefileName                      : " + tracefileName + "\n";
400
        returnData += "cpuNumber                          : " + cpuNumber + "\n";
401
        returnData += "tid                                : " + tid + "\n";
402
        returnData += "pgid                               : " + pgid + "\n";
403
        returnData += "creation                           : " + creation + "\n";
404
        returnData += "tracePtr                           : 0x" + java.lang.Long.toHexString(tracePtr) + "\n";
405
        returnData += "markerDataPtr                      : 0x" + java.lang.Long.toHexString(markerDataPtr) + "\n";
406
        returnData += "CFileDescriptor                    : " + CFileDescriptor + "\n";
407
        returnData += "fileSize                           : " + fileSize + "\n";
408
        returnData += "blocksNumber                       : " + blocksNumber + "\n";
409
        returnData += "isBytesOrderReversed               : " + isBytesOrderReversed + "\n";
410
        returnData += "isFloatWordOrdered                 : " + isFloatWordOrdered + "\n";
411
        returnData += "alignement                         : " + alignement + "\n";
412
        returnData += "bufferHeaderSize                   : " + bufferHeaderSize + "\n";
413
        returnData += "bitsOfCurrentTimestampCounter      : " + bitsOfCurrentTimestampCounter + "\n";
414
        returnData += "bitsOfEvent                        : " + bitsOfEvent + "\n";
415
        returnData += "currentTimestampCounterMask        : " + currentTimestampCounterMask + "\n";
416
        returnData += "currentTimestampCounterMaskNextBit : " + currentTimestampCounterMaskNextBit + "\n";
417
        returnData += "eventsLost                         : " + eventsLost + "\n";
418
        returnData += "subBufferCorrupt                   : " + subBufferCorrupt + "\n";
419
        returnData += "currentEvent                       : " + currentEvent.getReferenceToString() + "\n"; // Hack to avoid ending up with event.toString()
420
        returnData += "bufferPtr                          : 0x" + java.lang.Long.toHexString(bufferPtr) + "\n";
421
        returnData += "bufferSize                         : " + bufferSize + "\n";
422
        returnData += "tracefileMarkersMap                : " + tracefileMarkersMap.keySet() + "\n"; // Hack to avoid ending up with tracefileMarkersMap.toString()
423
424
        return returnData;
425
    }
426
427
    /**
428
     * Print information for this tracefile. <u>Intended to debug</u><br>
429
     * 
430
     * This function will call Ltt to print, so information printed will be the
431
     * one from the C structure<br>
432
     * <br>
433
     * This function will not throw but will complain loudly if pointer is NULL
434
     */
435
    public void printTracefileInformation() {
436
437
        // If null pointer, print a warning!
438
        if (thisTracefilePtr.getPointer() == NULL) {
439
            printlnC("Pointer is NULL, cannot print. (printTracefileInformation)");
440
        } else {
441
            ltt_printTracefile( thisTracefilePtr.getPointer() );
442
        }
443
    }
444
}
445
0
  + text/plain
446
  + text/plain
(-)src/org/eclipse/linuxtools/lttng/jni/JniEvent.java (+433 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 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
 *   William Bourque (wbourque@gmail.com) - Initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.linuxtools.lttng.jni;
14
15
import java.util.HashMap;
16
17
/**
18
 * <b><u>JniEvent</u></b>
19
 * <p>
20
 * A JniEvent has the actual content that got traced by Lttng It provides access to the LttEvent C structure in java.
21
 * <p>
22
 * Most important fields in the JniEvent are :
23
 * <ul>
24
 * <li>an event time, which is a digested timestamp
25
 * </ul>
26
 * Note that the JniEvent content is not directly accessibe and should be obtained
27
 * using the requestEventContent() or parse() method.
28
 */
29
public final class JniEvent extends Jni_C_Common {
30
    // Variables to detect if the event have been filled at least once
31
    // this make possible the detection of "uninitialized" struct in Ltt
32
    // Can be "EOK", "ERANGE" or "EPERM" (defined in Jaf_C_Common)
33
    private int eventState = EPERM; // Start with EPERM to ensure sanity
34
35
    // Internal C pointer of the JniEvent used in LTT
36
    private C_Pointer thisEventPtr = new C_Pointer();
37
38
    // Reference to the parent tracefile
39
    private JniTracefile parentTracefile = null;
40
41
    // This map hold marker relative to the parent tracefile of this event
42
    // They are "our" marker in this event
43
    private HashMap<Integer, JniMarker> markersMap;
44
45
    // Data we should populate from ltt
46
    // Note that all type have been scaled up as there is no "unsigned" in java
47
    // This might be a problem about "unsigned long" as there is no equivalent
48
    // in java
49
    private C_Pointer tracefilePtr = new C_Pointer();;
50
    private int eventMarkerId = 0;
51
    private JniTime eventTime = null;
52
    private long eventDataSize = 0;
53
54
    // These methods need a tracefile pointer, instead of a event pointer
55
    private native int      ltt_readNextEvent(long tracefilePtr);
56
    private native int      ltt_seekEvent(long tracefilePtr, JniTime givenTime);
57
    private native int      ltt_positionToFirstEvent(long tracefilePtr);
58
        
59
    // Native access functions
60
    private native long     ltt_getTracefilePtr(long eventPtr);
61
    @SuppressWarnings("unused")
62
    private native long     ltt_getBlock(long eventPtr);
63
    @SuppressWarnings("unused")
64
    private native long     ltt_getOffset(long eventPtr);
65
    @SuppressWarnings("unused")
66
    private native long     ltt_getCurrentTimestampCounter(long eventPtr);
67
    @SuppressWarnings("unused")
68
    private native long     ltt_getTimestamp(long eventPtr);
69
    private native int      ltt_getEventMarkerId(long eventPtr);
70
    private native void     ltt_feedEventTime(long eventPtr, JniTime eventTime);
71
    private native long     ltt_getEventDataSize(long eventPtr);
72
    @SuppressWarnings("unused")
73
    private native long     ltt_getEventSize(long eventPtr);
74
    @SuppressWarnings("unused")
75
    private native int      ltt_getCount(long eventPtr);
76
    @SuppressWarnings("unused")
77
    private native long     ltt_getOverflowNanoSeconds(long eventPtr);
78
        
79
    // This method an event pointer
80
    private native void     ltt_getDataContent(long eventPtr, long dataSize, byte[] returnedContent);
81
        
82
    // Debug native function, ask LTT to print event structure
83
    private native void     ltt_printEvent(long eventPtr);
84
85
    static {
86
        System.loadLibrary("lttvtraceread");
87
    }
88
89
    
90
    /**
91
     * Default constructor is forbidden
92
     */
93
    @SuppressWarnings("unused")
94
    private JniEvent() {
95
    };
96
97
    /**
98
     * Copy constructor.
99
     * 
100
     * @param oldEvent
101
     *            A reference to the JniEvent you want to copy. 
102
     */
103
    public JniEvent(JniEvent oldEvent) {
104
        thisEventPtr = oldEvent.thisEventPtr;
105
        markersMap = oldEvent.markersMap;
106
        parentTracefile = oldEvent.parentTracefile;
107
        eventState = oldEvent.eventState;
108
109
        tracefilePtr = oldEvent.tracefilePtr;
110
        eventMarkerId = oldEvent.eventMarkerId;
111
        eventTime = oldEvent.eventTime;
112
        eventDataSize = oldEvent.eventDataSize;
113
    }
114
    
115
    /**
116
     * Constructor with parameters<br>
117
     * <br>
118
     * This constructor could throw. It will happen if an event can not be populated on first read.<br>
119
     * In that case, the parent tracefile is probably useless and should be deleted.
120
     * 
121
     * @param newEventPtr         C pointer (converted in long) of the LttEvent C structure.
122
     * @param newMarkersMap       Reference an already populated HashMap of JniMarker objects 
123
     * @param newParentTracefile  Reference to the parent JniTracefile of this JniEvent
124
     *            
125
     * @exception JniException           
126
     */
127
    public JniEvent(C_Pointer newEventPtr, HashMap<Integer, JniMarker> newMarkersMap, JniTracefile newParentTracefile) throws JniException {
128
129
        // Basic test to make sure we didn't get null/empty value 
130
        if ((newEventPtr.getPointer() == NULL)
131
                || (newMarkersMap == null) 
132
                || (newMarkersMap.size() == 0)
133
                || (newParentTracefile == null)) {
134
            throw new JniEventException("Null or empty value passed to constructor, object is invalid! (JniEvent)");
135
        }
136
137
        thisEventPtr = newEventPtr;
138
        tracefilePtr = newParentTracefile.getTracefilePtr();
139
        markersMap = newMarkersMap;
140
        parentTracefile = newParentTracefile;
141
142
        eventTime = new JniTime();
143
144
        // Try to move to the first event
145
        // If the event is Out of Range (ERANGE) at the first range, this event
146
        // type will never been usable
147
        // In that case, throw JafEventOutOfRangeException to warn the parent
148
        // tracefile
149
        //
150
        // Position ourself on the next (first?) event
151
        eventState = positionToFirstEvent();
152
        if (eventState != EOK) {
153
            throw new JniNoSuchEventException("Object not populated, unusable. There is probably no event of that type in the trace. (JniEvent)");
154
        }
155
        else {
156
            populateEventInformation();
157
        }
158
    }
159
160
    /**
161
     * Move to the next event and populate LttEvent structure into the java object.<br>
162
     * <br>
163
     * If the move fails, the event will not get populated and the last event's data will still be available.
164
     * 
165
     * @return The read status, as defined in Jni_C_Common
166
     * @see org.eclipse.linuxtools.lttng.jni.Jni_C_Common
167
     */
168
     public int readNextEvent() {
169
        // Ask Ltt to read the next event for this particular tracefile
170
        eventState = ltt_readNextEvent(tracefilePtr.getPointer() );
171
172
        // If the event state is sane populate it
173
        if (eventState == EOK) {
174
            populateEventInformation();
175
        }
176
177
        return eventState;
178
    }
179
180
    /**
181
     * Seek to a certain time.<br>
182
     * <br>
183
     * Seek to a certain time and read event at this exact time or the next one if there is no event there.<br>
184
     * <br>
185
     * Note that this function could end in an invalid position if we seek after the last event. <br>
186
     * In that case, a seek back would be required to get back to a consistent state.<br>
187
     * <br>
188
     * If the seek fails, the event will not get populated and the last event's data will still be available.
189
     * 
190
     * @return The read status, as defined in Jni_C_Common
191
     * @see org.eclipse.linuxtools.lttng.jni.Jni_C_Common
192
     */
193
    public int seekToTime(JniTime seekTime) {
194
        // Ask Ltt to read the next event for this particular tracefile
195
        eventState = ltt_seekEvent(tracefilePtr.getPointer(), seekTime);
196
197
        // If the event state is sane populate it
198
        if (eventState == EOK) {
199
            populateEventInformation();
200
        }
201
202
        return eventState;
203
    }
204
205
    /**
206
     * Seek to a certain time or seek back if it fails.<br>
207
     * <br>
208
     * Seek to a certain time and read event at this exact time or the next one if there is no event there.<br>
209
     * If the seek fails, we will seek back to the previous position, so the event will stay in a consistent state. 
210
     * 
211
     * @return The read status, as defined in Jni_C_Common
212
     * @see org.eclipse.linuxtools.lttng.jni.Jni_C_Common
213
     */
214
    public int seekOrFallBack(JniTime seekTime) {
215
        // Save the old time
216
        JniTime oldTime = eventTime;
217
218
        // Call seek to move ahead
219
        seekToTime(seekTime);
220
        // Save the state for the return
221
        int returnState = eventState;
222
223
        // If the event state is sane populate it
224
        if (eventState == EOK) {
225
            populateEventInformation();
226
        }
227
228
        // Move to Next event only if the state of the event is sane
229
        if (eventState != EOK) {
230
            seekToTime(oldTime);
231
        }
232
233
        return returnState;
234
    }
235
236
    /**
237
     * Position on the first event in the tracefile.<br>
238
     * <br>
239
     * The function will return the read status of the event.<br>
240
     * An erronous status probably means there is no event of that type associated to the tracefile.
241
     * 
242
     * @return The read status, as defined in Jni_C_Common
243
     * @see org.eclipse.linuxtools.lttng.jni.Jni_C_Common
244
     */
245
    public int positionToFirstEvent() {
246
        eventState = ltt_positionToFirstEvent(tracefilePtr.getPointer());
247
        
248
        return eventState;
249
    }
250
    
251
    /**
252
     * Method to obtain a marker associated with this particular event.
253
     * 
254
     * @return  Reference to the JniMarker object for this event or null if none. 
255
     * @see org.eclipse.linuxtools.lttng.jni.JniMarker
256
     */
257
    public JniMarker requestEventMarker() {
258
        return markersMap.get(eventMarkerId);
259
    }
260
261
    /**
262
     * Method to obtain the raw data of a LttEvent object.<br>
263
     * <br>
264
     * Note : The data will be in raw C bytes, not java bytes. 
265
     * 
266
     * @return  bytes array of raw data.
267
     */
268
    public byte[] requestEventContent() {
269
270
        byte dataContent[] = new byte[(int) eventDataSize];
271
272
        ltt_getDataContent(thisEventPtr.getPointer(), eventDataSize, dataContent);
273
274
        return dataContent;
275
    }
276
277
    // *** TODO ***
278
    // No "Source" of event exist in Ltt so far
279
    // It would be a good addition to have a way to detect where an event come
280
    // from, like "kernel" or "userspace"
281
    // 
282
    /**
283
     * Method to obtain an event source.<br>
284
     * <br>
285
     * This is not implemented yet and will always return "Kernel core" for now.
286
     * 
287
     * @return  Reference to the JniMarker object for this event or null if none. 
288
     * @see org.eclipse.linuxtools.lttng.jni.JniMarker
289
     */
290
    public String requestEventSource() {
291
        return "Kernel Core";
292
    }
293
    
294
    /**
295
     * Method to parse a particular field in the event payload, identified by its id (position).
296
     * 
297
     * @return Object that contain the parsed payload
298
     */
299
    public Object parseFieldById(int fieldId) {
300
        return JniParser.parseField(this, fieldId);
301
    }
302
    
303
    /**
304
     * Method to parse a particular field in the event payload, identified by its name.
305
     * 
306
     * @return Object that contain the parsed payload
307
     */
308
    public Object parseFieldByName(String fieldName) {
309
        return JniParser.parseField(this, fieldName);
310
    }
311
    
312
    /**
313
     * Method to parse all the event payload.
314
     * 
315
     * @return  ArrayList of ParsedContent objects. 
316
     */
317
    public HashMap<String, Object> parseAllFields() {
318
        return JniParser.parseAllFields(this);
319
    }
320
321
    /* 
322
     * This function populates the event data with data from LTT
323
     * 
324
     */
325
    private void populateEventInformation() {
326
        if (thisEventPtr.getPointer() == NULL) {
327
            printlnC("Pointer is NULL, trace closed? (populateEventInformation)");
328
        }
329
        else {
330
            tracefilePtr = new C_Pointer( ltt_getTracefilePtr(thisEventPtr.getPointer()) );
331
            eventMarkerId = ltt_getEventMarkerId(thisEventPtr.getPointer());
332
333
            // Creation of time is a bit different, we need to pass the object
334
            // reference to C
335
            ltt_feedEventTime(thisEventPtr.getPointer(), eventTime);
336
337
            eventDataSize = ltt_getEventDataSize(thisEventPtr.getPointer());
338
        }
339
    }
340
    
341
    public int getEventMarkerId() {
342
        return eventMarkerId;
343
    }
344
345
    public JniTime getEventTime() {
346
        return eventTime;
347
    }
348
349
    public long getEventDataSize() {
350
        return eventDataSize;
351
    }
352
353
    public HashMap<Integer, JniMarker> getMarkersMap() {
354
        return markersMap;
355
    }
356
357
    
358
    /**
359
     * Pointer to the parent LttEvent C structure<br>
360
     * <br>
361
     * The pointer should only be used INTERNALY, do not use these unless you
362
     * know what you are doing.
363
     * 
364
     * @return The actual (long converted) pointer or NULL
365
     */
366
    public C_Pointer getTracefilePtr() {
367
        return tracefilePtr;
368
    }
369
370
    /**
371
     * Pointer to the LttEvent C structure<br>
372
     * <br>
373
     * The pointer should only be used INTERNALY, do not use these unless you
374
     * know what you are doing.
375
     * 
376
     * @return The actual (long converted) pointer or NULL
377
     */
378
    public C_Pointer getEventPtr() {
379
        return thisEventPtr;
380
    }
381
382
    public int getEventState() {
383
        return eventState;
384
    }
385
386
    /**
387
     * Getter to the parent tracefile for this event.
388
     *
389
     * 
390
     * @return  the parent tracefile 
391
     * @see org.eclipse.linuxtools.lttng.jni.JniTracefile
392
     */
393
    public JniTracefile getParentTracefile() {
394
        return parentTracefile;
395
    }
396
397
    /**
398
     * toString() method. <u>Intended to debug</u><br>
399
     * 
400
     * @return String Attributes of the object concatenated in String
401
     */
402
    public String toString() {
403
        String returnData = "";
404
405
        returnData += "tracefilePtr            : " + tracefilePtr + "\n";
406
        returnData += "eventMarkerId           : " + eventMarkerId + "\n";
407
        returnData += "eventTime               : " + eventTime.getReferenceToString() + "\n";
408
        returnData += "   seconds              : " + eventTime.getSeconds() + "\n";
409
        returnData += "   nanoSeconds          : " + eventTime.getNanoSeconds() + "\n";
410
        returnData += "eventDataSize           : " + eventDataSize + "\n";
411
        returnData += "markersMap              : " + markersMap.keySet() + "\n"; // Hack to avoid ending up with markersMap.toString()
412
413
        return returnData;
414
    }
415
416
    /**
417
     * Print information for this event. <u>Intended to debug</u><br>
418
     * 
419
     * This function will call Ltt to print, so information printed will be the one from the C structure<br>
420
     * <br>
421
     * This function will not throw but will complain loudly if pointer is NULL
422
     */
423
    public void printEventInformation() {
424
425
        // If null pointer, print a warning!
426
        if (thisEventPtr.getPointer() == NULL) {
427
            printlnC("Pointer is NULL, cannot print. (printEventInformation)");
428
        }
429
        else {
430
            ltt_printEvent(thisEventPtr.getPointer());
431
        }
432
    }
433
}
0
  + text/plain
434
  + text/plain
(-)src/org/eclipse/linuxtools/lttng/jni/JniMarker.java (+226 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 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
 *   William Bourque (wbourque@gmail.com) - Initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.linuxtools.lttng.jni;
14
15
import java.util.ArrayList;
16
import java.util.HashMap;
17
18
/**
19
 * <b><u>JniMarker</u></b>
20
 * <p>
21
 * A JniMarker contain information how to interpret the unparsed content (payload) of an event.<br>
22
 * Each JniMarker contains several MarkerFields for each fields in the event's payload.
23
 * <p>
24
 * Most important fields in the JniMarker are :
25
 * <ul>
26
 * <li> the name of the marker in String
27
 * <li> an overview of the marker format (in C style printf format)
28
 * <li> a reference to an ArrayList that contains MarkerFields object of this JniMarker
29
 * </ul>
30
 */
31
public final class JniMarker extends Jni_C_Common
32
{
33
    // Internal C pointer of the JniEvent used in LTT
34
    private C_Pointer thisMarkerPtr = new C_Pointer();
35
36
    private String name = "";
37
    private String formatOverview = "";
38
    
39
    // These two contains hold references to the same MarkerField object
40
    //  The ArrayList can be used to efficiently find a field by its position
41
    //  The HashMap can be used to find a field by its name
42
    private HashMap<String, JniMarkerField> markerFieldsHashMap = null;
43
    private ArrayList<JniMarkerField> markerFieldsArrayList = null;
44
45
    // Native access method
46
    private native String ltt_getName(long markerPtr);   
47
    private native String ltt_getFormatOverview(long markerPtr);
48
    @SuppressWarnings("unused")
49
    private native long ltt_getSize(long markerPtr);
50
    @SuppressWarnings("unused")
51
    private native short ltt_getLargestAlign(long markerPtr);
52
    @SuppressWarnings("unused")
53
    private native short ltt_getIntSize(long markerPtr);
54
    @SuppressWarnings("unused")
55
    private native short ltt_getLongSize(long markerPtr);
56
    @SuppressWarnings("unused")
57
    private native short ltt_getPointerSize(long markerPtr);
58
    @SuppressWarnings("unused")
59
    private native short ltt_getSize_tSize(long markerPtr);
60
    private native void ltt_getAllMarkerFields(long tracePtr);
61
    @SuppressWarnings("unused")
62
    private native short ltt_getAlignement(long markerPtr);
63
    @SuppressWarnings("unused")
64
    private native long ltt_getNextMarkerPtr(long markerPtr);
65
66
    // Debug native function, ask LTT to print marker structure
67
    private native void ltt_printMarker(long markerPtr);
68
69
    static {
70
        System.loadLibrary("lttvtraceread");
71
    }
72
73
    /**
74
     * Default constructor is forbidden
75
     */
76
    @SuppressWarnings("unused")
77
    private JniMarker() {
78
    }
79
    
80
    /**
81
     * Copy constructor.
82
     * 
83
     * @param oldMarker
84
     *            A reference to the JniMarker you want to copy. 
85
     */
86
    public JniMarker(JniMarker oldMarker) {
87
        thisMarkerPtr = oldMarker.thisMarkerPtr;
88
        name = oldMarker.name;
89
        formatOverview = oldMarker.formatOverview;
90
        markerFieldsHashMap = oldMarker.markerFieldsHashMap;
91
        markerFieldsArrayList = oldMarker.markerFieldsArrayList;
92
93
    }
94
95
    /**
96
     * Copy constructor, using pointer.
97
     * 
98
     * @param newMarkerPtr  Pointer to a C marker_info structure
99
     * 
100
     * @exception JniException
101
     */
102
    public JniMarker(C_Pointer newMarkerPtr) throws JniException {
103
        thisMarkerPtr = newMarkerPtr;
104
        markerFieldsArrayList = new ArrayList<JniMarkerField>();
105
        markerFieldsHashMap = new HashMap<String, JniMarkerField>();
106
107
        // Populate the marker
108
        populateMarkerInformation();
109
    }
110
111
    
112
    /* 
113
     * This function populates the marker data with data from LTT
114
     * 
115
     */
116
    private void populateMarkerInformation() throws JniException {
117
        if (thisMarkerPtr.getPointer() == NULL) {
118
            throw new JniMarkerException("Pointer is NULL, trace closed? (populateMarkerInformatOverviewion)");
119
        } else {
120
            name = ltt_getName( thisMarkerPtr.getPointer() );
121
            formatOverview = ltt_getFormatOverview( thisMarkerPtr.getPointer() );
122
            // To fill the markerFieldArray is a bit different
123
            ltt_getAllMarkerFields( thisMarkerPtr.getPointer() );
124
        }
125
    }
126
127
    /* 
128
     * Fills a map of all the JniMarkerField associated with this JniMarker.
129
     * 
130
     * Note: This function is called from C and there is no way to propagate
131
     * exception back to the caller without crashing JNI. Therefore, it MUST
132
     * catch all exceptions.
133
     * 
134
     * @param markerName        Name of the parent marker
135
     * @param markerFieldPtr    C Pointer (converted in long) to marker_field C Structure
136
     */
137
    @SuppressWarnings("unused")
138
    private void addMarkerFieldFromC(String markerFieldName, long markerFieldPtr) {
139
        // Create a new Jaf_markerField object and insert it in the map
140
        // the maker field fill itself with LTT data while being constructed
141
        try {
142
            JniMarkerField newMarkerField = new JniMarkerField( new C_Pointer(markerFieldPtr) );
143
            markerFieldsArrayList.add(newMarkerField);
144
            markerFieldsHashMap.put(markerFieldName, newMarkerField);
145
            
146
        } catch (JniException e) {
147
            printlnC("Failed to add marker field " + markerFieldName + " to marker fields list!(addMarkerFieldFromC)\n\tException raised : " + e.toString() );
148
        }
149
    }
150
151
    // Access to class variable. Most of them doesn't have setter
152
    public String getName() {
153
        return name;
154
    }
155
156
    public String getFormatOverview() {
157
        return formatOverview;
158
    }
159
160
    public HashMap<String,JniMarkerField> getMarkerFieldsHashMap() {
161
        return markerFieldsHashMap;
162
    }
163
    
164
    public ArrayList<JniMarkerField> getMarkerFieldsArrayList() {
165
        return markerFieldsArrayList;
166
    }
167
168
169
    /**
170
     * Pointer to the marker_info C structure<br>
171
     * <br>
172
     * The pointer should only be used INTERNALY, do not use these unless you
173
     * know what you are doing.
174
     * 
175
     * @return The actual (long converted) pointer or NULL
176
     */
177
    public C_Pointer getMarkerPtr() {
178
        return thisMarkerPtr;
179
    }
180
181
    /**
182
     * toString() method. <u>Intended to debug</u><br>
183
     * 
184
     * @return String Attributes of the object concatenated in String
185
     */
186
    public String toString() {
187
        String returnData = "";
188
189
        returnData += "name                    : " + name + "\n";
190
        returnData += "formatOverview          : " + formatOverview + "\n";
191
        returnData += "markerFieldArrayList    : " + markerFieldsArrayList.toArray() + "\n";
192
193
        return returnData;
194
    }
195
196
    
197
    /**
198
     * Print information for ALL marker fields for this marker. <u>Intended to debug</u><br>
199
     * 
200
     * This function will call Ltt to print, so information printed will be the one from the C structure
201
     */
202
    public void printAllMarkerFieldsInformation() {
203
        Object[] allMarkersField = markerFieldsArrayList.toArray();
204
205
        for (int pos = 0; pos < allMarkersField.length; pos++) {
206
            printlnC(allMarkersField[pos].toString());
207
        }
208
    }
209
210
    /**
211
     * Print information for this JniMarker. <u>Intended to debug</u><br>
212
     * 
213
     * This function will call Ltt to print, so information printed will be the one from the C structure<br>
214
     * <br>
215
     * This function will not throw but will complain loudly if pointer is NULL
216
     */
217
    public void printMarkerInformation() {
218
219
        // If null pointer, print a warning!
220
        if (thisMarkerPtr.getPointer() == NULL) {
221
            printlnC("Pointer is NULL, cannot print. (printMarkerInformation)");
222
        } else {
223
            ltt_printMarker(thisMarkerPtr.getPointer());
224
        }
225
    }
226
}
0
  + text/plain
227
  + text/plain
(-)src/org/eclipse/linuxtools/lttng/jni/JniMarkerField.java (+152 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 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
 *   William Bourque (wbourque@gmail.com) - Initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.linuxtools.lttng.jni;
14
15
/**
16
 * <b><u>JniMarkerField</u></b>
17
 * <p>
18
 * A JniMarkerField is one of the field of the unparsed content (payload) of an event
19
 * <p>
20
 * Most important attributes in the JniMarkerField are :
21
 * <ul>
22
 * <li> the name (field) of in String
23
 * <li> the marker field format (in C style printf format)
24
 * </ul>
25
 */
26
public final class JniMarkerField extends Jni_C_Common
27
{
28
    // Internal C pointer of the JniEvent used in LTT
29
    private C_Pointer thisMarkerFieldPtr = new C_Pointer();
30
31
    private String field = "";
32
    private String format = "";
33
34
    // Native access method
35
    private native String ltt_getField(long markerFieldPtr);
36
    @SuppressWarnings("unused")
37
    private native int ltt_getType(long markerFieldPtr);
38
    @SuppressWarnings("unused")
39
    private native long ltt_getOffset(long markerFieldPtr);
40
    @SuppressWarnings("unused")
41
    private native long ltt_getSize(long markerFieldPtr);
42
    @SuppressWarnings("unused")
43
    private native long ltt_getAlignment(long markerFieldPtr);
44
    @SuppressWarnings("unused")
45
    private native long ltt_getAttributes(long markerFieldPtr);
46
    @SuppressWarnings("unused")
47
    private native int ltt_getStatic_offset(long markerFieldPtr);
48
    private native String ltt_getFormat(long markerFieldPtr);
49
50
    // Debug native function, ask LTT to print marker structure
51
    private native void ltt_printMarkerField(long markerFieldPtr);
52
53
    static {
54
        System.loadLibrary("lttvtraceread");
55
    }
56
57
    /**
58
     * Default constructor is forbidden
59
     */
60
    @SuppressWarnings("unused")
61
    private JniMarkerField() {
62
    }
63
64
    /**
65
     * Copy constructor.
66
     * 
67
     * @param oldMarkerField
68
     *            A reference to the JniMarkerField you want to copy. 
69
     */
70
    public JniMarkerField(JniMarkerField oldMarkerField) {
71
        thisMarkerFieldPtr = oldMarkerField.getMarkerFieldPtr();
72
        field = oldMarkerField.getField();
73
        format = oldMarkerField.getFormat();
74
    }
75
76
    /**
77
     * Copy constructor, using pointer.
78
     * 
79
     * @param newMarkerFieldPtr  Pointer to a C marker_field structure
80
     * 
81
     * @exception JniException
82
     */
83
    public JniMarkerField(C_Pointer newMarkerFieldPtr) throws JniException {
84
        thisMarkerFieldPtr = newMarkerFieldPtr;
85
86
        // Populate the marker field
87
        populateMarkerFieldInformation();
88
    }
89
90
    /* 
91
     * This function populates the marker field data with data from LTT
92
     * 
93
     */
94
    private void populateMarkerFieldInformation() throws JniException {
95
        if (thisMarkerFieldPtr.getPointer() == NULL) {
96
            throw new JniMarkerFieldException(
97
                    "Pointer is NULL, trace closed? (populateMarkerInformation)");
98
        } else {
99
            field = ltt_getField(thisMarkerFieldPtr.getPointer());
100
            format = ltt_getFormat(thisMarkerFieldPtr.getPointer());
101
        }
102
    }
103
104
    public String getField() {
105
        return field;
106
    }
107
108
    public String getFormat() {
109
        return format;
110
    }
111
112
    /**
113
     * Pointer to the marker_field C structure<br>
114
     * <br>
115
     * The pointer should only be used INTERNALY, do not use these unless you
116
     * know what you are doing.
117
     * 
118
     * @return The actual (long converted) pointer or NULL
119
     */
120
    public C_Pointer getMarkerFieldPtr() {
121
        return thisMarkerFieldPtr;
122
    }
123
124
    /**
125
     * toString() method. <u>Intended to debug</u><br>
126
     * 
127
     * @return String Attributes of the object concatenated in String
128
     */
129
    public String toString() {
130
        String returnData = "";
131
        returnData += "field                   : " + field + "\n";
132
        returnData += "format                  : " + format + "\n";
133
        return returnData;
134
    }
135
136
    /**
137
     * Print information for this event. <u>Intended to debug</u><br>
138
     * 
139
     * This function will call Ltt to print, so information printed will be the one from the C structure<br>
140
     * <br>
141
     * This function will not throw but will complain loudly if pointer is NULL
142
     */
143
    public void printMarkerFieldInformation() {
144
145
        // If null pointer, print a warning!
146
        if (thisMarkerFieldPtr.getPointer() == NULL) {
147
            printlnC("Pointer is NULL, cannot print. (printMarkerFieldInformation)");
148
        } else {
149
            ltt_printMarkerField(thisMarkerFieldPtr.getPointer());
150
        }
151
    }
152
}
0
  + text/plain
153
  + text/plain
(-)src/org/eclipse/linuxtools/lttng/jni/Jni_C_Common.java (+136 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 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
 *   William Bourque (wbourque@gmail.com) - Initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.linuxtools.lttng.jni;
14
15
/**
16
 * <b><u>Jni_C_Common</u></b>
17
 * <p>
18
 * Common constante and methods that should be shared between JNI objects
19
 */
20
public abstract class Jni_C_Common {
21
22
    // Needed for native types
23
    public static final int NULL = 0;
24
25
    // C errno correspondance. Used to interpret LTT return value
26
    public static final int EOK    =  0;
27
    public static final int EPERM  =  1;
28
    public static final int ERANGE = 34;
29
30
    // Timestamps are in nanoseconds
31
    public static final long NANO = 1000000000;
32
33
    // Native console printing function
34
    private native void ltt_printC(String string_to_print);
35
36
    // Load LTTV library (order is important)
37
    static {
38
        System.loadLibrary("lttvtraceread");
39
    }
40
41
    /**
42
     * Java-side console printing function.
43
     * 
44
     * Call the C printing function to make sure all printing happen on the same side.
45
     * 
46
     * @param msg
47
     */
48
    public void printC(String msg) {
49
        // Need to escape "%"
50
        msg = msg.replaceAll("%", "%%");
51
        ltt_printC(msg);
52
    }
53
54
    /**
55
     * Java-side console printing function. Add a return line at the end of the message.
56
     * 
57
     * Call the C printing function to make sure all printing happen on the same side.
58
     * 
59
     * @param msg
60
     */
61
    public void printlnC(String msg) {
62
        printC(msg + "\n");
63
    }
64
65
    /**
66
     * This method is to be used as an "alternate" .toString()<br>
67
     * <br>
68
     * Simulates the way Java Object implements "toString()"
69
     * 
70
     * @return the Java hashed UID of the object (i.e. : NAME@HASH)
71
     */
72
    public String getReferenceToString() {
73
        return this.getClass().getName() + "@" + Integer.toHexString(this.hashCode());
74
    }
75
}
76
77
/**
78
 * <b><u>C_Pointer</u></b>
79
 * <p>
80
 * Class pointer to handle properly "C pointer" <br>
81
 * 
82
 * Can transparently handle pointer of 32 or 64 bits.
83
 */
84
class C_Pointer extends Jni_C_Common {
85
86
    private long ptr = NULL;
87
    private boolean isLong = true;
88
89
    public C_Pointer() {
90
        ptr  = NULL;
91
    }
92
93
    public C_Pointer(long newPtr) {
94
        ptr = newPtr;
95
        isLong = true; 
96
    }
97
98
    public C_Pointer(int newPtr) {
99
        ptr = (long)newPtr;
100
        isLong = false; 
101
    }
102
103
    public long getPointer() {
104
        return ptr;
105
    }
106
107
    public void setPointer(long newPtr) {
108
        ptr = newPtr;
109
        isLong = true;
110
    }
111
112
    public void setPointer(int newPtr) {
113
        ptr = newPtr;
114
        isLong = false;
115
    }
116
117
    /**
118
     * toString() method<br>
119
     * <br>
120
     * Convert the pointer to a nice looking hexadecimal format 
121
     * 
122
     * @return String Attributes of the object concatenated in String
123
     */
124
    public String toString() {
125
        String returnData = "0x";
126
127
        if (isLong == true) {
128
            returnData += Long.toHexString(ptr);
129
        }
130
        else {
131
            returnData += Integer.toHexString((int) ptr);
132
        }
133
134
        return returnData;
135
    }
136
}
0
  + text/plain
137
  + text/plain
(-)src/org/eclipse/linuxtools/lttng/jni/JniParser.java (+292 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 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
 *   William Bourque (wbourque@gmail.com) - Initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.linuxtools.lttng.jni;
14
15
import java.util.HashMap;
16
17
/**
18
 * <b><u>JniParser</u></b>
19
 * <p>
20
 * JniParser class.
21
 * All methods are static, the parser shouldn't be instantiated.
22
 */
23
public class JniParser extends Jni_C_Common
24
{
25
    private static native void ltt_getParsedData(ParsedObjectContent parseddata, long eventPtr, long markerFieldPtr);
26
27
    static {
28
        System.loadLibrary("lttvtraceread");
29
    }
30
31
    /**
32
     * Default constructor is forbidden
33
     */
34
    private JniParser() {
35
    }
36
    
37
    
38
    
39
    /**
40
     * Method to parse a single field identified by its id<br>
41
     * All parsing will be done on C side as we need Ltt function
42
     * 
43
     * @param   eventToParse    The jni event we want to parse. 
44
     * @param   fieldPosition   The position (or id) of the field we want to parse
45
     * 
46
     * @return                  An Object that contain the JniEvent payload parsed by the C, or null, if if was impossible to parse (i.e., wrong position)
47
     * 
48
     * @see org.eclipse.linuxtools.lttng.jni.JniEvent
49
     */
50
    static public Object parseField(JniEvent eventToParse, int fieldPosition) {
51
        
52
        // Sanity check
53
        if ( (fieldPosition < 0) || ( fieldPosition >= eventToParse.requestEventMarker().getMarkerFieldsArrayList().size() ) ){
54
            return null;
55
        }
56
        
57
        // *** HACK ***
58
        // We cannot use "Object" directly as java does not support swapping primitive value
59
        //  We either need to create a new object type or to use a "non-primitive" type that have "Setter()" functions
60
        // ***
61
        ParsedObjectContent parsedData = new ParsedObjectContent();
62
        
63
        // Call the parsing function in C. The result will be put in parsedData object
64
        ltt_getParsedData(parsedData, eventToParse.getEventPtr().getPointer(), eventToParse.requestEventMarker().getMarkerFieldsArrayList().get(fieldPosition).getMarkerFieldPtr().getPointer() );
65
        
66
        return parsedData.getData();
67
    }
68
    
69
    
70
    /**
71
     * Method to parse a single field identified by its name<br>
72
     * All parsing will be done on C side as we need Ltt function
73
     * 
74
     * @param   eventToParse    The jni event we want to parse. 
75
     * @param   fieldPosition   The position (or id) of the field we want to parse
76
     * 
77
     * @return                  An Object that contain the JniEvent payload parsed by the C, or null, if if was impossible to parse (i.e., wrong position)
78
     * 
79
     * @see org.eclipse.linuxtools.lttng.jni.JniEvent
80
     */
81
    static public Object parseField(JniEvent eventToParse, String fieldName) {
82
        
83
        JniMarkerField tmpField = eventToParse.requestEventMarker().getMarkerFieldsHashMap().get(fieldName);
84
        
85
        // return immediately if there is no field by that name
86
        if ( tmpField == null ) {
87
            return null;
88
        }
89
        
90
        // *** HACK ***
91
        // We cannot use "Object" directly as java does not support swapping on primitive value
92
        //  We either need to create a new object type or to use a "non-primitive" type that have "Setter()" functions
93
        // ***
94
        ParsedObjectContent parsedData = new ParsedObjectContent();
95
        
96
        ltt_getParsedData(parsedData, eventToParse.getEventPtr().getPointer(), tmpField.getMarkerFieldPtr().getPointer() );
97
        
98
        return parsedData.getData();
99
    }
100
    
101
    
102
    
103
    /**
104
     * Method to parse all field at once<br>
105
     * All parsing will be done on C side as we need Ltt function
106
     * 
107
     * @param   eventToParse    The jni event we want to parse.  
108
     * @return                  An HashMap of Object that contain the is the JniEvent's payload parsed by the C
109
     * 
110
     * @see org.eclipse.linuxtools.lttng.jni.JniEvent
111
     */
112
    static public HashMap<String, Object> parseAllFields(JniEvent eventToParse) {
113
        JniMarker markerData = eventToParse.requestEventMarker();
114
        int nbMarkerField = markerData.getMarkerFieldsArrayList().size();
115
        
116
         // This hashmap will contain the parsed content.
117
         // ParsedContent is defined at the end of this file
118
         HashMap<String, Object> parsedDataArray = new HashMap<String, Object>(nbMarkerField);
119
        
120
         // *** HACK ***
121
         // We cannot use "Object" directly as java does not support swapping on primitive value
122
         //  We either need to create a new object type or to use a "non-primitive" type that have "Setter()" functions
123
         // ***
124
         ParsedObjectContent parsedData = new ParsedObjectContent();
125
         
126
        // Loop on markerfield, as we need to parse each field in the event data
127
        for (int pos = 0; pos < nbMarkerField; pos++) {
128
            // Call the C to parse the data
129
            ltt_getParsedData(parsedData, eventToParse.getEventPtr().getPointer(), markerData.getMarkerFieldsArrayList().get(pos).getMarkerFieldPtr().getPointer() );
130
            // Save the result into the HashMap
131
            parsedDataArray.put(markerData.getMarkerFieldsArrayList().get(pos).getField(), parsedData.getData() );
132
        }
133
        
134
         return parsedDataArray;
135
    }
136
    
137
    /* 
138
     * Add a parsed String value to the Array<br>
139
     * <br>
140
     * Note : this function will be called from the C side.
141
     * Note2: contentHolder is of type "Object" instead of "ParsedObjectContent" to be able to use the most generic function signature on the C side.
142
     *          its goal is to give a generic interface to people that would like to use the JNI library
143
     * 
144
     * @param parsedArray   Array where to store the value
145
     * @param fieldName     The name of the parsed field
146
     * @param stringToAdd   The parsed data to add
147
     * @param formatToAdd   The format of the raw data
148
     */
149
    @SuppressWarnings("unused")
150
    static private void addStringToParsingFromC(Object contentHolder, String fieldName, String stringToAdd) {
151
        ((ParsedObjectContent)contentHolder).setData( stringToAdd);
152
    }
153
154
    /* 
155
     * Add a parsed 64 bits Pointer value to the Array<br>
156
     * <br>
157
     * Note : this function will be called from the C side.
158
     * Note2: contentHolder is of type "Object" instead of "ParsedObjectContent" to be able to use the most generic function signature on the C side.
159
     *          its goal is to give a generic interface to people that would like to use the JNI library
160
     * 
161
     * @param contentHolder Object where to store the parsed value
162
     * @param fieldName     The name of the parsed field
163
     * @param pointerToAdd  The parsed data to add (in 64 bits long!)
164
     * @param formatToAdd   The format of the raw data
165
     */
166
    @SuppressWarnings("unused")
167
    static private void addLongPointerToParsingFromC(Object contentHolder, String fieldName, long pointerToAdd) {
168
        ((ParsedObjectContent)contentHolder).setData( new C_Pointer((long) pointerToAdd));
169
    }
170
171
    /* 
172
     * Add a parsed 32 bits Pointer value to the Array<br>
173
     * <br>
174
     * Note : this function will be called from the C side.
175
     * Note2: contentHolder is of type "Object" instead of "ParsedObjectContent" to be able to use the most generic function signature on the C side.
176
     *          its goal is to give a generic interface to people that would like to use the JNI library
177
     * 
178
     * @param contentHolder Object where to store the parsed value
179
     * @param fieldName     The name of the parsed field
180
     * @param pointerToAdd  The parsed data to add (converted in 64 bits long!)
181
     * @param formatToAdd   The format of the raw data
182
     */
183
    @SuppressWarnings("unused")
184
    static private void addIntPointerToParsingFromC(Object contentHolder, String fieldName, long pointerToAdd) {
185
        ((ParsedObjectContent)contentHolder).setData( new C_Pointer((int) pointerToAdd));
186
    }
187
188
    /* 
189
     * Add a parsed short value to the Array<br>
190
     * <br>
191
     * Note : this function will be called from the C side.
192
     * Note2: contentHolder is of type "Object" instead of "ParsedObjectContent" to be able to use the most generic function signature on the C side.
193
     *          its goal is to give a generic interface to people that would like to use the JNI library
194
     * 
195
     * @param contentHolder Object where to store the parsed value
196
     * @param fieldName     The name of the parsed field
197
     * @param shortToAdd    The parsed data to add
198
     * @param formatToAdd   The format of the raw data
199
     */
200
    @SuppressWarnings("unused")
201
    static private void addShortToParsingFromC(Object contentHolder, String fieldName, short shortToAdd) {
202
        ((ParsedObjectContent)contentHolder).setData( new Short(shortToAdd));
203
    }
204
205
    /* 
206
     * Add a parsed integer value to the Array<br>
207
     * <br>
208
     * Note : this function will be called from the C side.
209
     * Note2: contentHolder is of type "Object" instead of "ParsedObjectContent" to be able to use the most generic function signature on the C side.
210
     *          its goal is to give a generic interface to people that would like to use the JNI library
211
     * 
212
     * @param contentHolder Object where to store the parsed value
213
     * @param fieldName     The name of the parsed field
214
     * @param intToAdd      The parsed data to add
215
     * @param formatToAdd   The format of the raw data
216
     */
217
    @SuppressWarnings("unused")
218
    static private void addIntegerToParsingFromC(Object contentHolder, String fieldName, int intToAdd) {
219
        ((ParsedObjectContent)contentHolder).setData( new Integer(intToAdd));
220
    }
221
222
    /* 
223
     * Add a parsed long value to the Array<br>
224
     * <br>
225
     * Note : this function will be called from the C side.
226
     * Note2: contentHolder is of type "Object" instead of "ParsedObjectContent" to be able to use the most generic function signature on the C side.
227
     *          its goal is to give a generic interface to people that would like to use the JNI library
228
     * 
229
     * @param contentHolder Object where to store the parsed value
230
     * @param fieldName     The name of the parsed field
231
     * @param longToAdd     The parsed data to add
232
     * @param formatToAdd   The format of the raw data
233
     */
234
    @SuppressWarnings("unused")
235
    static private void addLongToParsingFromC(Object contentHolder, String fieldName, long longToAdd) {
236
        ((ParsedObjectContent)contentHolder).setData( new Long(longToAdd));
237
    }
238
239
    /* 
240
     * Add a parsed float value to the Array<br>
241
     * <br>
242
     * Note : this function will be called from the C side.
243
     * Note2: contentHolder is of type "Object" instead of "ParsedObjectContent" to be able to use the most generic function signature on the C side.
244
     *          its goal is to give a generic interface to people that would like to use the JNI library
245
     * 
246
     * @param contentHolder Object where to store the parsed value
247
     * @param fieldName     The name of the parsed field
248
     * @param floatToAdd    The parsed data to add
249
     * @param formatToAdd   The format of the raw data
250
     */
251
    @SuppressWarnings("unused")
252
    static private void addFloatToParsingFromC(Object contentHolder, String fieldName, float floatToAdd) {
253
        ((ParsedObjectContent)contentHolder).setData( new Float(floatToAdd));
254
    }
255
256
    /* 
257
     * Add a parsed double value to the Array<br>
258
     * <br>
259
     * Note : this function will be called from the C side.
260
     * Note2: contentHolder is of type "Object" instead of "ParsedObjectContent" to be able to use the most generic function signature on the C side.
261
     *          its goal is to give a generic interface to people that would like to use the JNI library
262
     * 
263
     * 
264
     * @param contentHolder Object where to store the parsed value
265
     * @param fieldName     The name of the parsed field
266
     * @param doubleToAdd   The parsed data to add
267
     * @param formatToAdd   The format of the raw data
268
     */
269
    @SuppressWarnings("unused")
270
    static private void addDoubleToParsingFromC(Object contentHolder, String fieldName, double doubleToAdd) {
271
        ((ParsedObjectContent)contentHolder).setData( new Double(doubleToAdd));
272
    }
273
    
274
}
275
276
/**
277
 * <b><u>ParsedObjectContent</u></b>
278
 * <p>
279
 * ParsedObjectContent class.
280
 * This class will only be used locally in this object to parse event data more efficiently in the C
281
 */
282
class ParsedObjectContent {
283
    private Object parsedData = null;
284
    
285
    public Object getData() {
286
        return parsedData;
287
    }
288
    
289
    public void setData(Object newData) {
290
        parsedData = newData;
291
    }
292
}
0
  + text/plain
293
  + text/plain
(-)src/org/eclipse/linuxtools/lttng/event/LttngEventFormat.java (+138 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 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
 *   William Bourque (wbourque@gmail.com) - Initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.linuxtools.lttng.event;
14
15
import java.util.HashMap;
16
import java.util.Iterator;
17
18
import org.eclipse.linuxtools.tmf.event.TmfEventFormat;
19
20
/**
21
 * <b><u>LttngEventFormat</u></b>
22
 * <p>
23
 * Lttng specific implementation of the TmfEventFormat
24
 * <p>
25
 * The Lttng implementation of format override parse but require a LttngEvent for most functions so it can call Jni
26
 */
27
public class LttngEventFormat extends TmfEventFormat {
28
29
    /**
30
     * Default constructor
31
     */
32
    public LttngEventFormat() {
33
        
34
    }
35
36
    /**
37
     * Getter for the label of the fields for this event.<br>
38
     * 
39
     * @return String[]     A string array that contain the labels name
40
     */
41
    public String[] getLabels(LttngEvent thisEvent) {
42
        String[] returnedLabels = null; 
43
        returnedLabels = thisEvent.convertEventTmfToJni().requestEventMarker().getMarkerFieldsHashMap().keySet().toArray(returnedLabels);
44
        
45
        return returnedLabels;
46
    }
47
    
48
    /**
49
     * Parse the LttngEvent linked to this LttngEventFormat.<br>
50
     * 
51
     * @return LttngEventField[]     An array of LttngEventField that contain the parsed data
52
     */
53
    public LttngEventField[] parse(LttngEvent thisEvent) {
54
        HashMap<String, Object> parsedMap = thisEvent.convertEventTmfToJni().parseAllFields();
55
        LttngEventField[] returnedField = new LttngEventField[parsedMap.size()];
56
        
57
        String fieldName = null;
58
        int position = 0;
59
        Iterator<String> iterator = parsedMap.keySet().iterator();
60
        while (iterator.hasNext()) {
61
            fieldName = iterator.next();
62
            returnedField[position] = new LttngEventField( fieldName, parsedMap.get(fieldName) );
63
            position++;
64
        }
65
        
66
        return returnedField;
67
    }
68
    
69
    
70
    
71
    /* *** FIXME
72
     * TEMPORARY IMPLEMENTATION
73
     * THIS WILL DISAPEAR ( ?? )
74
     */
75
    public LttngEventField[] parse(HashMap<String, Object> parsedEvents) {
76
        LttngEventField[] returnedField = new LttngEventField[parsedEvents.size()];
77
        
78
        String fieldName = null;
79
        int position = 0;
80
        Iterator<String> iterator = parsedEvents.keySet().iterator();
81
        while (iterator.hasNext()) {
82
            fieldName = iterator.next();
83
            returnedField[position] = new LttngEventField( fieldName, parsedEvents.get(fieldName) );
84
            position++;
85
        }
86
        
87
        return returnedField;
88
    }
89
    
90
    /* *** FIXME ***
91
     * Evil "do at least something" parse function
92
     * THIS IS JUST FOR COMPATIBILITY! DO NOT USE!
93
     * Content/Format/Fields interelation need to be revisited ASAP
94
     */ 
95
    public LttngEventField[] parse(String uselessContent) {
96
        // *** Begining of the evil "parse String" function
97
        // 
98
        // - 1st : Find the number of ":" in the String. This will be the number of fields in the String. 
99
        //      Highly unreliable, as we depend on String content that we don't control!
100
        int nbFields = 0;
101
        for ( int pos = 0; pos < uselessContent.length(); pos++ ) {
102
            if ( uselessContent.substring(pos, pos+1).equals(":") ) {
103
                nbFields++;
104
            }
105
        }
106
        
107
        // - 2nd : Create the fields array
108
        LttngEventField[] tmpFields = new LttngEventField[nbFields];
109
        
110
        // - 3rd : Fill the array
111
        int fieldPosition = 0;
112
        
113
        int lastFieldPos = 0;
114
        int lastDoubleDottedPos = 0;
115
        int lastSpacePos = 0;
116
        
117
        for ( int pos = 0; pos < uselessContent.length(); pos++ ) {
118
            if ( uselessContent.substring(pos, pos+1).equals(":") ) {
119
                lastDoubleDottedPos = pos;
120
            }
121
            else if ( uselessContent.substring(pos, pos+1).equals(" ") ) {
122
                lastSpacePos = pos;
123
                
124
                // ANOTHER highly unreliable assumption : 
125
                //  Usually, most fields are in the form : "NAME : DATA"
126
                //  We need to skip the space following the double dots
127
                if ( pos > lastDoubleDottedPos+1 ) {
128
                    tmpFields[fieldPosition] = new LttngEventField( uselessContent.substring(lastFieldPos, lastDoubleDottedPos), uselessContent.substring(lastDoubleDottedPos, lastSpacePos)  );
129
                    
130
                    lastFieldPos = pos;
131
                }
132
            }
133
        }
134
        
135
        return tmpFields;
136
    }
137
138
}
0
  + text/plain
139
  + text/plain
(-)src/org/eclipse/linuxtools/lttng/event/LttngEventContent.java (+130 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 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
 *   William Bourque (wbourque@gmail.com) - Initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.linuxtools.lttng.event;
14
15
import org.eclipse.linuxtools.tmf.event.TmfEventContent;
16
17
/**
18
 * <b><u>LttngEventContent</u></b>
19
 * <p>
20
 * Lttng specific implementation of the TmfEventContent
21
 * <p>
22
 * Lttng LttngEventContent is very similar from TMF basic one. <br>
23
 */
24
public class LttngEventContent extends TmfEventContent {
25
    
26
    /**
27
     * Constructor with parameters<br>
28
     * <br>
29
     * Content will be null as no parsed content is given.
30
     * 
31
     * @param thisFormat    The LttngEventFormat relative to the JniEvent
32
     */
33
    public LttngEventContent(LttngEventFormat thisFormat) {
34
        super(null, thisFormat);
35
    }
36
37
    /**
38
     * Constructor with parameters<br>
39
     * 
40
     * @param thisFormat        The LttngEventFormat relative to this JniEvent
41
     * @param thisParsedContent The string content of the JniEvent, already parsed
42
     * 
43
     */
44
    public LttngEventContent(LttngEventFormat thisFormat, String thisParsedContent, LttngEventField[] thisFields) {
45
        super(thisParsedContent, thisFormat);
46
        setFields(thisFields);
47
    }
48
    
49
    
50
    /* (non-Javadoc)
51
     * @see org.eclipse.linuxtools.tmf.event.TmfEventContent#getFields()
52
     */
53
    @Override
54
    public LttngEventField[] getFields() {
55
    	
56
    	// Request the field variable from the inherited class
57
        LttngEventField[] fields = (LttngEventField[])super.getFields();
58
        
59
        // Field may be null if the content hasn't been parse yet
60
        // If that's the case, call the parsing function
61
        if (fields == null) {
62
            fields = ((LttngEventFormat) this.getFormat()).parse(this.getContent());
63
            setFields(fields);
64
        }
65
        return fields;
66
    }
67
68
    /* (non-Javadoc)
69
     * @see org.eclipse.linuxtools.tmf.event.TmfEventContent#getField(int)
70
     */
71
    @Override
72
    public LttngEventField getField(int id) {
73
        assert id >= 0 && id < this.getNbFields();
74
        
75
        LttngEventField returnedField = null;
76
        LttngEventField[] allFields = this.getFields();
77
        
78
        if ( allFields != null ) {
79
        	returnedField = allFields[id];
80
        }
81
        
82
        return returnedField;
83
    }
84
    
85
    /**
86
     * @param thisEvent
87
     * @return
88
     */
89
    public LttngEventField[] getFields(LttngEvent thisEvent) {
90
    	
91
    	// Request the field variable from the inherited class
92
        LttngEventField[] fields = (LttngEventField[])super.getFields();
93
        
94
        // Field may be null if the content hasn't been parse yet
95
        // If that's the case, call the parsing function
96
        if (fields == null) {
97
            fields = ((LttngEventFormat)this.getFormat()).parse(thisEvent);
98
            setFields(fields);
99
        }
100
        return fields;
101
    }
102
    
103
    /**
104
     * @param id
105
     * @param thisEvent
106
     * @return
107
     */
108
    public LttngEventField getField(int id, LttngEvent thisEvent) {
109
        assert id >= 0 && id < this.getNbFields();
110
        
111
        LttngEventField returnedField = null;
112
        LttngEventField[] allFields = this.getFields(thisEvent);
113
        
114
        if ( allFields != null ) {
115
        	returnedField = allFields[id];
116
        }
117
        
118
        return returnedField;
119
    }
120
    
121
122
    /**
123
     * basic toString() method.
124
     * 
125
     * @return Attributes of the object concatenated in String
126
     */
127
    public String toString() {
128
        return getContent().toString();
129
    }
130
}
0
  + text/plain
131
  + text/plain
(-)src/org/eclipse/linuxtools/lttng/event/LttngEventReference.java (+50 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 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
 *   William Bourque (wbourque@gmail.com) - Initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.linuxtools.lttng.event;
14
15
import org.eclipse.linuxtools.tmf.event.*;
16
17
/**
18
 * <b><u>LttngEventReference</u></b>
19
 * <p>
20
 * Lttng specific implementation of the TmfEventReference
21
 * <p>
22
 * The Lttng implementation is the same as the basic Tmf Implementation but allow construction with a String
23
 */
24
public class LttngEventReference extends TmfEventReference {
25
    
26
    
27
    private String tracepath = ""; 
28
    
29
    /**
30
     * Constructor with parameters
31
     * 
32
     * @param referencePath  A string that will be our reference
33
     */
34
    public LttngEventReference(String newTracefilePath, String newTracePath) {
35
        super(newTracefilePath);
36
        
37
        // Save the path of the trace 
38
        tracepath = newTracePath;
39
    }
40
    
41
    
42
    public String getTracepath() {
43
        return tracepath;
44
    }
45
46
    public void setTracepath(String tracepath) {
47
        this.tracepath = tracepath;
48
    }
49
    
50
}
0
  + text/plain
51
  + text/plain
(-)src/org/eclipse/linuxtools/lttng/event/LttngEvent.java (+111 lines)
Line 0 Link Here
1
package org.eclipse.linuxtools.lttng.event;
2
3
import org.eclipse.linuxtools.tmf.event.TmfEvent;
4
import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
5
import org.eclipse.linuxtools.lttng.jni.JniEvent;
6
7
/**
8
 * <b><u>LttngEvent</u></b>
9
 * <p>
10
 * Lttng specific TmfEvent implementation
11
 * <p>
12
 * The main difference from the basic Tmf implementation is that we keep an internal reference to the Jni JniEvent<br>
13
 * The conversion from this LttngEvent to the JniEvent is then possible. 
14
 * </ul>
15
 */
16
@SuppressWarnings("unused")
17
public class LttngEvent extends TmfEvent {
18
    // Reference to the JNI JniEvent. Should only used INTERNALLY
19
    JniEvent jniEventReference = null;
20
    
21
    /**
22
     * Constructor with parameters <br>
23
     * <br>
24
     * 
25
     * @param timestamp  The timestamp of this event   
26
     * @param source     The source of this event
27
     * @param type       The type of this event
28
     * @param content    The content of this event
29
     * @param reference  The reference of this event
30
     * @param lttEvent   A reference to a valid JniEvent object
31
     * 
32
     * @see org.eclipse.linuxtools.tmf.event.TmfTimestamp
33
     * @see org.eclipse.linuxtools.lttng.event.LttngEventSource
34
     * @see org.eclipse.linuxtools.lttng.event.LttngEventType
35
     * @see org.eclipse.linuxtools.lttng.event.LttngEventContent
36
     * @see org.eclipse.linuxtools.lttng.event.LttngEventReference
37
     * @see org.eclipse.linuxtools.lttng.jni.JniEvent
38
     * 
39
     */
40
    public LttngEvent(LttngTimestamp timestamp, LttngEventSource source, LttngEventType type, LttngEventContent content, LttngEventReference reference, JniEvent lttEvent) { 
41
        super(timestamp, source, type, content, reference);
42
        
43
        jniEventReference = lttEvent;
44
    }
45
    
46
    /**
47
     * Return the channel name of this event<br>
48
     * 
49
     * @return String The name of the channel
50
     */
51
    public String getChannelName() {
52
        String returnedValue = "";
53
        
54
        if ( this.getType() instanceof LttngEventType ) {
55
            returnedValue = ( (LttngEventType)this.getType() ).getChannelName();
56
        }
57
        
58
        return returnedValue;
59
    }
60
    
61
    /**
62
     * Return the cpu id number of this event<br>
63
     * 
64
     * @return long The cpu id
65
     */
66
    public long getCpuId() {
67
        long returnedValue =-1;
68
        
69
        if ( this.getType() instanceof LttngEventType ) {
70
            returnedValue = ( (LttngEventType)this.getType() ).getCpuId();
71
        }
72
        
73
        return returnedValue;
74
    }
75
    
76
    /**
77
     * Return the marker name of this event<br>
78
     * 
79
     * @return String The marker name
80
     */
81
    public String getMarkerName() {
82
        String returnedValue = "";
83
        
84
        if ( this.getType() instanceof LttngEventType ) {
85
            returnedValue = ( (LttngEventType)this.getType() ).getMarkerName();
86
        }
87
        
88
        return returnedValue;
89
    }
90
    
91
    /**
92
     * Convert this event into a Jni JniEvent<br>
93
     * <br>
94
     * Note : Some verification are done to make sure the event is still valid on the Jni side.<br>
95
     * If it is not the case, null will be returned.
96
     * 
97
     * @return JniEvent The converted event
98
     * @see org.eclipse.linuxtools.lttng.jni.JniEvent
99
     */
100
    public JniEvent convertEventTmfToJni() {
101
        JniEvent tmpEvent = null;
102
        
103
        // We don't want to send away events that are outdated as their informations could be invalid
104
        //  If the timestamp between the event and the trace are not coherent we will not perform the conversion
105
        if ( jniEventReference.getParentTracefile().getParentTrace().getCurrentEventTimestamp().getTime() == getTimestamp().getValue() ) {
106
            tmpEvent = jniEventReference;
107
        }
108
109
        return tmpEvent;
110
    }
111
}
0
  + text/plain
112
  + text/plain
(-)src/org/eclipse/linuxtools/lttng/event/LttngEventSource.java (+33 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 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
 *   William Bourque (wbourque@gmail.com) - Initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.linuxtools.lttng.event;
14
15
import org.eclipse.linuxtools.tmf.event.*;
16
17
/**
18
 * <b><u>LttngEventSource</u></b>
19
 * <p>
20
 * Lttng specific implementation of the TmfEventSource
21
 * <p>
22
 * The Lttng implementation is the same as the basic Tmf Implementation but allow construction with a String as paramter
23
 */
24
public class LttngEventSource extends TmfEventSource {
25
    /**
26
     * Constructor with parameters
27
     * 
28
     * @param newSource    Name as string of the source.
29
     */
30
    public LttngEventSource(String newSource) {
31
        super(newSource);
32
    }
33
}
0
  + text/plain
34
  + text/plain
(-)src/org/eclipse/linuxtools/lttng/event/LttngEventType.java (+70 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 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
 *   William Bourque (wbourque@gmail.com) - Initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.linuxtools.lttng.event;
14
15
import org.eclipse.linuxtools.tmf.event.*;
16
17
/**
18
 * <b><u>LttngEventType</u></b>
19
 * <p>
20
 * Lttng specific implementation of the TmfEventType
21
 * <p>
22
 * This implementation add some attributes to the basic Tmf object.
23
 */
24
public class LttngEventType extends TmfEventType {
25
    private String  channelName = "";
26
    private long    cpuId = 0;
27
    private String  markerName = "";
28
    
29
    /**
30
     * Constructor with parameters
31
     * 
32
     * @param thisChannelName   Channel name. It is the Tracefile name in LTT.
33
     * @param thisCpuId         CPU id number from LTT
34
     * @param thisMarkerName    JniMarker name. It is the marker_info name in LTT.
35
     * @param thisFormat        The format relative to the event
36
     * @see org.eclipse.linuxtools.lttng.event.LttngEventFormat
37
     */
38
    public LttngEventType(String thisChannelName, long thisCpuId, String thisMarkerName, LttngEventFormat thisFormat) {
39
        super( thisChannelName + "/" + thisCpuId + "/" + thisMarkerName, thisFormat);
40
        
41
        channelName = thisChannelName;
42
        cpuId       = thisCpuId;
43
        markerName  = thisMarkerName;
44
    }
45
46
    
47
    public String getChannelName() {
48
        return channelName;
49
    }
50
    
51
    
52
    public long getCpuId() {
53
        return cpuId;
54
    }
55
    
56
    
57
    public String getMarkerName() {
58
        return markerName;
59
    }
60
    
61
    
62
    /**
63
     * toString() method.
64
     * 
65
     * @return String  TypeId of the object
66
     */
67
    public String toString() {
68
        return getTypeId();
69
    }
70
}
0
  + text/plain
71
  + text/plain
(-)src/org/eclipse/linuxtools/lttng/event/LttngTimestamp.java (+151 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 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
 *   William Bourque (wbourque@gmail.com) - Initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.linuxtools.lttng.event;
14
15
import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
16
17
/**
18
 * <b><u>LttngTimestamp</u></b>
19
 * <p>
20
 * Lttng specific implementation of the TmfTimestamp
21
 * <p>
22
 * The Lttng implementation is the same as the basic Tmf Implementation but allow construction with a TmfTimestamp and a long
23
 */
24
public class LttngTimestamp extends TmfTimestamp {
25
    
26
    /**
27
     * Copy Constructor<br>
28
     * <br>
29
     * Note : this constructor require a TmfTimestamp instead of a LttngTimestamp to save us some casts
30
     * 
31
     * @param newEventTime    The TmfTimestamp object we want to copy
32
     */
33
    public LttngTimestamp(TmfTimestamp newEventTime) {
34
        super(newEventTime);
35
    }
36
    
37
    /**
38
     * Constructor with parameters
39
     * 
40
     * @param newEventTime    JniTime as long, unit expected to be nanoseconds.
41
     */
42
    public LttngTimestamp(long newEventTime) {
43
        super(newEventTime, (byte) -9);
44
    }
45
    
46
    /**
47
     * toString() method.
48
     * 
49
     * @return String  Attributes of this object.
50
     */
51
    public String toString() {
52
//        String returnData = "";
53
//
54
//        returnData += "[lttng_Timestamp: " + getValue() / Jni_C_Common.NANO;
55
//        returnData += "." + getValue() % Jni_C_Common.NANO;
56
//        returnData += " ]";
57
//
58
//        return returnData;
59
60
        // If we are dealing with units of seconds (or higher),
61
        // use the plain formatter
62
        if (fScale >= 0) {
63
            Double value = fValue * Math.pow(10, fScale);
64
            return value.toString();
65
        }
66
67
        // Define a format string
68
        String format = String.format("%%1d.%%0%dd", -fScale);
69
70
        // And format the timestamp value
71
        double scale = Math.pow(10, fScale);
72
        long seconds = (long) (fValue * scale);
73
        long fracts  = fValue - (long) ((double) seconds / scale); 
74
        String result = String.format(format, seconds, fracts);
75
76
        return result;
77
    }
78
79
	/**
80
	 * This method does not use scale and assumes contents to be in nano seconds
81
	 * 
82
	 * @return String Attributes of this object.
83
	 */
84
	public String getSeconds() {
85
		return formatSecs(fValue);
86
	}
87
88
	/**
89
	 * This method does not use scale and assumes contents to be in nano seconds
90
	 * 
91
	 * @return String Attributes of this object.
92
	 */
93
	public String getNanoSeconds() {
94
		return formatNs(fValue);
95
	}
96
97
	/**
98
	 * @param time
99
	 * @return
100
	 */
101
	private String formatSecs(long time) {
102
		long sec = (long) (time * 1E-9);
103
		return String.valueOf(sec);
104
	}
105
106
	/**
107
	 * Obtains the remainder fraction on unit Seconds of the entered value in
108
	 * nanoseconds. e.g. input: 1241207054171080214 ns The number of fraction
109
	 * seconds can be obtained by removing the last 9 digits: 1241207054 the
110
	 * fractional portion of seconds, expressed in ns is: 171080214
111
	 * 
112
	 * @param time
113
	 * @param res
114
	 * @return
115
	 */
116
	private String formatNs(long time) {
117
		boolean neg = time < 0;
118
		if (neg) {
119
			time = -time;
120
		}
121
		// The following approach could be used although performance
122
		// decreases in half.
123
		// String strVal = String.format("%09d", time);
124
		// String tmp = strVal.substring(strVal.length() - 9);
125
126
		StringBuffer temp = new StringBuffer();
127
		long ns = time;
128
		ns %= 1000000000;
129
		if (ns < 10) {
130
			temp.append("00000000");
131
		} else if (ns < 100) {
132
			temp.append("0000000");
133
		} else if (ns < 1000) {
134
			temp.append("000000");
135
		} else if (ns < 10000) {
136
			temp.append("00000");
137
		} else if (ns < 100000) {
138
			temp.append("0000");
139
		} else if (ns < 1000000) {
140
			temp.append("000");
141
		} else if (ns < 10000000) {
142
			temp.append("00");
143
		} else if (ns < 100000000) {
144
			temp.append("0");
145
		}
146
147
		temp.append(ns);
148
		return temp.toString();
149
	}
150
151
}
0
  + text/plain
152
  + text/plain
(-)src/org/eclipse/linuxtools/lttng/event/LttngEventField.java (+59 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 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
 *   William Bourque (wbourque@gmail.com) - Initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.linuxtools.lttng.event;
14
15
import org.eclipse.linuxtools.tmf.event.*;
16
17
/**
18
 * <b><u>LttngEventField</u></b>
19
 * <p>
20
 * Lttng specific implementation of the TmfEventField
21
 * <p>
22
 * Lttng LttngEventField add a "Name" attribute to the Tmf implementation
23
 * This mean the fields will have a name and a value.
24
 */
25
public class LttngEventField extends TmfEventField 
26
{
27
        private String fieldName = "";
28
        
29
        /**
30
         * Constructor with parameters<br>
31
         * 
32
         * @param newContent    The parsedContent we want to populate the field with. 
33
         * 
34
         * @see org.eclipse.linuxtools.lttng.jni.ParsedContent   
35
         */
36
        public LttngEventField(String name, Object newContent) {
37
                super( newContent );
38
        
39
                fieldName = name;
40
        }
41
        
42
        /**
43
         * getter for the name attribute.
44
         */
45
        public String getName() {
46
                return fieldName;
47
        }
48
        
49
        /**
50
         * overrided toString() method.<br>
51
         * <br>
52
         * Print both field name and value.
53
         */
54
        @Override
55
        public String toString() {
56
                return fieldName + " : " + getValue().toString();
57
        }
58
}
59
0
  + text/plain
60
  + text/plain
(-)src/org/eclipse/linuxtools/lttng/trace/LttngEventStream.java (+249 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 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
 *   William Bourque (wbourque@gmail.com) - Initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.linuxtools.lttng.trace;
14
15
import java.io.FileNotFoundException;
16
17
import org.eclipse.linuxtools.lttng.event.LttngEvent;
18
import org.eclipse.linuxtools.lttng.event.LttngEventContent;
19
import org.eclipse.linuxtools.lttng.event.LttngEventField;
20
import org.eclipse.linuxtools.lttng.event.LttngEventFormat;
21
import org.eclipse.linuxtools.lttng.event.LttngEventReference;
22
import org.eclipse.linuxtools.lttng.event.LttngEventSource;
23
import org.eclipse.linuxtools.lttng.event.LttngEventType;
24
import org.eclipse.linuxtools.lttng.event.LttngTimestamp;
25
import org.eclipse.linuxtools.lttng.jni.JniEvent;
26
import org.eclipse.linuxtools.lttng.jni.JniException;
27
import org.eclipse.linuxtools.lttng.jni.JniTime;
28
import org.eclipse.linuxtools.lttng.jni.JniTrace;
29
import org.eclipse.linuxtools.tmf.event.TmfEvent;
30
import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
31
import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
32
import org.eclipse.linuxtools.tmf.trace.TmfTrace;
33
34
/**
35
 * <b><u>LttngEventStream</u></b>
36
 * <p>
37
 * LTTng trace implementation. It accesses the C trace handling library
38
 * (seeking, reading and parsing) through the JNI component.
39
 */
40
public class LttngEventStream extends TmfTrace {
41
42
	private final static boolean IS_PARSING_NEEDED_DEFAULT = true;
43
	private final static int     CHECKPOINT_PAGE_SIZE = 1000;
44
	
45
    // Reference to the current LttngEvent
46
    private LttngEvent currentLttngEvent = null;
47
    
48
    // Reference to our JNI trace
49
    private JniTrace currentJniTrace = null;
50
    
51
    /**
52
     * Constructor
53
     * <p>
54
     * @param path Path to a <b>directory</b> that contain an LTTng trace.
55
     * @exception Exception Trace opening failed (FileNotFoundException)
56
     * 
57
     * @see org.eclipse.linuxtools.lttng.jni.JniTrace
58
     */
59
    public LttngEventStream(String path) throws Exception {
60
        super(path, CHECKPOINT_PAGE_SIZE);
61
        try {
62
            currentJniTrace = new JniTrace(path);
63
        }
64
        catch (JniException e) {
65
            throw new FileNotFoundException();
66
        }
67
        TmfTimestamp startTime = new LttngTimestamp(currentJniTrace.getStartTimeFromTimestampCurrentCounter().getTime());
68
        setTimeRange(new TmfTimeRange(startTime, startTime));
69
        indexStream();
70
    }
71
    
72
	/* (non-Javadoc)
73
	 * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#parseNextEvent()
74
	 */
75
	public synchronized TmfEvent parseNextEvent() {
76
    	JniEvent jniEvent = currentJniTrace.readNextEvent();
77
    	currentLttngEvent = convertJniEventToTmf(jniEvent);
78
        return currentLttngEvent;
79
	}
80
81
    /**
82
     * Return a reference to the current LttngTrace we are reading from.
83
     * 
84
     * @return JniTrace
85
     * @see org.eclipse.linuxtools.lttng.jni.JniTrace
86
     */
87
    public JniTrace getCurrentJniTrace() {
88
        return currentJniTrace;
89
    }
90
    
91
    
92
    /**
93
     * Return a reference to the current LttngEvent we are reading.
94
     * 
95
     * @return LttngEvent
96
     * @see org.eclipse.linuxtools.lttng.event.LttngEvent
97
     */
98
    public LttngEvent getCurrentEvent() {
99
        return currentLttngEvent;
100
    }
101
    
102
    
103
    /**
104
     * Method to convert a JniEvent into a LttngEvent.<br>
105
     * <br>
106
     * Note : This method will call LttngEvent convertEventJniToTmf(JniEvent, boolean)
107
     * with a default value for isParsingNeeded
108
     * 
109
     * @param   newEvent     The JniEvent to convert
110
     * @return  LttngEvent   The converted event
111
     * @see org.eclipse.linuxtools.lttng.jni.JniEvent
112
     */
113
    public LttngEvent convertJniEventToTmf(JniEvent newEvent) {
114
    	LttngEvent event = null;
115
    	if (newEvent != null)
116
    		event = convertJniEventToTmf(newEvent, IS_PARSING_NEEDED_DEFAULT);
117
    	return event;
118
    }
119
    
120
    /**
121
     * Method tp convert a JniEvent into a LttngEvent
122
     * 
123
     * @param   jniEvent        The JniEvent to convert
124
     * @param   isParsingNeeded A boolean value telling if the event should be parsed or not.
125
     * @return  LttngEvent   The converted event
126
     * @see org.eclipse.linuxtools.lttng.jni.JniEvent
127
     */
128
    // Conversion method to transform a JafEvent into a TmfEvent
129
    public LttngEvent convertJniEventToTmf(JniEvent jniEvent, boolean isParsingNeeded) {
130
        LttngEventFormat eventFormat = new LttngEventFormat();
131
        String content = "";
132
        LttngEventField[] fields = null;
133
134
        if (isParsingNeeded == true) {
135
            fields = eventFormat.parse(jniEvent.parseAllFields());
136
            for (int y = 0; y < fields.length; y++) {
137
                content += fields[y].toString() + " ";
138
            }
139
        }
140
        
141
        LttngEvent event = new LttngEvent(
142
        		new LttngTimestamp(jniEvent.getEventTime().getTime()),
143
                new LttngEventSource(jniEvent.requestEventSource() ), 
144
                new LttngEventType(jniEvent.getParentTracefile().getTracefileName(),
145
                                   jniEvent.getParentTracefile().getCpuNumber(),
146
                                   jniEvent.requestEventMarker().getName(),
147
                                   eventFormat),
148
                new LttngEventContent(eventFormat, content, fields), 
149
                new LttngEventReference(jniEvent.getParentTracefile().getTracefilePath(), this.getName()),
150
                jniEvent);
151
        
152
        return event;
153
    }
154
    
155
    
156
    /**
157
     * Return location (timestamp) of our current position in the trace.
158
     * 
159
     * @return LttngTimestamp The current Ltt timestamp, in long. Unit is nanosecond.
160
     */
161
    public Object getCurrentLocation() {
162
        return new LttngTimestamp(currentJniTrace.getCurrentEventTimestamp().getTime());
163
    }
164
    
165
    /**
166
     * Seek (move) to a certain location in the trace.
167
     * 
168
     * @param location  a LttngTimestamp of a position in the trace
169
     * @return StreamContext pointing to the current (after seek) position in the trace
170
     */
171
    public TmfTraceContext seekLocation(Object location) {
172
        
173
        // If location is null, interpret this as a request to get back to the beginning of the trace
174
        // Change the location, the seek will happen below
175
    	if (location == null) {
176
    		location = getStartTime();
177
    	}
178
    	
179
        TmfTraceContext context = null;
180
    	if (location instanceof LttngTimestamp) {
181
    		long value = ((LttngTimestamp) location).getValue();
182
    		if (value != currentJniTrace.getCurrentEventTimestamp().getTime()) {
183
    			currentJniTrace.seekToTime(new JniTime(value));
184
    			context = new TmfTraceContext(new LttngTimestamp(currentJniTrace.getCurrentEventTimestamp().getTime()), 0);
185
    		}
186
    	}
187
    	
188
        return context;
189
    }
190
    
191
    
192
    // !!! THIS MAIN IS FOR TESTING ONLY !!!
193
    public static void main(String[] args) {
194
195
//        LttngEventStream testStream = null;
196
//        try {
197
//            testStream = new LttngEventStream("/home/william/trace1");
198
//            Thread.sleep(5000);
199
//            
200
//            System.out.println("NB Events : " + testStream.getNbEvents());
201
//            System.out.println("Beginning test run parsing event");
202
//            
203
//            LttngEvent tmpEvent = null;
204
//            Random generator = new Random();
205
//            
206
//            int number = 0;
207
//            long execStartTime = System.currentTimeMillis();
208
//            for (int x = 0; x < 10; x++) {
209
//                number = generator.nextInt(testStream.getNbEvents());
210
//                
211
//                tmpEvent = (LttngEvent) testStream.getEvent(new TmfTraceContext(null), number);
212
//                
213
//                
214
//                System.out.println("GETTING EVENT #" + number);
215
//                
216
//                // *****************
217
//                // ***  OLD EVIL WAY  
218
//                TmfEventField[] tmpJoieFields = tmpEvent.getContent().getFields();
219
//                for ( int pos = 0; pos< tmpJoieFields.length; pos++  )
220
//                {
221
//                    System.out.print(tmpJoieFields[pos].toString() + " ");
222
//                }
223
//                System.out.println("");
224
//                // ***
225
//                // *****************
226
//                
227
//                
228
//                // *****************
229
//                // ***  NEW CAST-O-RAMA WAY  
230
//                TmfEventField[] tmpJoieFields2 = ( (LttngEventContent)tmpEvent.getContent()).getFields(tmpEvent);
231
//                for ( int pos = 0; pos< tmpJoieFields2.length; pos++  )
232
//                {
233
//                    System.out.print(tmpJoieFields2[pos].toString() + " ");
234
//                }
235
//                System.out.println("");
236
//                // ***
237
//                // *****************
238
//            }
239
//            long execEndTime = System.currentTimeMillis();
240
//            System.out.println("Execution time: " + (execEndTime - execStartTime) + "ms");
241
//            
242
//
243
//        } catch (Exception e) {
244
//            System.out.println("FAILED WITH : " + e.getMessage() + "\n");
245
//        }
246
247
    }
248
249
}
0
  + text/plain
250
  + text/plain

Return to bug 290046