Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 147783 Details for
Bug 290046
[LTTng] Integrate LTTng
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
LTTng library integration
LTTng.patch (text/plain), 140.74 KB, created by
Francois Chouinard
on 2009-09-22 10:41:51 EDT
(
hide
)
Description:
LTTng library integration
Filename:
MIME Type:
Creator:
Francois Chouinard
Created:
2009-09-22 10:41:51 EDT
Size:
140.74 KB
patch
obsolete
>Index: META-INF/MANIFEST.MF >=================================================================== >--- META-INF/MANIFEST.MF (revision 23014) >+++ META-INF/MANIFEST.MF (revision 23015) >@@ -9,3 +9,6 @@ > org.eclipse.linuxtools.tmf;bundle-version="0.0.1" > Bundle-RequiredExecutionEnvironment: J2SE-1.5 > Bundle-ActivationPolicy: lazy >+Export-Package: org.eclipse.linuxtools.lttng, >+ org.eclipse.linuxtools.lttng.event, >+ org.eclipse.linuxtools.lttng.trace >Index: src/org/eclipse/linuxtools/lttng/jni/JniException.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/jni/JniException.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/jni/JniException.java (revision 23015) >@@ -0,0 +1,169 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * William Bourque (wbourque@gmail.com) - Initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.linuxtools.lttng.jni; >+ >+/** >+ * <b><u>JniException</u></b> >+ * <p> >+ * Super exception class for JNI >+ */ >+public class JniException extends Exception { >+ private static final long serialVersionUID = -6620784221853154537L; >+ >+ JniException(String errMsg) { >+ super(errMsg); >+ } >+} >+ >+/** >+ * <b><u>JniTraceException</u></b> >+ * <p> >+ * Basic exception class for the JniTrace class >+ */ >+class JniTraceException extends JniException { >+ private static final long serialVersionUID = -6873007333085268143L; >+ >+ JniTraceException(String errMsg) { >+ super(errMsg); >+ } >+} >+ >+/** >+ * <b><u>JniOpenTraceFailedException</u></b> >+ * <p> >+ * Sub-exception class type for JniTraceException >+ * This type will get thrown when a trace fail to open >+ * Most likely to be caused by a bad tracepath >+ */ >+class JniOpenTraceFailedException extends JniTraceException { >+ private static final long serialVersionUID = 877769692366394895L; >+ >+ JniOpenTraceFailedException(String errMsg) { >+ super(errMsg); >+ } >+} >+ >+/** >+ * <b><u>JniNoNextEventInTraceException</u></b> >+ * <p> >+ * Sub-exception class type for JniTraceException >+ * This type will get thrown when we can't find any "next" event >+ * This should usually mean there is no more event in the trace >+ >+ */ >+class JniNoNextEventInTraceException extends JniTraceException { >+ private static final long serialVersionUID = -2887528566100063849L; >+ >+ JniNoNextEventInTraceException(String errMsg) { >+ super(errMsg); >+ } >+} >+ >+// >+/** >+ * <b><u>JniTracefileException</u></b> >+ * <p> >+ * Basic exception class for the JniTracefile class >+ */ >+class JniTracefileException extends JniException { >+ private static final long serialVersionUID = 5081317864491800084L; >+ >+ JniTracefileException(String errMsg) { >+ super(errMsg); >+ } >+} >+ >+/** >+ * <b><u>JniTracefileWithoutEventException</u></b> >+ * <p> >+ * Sub-exception class type for JniTracefileException >+ * This type will get thrown when a trace file contain no readable events >+ * The proper course of action would usually be to ignore this useless trace file >+ */ >+class JniTracefileWithoutEventException extends JniTracefileException { >+ private static final long serialVersionUID = -8183967479236071261L; >+ >+ JniTracefileWithoutEventException(String errMsg) { >+ super(errMsg); >+ } >+} >+ >+/** >+ * <b><u>JniEventException</u></b> >+ * <p> >+ * Basic exception class for the JniEvent class >+ */ >+class JniEventException extends JniException { >+ private static final long serialVersionUID = -5891749130387304519L; >+ >+ JniEventException(String errMsg) { >+ super(errMsg); >+ } >+} >+ >+/** >+ * <b><u>JniNoSuchEventException</u></b> >+ * <p> >+ * Sub-exception type for the JniEventException type >+ * This exception type will get thrown when an event is unavailable >+ * This might happen at construction because some events type are not present in >+ * the trace >+ */ >+class JniNoSuchEventException extends JniEventException { >+ private static final long serialVersionUID = -4379712949891538051L; >+ >+ JniNoSuchEventException(String errMsg) { >+ super(errMsg); >+ } >+} >+ >+/** >+ * <b><u>JniEventOutOfRangeException</u></b> >+ * <p> >+ * Sub-exception type for the JniEventException type >+ * This exception type will get thrown when there is no more event of this type >+ * available >+ */ >+class JniEventOutOfRangeException extends JniEventException { >+ private static final long serialVersionUID = -4645877232795324541L; >+ >+ JniEventOutOfRangeException(String errMsg) { >+ super(errMsg); >+ } >+} >+ >+/** >+ * <b><u>JniMarkerException</u></b> >+ * <p> >+ * Basic Exception class for the JniMarker class >+ */ >+class JniMarkerException extends JniException { >+ private static final long serialVersionUID = -4694173610721983794L; >+ >+ JniMarkerException(String errMsg) { >+ super(errMsg); >+ } >+} >+ >+/** >+ * <b><u>JniMarkerFieldException</u></b> >+ * <p> >+ * Basic Exception class for the JniMarkerField class >+ */ >+class JniMarkerFieldException extends JniException { >+ private static final long serialVersionUID = 6066381741374806879L; >+ >+ JniMarkerFieldException(String errMsg) { >+ super(errMsg); >+ } >+} > >Property changes on: src/org/eclipse/linuxtools/lttng/jni/JniException.java >___________________________________________________________________ >Added: svn:mime-type > + text/plain > >Index: src/org/eclipse/linuxtools/lttng/jni/JniTime.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/jni/JniTime.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/jni/JniTime.java (revision 23015) >@@ -0,0 +1,157 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * William Bourque (wbourque@gmail.com) - Initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.linuxtools.lttng.jni; >+ >+/** >+ * <b><u>JniTime</u></b> >+ * <p> >+ * JniTime object linked to the LttTime C structure >+ */ >+public final class JniTime extends Jni_C_Common >+{ >+ private long time = 0; >+ >+ /** >+ * Default constructor. >+ * >+ */ >+ JniTime() { >+ time = 0; >+ } >+ >+ /** >+ * Copy constructor. >+ * >+ * @param oldTime A reference to the JniTime you want to copy. >+ */ >+ JniTime(JniTime oldTime) { >+ time = oldTime.getTime(); >+ } >+ >+ /** >+ * Constructor with parameters >+ * <br> >+ * "Ltt style" constructor with Seconds et Nanoseconds >+ * >+ * @param newSec Seconds of the JniTime >+ * @param newNanoSec Nanoseconds of the JniTime >+ */ >+ JniTime(long newSec, long newNanoSec) { >+ time = (newSec * NANO) + newNanoSec; >+ } >+ >+ /** >+ * Constructor with parameters >+ * <br> >+ * Usual "nanosecond only" constructor >+ * >+ * @param newNanoSecTime JniTime in nanoseconds >+ */ >+ public JniTime(long newNanoSecTime) { >+ time = newNanoSecTime; >+ } >+ >+ /** >+ * Getter for the second of the time >+ * <br> >+ * This only return seconds part, i.e. multiple of 1 000 000, of the stored time >+ * >+ * @return long Second of the time >+ */ >+ public long getSeconds() { >+ return (time / NANO); >+ } >+ >+ /** >+ * Getter for the nanosecond of the time >+ * <br> >+ * This only nanosecondspart , i.e. modulo of 1 000 000, of the stored time >+ * >+ * @return long Nanoseconds of the time >+ */ >+ public long getNanoSeconds() { >+ return time % NANO; >+ } >+ >+ /** >+ * Getter for the full time, in nanoseconds >+ * >+ * @return The complete time in nanoseconds >+ */ >+ public long getTime() { >+ return time; >+ } >+ >+ /** >+ * Comparaison operator <= >+ * >+ * @param comparedTime The time we want to compare with this one >+ * @return boolean true if the compared time is smaller or equal, false otherwise >+ */ >+ public boolean isGivenTimeSmallerOrEqual(JniTime comparedTime) { >+ >+ // NOTE : We check <= instead of just < >+ // This mean the RIGHT OPERAND (comparedTime) always prevails >+ if (comparedTime.getTime() < this.getTime()) { >+ return true; >+ } else { >+ return false; >+ } >+ } >+ >+ /** >+ * Integer Comparaison operator >+ * >+ * @param comparedTime The time we want to compare with this one >+ * @return int Integer of value -1, 0 or 1, as the pased argument is bigger, equal or smaller than this time >+ */ >+ public int compare(JniTime comparedTime) { >+ if ( comparedTime.getTime() < this.getTime() ) { >+ return 1; >+ } >+ else if ( comparedTime.getTime() > this.getTime() ) { >+ return -1; >+ } >+ else { >+ return 0; >+ } >+ } >+ >+ /* >+ * Populate this time object >+ * >+ * Note: This function is called from C side. >+ * >+ * @param newTime The time we want to populate >+ */ >+ @SuppressWarnings("unused") >+ private void setTimeFromC(long newTime) { >+ time = newTime; >+ } >+ >+ /** >+ * toString() method. <u>Intended to debug</u><br> >+ * <br> >+ * NOTE : we output the time in the same format as LTT (seconds and nanosecond separatly) >+ * >+ * @return String Attributes of the object concatenated in String >+ */ >+ public String toString() { >+ String returnData = ""; >+ >+ returnData += "seconds : " + this.getSeconds() + "\n"; >+ returnData += "nanoSeconds : " + this.getNanoSeconds() + "\n"; >+ >+ return returnData; >+ } >+} > >Property changes on: src/org/eclipse/linuxtools/lttng/jni/JniTime.java >___________________________________________________________________ >Added: svn:mime-type > + text/plain > >Index: src/org/eclipse/linuxtools/lttng/jni/JniTrace.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/jni/JniTrace.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/jni/JniTrace.java (revision 23015) >@@ -0,0 +1,741 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * William Bourque (wbourque@gmail.com) - Initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.linuxtools.lttng.jni; >+ >+import java.util.Comparator; >+import java.util.HashMap; >+import java.util.Iterator; >+import java.util.PriorityQueue; >+ >+/** >+ * <b><u>JniTrace</u></b> >+ * <p> >+ * This is the top level class in the JNI. It provides access to the >+ * LttTrace C structure in java. >+ * <p> >+ * Most important fields in the JniTrace are : >+ * <ul> >+ * <li>a JniTrace path (a trace <b>directory</b>) >+ * <li>a HashMap of tracefiles that exists in this trace >+ * </ul> >+ */ >+public class JniTrace extends Jni_C_Common { >+ >+ // Internal C pointer of the JniTrace used in LTT >+ private C_Pointer thisTracePtr = new C_Pointer(); >+ >+ // Data we should populate from LTT >+ // Note that all type have been scaled up as there is no "unsigned" in java >+ // This might be a problem about "unsigned long" as there is no equivalent >+ // in java >+ >+ private String tracepath = ""; // Path of the trace. Should be a directory (like : /tmp/traceX) >+ private int cpuNumber = 0; >+ private long archType = 0; >+ private long archVariant = 0; >+ private short archSize = 0; >+ private short lttMajorVersion = 0; >+ private short lttMinorVersion = 0; >+ private short flightRecorder = 0; >+ private long freqScale = 0; >+ private long startFreq = 0; >+ private long startTimestampCurrentCounter = 0; >+ private long startMonotonic = 0; >+ private JniTime startTime = null; >+ private JniTime startTimeFromTimestampCurrentCounter = null; >+ >+ // This Map holds a reference to the tracefiles owned by this trace >+ private HashMap<String, JniTracefile> tracefilesMap = null; >+ // The priority queue (similar to heap) hold events >+ private PriorityQueue<JniEvent> eventsHeap = null; >+ >+ // This variable will hold the content of the "last" event we read >+ private JniTime currentEventTimestamp = new JniTime(); >+ >+ // Comparator we will need for the heap construction >+ private Comparator<JniEvent> eventComparator = new Comparator<JniEvent>() { >+ public int compare(JniEvent left, JniEvent right ){ >+ return ( left.getEventTime().compare( right.getEventTime() ) ); >+ } >+ }; >+ >+ >+ // Open/close native functions >+ private native long ltt_openTrace(String pathname); >+ private native void ltt_closeTrace(long tracePtr); >+ >+ // Native access functions >+ private native String ltt_getTracepath(long tracePtr); >+ private native int ltt_getCpuNumber(long tracePtr); >+ private native long ltt_getArchType(long tracePtr); >+ private native long ltt_getArchVariant(long tracePtr); >+ private native short ltt_getArchSize(long tracePtr); >+ private native short ltt_getLttMajorVersion(long tracePtr); >+ private native short ltt_getLttMinorVersion(long tracePtr); >+ private native short ltt_getFlightRecorder(long tracePtr); >+ private native long ltt_getFreqScale(long tracePtr); >+ private native long ltt_getStartFreq(long tracePtr); >+ private native long ltt_getStartTimestampCurrentCounter(long tracePtr); >+ private native long ltt_getStartMonotonic(long tracePtr); >+ >+ // Native function to fill out startTime >+ private native void ltt_feedStartTime(long tracePtr, JniTime startTime); >+ >+ // Native function to fill out startTimeFromTimestampCurrentCounter >+ private native void ltt_feedStartTimeFromTimestampCurrentCounter(long tracePtr, JniTime startTime); >+ >+ // Native function to fill out tracefilesMap >+ private native void ltt_getAllTracefiles(long tracePtr); >+ >+ // Debug native function, ask LTT to print trace structure >+ private native void ltt_printTrace(long tracePtr); >+ >+ static { >+ System.loadLibrary("lttvtraceread"); >+ } >+ >+ /** >+ * Default constructor is forbidden >+ */ >+ @SuppressWarnings("unused") >+ private JniTrace() { >+ } >+ >+ /** >+ * Copy constructor. >+ * >+ * @param oldTrace >+ * A reference to the JniTrace you want to copy. >+ */ >+ public JniTrace(JniTrace oldTrace) { >+ thisTracePtr = oldTrace.thisTracePtr; >+ >+ tracepath = oldTrace.tracepath; >+ cpuNumber = oldTrace.cpuNumber; >+ archType = oldTrace.archType; >+ archVariant = oldTrace.archVariant; >+ archSize = oldTrace.archSize; >+ lttMajorVersion = oldTrace.lttMajorVersion; >+ lttMinorVersion = oldTrace.lttMinorVersion; >+ flightRecorder = oldTrace.flightRecorder; >+ freqScale = oldTrace.freqScale; >+ startFreq = oldTrace.startFreq; >+ startTimestampCurrentCounter = oldTrace.startTimestampCurrentCounter; >+ startMonotonic = oldTrace.startMonotonic; >+ startTime = oldTrace.startTime; >+ startTimeFromTimestampCurrentCounter = oldTrace.startTimeFromTimestampCurrentCounter; >+ >+ tracefilesMap = new HashMap<String, JniTracefile>(oldTrace.tracefilesMap.size()); >+ tracefilesMap = oldTrace.tracefilesMap; >+ >+ eventsHeap = new PriorityQueue<JniEvent>( oldTrace.eventsHeap.size(), eventComparator ); >+ eventsHeap = oldTrace.eventsHeap; >+ } >+ >+ /** >+ * Copy constructor, using pointer. >+ * >+ * @param newPtr The pointer to an already opened LttTrace C structure >+ * >+ * @exception JniException >+ */ >+ public JniTrace(C_Pointer newPtr) throws JniException { >+ thisTracePtr = newPtr; >+ >+ // Populate our trace >+ populateTraceInformation(); >+ } >+ >+ /** >+ * Constructor that takes a tracepath parameter >+ * <br> >+ * This constructor also opens the trace >+ * >+ * @param newpath The <b>directory</b> of the trace to be opened >+ * >+ * @exception JniException >+ */ >+ public JniTrace(String newpath) throws JniException { >+ tracepath = newpath; >+ thisTracePtr = new C_Pointer(); >+ >+ openTrace(newpath); >+ } >+ >+ /** >+ * Open an existing trace<br> >+ * <br> >+ * The tracepath is a directory and needs to exist, otherwise >+ * a JafOpenTraceFailedException is raised. >+ * >+ * @param newPath >+ * The <b>directory</b> of the trace to be opened >+ * @exception JafOpenTraceFailedException >+ * Thrown if the open failed >+ */ >+ public void openTrace(String newPath) throws JniException { >+ // If open is called while a trace is already opened, we will try to close it first >+ if (thisTracePtr.getPointer() != NULL) { >+ closeTrace(); >+ } >+ >+ // Set the tracepath and open it >+ tracepath = newPath; >+ openTrace(); >+ } >+ >+ /** >+ * Open an existing trace<br> >+ * <br> >+ * The tracepath should have been set already, >+ * >+ * @exception JafOpenTraceFailedException >+ * Thrown if the open failed >+ */ >+ public void openTrace() throws JniException { >+ >+ // Raise an exception if the tracepath is empty, otherwise open the trace >+ if (tracepath == "") { >+ throw new JniTraceException("Tracepath is not set. (openTrace)"); >+ } >+ >+ // If the file is already opened, close it first >+ if (thisTracePtr.getPointer() != NULL) { >+ closeTrace(); >+ } >+ >+ // Call the LTT to open the trace >+ long newPtr = ltt_openTrace(tracepath); >+ if (newPtr == NULL) { >+ throw new JniOpenTraceFailedException("Error while opening trace. Is the tracepath correct? (openTrace)"); >+ } >+ >+ // This is OUR pointer >+ thisTracePtr = new C_Pointer(newPtr); >+ >+ // Populate the trace with LTT information >+ populateTraceInformation(); >+ } >+ >+ /** >+ * Close a trace >+ * >+ * If the trace is already closed, will silently do nothing. >+ */ >+ public void closeTrace() { >+ if (thisTracePtr.getPointer() != NULL) { >+ ltt_closeTrace(thisTracePtr.getPointer()); >+ thisTracePtr = new C_Pointer(NULL); >+ >+ // Clear the tracefile map >+ tracefilesMap.clear(); >+ tracefilesMap = null; >+ >+ // Clear the eventsHeap and make it points to null >+ eventsHeap.clear(); >+ eventsHeap = null; >+ >+ // Ask the garbage collector to make a little pass here, as we could >+ // be left with 100's of unreferenced objects >+ System.gc(); >+ } >+ } >+ >+ /* >+ * This function populates the trace data with data from LTT >+ * >+ * @throws JafException >+ */ >+ private void populateTraceInformation() throws JniException { >+ if (thisTracePtr.getPointer() == NULL) { >+ throw new JniTraceException("Pointer is NULL, trace not opened/already closed? (populateTraceInformation)"); >+ } >+ >+ // Populate from the LTT library >+ tracepath = ltt_getTracepath( thisTracePtr.getPointer() ); >+ cpuNumber = ltt_getCpuNumber( thisTracePtr.getPointer() ); >+ archType = ltt_getArchType( thisTracePtr.getPointer() ); >+ archVariant = ltt_getArchVariant( thisTracePtr.getPointer() ); >+ archSize = ltt_getArchSize( thisTracePtr.getPointer() ); >+ lttMajorVersion = ltt_getLttMajorVersion( thisTracePtr.getPointer() ); >+ lttMinorVersion = ltt_getLttMinorVersion( thisTracePtr.getPointer() ); >+ flightRecorder = ltt_getFlightRecorder( thisTracePtr.getPointer() ); >+ freqScale = ltt_getFreqScale( thisTracePtr.getPointer() ); >+ startFreq = ltt_getStartFreq( thisTracePtr.getPointer() ); >+ startTimestampCurrentCounter = ltt_getStartTimestampCurrentCounter( thisTracePtr.getPointer() ); >+ startMonotonic = ltt_getStartMonotonic( thisTracePtr.getPointer() ); >+ >+ // Creation of time is a bit different, we need to pass the object reference to C >+ startTime = new JniTime(); >+ ltt_feedStartTime( thisTracePtr.getPointer(), startTime ); >+ >+ startTimeFromTimestampCurrentCounter = new JniTime(); >+ ltt_feedStartTimeFromTimestampCurrentCounter( thisTracePtr.getPointer(), startTimeFromTimestampCurrentCounter ); >+ >+ // Call the fill up function for the tracefiles map >+ if ( tracefilesMap== null ) { >+ tracefilesMap = new HashMap<String, JniTracefile>(); >+ } >+ >+ ltt_getAllTracefiles( thisTracePtr.getPointer() ); >+ >+ if (eventsHeap == null) { >+ eventsHeap = new PriorityQueue<JniEvent>(tracefilesMap.size(), eventComparator); >+ } >+ >+ // Populate the heap with events >+ populateEventHeap(); >+ } >+ >+ /* >+ * This function populates the event heap with one event from each tracefile >+ * It should be called after each seek or when the object is constructed >+ */ >+ private void populateEventHeap() { >+ currentEventTimestamp = new JniTime(); >+ eventsHeap.clear(); >+ >+ Object new_key = null; >+ JniTracefile tmpTracefile = null; >+ >+ Iterator<String> iterator = tracefilesMap.keySet().iterator(); >+ while( iterator.hasNext() ) { >+ new_key = iterator.next(); >+ >+ tmpTracefile = tracefilesMap.get(new_key); >+ if ( tmpTracefile.getCurrentEvent().getEventState() == EOK ) { >+ eventsHeap.add( tmpTracefile.getCurrentEvent() ); >+ } >+ } >+ } >+ >+ /* >+ * Fills a map of all the trace files. >+ * >+ * Note: This function is called from C and there is no way to propagate >+ * exception back to the caller without crashing JNI. Therefore, it MUST >+ * catch all exceptions. >+ * >+ * @param tracefileName >+ * @param tracefilePtr >+ */ >+ @SuppressWarnings("unused") >+ private void addTracefileFromC(String tracefileName, long tracefilePtr) { >+ // Create a new tracefile object and insert it in the map >+ // the tracefile fill itself with LTT data while being constructed >+ try { >+ JniTracefile newTracefile = new JniTracefile( new C_Pointer(tracefilePtr), this ); >+ tracefilesMap.put(tracefileName, newTracefile); >+ } >+ catch(JniTracefileWithoutEventException e) { >+ printlnC("JniTracefile " + tracefileName + " has no event (addTracefileFromC). Ignoring."); >+ } >+ catch(Exception e) { >+ printlnC("Failed to add tracefile " + tracefileName + " to tracefilesMap!(addTracefileFromC)\n\tException raised : " + e.toString() ); >+ } >+ } >+ >+ >+ /** >+ * Return the next event, determined by timestamp, among the trace files. >+ * The event content is populated. >+ * >+ * Returns null in case of error or if we reach end of trace. >+ * >+ * @return The next event in the trace or null >+ * @see org.eclipse.linuxtools.lttng.jni.JniEvent >+ */ >+ public JniEvent readNextEvent() { >+ // Get the "next" event on the top of the heap but DO NOT remove it >+ JniEvent tmpEvent = eventsHeap.peek(); >+ >+ // If the event is null, it was the last one in the trace we can leave the function >+ if (tmpEvent == null) { >+ return null; >+ } >+ >+ // Otherwise, we need to make sure the timestamp of the event we got is not the same as the last "NextEvent" we requested >+ if (tmpEvent.getEventTime().getTime() == currentEventTimestamp.getTime() ) { >+ // Remove the event on top as it is the same currentEventTimestamp >+ eventsHeap.poll(); >+ >+ // Read the next event for this particular event type >+ tmpEvent.readNextEvent(); >+ >+ // If the event state is sane (not Out of Range), put it back in the heap >+ if ( tmpEvent.getEventState() == EOK ) { >+ eventsHeap.add(tmpEvent); >+ } >+ >+ // Pick the top event again >+ tmpEvent = eventsHeap.peek(); >+ >+ // Save the timestamp if the event is not null (null mean we reached the last event in the trace) >+ if (tmpEvent != null) { >+ currentEventTimestamp = tmpEvent.getEventTime(); >+ } >+ } >+ // If the event on top has differetn timestamp than the currentTimestamp, just save this timestamp as current >+ else { >+ currentEventTimestamp = tmpEvent.getEventTime(); >+ } >+ >+ return tmpEvent; >+ } >+ >+ /** >+ * Return the next event, determined by timestamp, among the trace files. >+ * The event content is NOT populated (requires a call to readNextEvent()). >+ * >+ * Returns null in case of error or EOF. >+ * >+ * @return The next event, or null if none is available >+ * @see org.eclipse.linuxtools.lttng.jni.JniEvent >+ */ >+ public JniEvent findNextEvent() { >+ return eventsHeap.peek(); >+ } >+ >+ /** >+ * Seek to a certain time and read the next event from that time.<br> >+ * <br> >+ * If no more events are available or an error happen, null will be returned >+ * >+ * @param seekTime The time where we want to seek to >+ * @return JniEvent The next event after the seek time or null >+ * >+ * @see org.eclipse.linuxtools.lttng.jni.JniEvent >+ */ >+ public JniEvent seekAndRead(JniTime seekTime) { >+ JniEvent returnedEvent = null; >+ seekToTime(seekTime); >+ >+ // The trace should be correctly positionned, let's get the event >+ returnedEvent = readNextEvent(); >+ >+ return returnedEvent; >+ } >+ >+ /** >+ * Seek to a certain time but <b>do not</b> read the next event.<br> >+ * <br> >+ * This only position the trace, it will not return anything. >+ * >+ * @param seekTime The time where we want to seek to >+ */ >+ public void seekToTime(JniTime seekTime) { >+ Object tracefile_name = null; >+ Iterator<String> iterator = tracefilesMap.keySet().iterator(); >+ >+ while (iterator.hasNext() ) { >+ // We seek to the given event for ALL tracefiles >+ tracefile_name = iterator.next(); >+ tracefilesMap.get(tracefile_name).seekToTime(seekTime); >+ } >+ >+ populateEventHeap(); >+ } >+ >+ /** >+ * Get a certain tracefile from its given name<br> >+ * >+ * @param tracefileName The name of the tracefile >+ * @return JniTracefile The tracefile found or null if none >+ * @see org.eclipse.linuxtools.lttng.jni.JniTracefile >+ */ >+ public JniTracefile requestTracefileByName(String tracefileName) { >+ return tracefilesMap.get(tracefileName); >+ } >+ >+ /** >+ * Get a certain event associated to a trace file from the trace file name<br> >+ * >+ * @param tracefileName The name of the trace file >+ * @return The JniEvent found or null if none >+ * @see org.eclipse.linuxtools.lttng.jni.JniEvent >+ */ >+ public JniEvent requestEventByName(String tracefileName) { >+ JniEvent returnValue = null; >+ >+ JniTracefile tmpTracefile = tracefilesMap.get(tracefileName); >+ >+ // If the tracefile is found, return the current event >+ // There should always be an event linked to a tracefile >+ if (tmpTracefile != null) { >+ returnValue = tmpTracefile.getCurrentEvent(); >+ } >+ >+ return returnValue; >+ } >+ >+ // Access to class variable. Most of them doesn't have setter >+ public String getTracepath() { >+ return tracepath; >+ } >+ >+ public int getCpuNumber() { >+ return cpuNumber; >+ } >+ >+ public long getArchType() { >+ return archType; >+ } >+ >+ public long getArchVariant() { >+ return archVariant; >+ } >+ >+ public short getArchSize() { >+ return archSize; >+ } >+ >+ public short getLttMajorVersion() { >+ return lttMajorVersion; >+ } >+ >+ public short getLttMinorVersion() { >+ return lttMinorVersion; >+ } >+ >+ public short getFlightRecorder() { >+ return flightRecorder; >+ } >+ >+ public long getFreqScale() { >+ return freqScale; >+ } >+ >+ public long getStartFreq() { >+ return startFreq; >+ } >+ >+ public long getStartTimestampCurrentCounter() { >+ return startTimestampCurrentCounter; >+ } >+ >+ public long getStartMonotonic() { >+ return startMonotonic; >+ } >+ >+ public JniTime getStartTime() { >+ return startTime; >+ } >+ >+ public JniTime getStartTimeFromTimestampCurrentCounter() { >+ return startTimeFromTimestampCurrentCounter; >+ } >+ >+ public HashMap<String, JniTracefile> getTracefilesMap() { >+ return tracefilesMap; >+ } >+ >+ /** >+ * Getter for the last read event timestamp<br> >+ * >+ * @return The time of the last event read >+ */ >+ public JniTime getCurrentEventTimestamp() { >+ return currentEventTimestamp; >+ } >+ >+ /** >+ * Pointer to the LttTrace C structure<br> >+ * <br> >+ * The pointer should only be used INTERNALY, do not use these unless you >+ * know what you are doing. >+ * >+ * @return The actual (long converted) pointer or NULL >+ */ >+ public C_Pointer getTracePtr() { >+ return thisTracePtr; >+ } >+ >+ /** >+ * Print information for all the tracefiles associated with this trace. >+ * <u>Intended to debug</u><br> >+ * >+ * This function will call Ltt to print, so information printed will be the >+ * one from the C structure >+ * >+ * @see org.eclipse.linuxtools.lttng.jni.JniTracefile >+ */ >+ public void printAllTracefilesInformation() { >+ >+ Object new_key = null; >+ JniTracefile tracefile; >+ >+ Iterator<String> iterator = tracefilesMap.keySet().iterator(); >+ while (iterator.hasNext()) { >+ new_key = iterator.next(); >+ >+ tracefile = tracefilesMap.get(new_key); >+ >+ tracefile.printTracefileInformation(); >+ } >+ } >+ >+ /** >+ * Print information for this trace. <u>Intended to debug</u><br> >+ * >+ * This function will call Ltt to print, so information printed will be the >+ * one from the C structure<br> >+ * <br> >+ * This function will not throw but will complain loudly if pointer is NULL >+ */ >+ public void printTraceInformation() { >+ >+ // If null pointer, print a warning! >+ if (thisTracePtr.getPointer() == NULL) { >+ printlnC("Pointer is NULL, cannot print. (printTraceInformation)"); >+ } else { >+ ltt_printTrace( thisTracePtr.getPointer() ); >+ } >+ } >+ >+ /** >+ * toString() method. <u>Intended to debug</u><br> >+ * >+ * @return String Attributes of the object concatenated in String >+ */ >+ public String toString() { >+ String returnData = ""; >+ returnData += "tracepath : " + tracepath + "\n"; >+ returnData += "cpuNumber : " + cpuNumber + "\n"; >+ returnData += "archType : " + archType + "\n"; >+ returnData += "archVariant : " + archVariant + "\n"; >+ returnData += "archSize : " + archSize + "\n"; >+ returnData += "lttMajorVersion : " + lttMajorVersion + "\n"; >+ returnData += "lttMinorVersion : " + lttMinorVersion + "\n"; >+ returnData += "flightRecorder : " + flightRecorder + "\n"; >+ returnData += "freqScale : " + freqScale + "\n"; >+ returnData += "startFreq : " + startFreq + "\n"; >+ returnData += "startTimestampCurrentCounter : " + startTimestampCurrentCounter + "\n"; >+ returnData += "startMonotonic : " + startMonotonic + "\n"; >+ returnData += "startTime : " + startTime.getReferenceToString() + "\n"; >+ returnData += " seconds : " + startTime.getSeconds() + "\n"; >+ returnData += " nanoSeconds : " + startTime.getNanoSeconds() + "\n"; >+ returnData += "startTimeFromTimestampCurrentCounter : " + startTimeFromTimestampCurrentCounter.getReferenceToString() + "\n"; >+ returnData += " seconds : " + startTimeFromTimestampCurrentCounter.getSeconds() + "\n"; >+ returnData += " nanoSeconds : " + startTimeFromTimestampCurrentCounter.getNanoSeconds() + "\n"; >+ returnData += "tracefilesMap : " + tracefilesMap.keySet() + "\n"; // Hack to avoid ending up with tracefilesMap.toString() >+ >+ return returnData; >+ } >+ >+ /* >+ * MAIN : For testing only! >+ */ >+ public static void main(String[] args) { >+ JniTrace testTrace = null; >+ JniEvent tmpEvent = null; >+ >+ try { >+ testTrace = new JniTrace("/home/william/trace1"); >+ } >+ catch (JniException e) { >+ System.out.println(e.getMessage() ); >+ return; >+ } >+ >+ >+ testTrace.printlnC( testTrace.toString() ); >+ >+ long nbEvent = 0; >+ >+ testTrace.printlnC("Beginning test run on 600k events"); >+ tmpEvent = testTrace.readNextEvent(); >+ while (tmpEvent != null) { >+ nbEvent++; >+ tmpEvent = testTrace.readNextEvent(); >+ >+ if ( tmpEvent != null ) { >+ tmpEvent.parseAllFields(); >+ } >+ } >+ testTrace.printlnC("We read " + nbEvent + " total events (JAF)\n"); >+ >+ >+ /* >+ >+ tmpEvent = testTrace.readNextEvent(); >+ >+ JniTime test_time = new JniTime(960386633737L); >+ tmpEvent = testTrace.seekAndRead(test_time); >+ >+ testTrace.printlnC(tmpEvent.getParentTracefile().getTracefileName().toString() ); >+ testTrace.printlnC(tmpEvent.toString() ); >+ >+ >+ test_time = new JniTime(960386638531L); >+ tmpEvent = testTrace.seekAndRead(test_time); >+ >+ testTrace.printlnC(tmpEvent.getParentTracefile().getTracefileName().toString() ); >+ testTrace.printlnC(tmpEvent.toString() ); >+ >+ >+ tmpEvent = testTrace.readNextEvent(); >+ if ( tmpEvent == null ) { >+ testTrace.printlnC("NULL NULL NULL1"); >+ } >+ else { >+ testTrace.printlnC(tmpEvent.getParentTracefile().getTracefileName().toString() ); >+ testTrace.printlnC(tmpEvent.toString() ); >+ } >+ >+ tmpEvent = testTrace.readNextEvent(); >+ if ( tmpEvent == null ) { >+ testTrace.printlnC("NULL NULL NULL2"); >+ } >+ else { >+ testTrace.printlnC(tmpEvent.getParentTracefile().getTracefileName().toString() ); >+ testTrace.printlnC(tmpEvent.toString() ); >+ } >+ */ >+ >+ >+ >+ >+ >+ >+ /* >+ testTrace.printlnC("Beginning test run seek time"); >+ JniTime test_time = new JniTime(953, 977711854); >+ testTrace.seekToTime(test_time); >+ tmpEvent = testTrace.findNextEvent(); >+ testTrace.printlnC(tmpEvent.toString() ); >+ */ >+ >+ /* >+ testTrace.printlnC("Beginning test run parsing event"); >+ Object[] parsedName = null; >+ HashMap<String,Object> parsedData = null; >+ for ( int x = 0; x<30; x++) { >+ tmpEvent = testTrace.readNextEvent(); >+ >+ testTrace.printlnC(tmpEvent.getParentTracefile().getTracefileName().toString() ); >+ testTrace.printC(tmpEvent.toString() ); >+ >+ testTrace.printlnC("Format : " + tmpEvent.requestEventMarker().getFormatOverview().toString() ); >+ parsedData = tmpEvent.parse(); >+ parsedName = parsedData.keySet().toArray(); >+ >+ testTrace.printC(" "); >+ for ( int pos=0; pos<parsedName.length; pos++) { >+ testTrace.printC( parsedName[pos].toString() + " " + parsedData.get(parsedName[pos]).toString() + " "); >+ } >+ testTrace.printlnC("\n"); >+ }*/ >+ >+ } >+ >+} >\ No newline at end of file > >Property changes on: src/org/eclipse/linuxtools/lttng/jni/JniTrace.java >___________________________________________________________________ >Added: svn:mime-type > + text/plain > >Index: src/org/eclipse/linuxtools/lttng/jni/JniTracefile.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/jni/JniTracefile.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/jni/JniTracefile.java (revision 23015) >@@ -0,0 +1,445 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * William Bourque (wbourque@gmail.com) - Initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.linuxtools.lttng.jni; >+ >+import java.util.HashMap; >+ >+/** >+ * <b><u>JniTracefile</u></b> >+ * <p> >+ * A tracefile own an event of a certain type >+ * It provides access to the LttTracefile C structure in java. >+ * <p> >+ * Most important fields in the JniTracefile are : >+ * <ul> >+ * <li> a JniTracefile path (a tracefile <b>file</b> with a JniTrace directory) >+ * <li> a name (basically the name without the directory part) >+ * <li> a reference to a single event object >+ * <li> a HashMap of marker associated with this tracefile >+ * </ul> >+ */ >+public final class JniTracefile extends Jni_C_Common { >+ >+ // Internal C pointer of the JniTracefile used in LTT >+ private C_Pointer thisTracefilePtr = new C_Pointer(); >+ >+ // Reference to the parent trace >+ private JniTrace parentTrace = null; >+ >+ // Data we should populate from LTT >+ // Note that all type have been scaled up as there is no "unsigned" in java >+ // This might be a problem about "unsigned long" as there is no equivalent in java >+ private boolean isCpuOnline = false; >+ private String tracefilePath = ""; >+ private String tracefileName = ""; >+ private long cpuNumber = 0; >+ private long tid = 0; >+ private long pgid = 0; >+ private long creation = 0; >+ private long tracePtr = 0; >+ private long markerDataPtr = 0; >+ private int CFileDescriptor = 0; >+ private long fileSize = 0; >+ private long blocksNumber = 0; >+ private boolean isBytesOrderReversed = false; >+ private boolean isFloatWordOrdered = false; >+ private long alignement = 0; >+ private long bufferHeaderSize = 0; >+ private int bitsOfCurrentTimestampCounter = 0; >+ private int bitsOfEvent = 0; >+ private long currentTimestampCounterMask = 0; >+ private long currentTimestampCounterMaskNextBit = 0; >+ private long eventsLost = 0; >+ private long subBufferCorrupt = 0; >+ private JniEvent currentEvent = null; >+ private long bufferPtr = NULL; >+ private long bufferSize = 0; >+ >+ // This map will hold markers_info owned by this tracefile >+ private HashMap<Integer, JniMarker> tracefileMarkersMap; >+ >+ // Native access functions >+ private native boolean ltt_getIsCpuOnline(long tracefilePtr); >+ private native String ltt_getTracefilepath(long tracefilePtr); >+ private native String ltt_getTracefilename(long tracefilePtr); >+ private native long ltt_getCpuNumber(long tracefilePtr); >+ private native long ltt_getTid(long tracefilePtr); >+ private native long ltt_getPgid(long tracefilePtr); >+ private native long ltt_getCreation(long tracefilePtr); >+ private native long ltt_getTracePtr(long tracefilePtr); >+ private native long ltt_getMarkerDataPtr(long tracefilePtr); >+ private native int ltt_getCFileDescriptor(long tracefilePtr); >+ private native long ltt_getFileSize(long tracefilePtr); >+ private native long ltt_getBlockNumber(long tracefilePtr); >+ private native boolean ltt_getIsBytesOrderReversed(long tracefilePtr); >+ private native boolean ltt_getIsFloatWordOrdered(long tracefilePtr); >+ private native long ltt_getAlignement(long tracefilePtr); >+ private native long ltt_getBufferHeaderSize(long tracefilePtr); >+ private native int ltt_getBitsOfCurrentTimestampCounter(long tracefilePtr); >+ private native int ltt_getBitsOfEvent(long tracefilePtr); >+ private native long ltt_getCurrentTimestampCounterMask(long tracefilePtr); >+ private native long ltt_getCurrentTimestampCounterMaskNextBit(long tracefilePtr); >+ private native long ltt_getEventsLost(long tracefilePtr); >+ private native long ltt_getSubBufferCorrupt(long tracefilePtr); >+ private native long ltt_getEventPtr(long tracefilePtr); >+ private native long ltt_getBufferPtr(long tracefilePtr); >+ private native long ltt_getBufferSize(long tracefilePtr); >+ >+ // Method to fill a map with marker object >+ private native void ltt_getAllMarkers(long tracefilePtr); >+ >+ // Debug native function, ask LTT to print tracefile structure >+ private native void ltt_printTracefile(long tracefilePtr); >+ >+ static { >+ System.loadLibrary("lttvtraceread"); >+ } >+ >+ /** >+ * Default constructor is forbidden >+ */ >+ @SuppressWarnings("unused") >+ private JniTracefile() { >+ }; >+ >+ /** >+ * Copy constructor. >+ * >+ * @param oldTracefile >+ * A reference to the JniTracefile you want to copy. >+ */ >+ public JniTracefile(JniTracefile oldTracefile) { >+ thisTracefilePtr = oldTracefile.thisTracefilePtr; >+ parentTrace = oldTracefile.parentTrace; >+ tracefileMarkersMap = oldTracefile.tracefileMarkersMap; >+ >+ isCpuOnline = oldTracefile.isCpuOnline; >+ tracefilePath = oldTracefile.tracefilePath; >+ tracefileName = oldTracefile.tracefileName; >+ cpuNumber = oldTracefile.cpuNumber; >+ tid = oldTracefile.tid; >+ pgid = oldTracefile.pgid; >+ creation = oldTracefile.creation; >+ tracePtr = oldTracefile.tracePtr; >+ markerDataPtr = oldTracefile.markerDataPtr; >+ CFileDescriptor = oldTracefile.CFileDescriptor; >+ fileSize = oldTracefile.fileSize; >+ blocksNumber = oldTracefile.blocksNumber; >+ isBytesOrderReversed = oldTracefile.isBytesOrderReversed; >+ isFloatWordOrdered = oldTracefile.isFloatWordOrdered; >+ alignement = oldTracefile.alignement; >+ bufferHeaderSize = oldTracefile.bufferHeaderSize; >+ bitsOfCurrentTimestampCounter = oldTracefile.bitsOfCurrentTimestampCounter; >+ bitsOfEvent = oldTracefile.bitsOfEvent; >+ currentTimestampCounterMask = oldTracefile.currentTimestampCounterMask; >+ currentTimestampCounterMaskNextBit = oldTracefile.currentTimestampCounterMaskNextBit; >+ eventsLost = oldTracefile.eventsLost; >+ subBufferCorrupt = oldTracefile.subBufferCorrupt; >+ currentEvent = oldTracefile.currentEvent; >+ bufferPtr = oldTracefile.bufferPtr; >+ bufferSize = oldTracefile.bufferSize; >+ } >+ >+ /** >+ * Copy constructor, using pointer. >+ * >+ * @param newPtr The pointer to an already opened LttTracefile C Structure >+ * >+ * @exception JniException >+ */ >+ public JniTracefile(C_Pointer newPtr, JniTrace newParentTrace) throws JniException { >+ thisTracefilePtr = newPtr; >+ parentTrace = newParentTrace; >+ tracefileMarkersMap = new HashMap<Integer, JniMarker>(); >+ >+ // Retrieve the trace file information and load the first event. >+ try { >+ populateTracefileInformation(); >+ } catch (JniNoSuchEventException e) { >+ throw new JniTracefileWithoutEventException( >+ "JniEvent constructor reported that no event of this type are usable. (Jaf_Tracefile)"); >+ } >+ } >+ >+ /** >+ * Move the current event to the next one. >+ * >+ * @return The read status, as defined in Jni_C_Common >+ * @see org.eclipse.linuxtools.lttng.jni.Jni_C_Common >+ */ >+ public int readNextEvent() { >+ return currentEvent.readNextEvent(); >+ } >+ >+ /** >+ * Move the current event to the time given.<br> >+ * >+ * @param seekTime JniTime where to seek to >+ * @return The read status, as defined in Jni_C_Common >+ * @see org.eclipse.linuxtools.lttng.jni.Jni_C_Common >+ */ >+ public int seekToTime(JniTime seekTime) { >+ return currentEvent.seekToTime(seekTime); >+ } >+ >+ /* >+ * This function populates the tracefile data with data from LTT >+ * >+ * @throws JafException >+ */ >+ private void populateTracefileInformation() throws JniException { >+ if (thisTracefilePtr.getPointer() == NULL) { >+ throw new JniTracefileException( >+ "Pointer is NULL, trace closed? (populateTracefileInformation)"); >+ } >+ >+ isCpuOnline = ltt_getIsCpuOnline( thisTracefilePtr.getPointer() ); >+ tracefilePath = ltt_getTracefilepath( thisTracefilePtr.getPointer() ); >+ tracefileName = ltt_getTracefilename( thisTracefilePtr.getPointer() ); >+ cpuNumber = ltt_getCpuNumber( thisTracefilePtr.getPointer() ); >+ tid = ltt_getTid( thisTracefilePtr.getPointer() ); >+ pgid = ltt_getPgid( thisTracefilePtr.getPointer() ); >+ creation = ltt_getCreation( thisTracefilePtr.getPointer() ); >+ tracePtr = ltt_getTracePtr( thisTracefilePtr.getPointer() ); >+ markerDataPtr = ltt_getMarkerDataPtr( thisTracefilePtr.getPointer() ); >+ CFileDescriptor = ltt_getCFileDescriptor( thisTracefilePtr.getPointer() ); >+ fileSize = ltt_getFileSize( thisTracefilePtr.getPointer() ); >+ blocksNumber = ltt_getBlockNumber( thisTracefilePtr.getPointer() ); >+ isBytesOrderReversed = ltt_getIsBytesOrderReversed( thisTracefilePtr.getPointer() ); >+ isFloatWordOrdered = ltt_getIsFloatWordOrdered( thisTracefilePtr.getPointer() ); >+ alignement = ltt_getAlignement( thisTracefilePtr.getPointer() ); >+ bufferHeaderSize = ltt_getBufferHeaderSize( thisTracefilePtr.getPointer() ); >+ bitsOfCurrentTimestampCounter = ltt_getBitsOfCurrentTimestampCounter( thisTracefilePtr.getPointer() ); >+ bitsOfEvent = ltt_getBitsOfEvent( thisTracefilePtr.getPointer() ); >+ currentTimestampCounterMask = ltt_getCurrentTimestampCounterMask( thisTracefilePtr.getPointer() ); >+ currentTimestampCounterMaskNextBit = ltt_getCurrentTimestampCounterMaskNextBit( thisTracefilePtr.getPointer() ); >+ eventsLost = ltt_getEventsLost( thisTracefilePtr.getPointer() ); >+ subBufferCorrupt = ltt_getSubBufferCorrupt( thisTracefilePtr.getPointer() ); >+ bufferPtr = ltt_getBufferPtr( thisTracefilePtr.getPointer() ); >+ bufferSize = ltt_getBufferSize( thisTracefilePtr.getPointer() ); >+ >+ // To fill the map is a bit different >+ ltt_getAllMarkers( thisTracefilePtr.getPointer() ); >+ >+ C_Pointer tmpEventPointer = new C_Pointer(ltt_getEventPtr(thisTracefilePtr.getPointer())); >+ currentEvent = new JniEvent(tmpEventPointer , tracefileMarkersMap, this); >+ } >+ >+ /* >+ * Fills a map of all the markers associated with this tracefile. >+ * >+ * Note: This function is called from C and there is no way to propagate >+ * exception back to the caller without crashing JNI. Therefore, it MUST >+ * catch all exceptions. >+ * >+ * @param markerId Id of the marker (int) >+ * @param markerInfoPtr C Pointer to a marker_info C structure >+ */ >+ @SuppressWarnings("unused") >+ private void addMarkersFromC(int markerId, long markerInfoPtr) { >+ // Create a new tracefile object and insert it in the map >+ // the tracefile fill itself with LTT data while being constructed >+ try { >+ JniMarker newMarker = new JniMarker( new C_Pointer(markerInfoPtr) ); >+ >+ tracefileMarkersMap.put(markerId, newMarker); >+ } catch (Exception e) { >+ printlnC("Failed to add marker to tracefileMarkersMap!(addMarkersFromC)\n\tException raised : " + e.toString()); >+ } >+ } >+ >+ // Access to class variable. Most of them doesn't have setter >+ public boolean getIsCpuOnline() { >+ return isCpuOnline; >+ } >+ >+ public String getTracefilePath() { >+ return tracefilePath; >+ } >+ >+ public String getTracefileName() { >+ return tracefileName; >+ } >+ >+ public long getCpuNumber() { >+ return cpuNumber; >+ } >+ >+ public long getTid() { >+ return tid; >+ } >+ >+ public long getPgid() { >+ return pgid; >+ } >+ >+ public long getCreation() { >+ return creation; >+ } >+ >+ public long getTracePtr() { >+ return tracePtr; >+ } >+ >+ public long getMarkerDataPtr() { >+ return markerDataPtr; >+ } >+ >+ public int getCFileDescriptor() { >+ return CFileDescriptor; >+ } >+ >+ public long getFileSize() { >+ return fileSize; >+ } >+ >+ public long getBlocksNumber() { >+ return blocksNumber; >+ } >+ >+ public boolean getIsBytesOrderReversed() { >+ return isBytesOrderReversed; >+ } >+ >+ public boolean getIsFloatWordOrdered() { >+ return isFloatWordOrdered; >+ } >+ >+ public long getAlignement() { >+ return alignement; >+ } >+ >+ public long getBufferHeaderSize() { >+ return bufferHeaderSize; >+ } >+ >+ public int getBitsOfCurrentTimestampCounter() { >+ return bitsOfCurrentTimestampCounter; >+ } >+ >+ public int getBitsOfEvent() { >+ return bitsOfEvent; >+ } >+ >+ public long getCurrentTimestampCounterMask() { >+ return currentTimestampCounterMask; >+ } >+ >+ public long getCurrentTimestampCounterMaskNextBit() { >+ return currentTimestampCounterMaskNextBit; >+ } >+ >+ public long getEventsLost() { >+ return eventsLost; >+ } >+ >+ public long getSubBufferCorrupt() { >+ return subBufferCorrupt; >+ } >+ >+ public JniEvent getCurrentEvent() { >+ return currentEvent; >+ } >+ >+ public long getBufferPtr() { >+ return bufferPtr; >+ } >+ >+ public long getBufferSize() { >+ return bufferSize; >+ } >+ >+ public HashMap<Integer, JniMarker> getTracefileMarkersMap() { >+ return tracefileMarkersMap; >+ } >+ >+ /** >+ * Getter to the parent trace for this tracefile. >+ * >+ * >+ * @return the parent trace >+ * @see org.eclipse.linuxtools.lttng.jni.JniTrace >+ */ >+ public JniTrace getParentTrace() { >+ return parentTrace; >+ } >+ >+ /** >+ * Pointer to the LttTracefile C structure<br> >+ * <br> >+ * The pointer should only be used INTERNALY, do not use these unless you >+ * know what you are doing. >+ * >+ * @return The actual (long converted) pointer or NULL >+ */ >+ public C_Pointer getTracefilePtr() { >+ return thisTracefilePtr; >+ } >+ >+ /** >+ * toString() method. <u>Intended to debug</u><br> >+ * >+ * @return String Attributes of the object concatenated in String >+ */ >+ public String toString() { >+ String returnData = ""; >+ >+ returnData += "isCpuOnline : " + isCpuOnline + "\n"; >+ returnData += "tracefilePath : " + tracefilePath + "\n"; >+ returnData += "tracefileName : " + tracefileName + "\n"; >+ returnData += "cpuNumber : " + cpuNumber + "\n"; >+ returnData += "tid : " + tid + "\n"; >+ returnData += "pgid : " + pgid + "\n"; >+ returnData += "creation : " + creation + "\n"; >+ returnData += "tracePtr : 0x" + java.lang.Long.toHexString(tracePtr) + "\n"; >+ returnData += "markerDataPtr : 0x" + java.lang.Long.toHexString(markerDataPtr) + "\n"; >+ returnData += "CFileDescriptor : " + CFileDescriptor + "\n"; >+ returnData += "fileSize : " + fileSize + "\n"; >+ returnData += "blocksNumber : " + blocksNumber + "\n"; >+ returnData += "isBytesOrderReversed : " + isBytesOrderReversed + "\n"; >+ returnData += "isFloatWordOrdered : " + isFloatWordOrdered + "\n"; >+ returnData += "alignement : " + alignement + "\n"; >+ returnData += "bufferHeaderSize : " + bufferHeaderSize + "\n"; >+ returnData += "bitsOfCurrentTimestampCounter : " + bitsOfCurrentTimestampCounter + "\n"; >+ returnData += "bitsOfEvent : " + bitsOfEvent + "\n"; >+ returnData += "currentTimestampCounterMask : " + currentTimestampCounterMask + "\n"; >+ returnData += "currentTimestampCounterMaskNextBit : " + currentTimestampCounterMaskNextBit + "\n"; >+ returnData += "eventsLost : " + eventsLost + "\n"; >+ returnData += "subBufferCorrupt : " + subBufferCorrupt + "\n"; >+ returnData += "currentEvent : " + currentEvent.getReferenceToString() + "\n"; // Hack to avoid ending up with event.toString() >+ returnData += "bufferPtr : 0x" + java.lang.Long.toHexString(bufferPtr) + "\n"; >+ returnData += "bufferSize : " + bufferSize + "\n"; >+ returnData += "tracefileMarkersMap : " + tracefileMarkersMap.keySet() + "\n"; // Hack to avoid ending up with tracefileMarkersMap.toString() >+ >+ return returnData; >+ } >+ >+ /** >+ * Print information for this tracefile. <u>Intended to debug</u><br> >+ * >+ * This function will call Ltt to print, so information printed will be the >+ * one from the C structure<br> >+ * <br> >+ * This function will not throw but will complain loudly if pointer is NULL >+ */ >+ public void printTracefileInformation() { >+ >+ // If null pointer, print a warning! >+ if (thisTracefilePtr.getPointer() == NULL) { >+ printlnC("Pointer is NULL, cannot print. (printTracefileInformation)"); >+ } else { >+ ltt_printTracefile( thisTracefilePtr.getPointer() ); >+ } >+ } >+} >+ > >Property changes on: src/org/eclipse/linuxtools/lttng/jni/JniTracefile.java >___________________________________________________________________ >Added: svn:mime-type > + text/plain > >Index: src/org/eclipse/linuxtools/lttng/jni/JniEvent.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/jni/JniEvent.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/jni/JniEvent.java (revision 23015) >@@ -0,0 +1,433 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * William Bourque (wbourque@gmail.com) - Initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.linuxtools.lttng.jni; >+ >+import java.util.HashMap; >+ >+/** >+ * <b><u>JniEvent</u></b> >+ * <p> >+ * A JniEvent has the actual content that got traced by Lttng It provides access to the LttEvent C structure in java. >+ * <p> >+ * Most important fields in the JniEvent are : >+ * <ul> >+ * <li>an event time, which is a digested timestamp >+ * </ul> >+ * Note that the JniEvent content is not directly accessibe and should be obtained >+ * using the requestEventContent() or parse() method. >+ */ >+public final class JniEvent extends Jni_C_Common { >+ // Variables to detect if the event have been filled at least once >+ // this make possible the detection of "uninitialized" struct in Ltt >+ // Can be "EOK", "ERANGE" or "EPERM" (defined in Jaf_C_Common) >+ private int eventState = EPERM; // Start with EPERM to ensure sanity >+ >+ // Internal C pointer of the JniEvent used in LTT >+ private C_Pointer thisEventPtr = new C_Pointer(); >+ >+ // Reference to the parent tracefile >+ private JniTracefile parentTracefile = null; >+ >+ // This map hold marker relative to the parent tracefile of this event >+ // They are "our" marker in this event >+ private HashMap<Integer, JniMarker> markersMap; >+ >+ // Data we should populate from ltt >+ // Note that all type have been scaled up as there is no "unsigned" in java >+ // This might be a problem about "unsigned long" as there is no equivalent >+ // in java >+ private C_Pointer tracefilePtr = new C_Pointer();; >+ private int eventMarkerId = 0; >+ private JniTime eventTime = null; >+ private long eventDataSize = 0; >+ >+ // These methods need a tracefile pointer, instead of a event pointer >+ private native int ltt_readNextEvent(long tracefilePtr); >+ private native int ltt_seekEvent(long tracefilePtr, JniTime givenTime); >+ private native int ltt_positionToFirstEvent(long tracefilePtr); >+ >+ // Native access functions >+ private native long ltt_getTracefilePtr(long eventPtr); >+ @SuppressWarnings("unused") >+ private native long ltt_getBlock(long eventPtr); >+ @SuppressWarnings("unused") >+ private native long ltt_getOffset(long eventPtr); >+ @SuppressWarnings("unused") >+ private native long ltt_getCurrentTimestampCounter(long eventPtr); >+ @SuppressWarnings("unused") >+ private native long ltt_getTimestamp(long eventPtr); >+ private native int ltt_getEventMarkerId(long eventPtr); >+ private native void ltt_feedEventTime(long eventPtr, JniTime eventTime); >+ private native long ltt_getEventDataSize(long eventPtr); >+ @SuppressWarnings("unused") >+ private native long ltt_getEventSize(long eventPtr); >+ @SuppressWarnings("unused") >+ private native int ltt_getCount(long eventPtr); >+ @SuppressWarnings("unused") >+ private native long ltt_getOverflowNanoSeconds(long eventPtr); >+ >+ // This method an event pointer >+ private native void ltt_getDataContent(long eventPtr, long dataSize, byte[] returnedContent); >+ >+ // Debug native function, ask LTT to print event structure >+ private native void ltt_printEvent(long eventPtr); >+ >+ static { >+ System.loadLibrary("lttvtraceread"); >+ } >+ >+ >+ /** >+ * Default constructor is forbidden >+ */ >+ @SuppressWarnings("unused") >+ private JniEvent() { >+ }; >+ >+ /** >+ * Copy constructor. >+ * >+ * @param oldEvent >+ * A reference to the JniEvent you want to copy. >+ */ >+ public JniEvent(JniEvent oldEvent) { >+ thisEventPtr = oldEvent.thisEventPtr; >+ markersMap = oldEvent.markersMap; >+ parentTracefile = oldEvent.parentTracefile; >+ eventState = oldEvent.eventState; >+ >+ tracefilePtr = oldEvent.tracefilePtr; >+ eventMarkerId = oldEvent.eventMarkerId; >+ eventTime = oldEvent.eventTime; >+ eventDataSize = oldEvent.eventDataSize; >+ } >+ >+ /** >+ * Constructor with parameters<br> >+ * <br> >+ * This constructor could throw. It will happen if an event can not be populated on first read.<br> >+ * In that case, the parent tracefile is probably useless and should be deleted. >+ * >+ * @param newEventPtr C pointer (converted in long) of the LttEvent C structure. >+ * @param newMarkersMap Reference an already populated HashMap of JniMarker objects >+ * @param newParentTracefile Reference to the parent JniTracefile of this JniEvent >+ * >+ * @exception JniException >+ */ >+ public JniEvent(C_Pointer newEventPtr, HashMap<Integer, JniMarker> newMarkersMap, JniTracefile newParentTracefile) throws JniException { >+ >+ // Basic test to make sure we didn't get null/empty value >+ if ((newEventPtr.getPointer() == NULL) >+ || (newMarkersMap == null) >+ || (newMarkersMap.size() == 0) >+ || (newParentTracefile == null)) { >+ throw new JniEventException("Null or empty value passed to constructor, object is invalid! (JniEvent)"); >+ } >+ >+ thisEventPtr = newEventPtr; >+ tracefilePtr = newParentTracefile.getTracefilePtr(); >+ markersMap = newMarkersMap; >+ parentTracefile = newParentTracefile; >+ >+ eventTime = new JniTime(); >+ >+ // Try to move to the first event >+ // If the event is Out of Range (ERANGE) at the first range, this event >+ // type will never been usable >+ // In that case, throw JafEventOutOfRangeException to warn the parent >+ // tracefile >+ // >+ // Position ourself on the next (first?) event >+ eventState = positionToFirstEvent(); >+ if (eventState != EOK) { >+ throw new JniNoSuchEventException("Object not populated, unusable. There is probably no event of that type in the trace. (JniEvent)"); >+ } >+ else { >+ populateEventInformation(); >+ } >+ } >+ >+ /** >+ * Move to the next event and populate LttEvent structure into the java object.<br> >+ * <br> >+ * If the move fails, the event will not get populated and the last event's data will still be available. >+ * >+ * @return The read status, as defined in Jni_C_Common >+ * @see org.eclipse.linuxtools.lttng.jni.Jni_C_Common >+ */ >+ public int readNextEvent() { >+ // Ask Ltt to read the next event for this particular tracefile >+ eventState = ltt_readNextEvent(tracefilePtr.getPointer() ); >+ >+ // If the event state is sane populate it >+ if (eventState == EOK) { >+ populateEventInformation(); >+ } >+ >+ return eventState; >+ } >+ >+ /** >+ * Seek to a certain time.<br> >+ * <br> >+ * Seek to a certain time and read event at this exact time or the next one if there is no event there.<br> >+ * <br> >+ * Note that this function could end in an invalid position if we seek after the last event. <br> >+ * In that case, a seek back would be required to get back to a consistent state.<br> >+ * <br> >+ * If the seek fails, the event will not get populated and the last event's data will still be available. >+ * >+ * @return The read status, as defined in Jni_C_Common >+ * @see org.eclipse.linuxtools.lttng.jni.Jni_C_Common >+ */ >+ public int seekToTime(JniTime seekTime) { >+ // Ask Ltt to read the next event for this particular tracefile >+ eventState = ltt_seekEvent(tracefilePtr.getPointer(), seekTime); >+ >+ // If the event state is sane populate it >+ if (eventState == EOK) { >+ populateEventInformation(); >+ } >+ >+ return eventState; >+ } >+ >+ /** >+ * Seek to a certain time or seek back if it fails.<br> >+ * <br> >+ * Seek to a certain time and read event at this exact time or the next one if there is no event there.<br> >+ * If the seek fails, we will seek back to the previous position, so the event will stay in a consistent state. >+ * >+ * @return The read status, as defined in Jni_C_Common >+ * @see org.eclipse.linuxtools.lttng.jni.Jni_C_Common >+ */ >+ public int seekOrFallBack(JniTime seekTime) { >+ // Save the old time >+ JniTime oldTime = eventTime; >+ >+ // Call seek to move ahead >+ seekToTime(seekTime); >+ // Save the state for the return >+ int returnState = eventState; >+ >+ // If the event state is sane populate it >+ if (eventState == EOK) { >+ populateEventInformation(); >+ } >+ >+ // Move to Next event only if the state of the event is sane >+ if (eventState != EOK) { >+ seekToTime(oldTime); >+ } >+ >+ return returnState; >+ } >+ >+ /** >+ * Position on the first event in the tracefile.<br> >+ * <br> >+ * The function will return the read status of the event.<br> >+ * An erronous status probably means there is no event of that type associated to the tracefile. >+ * >+ * @return The read status, as defined in Jni_C_Common >+ * @see org.eclipse.linuxtools.lttng.jni.Jni_C_Common >+ */ >+ public int positionToFirstEvent() { >+ eventState = ltt_positionToFirstEvent(tracefilePtr.getPointer()); >+ >+ return eventState; >+ } >+ >+ /** >+ * Method to obtain a marker associated with this particular event. >+ * >+ * @return Reference to the JniMarker object for this event or null if none. >+ * @see org.eclipse.linuxtools.lttng.jni.JniMarker >+ */ >+ public JniMarker requestEventMarker() { >+ return markersMap.get(eventMarkerId); >+ } >+ >+ /** >+ * Method to obtain the raw data of a LttEvent object.<br> >+ * <br> >+ * Note : The data will be in raw C bytes, not java bytes. >+ * >+ * @return bytes array of raw data. >+ */ >+ public byte[] requestEventContent() { >+ >+ byte dataContent[] = new byte[(int) eventDataSize]; >+ >+ ltt_getDataContent(thisEventPtr.getPointer(), eventDataSize, dataContent); >+ >+ return dataContent; >+ } >+ >+ // *** TODO *** >+ // No "Source" of event exist in Ltt so far >+ // It would be a good addition to have a way to detect where an event come >+ // from, like "kernel" or "userspace" >+ // >+ /** >+ * Method to obtain an event source.<br> >+ * <br> >+ * This is not implemented yet and will always return "Kernel core" for now. >+ * >+ * @return Reference to the JniMarker object for this event or null if none. >+ * @see org.eclipse.linuxtools.lttng.jni.JniMarker >+ */ >+ public String requestEventSource() { >+ return "Kernel Core"; >+ } >+ >+ /** >+ * Method to parse a particular field in the event payload, identified by its id (position). >+ * >+ * @return Object that contain the parsed payload >+ */ >+ public Object parseFieldById(int fieldId) { >+ return JniParser.parseField(this, fieldId); >+ } >+ >+ /** >+ * Method to parse a particular field in the event payload, identified by its name. >+ * >+ * @return Object that contain the parsed payload >+ */ >+ public Object parseFieldByName(String fieldName) { >+ return JniParser.parseField(this, fieldName); >+ } >+ >+ /** >+ * Method to parse all the event payload. >+ * >+ * @return ArrayList of ParsedContent objects. >+ */ >+ public HashMap<String, Object> parseAllFields() { >+ return JniParser.parseAllFields(this); >+ } >+ >+ /* >+ * This function populates the event data with data from LTT >+ * >+ */ >+ private void populateEventInformation() { >+ if (thisEventPtr.getPointer() == NULL) { >+ printlnC("Pointer is NULL, trace closed? (populateEventInformation)"); >+ } >+ else { >+ tracefilePtr = new C_Pointer( ltt_getTracefilePtr(thisEventPtr.getPointer()) ); >+ eventMarkerId = ltt_getEventMarkerId(thisEventPtr.getPointer()); >+ >+ // Creation of time is a bit different, we need to pass the object >+ // reference to C >+ ltt_feedEventTime(thisEventPtr.getPointer(), eventTime); >+ >+ eventDataSize = ltt_getEventDataSize(thisEventPtr.getPointer()); >+ } >+ } >+ >+ public int getEventMarkerId() { >+ return eventMarkerId; >+ } >+ >+ public JniTime getEventTime() { >+ return eventTime; >+ } >+ >+ public long getEventDataSize() { >+ return eventDataSize; >+ } >+ >+ public HashMap<Integer, JniMarker> getMarkersMap() { >+ return markersMap; >+ } >+ >+ >+ /** >+ * Pointer to the parent LttEvent C structure<br> >+ * <br> >+ * The pointer should only be used INTERNALY, do not use these unless you >+ * know what you are doing. >+ * >+ * @return The actual (long converted) pointer or NULL >+ */ >+ public C_Pointer getTracefilePtr() { >+ return tracefilePtr; >+ } >+ >+ /** >+ * Pointer to the LttEvent C structure<br> >+ * <br> >+ * The pointer should only be used INTERNALY, do not use these unless you >+ * know what you are doing. >+ * >+ * @return The actual (long converted) pointer or NULL >+ */ >+ public C_Pointer getEventPtr() { >+ return thisEventPtr; >+ } >+ >+ public int getEventState() { >+ return eventState; >+ } >+ >+ /** >+ * Getter to the parent tracefile for this event. >+ * >+ * >+ * @return the parent tracefile >+ * @see org.eclipse.linuxtools.lttng.jni.JniTracefile >+ */ >+ public JniTracefile getParentTracefile() { >+ return parentTracefile; >+ } >+ >+ /** >+ * toString() method. <u>Intended to debug</u><br> >+ * >+ * @return String Attributes of the object concatenated in String >+ */ >+ public String toString() { >+ String returnData = ""; >+ >+ returnData += "tracefilePtr : " + tracefilePtr + "\n"; >+ returnData += "eventMarkerId : " + eventMarkerId + "\n"; >+ returnData += "eventTime : " + eventTime.getReferenceToString() + "\n"; >+ returnData += " seconds : " + eventTime.getSeconds() + "\n"; >+ returnData += " nanoSeconds : " + eventTime.getNanoSeconds() + "\n"; >+ returnData += "eventDataSize : " + eventDataSize + "\n"; >+ returnData += "markersMap : " + markersMap.keySet() + "\n"; // Hack to avoid ending up with markersMap.toString() >+ >+ return returnData; >+ } >+ >+ /** >+ * Print information for this event. <u>Intended to debug</u><br> >+ * >+ * This function will call Ltt to print, so information printed will be the one from the C structure<br> >+ * <br> >+ * This function will not throw but will complain loudly if pointer is NULL >+ */ >+ public void printEventInformation() { >+ >+ // If null pointer, print a warning! >+ if (thisEventPtr.getPointer() == NULL) { >+ printlnC("Pointer is NULL, cannot print. (printEventInformation)"); >+ } >+ else { >+ ltt_printEvent(thisEventPtr.getPointer()); >+ } >+ } >+} > >Property changes on: src/org/eclipse/linuxtools/lttng/jni/JniEvent.java >___________________________________________________________________ >Added: svn:mime-type > + text/plain > >Index: src/org/eclipse/linuxtools/lttng/jni/JniMarker.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/jni/JniMarker.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/jni/JniMarker.java (revision 23015) >@@ -0,0 +1,226 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * William Bourque (wbourque@gmail.com) - Initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.linuxtools.lttng.jni; >+ >+import java.util.ArrayList; >+import java.util.HashMap; >+ >+/** >+ * <b><u>JniMarker</u></b> >+ * <p> >+ * A JniMarker contain information how to interpret the unparsed content (payload) of an event.<br> >+ * Each JniMarker contains several MarkerFields for each fields in the event's payload. >+ * <p> >+ * Most important fields in the JniMarker are : >+ * <ul> >+ * <li> the name of the marker in String >+ * <li> an overview of the marker format (in C style printf format) >+ * <li> a reference to an ArrayList that contains MarkerFields object of this JniMarker >+ * </ul> >+ */ >+public final class JniMarker extends Jni_C_Common >+{ >+ // Internal C pointer of the JniEvent used in LTT >+ private C_Pointer thisMarkerPtr = new C_Pointer(); >+ >+ private String name = ""; >+ private String formatOverview = ""; >+ >+ // These two contains hold references to the same MarkerField object >+ // The ArrayList can be used to efficiently find a field by its position >+ // The HashMap can be used to find a field by its name >+ private HashMap<String, JniMarkerField> markerFieldsHashMap = null; >+ private ArrayList<JniMarkerField> markerFieldsArrayList = null; >+ >+ // Native access method >+ private native String ltt_getName(long markerPtr); >+ private native String ltt_getFormatOverview(long markerPtr); >+ @SuppressWarnings("unused") >+ private native long ltt_getSize(long markerPtr); >+ @SuppressWarnings("unused") >+ private native short ltt_getLargestAlign(long markerPtr); >+ @SuppressWarnings("unused") >+ private native short ltt_getIntSize(long markerPtr); >+ @SuppressWarnings("unused") >+ private native short ltt_getLongSize(long markerPtr); >+ @SuppressWarnings("unused") >+ private native short ltt_getPointerSize(long markerPtr); >+ @SuppressWarnings("unused") >+ private native short ltt_getSize_tSize(long markerPtr); >+ private native void ltt_getAllMarkerFields(long tracePtr); >+ @SuppressWarnings("unused") >+ private native short ltt_getAlignement(long markerPtr); >+ @SuppressWarnings("unused") >+ private native long ltt_getNextMarkerPtr(long markerPtr); >+ >+ // Debug native function, ask LTT to print marker structure >+ private native void ltt_printMarker(long markerPtr); >+ >+ static { >+ System.loadLibrary("lttvtraceread"); >+ } >+ >+ /** >+ * Default constructor is forbidden >+ */ >+ @SuppressWarnings("unused") >+ private JniMarker() { >+ } >+ >+ /** >+ * Copy constructor. >+ * >+ * @param oldMarker >+ * A reference to the JniMarker you want to copy. >+ */ >+ public JniMarker(JniMarker oldMarker) { >+ thisMarkerPtr = oldMarker.thisMarkerPtr; >+ name = oldMarker.name; >+ formatOverview = oldMarker.formatOverview; >+ markerFieldsHashMap = oldMarker.markerFieldsHashMap; >+ markerFieldsArrayList = oldMarker.markerFieldsArrayList; >+ >+ } >+ >+ /** >+ * Copy constructor, using pointer. >+ * >+ * @param newMarkerPtr Pointer to a C marker_info structure >+ * >+ * @exception JniException >+ */ >+ public JniMarker(C_Pointer newMarkerPtr) throws JniException { >+ thisMarkerPtr = newMarkerPtr; >+ markerFieldsArrayList = new ArrayList<JniMarkerField>(); >+ markerFieldsHashMap = new HashMap<String, JniMarkerField>(); >+ >+ // Populate the marker >+ populateMarkerInformation(); >+ } >+ >+ >+ /* >+ * This function populates the marker data with data from LTT >+ * >+ */ >+ private void populateMarkerInformation() throws JniException { >+ if (thisMarkerPtr.getPointer() == NULL) { >+ throw new JniMarkerException("Pointer is NULL, trace closed? (populateMarkerInformatOverviewion)"); >+ } else { >+ name = ltt_getName( thisMarkerPtr.getPointer() ); >+ formatOverview = ltt_getFormatOverview( thisMarkerPtr.getPointer() ); >+ // To fill the markerFieldArray is a bit different >+ ltt_getAllMarkerFields( thisMarkerPtr.getPointer() ); >+ } >+ } >+ >+ /* >+ * Fills a map of all the JniMarkerField associated with this JniMarker. >+ * >+ * Note: This function is called from C and there is no way to propagate >+ * exception back to the caller without crashing JNI. Therefore, it MUST >+ * catch all exceptions. >+ * >+ * @param markerName Name of the parent marker >+ * @param markerFieldPtr C Pointer (converted in long) to marker_field C Structure >+ */ >+ @SuppressWarnings("unused") >+ private void addMarkerFieldFromC(String markerFieldName, long markerFieldPtr) { >+ // Create a new Jaf_markerField object and insert it in the map >+ // the maker field fill itself with LTT data while being constructed >+ try { >+ JniMarkerField newMarkerField = new JniMarkerField( new C_Pointer(markerFieldPtr) ); >+ markerFieldsArrayList.add(newMarkerField); >+ markerFieldsHashMap.put(markerFieldName, newMarkerField); >+ >+ } catch (JniException e) { >+ printlnC("Failed to add marker field " + markerFieldName + " to marker fields list!(addMarkerFieldFromC)\n\tException raised : " + e.toString() ); >+ } >+ } >+ >+ // Access to class variable. Most of them doesn't have setter >+ public String getName() { >+ return name; >+ } >+ >+ public String getFormatOverview() { >+ return formatOverview; >+ } >+ >+ public HashMap<String,JniMarkerField> getMarkerFieldsHashMap() { >+ return markerFieldsHashMap; >+ } >+ >+ public ArrayList<JniMarkerField> getMarkerFieldsArrayList() { >+ return markerFieldsArrayList; >+ } >+ >+ >+ /** >+ * Pointer to the marker_info C structure<br> >+ * <br> >+ * The pointer should only be used INTERNALY, do not use these unless you >+ * know what you are doing. >+ * >+ * @return The actual (long converted) pointer or NULL >+ */ >+ public C_Pointer getMarkerPtr() { >+ return thisMarkerPtr; >+ } >+ >+ /** >+ * toString() method. <u>Intended to debug</u><br> >+ * >+ * @return String Attributes of the object concatenated in String >+ */ >+ public String toString() { >+ String returnData = ""; >+ >+ returnData += "name : " + name + "\n"; >+ returnData += "formatOverview : " + formatOverview + "\n"; >+ returnData += "markerFieldArrayList : " + markerFieldsArrayList.toArray() + "\n"; >+ >+ return returnData; >+ } >+ >+ >+ /** >+ * Print information for ALL marker fields for this marker. <u>Intended to debug</u><br> >+ * >+ * This function will call Ltt to print, so information printed will be the one from the C structure >+ */ >+ public void printAllMarkerFieldsInformation() { >+ Object[] allMarkersField = markerFieldsArrayList.toArray(); >+ >+ for (int pos = 0; pos < allMarkersField.length; pos++) { >+ printlnC(allMarkersField[pos].toString()); >+ } >+ } >+ >+ /** >+ * Print information for this JniMarker. <u>Intended to debug</u><br> >+ * >+ * This function will call Ltt to print, so information printed will be the one from the C structure<br> >+ * <br> >+ * This function will not throw but will complain loudly if pointer is NULL >+ */ >+ public void printMarkerInformation() { >+ >+ // If null pointer, print a warning! >+ if (thisMarkerPtr.getPointer() == NULL) { >+ printlnC("Pointer is NULL, cannot print. (printMarkerInformation)"); >+ } else { >+ ltt_printMarker(thisMarkerPtr.getPointer()); >+ } >+ } >+} > >Property changes on: src/org/eclipse/linuxtools/lttng/jni/JniMarker.java >___________________________________________________________________ >Added: svn:mime-type > + text/plain > >Index: src/org/eclipse/linuxtools/lttng/jni/JniMarkerField.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/jni/JniMarkerField.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/jni/JniMarkerField.java (revision 23015) >@@ -0,0 +1,152 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * William Bourque (wbourque@gmail.com) - Initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.linuxtools.lttng.jni; >+ >+/** >+ * <b><u>JniMarkerField</u></b> >+ * <p> >+ * A JniMarkerField is one of the field of the unparsed content (payload) of an event >+ * <p> >+ * Most important attributes in the JniMarkerField are : >+ * <ul> >+ * <li> the name (field) of in String >+ * <li> the marker field format (in C style printf format) >+ * </ul> >+ */ >+public final class JniMarkerField extends Jni_C_Common >+{ >+ // Internal C pointer of the JniEvent used in LTT >+ private C_Pointer thisMarkerFieldPtr = new C_Pointer(); >+ >+ private String field = ""; >+ private String format = ""; >+ >+ // Native access method >+ private native String ltt_getField(long markerFieldPtr); >+ @SuppressWarnings("unused") >+ private native int ltt_getType(long markerFieldPtr); >+ @SuppressWarnings("unused") >+ private native long ltt_getOffset(long markerFieldPtr); >+ @SuppressWarnings("unused") >+ private native long ltt_getSize(long markerFieldPtr); >+ @SuppressWarnings("unused") >+ private native long ltt_getAlignment(long markerFieldPtr); >+ @SuppressWarnings("unused") >+ private native long ltt_getAttributes(long markerFieldPtr); >+ @SuppressWarnings("unused") >+ private native int ltt_getStatic_offset(long markerFieldPtr); >+ private native String ltt_getFormat(long markerFieldPtr); >+ >+ // Debug native function, ask LTT to print marker structure >+ private native void ltt_printMarkerField(long markerFieldPtr); >+ >+ static { >+ System.loadLibrary("lttvtraceread"); >+ } >+ >+ /** >+ * Default constructor is forbidden >+ */ >+ @SuppressWarnings("unused") >+ private JniMarkerField() { >+ } >+ >+ /** >+ * Copy constructor. >+ * >+ * @param oldMarkerField >+ * A reference to the JniMarkerField you want to copy. >+ */ >+ public JniMarkerField(JniMarkerField oldMarkerField) { >+ thisMarkerFieldPtr = oldMarkerField.getMarkerFieldPtr(); >+ field = oldMarkerField.getField(); >+ format = oldMarkerField.getFormat(); >+ } >+ >+ /** >+ * Copy constructor, using pointer. >+ * >+ * @param newMarkerFieldPtr Pointer to a C marker_field structure >+ * >+ * @exception JniException >+ */ >+ public JniMarkerField(C_Pointer newMarkerFieldPtr) throws JniException { >+ thisMarkerFieldPtr = newMarkerFieldPtr; >+ >+ // Populate the marker field >+ populateMarkerFieldInformation(); >+ } >+ >+ /* >+ * This function populates the marker field data with data from LTT >+ * >+ */ >+ private void populateMarkerFieldInformation() throws JniException { >+ if (thisMarkerFieldPtr.getPointer() == NULL) { >+ throw new JniMarkerFieldException( >+ "Pointer is NULL, trace closed? (populateMarkerInformation)"); >+ } else { >+ field = ltt_getField(thisMarkerFieldPtr.getPointer()); >+ format = ltt_getFormat(thisMarkerFieldPtr.getPointer()); >+ } >+ } >+ >+ public String getField() { >+ return field; >+ } >+ >+ public String getFormat() { >+ return format; >+ } >+ >+ /** >+ * Pointer to the marker_field C structure<br> >+ * <br> >+ * The pointer should only be used INTERNALY, do not use these unless you >+ * know what you are doing. >+ * >+ * @return The actual (long converted) pointer or NULL >+ */ >+ public C_Pointer getMarkerFieldPtr() { >+ return thisMarkerFieldPtr; >+ } >+ >+ /** >+ * toString() method. <u>Intended to debug</u><br> >+ * >+ * @return String Attributes of the object concatenated in String >+ */ >+ public String toString() { >+ String returnData = ""; >+ returnData += "field : " + field + "\n"; >+ returnData += "format : " + format + "\n"; >+ return returnData; >+ } >+ >+ /** >+ * Print information for this event. <u>Intended to debug</u><br> >+ * >+ * This function will call Ltt to print, so information printed will be the one from the C structure<br> >+ * <br> >+ * This function will not throw but will complain loudly if pointer is NULL >+ */ >+ public void printMarkerFieldInformation() { >+ >+ // If null pointer, print a warning! >+ if (thisMarkerFieldPtr.getPointer() == NULL) { >+ printlnC("Pointer is NULL, cannot print. (printMarkerFieldInformation)"); >+ } else { >+ ltt_printMarkerField(thisMarkerFieldPtr.getPointer()); >+ } >+ } >+} > >Property changes on: src/org/eclipse/linuxtools/lttng/jni/JniMarkerField.java >___________________________________________________________________ >Added: svn:mime-type > + text/plain > >Index: src/org/eclipse/linuxtools/lttng/jni/Jni_C_Common.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/jni/Jni_C_Common.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/jni/Jni_C_Common.java (revision 23015) >@@ -0,0 +1,136 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * William Bourque (wbourque@gmail.com) - Initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.linuxtools.lttng.jni; >+ >+/** >+ * <b><u>Jni_C_Common</u></b> >+ * <p> >+ * Common constante and methods that should be shared between JNI objects >+ */ >+public abstract class Jni_C_Common { >+ >+ // Needed for native types >+ public static final int NULL = 0; >+ >+ // C errno correspondance. Used to interpret LTT return value >+ public static final int EOK = 0; >+ public static final int EPERM = 1; >+ public static final int ERANGE = 34; >+ >+ // Timestamps are in nanoseconds >+ public static final long NANO = 1000000000; >+ >+ // Native console printing function >+ private native void ltt_printC(String string_to_print); >+ >+ // Load LTTV library (order is important) >+ static { >+ System.loadLibrary("lttvtraceread"); >+ } >+ >+ /** >+ * Java-side console printing function. >+ * >+ * Call the C printing function to make sure all printing happen on the same side. >+ * >+ * @param msg >+ */ >+ public void printC(String msg) { >+ // Need to escape "%" >+ msg = msg.replaceAll("%", "%%"); >+ ltt_printC(msg); >+ } >+ >+ /** >+ * Java-side console printing function. Add a return line at the end of the message. >+ * >+ * Call the C printing function to make sure all printing happen on the same side. >+ * >+ * @param msg >+ */ >+ public void printlnC(String msg) { >+ printC(msg + "\n"); >+ } >+ >+ /** >+ * This method is to be used as an "alternate" .toString()<br> >+ * <br> >+ * Simulates the way Java Object implements "toString()" >+ * >+ * @return the Java hashed UID of the object (i.e. : NAME@HASH) >+ */ >+ public String getReferenceToString() { >+ return this.getClass().getName() + "@" + Integer.toHexString(this.hashCode()); >+ } >+} >+ >+/** >+ * <b><u>C_Pointer</u></b> >+ * <p> >+ * Class pointer to handle properly "C pointer" <br> >+ * >+ * Can transparently handle pointer of 32 or 64 bits. >+ */ >+class C_Pointer extends Jni_C_Common { >+ >+ private long ptr = NULL; >+ private boolean isLong = true; >+ >+ public C_Pointer() { >+ ptr = NULL; >+ } >+ >+ public C_Pointer(long newPtr) { >+ ptr = newPtr; >+ isLong = true; >+ } >+ >+ public C_Pointer(int newPtr) { >+ ptr = (long)newPtr; >+ isLong = false; >+ } >+ >+ public long getPointer() { >+ return ptr; >+ } >+ >+ public void setPointer(long newPtr) { >+ ptr = newPtr; >+ isLong = true; >+ } >+ >+ public void setPointer(int newPtr) { >+ ptr = newPtr; >+ isLong = false; >+ } >+ >+ /** >+ * toString() method<br> >+ * <br> >+ * Convert the pointer to a nice looking hexadecimal format >+ * >+ * @return String Attributes of the object concatenated in String >+ */ >+ public String toString() { >+ String returnData = "0x"; >+ >+ if (isLong == true) { >+ returnData += Long.toHexString(ptr); >+ } >+ else { >+ returnData += Integer.toHexString((int) ptr); >+ } >+ >+ return returnData; >+ } >+} > >Property changes on: src/org/eclipse/linuxtools/lttng/jni/Jni_C_Common.java >___________________________________________________________________ >Added: svn:mime-type > + text/plain > >Index: src/org/eclipse/linuxtools/lttng/jni/JniParser.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/jni/JniParser.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/jni/JniParser.java (revision 23015) >@@ -0,0 +1,292 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * William Bourque (wbourque@gmail.com) - Initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.linuxtools.lttng.jni; >+ >+import java.util.HashMap; >+ >+/** >+ * <b><u>JniParser</u></b> >+ * <p> >+ * JniParser class. >+ * All methods are static, the parser shouldn't be instantiated. >+ */ >+public class JniParser extends Jni_C_Common >+{ >+ private static native void ltt_getParsedData(ParsedObjectContent parseddata, long eventPtr, long markerFieldPtr); >+ >+ static { >+ System.loadLibrary("lttvtraceread"); >+ } >+ >+ /** >+ * Default constructor is forbidden >+ */ >+ private JniParser() { >+ } >+ >+ >+ >+ /** >+ * Method to parse a single field identified by its id<br> >+ * All parsing will be done on C side as we need Ltt function >+ * >+ * @param eventToParse The jni event we want to parse. >+ * @param fieldPosition The position (or id) of the field we want to parse >+ * >+ * @return An Object that contain the JniEvent payload parsed by the C, or null, if if was impossible to parse (i.e., wrong position) >+ * >+ * @see org.eclipse.linuxtools.lttng.jni.JniEvent >+ */ >+ static public Object parseField(JniEvent eventToParse, int fieldPosition) { >+ >+ // Sanity check >+ if ( (fieldPosition < 0) || ( fieldPosition >= eventToParse.requestEventMarker().getMarkerFieldsArrayList().size() ) ){ >+ return null; >+ } >+ >+ // *** HACK *** >+ // We cannot use "Object" directly as java does not support swapping primitive value >+ // We either need to create a new object type or to use a "non-primitive" type that have "Setter()" functions >+ // *** >+ ParsedObjectContent parsedData = new ParsedObjectContent(); >+ >+ // Call the parsing function in C. The result will be put in parsedData object >+ ltt_getParsedData(parsedData, eventToParse.getEventPtr().getPointer(), eventToParse.requestEventMarker().getMarkerFieldsArrayList().get(fieldPosition).getMarkerFieldPtr().getPointer() ); >+ >+ return parsedData.getData(); >+ } >+ >+ >+ /** >+ * Method to parse a single field identified by its name<br> >+ * All parsing will be done on C side as we need Ltt function >+ * >+ * @param eventToParse The jni event we want to parse. >+ * @param fieldPosition The position (or id) of the field we want to parse >+ * >+ * @return An Object that contain the JniEvent payload parsed by the C, or null, if if was impossible to parse (i.e., wrong position) >+ * >+ * @see org.eclipse.linuxtools.lttng.jni.JniEvent >+ */ >+ static public Object parseField(JniEvent eventToParse, String fieldName) { >+ >+ JniMarkerField tmpField = eventToParse.requestEventMarker().getMarkerFieldsHashMap().get(fieldName); >+ >+ // return immediately if there is no field by that name >+ if ( tmpField == null ) { >+ return null; >+ } >+ >+ // *** HACK *** >+ // We cannot use "Object" directly as java does not support swapping on primitive value >+ // We either need to create a new object type or to use a "non-primitive" type that have "Setter()" functions >+ // *** >+ ParsedObjectContent parsedData = new ParsedObjectContent(); >+ >+ ltt_getParsedData(parsedData, eventToParse.getEventPtr().getPointer(), tmpField.getMarkerFieldPtr().getPointer() ); >+ >+ return parsedData.getData(); >+ } >+ >+ >+ >+ /** >+ * Method to parse all field at once<br> >+ * All parsing will be done on C side as we need Ltt function >+ * >+ * @param eventToParse The jni event we want to parse. >+ * @return An HashMap of Object that contain the is the JniEvent's payload parsed by the C >+ * >+ * @see org.eclipse.linuxtools.lttng.jni.JniEvent >+ */ >+ static public HashMap<String, Object> parseAllFields(JniEvent eventToParse) { >+ JniMarker markerData = eventToParse.requestEventMarker(); >+ int nbMarkerField = markerData.getMarkerFieldsArrayList().size(); >+ >+ // This hashmap will contain the parsed content. >+ // ParsedContent is defined at the end of this file >+ HashMap<String, Object> parsedDataArray = new HashMap<String, Object>(nbMarkerField); >+ >+ // *** HACK *** >+ // We cannot use "Object" directly as java does not support swapping on primitive value >+ // We either need to create a new object type or to use a "non-primitive" type that have "Setter()" functions >+ // *** >+ ParsedObjectContent parsedData = new ParsedObjectContent(); >+ >+ // Loop on markerfield, as we need to parse each field in the event data >+ for (int pos = 0; pos < nbMarkerField; pos++) { >+ // Call the C to parse the data >+ ltt_getParsedData(parsedData, eventToParse.getEventPtr().getPointer(), markerData.getMarkerFieldsArrayList().get(pos).getMarkerFieldPtr().getPointer() ); >+ // Save the result into the HashMap >+ parsedDataArray.put(markerData.getMarkerFieldsArrayList().get(pos).getField(), parsedData.getData() ); >+ } >+ >+ return parsedDataArray; >+ } >+ >+ /* >+ * Add a parsed String value to the Array<br> >+ * <br> >+ * Note : this function will be called from the C side. >+ * Note2: contentHolder is of type "Object" instead of "ParsedObjectContent" to be able to use the most generic function signature on the C side. >+ * its goal is to give a generic interface to people that would like to use the JNI library >+ * >+ * @param parsedArray Array where to store the value >+ * @param fieldName The name of the parsed field >+ * @param stringToAdd The parsed data to add >+ * @param formatToAdd The format of the raw data >+ */ >+ @SuppressWarnings("unused") >+ static private void addStringToParsingFromC(Object contentHolder, String fieldName, String stringToAdd) { >+ ((ParsedObjectContent)contentHolder).setData( stringToAdd); >+ } >+ >+ /* >+ * Add a parsed 64 bits Pointer value to the Array<br> >+ * <br> >+ * Note : this function will be called from the C side. >+ * Note2: contentHolder is of type "Object" instead of "ParsedObjectContent" to be able to use the most generic function signature on the C side. >+ * its goal is to give a generic interface to people that would like to use the JNI library >+ * >+ * @param contentHolder Object where to store the parsed value >+ * @param fieldName The name of the parsed field >+ * @param pointerToAdd The parsed data to add (in 64 bits long!) >+ * @param formatToAdd The format of the raw data >+ */ >+ @SuppressWarnings("unused") >+ static private void addLongPointerToParsingFromC(Object contentHolder, String fieldName, long pointerToAdd) { >+ ((ParsedObjectContent)contentHolder).setData( new C_Pointer((long) pointerToAdd)); >+ } >+ >+ /* >+ * Add a parsed 32 bits Pointer value to the Array<br> >+ * <br> >+ * Note : this function will be called from the C side. >+ * Note2: contentHolder is of type "Object" instead of "ParsedObjectContent" to be able to use the most generic function signature on the C side. >+ * its goal is to give a generic interface to people that would like to use the JNI library >+ * >+ * @param contentHolder Object where to store the parsed value >+ * @param fieldName The name of the parsed field >+ * @param pointerToAdd The parsed data to add (converted in 64 bits long!) >+ * @param formatToAdd The format of the raw data >+ */ >+ @SuppressWarnings("unused") >+ static private void addIntPointerToParsingFromC(Object contentHolder, String fieldName, long pointerToAdd) { >+ ((ParsedObjectContent)contentHolder).setData( new C_Pointer((int) pointerToAdd)); >+ } >+ >+ /* >+ * Add a parsed short value to the Array<br> >+ * <br> >+ * Note : this function will be called from the C side. >+ * Note2: contentHolder is of type "Object" instead of "ParsedObjectContent" to be able to use the most generic function signature on the C side. >+ * its goal is to give a generic interface to people that would like to use the JNI library >+ * >+ * @param contentHolder Object where to store the parsed value >+ * @param fieldName The name of the parsed field >+ * @param shortToAdd The parsed data to add >+ * @param formatToAdd The format of the raw data >+ */ >+ @SuppressWarnings("unused") >+ static private void addShortToParsingFromC(Object contentHolder, String fieldName, short shortToAdd) { >+ ((ParsedObjectContent)contentHolder).setData( new Short(shortToAdd)); >+ } >+ >+ /* >+ * Add a parsed integer value to the Array<br> >+ * <br> >+ * Note : this function will be called from the C side. >+ * Note2: contentHolder is of type "Object" instead of "ParsedObjectContent" to be able to use the most generic function signature on the C side. >+ * its goal is to give a generic interface to people that would like to use the JNI library >+ * >+ * @param contentHolder Object where to store the parsed value >+ * @param fieldName The name of the parsed field >+ * @param intToAdd The parsed data to add >+ * @param formatToAdd The format of the raw data >+ */ >+ @SuppressWarnings("unused") >+ static private void addIntegerToParsingFromC(Object contentHolder, String fieldName, int intToAdd) { >+ ((ParsedObjectContent)contentHolder).setData( new Integer(intToAdd)); >+ } >+ >+ /* >+ * Add a parsed long value to the Array<br> >+ * <br> >+ * Note : this function will be called from the C side. >+ * Note2: contentHolder is of type "Object" instead of "ParsedObjectContent" to be able to use the most generic function signature on the C side. >+ * its goal is to give a generic interface to people that would like to use the JNI library >+ * >+ * @param contentHolder Object where to store the parsed value >+ * @param fieldName The name of the parsed field >+ * @param longToAdd The parsed data to add >+ * @param formatToAdd The format of the raw data >+ */ >+ @SuppressWarnings("unused") >+ static private void addLongToParsingFromC(Object contentHolder, String fieldName, long longToAdd) { >+ ((ParsedObjectContent)contentHolder).setData( new Long(longToAdd)); >+ } >+ >+ /* >+ * Add a parsed float value to the Array<br> >+ * <br> >+ * Note : this function will be called from the C side. >+ * Note2: contentHolder is of type "Object" instead of "ParsedObjectContent" to be able to use the most generic function signature on the C side. >+ * its goal is to give a generic interface to people that would like to use the JNI library >+ * >+ * @param contentHolder Object where to store the parsed value >+ * @param fieldName The name of the parsed field >+ * @param floatToAdd The parsed data to add >+ * @param formatToAdd The format of the raw data >+ */ >+ @SuppressWarnings("unused") >+ static private void addFloatToParsingFromC(Object contentHolder, String fieldName, float floatToAdd) { >+ ((ParsedObjectContent)contentHolder).setData( new Float(floatToAdd)); >+ } >+ >+ /* >+ * Add a parsed double value to the Array<br> >+ * <br> >+ * Note : this function will be called from the C side. >+ * Note2: contentHolder is of type "Object" instead of "ParsedObjectContent" to be able to use the most generic function signature on the C side. >+ * its goal is to give a generic interface to people that would like to use the JNI library >+ * >+ * >+ * @param contentHolder Object where to store the parsed value >+ * @param fieldName The name of the parsed field >+ * @param doubleToAdd The parsed data to add >+ * @param formatToAdd The format of the raw data >+ */ >+ @SuppressWarnings("unused") >+ static private void addDoubleToParsingFromC(Object contentHolder, String fieldName, double doubleToAdd) { >+ ((ParsedObjectContent)contentHolder).setData( new Double(doubleToAdd)); >+ } >+ >+} >+ >+/** >+ * <b><u>ParsedObjectContent</u></b> >+ * <p> >+ * ParsedObjectContent class. >+ * This class will only be used locally in this object to parse event data more efficiently in the C >+ */ >+class ParsedObjectContent { >+ private Object parsedData = null; >+ >+ public Object getData() { >+ return parsedData; >+ } >+ >+ public void setData(Object newData) { >+ parsedData = newData; >+ } >+} >\ No newline at end of file > >Property changes on: src/org/eclipse/linuxtools/lttng/jni/JniParser.java >___________________________________________________________________ >Added: svn:mime-type > + text/plain > >Index: src/org/eclipse/linuxtools/lttng/event/LttngEventFormat.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/event/LttngEventFormat.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/event/LttngEventFormat.java (revision 23015) >@@ -0,0 +1,138 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * William Bourque (wbourque@gmail.com) - Initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.linuxtools.lttng.event; >+ >+import java.util.HashMap; >+import java.util.Iterator; >+ >+import org.eclipse.linuxtools.tmf.event.TmfEventFormat; >+ >+/** >+ * <b><u>LttngEventFormat</u></b> >+ * <p> >+ * Lttng specific implementation of the TmfEventFormat >+ * <p> >+ * The Lttng implementation of format override parse but require a LttngEvent for most functions so it can call Jni >+ */ >+public class LttngEventFormat extends TmfEventFormat { >+ >+ /** >+ * Default constructor >+ */ >+ public LttngEventFormat() { >+ >+ } >+ >+ /** >+ * Getter for the label of the fields for this event.<br> >+ * >+ * @return String[] A string array that contain the labels name >+ */ >+ public String[] getLabels(LttngEvent thisEvent) { >+ String[] returnedLabels = null; >+ returnedLabels = thisEvent.convertEventTmfToJni().requestEventMarker().getMarkerFieldsHashMap().keySet().toArray(returnedLabels); >+ >+ return returnedLabels; >+ } >+ >+ /** >+ * Parse the LttngEvent linked to this LttngEventFormat.<br> >+ * >+ * @return LttngEventField[] An array of LttngEventField that contain the parsed data >+ */ >+ public LttngEventField[] parse(LttngEvent thisEvent) { >+ HashMap<String, Object> parsedMap = thisEvent.convertEventTmfToJni().parseAllFields(); >+ LttngEventField[] returnedField = new LttngEventField[parsedMap.size()]; >+ >+ String fieldName = null; >+ int position = 0; >+ Iterator<String> iterator = parsedMap.keySet().iterator(); >+ while (iterator.hasNext()) { >+ fieldName = iterator.next(); >+ returnedField[position] = new LttngEventField( fieldName, parsedMap.get(fieldName) ); >+ position++; >+ } >+ >+ return returnedField; >+ } >+ >+ >+ >+ /* *** FIXME >+ * TEMPORARY IMPLEMENTATION >+ * THIS WILL DISAPEAR ( ?? ) >+ */ >+ public LttngEventField[] parse(HashMap<String, Object> parsedEvents) { >+ LttngEventField[] returnedField = new LttngEventField[parsedEvents.size()]; >+ >+ String fieldName = null; >+ int position = 0; >+ Iterator<String> iterator = parsedEvents.keySet().iterator(); >+ while (iterator.hasNext()) { >+ fieldName = iterator.next(); >+ returnedField[position] = new LttngEventField( fieldName, parsedEvents.get(fieldName) ); >+ position++; >+ } >+ >+ return returnedField; >+ } >+ >+ /* *** FIXME *** >+ * Evil "do at least something" parse function >+ * THIS IS JUST FOR COMPATIBILITY! DO NOT USE! >+ * Content/Format/Fields interelation need to be revisited ASAP >+ */ >+ public LttngEventField[] parse(String uselessContent) { >+ // *** Begining of the evil "parse String" function >+ // >+ // - 1st : Find the number of ":" in the String. This will be the number of fields in the String. >+ // Highly unreliable, as we depend on String content that we don't control! >+ int nbFields = 0; >+ for ( int pos = 0; pos < uselessContent.length(); pos++ ) { >+ if ( uselessContent.substring(pos, pos+1).equals(":") ) { >+ nbFields++; >+ } >+ } >+ >+ // - 2nd : Create the fields array >+ LttngEventField[] tmpFields = new LttngEventField[nbFields]; >+ >+ // - 3rd : Fill the array >+ int fieldPosition = 0; >+ >+ int lastFieldPos = 0; >+ int lastDoubleDottedPos = 0; >+ int lastSpacePos = 0; >+ >+ for ( int pos = 0; pos < uselessContent.length(); pos++ ) { >+ if ( uselessContent.substring(pos, pos+1).equals(":") ) { >+ lastDoubleDottedPos = pos; >+ } >+ else if ( uselessContent.substring(pos, pos+1).equals(" ") ) { >+ lastSpacePos = pos; >+ >+ // ANOTHER highly unreliable assumption : >+ // Usually, most fields are in the form : "NAME : DATA" >+ // We need to skip the space following the double dots >+ if ( pos > lastDoubleDottedPos+1 ) { >+ tmpFields[fieldPosition] = new LttngEventField( uselessContent.substring(lastFieldPos, lastDoubleDottedPos), uselessContent.substring(lastDoubleDottedPos, lastSpacePos) ); >+ >+ lastFieldPos = pos; >+ } >+ } >+ } >+ >+ return tmpFields; >+ } >+ >+} > >Property changes on: src/org/eclipse/linuxtools/lttng/event/LttngEventFormat.java >___________________________________________________________________ >Added: svn:mime-type > + text/plain > >Index: src/org/eclipse/linuxtools/lttng/event/LttngEventContent.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/event/LttngEventContent.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/event/LttngEventContent.java (revision 23015) >@@ -0,0 +1,130 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * William Bourque (wbourque@gmail.com) - Initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.linuxtools.lttng.event; >+ >+import org.eclipse.linuxtools.tmf.event.TmfEventContent; >+ >+/** >+ * <b><u>LttngEventContent</u></b> >+ * <p> >+ * Lttng specific implementation of the TmfEventContent >+ * <p> >+ * Lttng LttngEventContent is very similar from TMF basic one. <br> >+ */ >+public class LttngEventContent extends TmfEventContent { >+ >+ /** >+ * Constructor with parameters<br> >+ * <br> >+ * Content will be null as no parsed content is given. >+ * >+ * @param thisFormat The LttngEventFormat relative to the JniEvent >+ */ >+ public LttngEventContent(LttngEventFormat thisFormat) { >+ super(null, thisFormat); >+ } >+ >+ /** >+ * Constructor with parameters<br> >+ * >+ * @param thisFormat The LttngEventFormat relative to this JniEvent >+ * @param thisParsedContent The string content of the JniEvent, already parsed >+ * >+ */ >+ public LttngEventContent(LttngEventFormat thisFormat, String thisParsedContent, LttngEventField[] thisFields) { >+ super(thisParsedContent, thisFormat); >+ setFields(thisFields); >+ } >+ >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.linuxtools.tmf.event.TmfEventContent#getFields() >+ */ >+ @Override >+ public LttngEventField[] getFields() { >+ >+ // Request the field variable from the inherited class >+ LttngEventField[] fields = (LttngEventField[])super.getFields(); >+ >+ // Field may be null if the content hasn't been parse yet >+ // If that's the case, call the parsing function >+ if (fields == null) { >+ fields = ((LttngEventFormat) this.getFormat()).parse(this.getContent()); >+ setFields(fields); >+ } >+ return fields; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.linuxtools.tmf.event.TmfEventContent#getField(int) >+ */ >+ @Override >+ public LttngEventField getField(int id) { >+ assert id >= 0 && id < this.getNbFields(); >+ >+ LttngEventField returnedField = null; >+ LttngEventField[] allFields = this.getFields(); >+ >+ if ( allFields != null ) { >+ returnedField = allFields[id]; >+ } >+ >+ return returnedField; >+ } >+ >+ /** >+ * @param thisEvent >+ * @return >+ */ >+ public LttngEventField[] getFields(LttngEvent thisEvent) { >+ >+ // Request the field variable from the inherited class >+ LttngEventField[] fields = (LttngEventField[])super.getFields(); >+ >+ // Field may be null if the content hasn't been parse yet >+ // If that's the case, call the parsing function >+ if (fields == null) { >+ fields = ((LttngEventFormat)this.getFormat()).parse(thisEvent); >+ setFields(fields); >+ } >+ return fields; >+ } >+ >+ /** >+ * @param id >+ * @param thisEvent >+ * @return >+ */ >+ public LttngEventField getField(int id, LttngEvent thisEvent) { >+ assert id >= 0 && id < this.getNbFields(); >+ >+ LttngEventField returnedField = null; >+ LttngEventField[] allFields = this.getFields(thisEvent); >+ >+ if ( allFields != null ) { >+ returnedField = allFields[id]; >+ } >+ >+ return returnedField; >+ } >+ >+ >+ /** >+ * basic toString() method. >+ * >+ * @return Attributes of the object concatenated in String >+ */ >+ public String toString() { >+ return getContent().toString(); >+ } >+} >\ No newline at end of file > >Property changes on: src/org/eclipse/linuxtools/lttng/event/LttngEventContent.java >___________________________________________________________________ >Added: svn:mime-type > + text/plain > >Index: src/org/eclipse/linuxtools/lttng/event/LttngEventReference.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/event/LttngEventReference.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/event/LttngEventReference.java (revision 23015) >@@ -0,0 +1,50 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * William Bourque (wbourque@gmail.com) - Initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.linuxtools.lttng.event; >+ >+import org.eclipse.linuxtools.tmf.event.*; >+ >+/** >+ * <b><u>LttngEventReference</u></b> >+ * <p> >+ * Lttng specific implementation of the TmfEventReference >+ * <p> >+ * The Lttng implementation is the same as the basic Tmf Implementation but allow construction with a String >+ */ >+public class LttngEventReference extends TmfEventReference { >+ >+ >+ private String tracepath = ""; >+ >+ /** >+ * Constructor with parameters >+ * >+ * @param referencePath A string that will be our reference >+ */ >+ public LttngEventReference(String newTracefilePath, String newTracePath) { >+ super(newTracefilePath); >+ >+ // Save the path of the trace >+ tracepath = newTracePath; >+ } >+ >+ >+ public String getTracepath() { >+ return tracepath; >+ } >+ >+ public void setTracepath(String tracepath) { >+ this.tracepath = tracepath; >+ } >+ >+} > >Property changes on: src/org/eclipse/linuxtools/lttng/event/LttngEventReference.java >___________________________________________________________________ >Added: svn:mime-type > + text/plain > >Index: src/org/eclipse/linuxtools/lttng/event/LttngEvent.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/event/LttngEvent.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/event/LttngEvent.java (revision 23015) >@@ -0,0 +1,111 @@ >+package org.eclipse.linuxtools.lttng.event; >+ >+import org.eclipse.linuxtools.tmf.event.TmfEvent; >+import org.eclipse.linuxtools.tmf.event.TmfTimestamp; >+import org.eclipse.linuxtools.lttng.jni.JniEvent; >+ >+/** >+ * <b><u>LttngEvent</u></b> >+ * <p> >+ * Lttng specific TmfEvent implementation >+ * <p> >+ * The main difference from the basic Tmf implementation is that we keep an internal reference to the Jni JniEvent<br> >+ * The conversion from this LttngEvent to the JniEvent is then possible. >+ * </ul> >+ */ >+@SuppressWarnings("unused") >+public class LttngEvent extends TmfEvent { >+ // Reference to the JNI JniEvent. Should only used INTERNALLY >+ JniEvent jniEventReference = null; >+ >+ /** >+ * Constructor with parameters <br> >+ * <br> >+ * >+ * @param timestamp The timestamp of this event >+ * @param source The source of this event >+ * @param type The type of this event >+ * @param content The content of this event >+ * @param reference The reference of this event >+ * @param lttEvent A reference to a valid JniEvent object >+ * >+ * @see org.eclipse.linuxtools.tmf.event.TmfTimestamp >+ * @see org.eclipse.linuxtools.lttng.event.LttngEventSource >+ * @see org.eclipse.linuxtools.lttng.event.LttngEventType >+ * @see org.eclipse.linuxtools.lttng.event.LttngEventContent >+ * @see org.eclipse.linuxtools.lttng.event.LttngEventReference >+ * @see org.eclipse.linuxtools.lttng.jni.JniEvent >+ * >+ */ >+ public LttngEvent(LttngTimestamp timestamp, LttngEventSource source, LttngEventType type, LttngEventContent content, LttngEventReference reference, JniEvent lttEvent) { >+ super(timestamp, source, type, content, reference); >+ >+ jniEventReference = lttEvent; >+ } >+ >+ /** >+ * Return the channel name of this event<br> >+ * >+ * @return String The name of the channel >+ */ >+ public String getChannelName() { >+ String returnedValue = ""; >+ >+ if ( this.getType() instanceof LttngEventType ) { >+ returnedValue = ( (LttngEventType)this.getType() ).getChannelName(); >+ } >+ >+ return returnedValue; >+ } >+ >+ /** >+ * Return the cpu id number of this event<br> >+ * >+ * @return long The cpu id >+ */ >+ public long getCpuId() { >+ long returnedValue =-1; >+ >+ if ( this.getType() instanceof LttngEventType ) { >+ returnedValue = ( (LttngEventType)this.getType() ).getCpuId(); >+ } >+ >+ return returnedValue; >+ } >+ >+ /** >+ * Return the marker name of this event<br> >+ * >+ * @return String The marker name >+ */ >+ public String getMarkerName() { >+ String returnedValue = ""; >+ >+ if ( this.getType() instanceof LttngEventType ) { >+ returnedValue = ( (LttngEventType)this.getType() ).getMarkerName(); >+ } >+ >+ return returnedValue; >+ } >+ >+ /** >+ * Convert this event into a Jni JniEvent<br> >+ * <br> >+ * Note : Some verification are done to make sure the event is still valid on the Jni side.<br> >+ * If it is not the case, null will be returned. >+ * >+ * @return JniEvent The converted event >+ * @see org.eclipse.linuxtools.lttng.jni.JniEvent >+ */ >+ public JniEvent convertEventTmfToJni() { >+ JniEvent tmpEvent = null; >+ >+ // We don't want to send away events that are outdated as their informations could be invalid >+ // If the timestamp between the event and the trace are not coherent we will not perform the conversion >+ if ( jniEventReference.getParentTracefile().getParentTrace().getCurrentEventTimestamp().getTime() == getTimestamp().getValue() ) { >+ tmpEvent = jniEventReference; >+ } >+ >+ return tmpEvent; >+ } >+} > >Property changes on: src/org/eclipse/linuxtools/lttng/event/LttngEvent.java >___________________________________________________________________ >Added: svn:mime-type > + text/plain > >Index: src/org/eclipse/linuxtools/lttng/event/LttngEventSource.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/event/LttngEventSource.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/event/LttngEventSource.java (revision 23015) >@@ -0,0 +1,33 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * William Bourque (wbourque@gmail.com) - Initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.linuxtools.lttng.event; >+ >+import org.eclipse.linuxtools.tmf.event.*; >+ >+/** >+ * <b><u>LttngEventSource</u></b> >+ * <p> >+ * Lttng specific implementation of the TmfEventSource >+ * <p> >+ * The Lttng implementation is the same as the basic Tmf Implementation but allow construction with a String as paramter >+ */ >+public class LttngEventSource extends TmfEventSource { >+ /** >+ * Constructor with parameters >+ * >+ * @param newSource Name as string of the source. >+ */ >+ public LttngEventSource(String newSource) { >+ super(newSource); >+ } >+} > >Property changes on: src/org/eclipse/linuxtools/lttng/event/LttngEventSource.java >___________________________________________________________________ >Added: svn:mime-type > + text/plain > >Index: src/org/eclipse/linuxtools/lttng/event/LttngEventType.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/event/LttngEventType.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/event/LttngEventType.java (revision 23015) >@@ -0,0 +1,70 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * William Bourque (wbourque@gmail.com) - Initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.linuxtools.lttng.event; >+ >+import org.eclipse.linuxtools.tmf.event.*; >+ >+/** >+ * <b><u>LttngEventType</u></b> >+ * <p> >+ * Lttng specific implementation of the TmfEventType >+ * <p> >+ * This implementation add some attributes to the basic Tmf object. >+ */ >+public class LttngEventType extends TmfEventType { >+ private String channelName = ""; >+ private long cpuId = 0; >+ private String markerName = ""; >+ >+ /** >+ * Constructor with parameters >+ * >+ * @param thisChannelName Channel name. It is the Tracefile name in LTT. >+ * @param thisCpuId CPU id number from LTT >+ * @param thisMarkerName JniMarker name. It is the marker_info name in LTT. >+ * @param thisFormat The format relative to the event >+ * @see org.eclipse.linuxtools.lttng.event.LttngEventFormat >+ */ >+ public LttngEventType(String thisChannelName, long thisCpuId, String thisMarkerName, LttngEventFormat thisFormat) { >+ super( thisChannelName + "/" + thisCpuId + "/" + thisMarkerName, thisFormat); >+ >+ channelName = thisChannelName; >+ cpuId = thisCpuId; >+ markerName = thisMarkerName; >+ } >+ >+ >+ public String getChannelName() { >+ return channelName; >+ } >+ >+ >+ public long getCpuId() { >+ return cpuId; >+ } >+ >+ >+ public String getMarkerName() { >+ return markerName; >+ } >+ >+ >+ /** >+ * toString() method. >+ * >+ * @return String TypeId of the object >+ */ >+ public String toString() { >+ return getTypeId(); >+ } >+} > >Property changes on: src/org/eclipse/linuxtools/lttng/event/LttngEventType.java >___________________________________________________________________ >Added: svn:mime-type > + text/plain > >Index: src/org/eclipse/linuxtools/lttng/event/LttngTimestamp.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/event/LttngTimestamp.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/event/LttngTimestamp.java (revision 23015) >@@ -0,0 +1,151 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * William Bourque (wbourque@gmail.com) - Initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.linuxtools.lttng.event; >+ >+import org.eclipse.linuxtools.tmf.event.TmfTimestamp; >+ >+/** >+ * <b><u>LttngTimestamp</u></b> >+ * <p> >+ * Lttng specific implementation of the TmfTimestamp >+ * <p> >+ * The Lttng implementation is the same as the basic Tmf Implementation but allow construction with a TmfTimestamp and a long >+ */ >+public class LttngTimestamp extends TmfTimestamp { >+ >+ /** >+ * Copy Constructor<br> >+ * <br> >+ * Note : this constructor require a TmfTimestamp instead of a LttngTimestamp to save us some casts >+ * >+ * @param newEventTime The TmfTimestamp object we want to copy >+ */ >+ public LttngTimestamp(TmfTimestamp newEventTime) { >+ super(newEventTime); >+ } >+ >+ /** >+ * Constructor with parameters >+ * >+ * @param newEventTime JniTime as long, unit expected to be nanoseconds. >+ */ >+ public LttngTimestamp(long newEventTime) { >+ super(newEventTime, (byte) -9); >+ } >+ >+ /** >+ * toString() method. >+ * >+ * @return String Attributes of this object. >+ */ >+ public String toString() { >+// String returnData = ""; >+// >+// returnData += "[lttng_Timestamp: " + getValue() / Jni_C_Common.NANO; >+// returnData += "." + getValue() % Jni_C_Common.NANO; >+// returnData += " ]"; >+// >+// return returnData; >+ >+ // If we are dealing with units of seconds (or higher), >+ // use the plain formatter >+ if (fScale >= 0) { >+ Double value = fValue * Math.pow(10, fScale); >+ return value.toString(); >+ } >+ >+ // Define a format string >+ String format = String.format("%%1d.%%0%dd", -fScale); >+ >+ // And format the timestamp value >+ double scale = Math.pow(10, fScale); >+ long seconds = (long) (fValue * scale); >+ long fracts = fValue - (long) ((double) seconds / scale); >+ String result = String.format(format, seconds, fracts); >+ >+ return result; >+ } >+ >+ /** >+ * This method does not use scale and assumes contents to be in nano seconds >+ * >+ * @return String Attributes of this object. >+ */ >+ public String getSeconds() { >+ return formatSecs(fValue); >+ } >+ >+ /** >+ * This method does not use scale and assumes contents to be in nano seconds >+ * >+ * @return String Attributes of this object. >+ */ >+ public String getNanoSeconds() { >+ return formatNs(fValue); >+ } >+ >+ /** >+ * @param time >+ * @return >+ */ >+ private String formatSecs(long time) { >+ long sec = (long) (time * 1E-9); >+ return String.valueOf(sec); >+ } >+ >+ /** >+ * Obtains the remainder fraction on unit Seconds of the entered value in >+ * nanoseconds. e.g. input: 1241207054171080214 ns The number of fraction >+ * seconds can be obtained by removing the last 9 digits: 1241207054 the >+ * fractional portion of seconds, expressed in ns is: 171080214 >+ * >+ * @param time >+ * @param res >+ * @return >+ */ >+ private String formatNs(long time) { >+ boolean neg = time < 0; >+ if (neg) { >+ time = -time; >+ } >+ // The following approach could be used although performance >+ // decreases in half. >+ // String strVal = String.format("%09d", time); >+ // String tmp = strVal.substring(strVal.length() - 9); >+ >+ StringBuffer temp = new StringBuffer(); >+ long ns = time; >+ ns %= 1000000000; >+ if (ns < 10) { >+ temp.append("00000000"); >+ } else if (ns < 100) { >+ temp.append("0000000"); >+ } else if (ns < 1000) { >+ temp.append("000000"); >+ } else if (ns < 10000) { >+ temp.append("00000"); >+ } else if (ns < 100000) { >+ temp.append("0000"); >+ } else if (ns < 1000000) { >+ temp.append("000"); >+ } else if (ns < 10000000) { >+ temp.append("00"); >+ } else if (ns < 100000000) { >+ temp.append("0"); >+ } >+ >+ temp.append(ns); >+ return temp.toString(); >+ } >+ >+} > >Property changes on: src/org/eclipse/linuxtools/lttng/event/LttngTimestamp.java >___________________________________________________________________ >Added: svn:mime-type > + text/plain > >Index: src/org/eclipse/linuxtools/lttng/event/LttngEventField.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/event/LttngEventField.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/event/LttngEventField.java (revision 23015) >@@ -0,0 +1,59 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * William Bourque (wbourque@gmail.com) - Initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.linuxtools.lttng.event; >+ >+import org.eclipse.linuxtools.tmf.event.*; >+ >+/** >+ * <b><u>LttngEventField</u></b> >+ * <p> >+ * Lttng specific implementation of the TmfEventField >+ * <p> >+ * Lttng LttngEventField add a "Name" attribute to the Tmf implementation >+ * This mean the fields will have a name and a value. >+ */ >+public class LttngEventField extends TmfEventField >+{ >+ private String fieldName = ""; >+ >+ /** >+ * Constructor with parameters<br> >+ * >+ * @param newContent The parsedContent we want to populate the field with. >+ * >+ * @see org.eclipse.linuxtools.lttng.jni.ParsedContent >+ */ >+ public LttngEventField(String name, Object newContent) { >+ super( newContent ); >+ >+ fieldName = name; >+ } >+ >+ /** >+ * getter for the name attribute. >+ */ >+ public String getName() { >+ return fieldName; >+ } >+ >+ /** >+ * overrided toString() method.<br> >+ * <br> >+ * Print both field name and value. >+ */ >+ @Override >+ public String toString() { >+ return fieldName + " : " + getValue().toString(); >+ } >+} >+ > >Property changes on: src/org/eclipse/linuxtools/lttng/event/LttngEventField.java >___________________________________________________________________ >Added: svn:mime-type > + text/plain > >Index: src/org/eclipse/linuxtools/lttng/trace/LttngEventStream.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/trace/LttngEventStream.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/trace/LttngEventStream.java (revision 23015) >@@ -0,0 +1,249 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * William Bourque (wbourque@gmail.com) - Initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.linuxtools.lttng.trace; >+ >+import java.io.FileNotFoundException; >+ >+import org.eclipse.linuxtools.lttng.event.LttngEvent; >+import org.eclipse.linuxtools.lttng.event.LttngEventContent; >+import org.eclipse.linuxtools.lttng.event.LttngEventField; >+import org.eclipse.linuxtools.lttng.event.LttngEventFormat; >+import org.eclipse.linuxtools.lttng.event.LttngEventReference; >+import org.eclipse.linuxtools.lttng.event.LttngEventSource; >+import org.eclipse.linuxtools.lttng.event.LttngEventType; >+import org.eclipse.linuxtools.lttng.event.LttngTimestamp; >+import org.eclipse.linuxtools.lttng.jni.JniEvent; >+import org.eclipse.linuxtools.lttng.jni.JniException; >+import org.eclipse.linuxtools.lttng.jni.JniTime; >+import org.eclipse.linuxtools.lttng.jni.JniTrace; >+import org.eclipse.linuxtools.tmf.event.TmfEvent; >+import org.eclipse.linuxtools.tmf.event.TmfTimeRange; >+import org.eclipse.linuxtools.tmf.event.TmfTimestamp; >+import org.eclipse.linuxtools.tmf.trace.TmfTrace; >+ >+/** >+ * <b><u>LttngEventStream</u></b> >+ * <p> >+ * LTTng trace implementation. It accesses the C trace handling library >+ * (seeking, reading and parsing) through the JNI component. >+ */ >+public class LttngEventStream extends TmfTrace { >+ >+ private final static boolean IS_PARSING_NEEDED_DEFAULT = true; >+ private final static int CHECKPOINT_PAGE_SIZE = 1000; >+ >+ // Reference to the current LttngEvent >+ private LttngEvent currentLttngEvent = null; >+ >+ // Reference to our JNI trace >+ private JniTrace currentJniTrace = null; >+ >+ /** >+ * Constructor >+ * <p> >+ * @param path Path to a <b>directory</b> that contain an LTTng trace. >+ * @exception Exception Trace opening failed (FileNotFoundException) >+ * >+ * @see org.eclipse.linuxtools.lttng.jni.JniTrace >+ */ >+ public LttngEventStream(String path) throws Exception { >+ super(path, CHECKPOINT_PAGE_SIZE); >+ try { >+ currentJniTrace = new JniTrace(path); >+ } >+ catch (JniException e) { >+ throw new FileNotFoundException(); >+ } >+ TmfTimestamp startTime = new LttngTimestamp(currentJniTrace.getStartTimeFromTimestampCurrentCounter().getTime()); >+ setTimeRange(new TmfTimeRange(startTime, startTime)); >+ indexStream(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#parseNextEvent() >+ */ >+ public synchronized TmfEvent parseNextEvent() { >+ JniEvent jniEvent = currentJniTrace.readNextEvent(); >+ currentLttngEvent = convertJniEventToTmf(jniEvent); >+ return currentLttngEvent; >+ } >+ >+ /** >+ * Return a reference to the current LttngTrace we are reading from. >+ * >+ * @return JniTrace >+ * @see org.eclipse.linuxtools.lttng.jni.JniTrace >+ */ >+ public JniTrace getCurrentJniTrace() { >+ return currentJniTrace; >+ } >+ >+ >+ /** >+ * Return a reference to the current LttngEvent we are reading. >+ * >+ * @return LttngEvent >+ * @see org.eclipse.linuxtools.lttng.event.LttngEvent >+ */ >+ public LttngEvent getCurrentEvent() { >+ return currentLttngEvent; >+ } >+ >+ >+ /** >+ * Method to convert a JniEvent into a LttngEvent.<br> >+ * <br> >+ * Note : This method will call LttngEvent convertEventJniToTmf(JniEvent, boolean) >+ * with a default value for isParsingNeeded >+ * >+ * @param newEvent The JniEvent to convert >+ * @return LttngEvent The converted event >+ * @see org.eclipse.linuxtools.lttng.jni.JniEvent >+ */ >+ public LttngEvent convertJniEventToTmf(JniEvent newEvent) { >+ LttngEvent event = null; >+ if (newEvent != null) >+ event = convertJniEventToTmf(newEvent, IS_PARSING_NEEDED_DEFAULT); >+ return event; >+ } >+ >+ /** >+ * Method tp convert a JniEvent into a LttngEvent >+ * >+ * @param jniEvent The JniEvent to convert >+ * @param isParsingNeeded A boolean value telling if the event should be parsed or not. >+ * @return LttngEvent The converted event >+ * @see org.eclipse.linuxtools.lttng.jni.JniEvent >+ */ >+ // Conversion method to transform a JafEvent into a TmfEvent >+ public LttngEvent convertJniEventToTmf(JniEvent jniEvent, boolean isParsingNeeded) { >+ LttngEventFormat eventFormat = new LttngEventFormat(); >+ String content = ""; >+ LttngEventField[] fields = null; >+ >+ if (isParsingNeeded == true) { >+ fields = eventFormat.parse(jniEvent.parseAllFields()); >+ for (int y = 0; y < fields.length; y++) { >+ content += fields[y].toString() + " "; >+ } >+ } >+ >+ LttngEvent event = new LttngEvent( >+ new LttngTimestamp(jniEvent.getEventTime().getTime()), >+ new LttngEventSource(jniEvent.requestEventSource() ), >+ new LttngEventType(jniEvent.getParentTracefile().getTracefileName(), >+ jniEvent.getParentTracefile().getCpuNumber(), >+ jniEvent.requestEventMarker().getName(), >+ eventFormat), >+ new LttngEventContent(eventFormat, content, fields), >+ new LttngEventReference(jniEvent.getParentTracefile().getTracefilePath(), this.getName()), >+ jniEvent); >+ >+ return event; >+ } >+ >+ >+ /** >+ * Return location (timestamp) of our current position in the trace. >+ * >+ * @return LttngTimestamp The current Ltt timestamp, in long. Unit is nanosecond. >+ */ >+ public Object getCurrentLocation() { >+ return new LttngTimestamp(currentJniTrace.getCurrentEventTimestamp().getTime()); >+ } >+ >+ /** >+ * Seek (move) to a certain location in the trace. >+ * >+ * @param location a LttngTimestamp of a position in the trace >+ * @return StreamContext pointing to the current (after seek) position in the trace >+ */ >+ public TmfTraceContext seekLocation(Object location) { >+ >+ // If location is null, interpret this as a request to get back to the beginning of the trace >+ // Change the location, the seek will happen below >+ if (location == null) { >+ location = getStartTime(); >+ } >+ >+ TmfTraceContext context = null; >+ if (location instanceof LttngTimestamp) { >+ long value = ((LttngTimestamp) location).getValue(); >+ if (value != currentJniTrace.getCurrentEventTimestamp().getTime()) { >+ currentJniTrace.seekToTime(new JniTime(value)); >+ context = new TmfTraceContext(new LttngTimestamp(currentJniTrace.getCurrentEventTimestamp().getTime()), 0); >+ } >+ } >+ >+ return context; >+ } >+ >+ >+ // !!! THIS MAIN IS FOR TESTING ONLY !!! >+ public static void main(String[] args) { >+ >+// LttngEventStream testStream = null; >+// try { >+// testStream = new LttngEventStream("/home/william/trace1"); >+// Thread.sleep(5000); >+// >+// System.out.println("NB Events : " + testStream.getNbEvents()); >+// System.out.println("Beginning test run parsing event"); >+// >+// LttngEvent tmpEvent = null; >+// Random generator = new Random(); >+// >+// int number = 0; >+// long execStartTime = System.currentTimeMillis(); >+// for (int x = 0; x < 10; x++) { >+// number = generator.nextInt(testStream.getNbEvents()); >+// >+// tmpEvent = (LttngEvent) testStream.getEvent(new TmfTraceContext(null), number); >+// >+// >+// System.out.println("GETTING EVENT #" + number); >+// >+// // ***************** >+// // *** OLD EVIL WAY >+// TmfEventField[] tmpJoieFields = tmpEvent.getContent().getFields(); >+// for ( int pos = 0; pos< tmpJoieFields.length; pos++ ) >+// { >+// System.out.print(tmpJoieFields[pos].toString() + " "); >+// } >+// System.out.println(""); >+// // *** >+// // ***************** >+// >+// >+// // ***************** >+// // *** NEW CAST-O-RAMA WAY >+// TmfEventField[] tmpJoieFields2 = ( (LttngEventContent)tmpEvent.getContent()).getFields(tmpEvent); >+// for ( int pos = 0; pos< tmpJoieFields2.length; pos++ ) >+// { >+// System.out.print(tmpJoieFields2[pos].toString() + " "); >+// } >+// System.out.println(""); >+// // *** >+// // ***************** >+// } >+// long execEndTime = System.currentTimeMillis(); >+// System.out.println("Execution time: " + (execEndTime - execStartTime) + "ms"); >+// >+// >+// } catch (Exception e) { >+// System.out.println("FAILED WITH : " + e.getMessage() + "\n"); >+// } >+ >+ } >+ >+} > >Property changes on: src/org/eclipse/linuxtools/lttng/trace/LttngEventStream.java >___________________________________________________________________ >Added: svn:mime-type > + text/plain >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
fchouinard
:
iplog+
Actions:
View
|
Diff
Attachments on
bug 290046
: 147783