From e4dc0a9a23c476eb354f577068b22e4508cf90d8 Mon Sep 17 00:00:00 2001 From: Francois Chouinard Date: Wed, 27 Jul 2011 16:19:57 -0400 Subject: [PATCH] Fix the trace vs. library version confusion --- .../linuxtools/lttng/jni/JniTrace.java | 800 ++++++++++-------- .../lttng/jni_v2_6/JniTrace_v2_6.java | 5 +- .../subsystems/TraceSubSystem.java | 5 + .../views/project/dialogs/messages.properties | 9 - 4 files changed, 438 insertions(+), 381 deletions(-) diff --git a/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/JniTrace.java b/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/JniTrace.java index 6911255b52..e84224bebc 100644 --- a/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/JniTrace.java +++ b/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/JniTrace.java @@ -1,4 +1,5 @@ package org.eclipse.linuxtools.lttng.jni; + /******************************************************************************* * Copyright (c) 2009 Ericsson * @@ -25,8 +26,8 @@ import org.eclipse.linuxtools.lttng.jni.exception.JniTracefileWithoutEventExcept /** * JniTrace *

- * This is the top level class in the JNI. It provides access to the - * LttTrace C structure in java. + * This is the top level class in the JNI. It provides access to the LttTrace C + * structure in java. *

* Most important fields in the JniTrace are : *

*

- * NOTE

- * This class is ABSTRACT, you need to extends it to support your specific LTTng version.
- * Please look at the abstract functions to override at the bottom of this file.

+ * NOTE + *

+ * This class is ABSTRACT, you need to extends it to support your specific LTTng + * version.
+ * Please look at the abstract functions to override at the bottom of this file. + *

*/ public abstract class JniTrace extends Jni_C_Common { - + private final static boolean DEFAULT_LTT_DEBUG = false; - + // Internal C pointer of the JniTrace used in LTT private Jni_C_Pointer_And_Library_Id thisTracePtr = new Jni_C_Pointer_And_Library_Id(); @@ -49,89 +53,103 @@ public abstract class JniTrace extends Jni_C_Common { // 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) //$NON-NLS-1$ - 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 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 startTimeNoAdjustement = null; private JniTime startTime = null; private JniTime endTime = null; - + // This Map holds a reference to the tracefiles owned by this trace private HashMap tracefilesMap = null; - // The priority queue (similar to heap) hold events + // The priority queue (similar to heap) hold events private PriorityQueue eventsHeap = null; - + // This variable will hold the content of the "last" event we read - private JniEvent currentEvent = null; - + private JniEvent currentEvent = null; + // Should we print debug in the C library or not? private boolean printLttDebug = DEFAULT_LTT_DEBUG; - + // flag determine if live trace is supported or not - private boolean isLiveTraceSupported = false; - - + // will be set to false in constructor if opening in live mode fails + private boolean isLiveTraceSupported = true; + // This need to be called prior to any operation protected native int ltt_initializeHandle(String libname); - + // This need to be called at the very end (destructor) protected native boolean ltt_freeHandle(int libId); - + // Open/close native functions protected native long ltt_openTrace(int libId, String pathname, boolean printDebug); + protected native long ltt_openTraceLive(int libId, String pathname, boolean printDebug); + protected native void ltt_closeTrace(int libId, long tracePtr); // Native access functions protected native String ltt_getTracepath(int libId, long tracePtr); - protected native int ltt_getCpuNumber(int libId, long tracePtr); - protected native long ltt_getArchType(int libId, long tracePtr); - protected native long ltt_getArchVariant(int libId, long tracePtr); - protected native short ltt_getArchSize(int libId, long tracePtr); - protected native short ltt_getLttMajorVersion(int libId, long tracePtr); - protected native short ltt_getLttMinorVersion(int libId, long tracePtr); - protected native short ltt_getFlightRecorder(int libId, long tracePtr); - protected native long ltt_getFreqScale(int libId, long tracePtr); - protected native long ltt_getStartFreq(int libId, long tracePtr); - protected native long ltt_getStartTimestampCurrentCounter(int libId, long tracePtr); - protected native long ltt_getStartMonotonic(int libId, long tracePtr); - + + protected native int ltt_getCpuNumber(int libId, long tracePtr); + + protected native long ltt_getArchType(int libId, long tracePtr); + + protected native long ltt_getArchVariant(int libId, long tracePtr); + + protected native short ltt_getArchSize(int libId, long tracePtr); + + protected native short ltt_getLttMajorVersion(int libId, long tracePtr); + + protected native short ltt_getLttMinorVersion(int libId, long tracePtr); + + protected native short ltt_getFlightRecorder(int libId, long tracePtr); + + protected native long ltt_getFreqScale(int libId, long tracePtr); + + protected native long ltt_getStartFreq(int libId, long tracePtr); + + protected native long ltt_getStartTimestampCurrentCounter(int libId, long tracePtr); + + protected native long ltt_getStartMonotonic(int libId, long tracePtr); + // Native function to update trace file and file size information protected native int ltt_updateTrace(int libId, long tracePtr); - + // Native function to fill out startTime protected native void ltt_feedStartTime(int libId, long tracePtr, JniTime startTime); - + // Native function to fill out startTimeFromTimestampCurrentCounter protected native void ltt_feedStartTimeFromTimestampCurrentCounter(int libId, long tracePtr, JniTime startTime); // Native function to fill out tracefilesMap protected native void ltt_feedAllTracefiles(int libId, long tracePtr); - + // Native function to fill out the start and end time of the trace protected native void ltt_feedTracefileTimeRange(int libId, long tracePtr, JniTime startTime, JniTime endTime); - + // Debug native function, ask LTT to print trace structure protected native void ltt_printTrace(int libId, long tracePtr); - + /* * Default constructor is forbidden */ protected JniTrace() { } - + /** - * Constructor that takes a tracepath parameter.

+ * Constructor that takes a tracepath parameter. + *

* * This constructor also opens the trace. * @@ -142,14 +160,16 @@ public abstract class JniTrace extends Jni_C_Common { public JniTrace(String newpath) throws JniException { this(newpath, DEFAULT_LTT_DEBUG); } - + /** - * Constructor that takes a tracepath parameter and a debug value.

+ * Constructor that takes a tracepath parameter and a debug value. + *

* * This constructor also opens the trace. * * @param newpath The directory of the trace to be opened - * @param newPrintDebug Should the debug information be printed in the LTT C library + * @param newPrintDebug Should the debug information be printed in the LTT C + * library * * @exception JniException */ @@ -157,49 +177,51 @@ public abstract class JniTrace extends Jni_C_Common { tracepath = newpath; thisTracePtr = new Jni_C_Pointer_And_Library_Id(); printLttDebug = newPrintDebug; - + openTrace(newpath); } - + /** * Copy constructor. * - * @param oldTrace A reference to the JniTrace to copy. + * @param oldTrace A reference to the JniTrace to copy. */ public JniTrace(JniTrace oldTrace) { - thisTracePtr = oldTrace.thisTracePtr; - - tracepath = oldTrace.tracepath; - cpuNumber = oldTrace.cpuNumber; - archType = oldTrace.archType; - archVariant = oldTrace.archVariant; - archSize = oldTrace.archSize; + 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; + flightRecorder = oldTrace.flightRecorder; + freqScale = oldTrace.freqScale; + startFreq = oldTrace.startFreq; startTimestampCurrentCounter = oldTrace.startTimestampCurrentCounter; - startMonotonic = oldTrace.startMonotonic; + startMonotonic = oldTrace.startMonotonic; startTimeNoAdjustement = oldTrace.startTimeNoAdjustement; - startTime = oldTrace.startTime; - endTime = oldTrace.endTime; + startTime = oldTrace.startTime; + endTime = oldTrace.endTime; tracefilesMap = new HashMap(oldTrace.tracefilesMap.size()); ltt_feedAllTracefiles(thisTracePtr.getLibraryId(), thisTracePtr.getPointer()); - - eventsHeap = new PriorityQueue( oldTrace.eventsHeap.size()); + + eventsHeap = new PriorityQueue(oldTrace.eventsHeap.size()); populateEventHeap(); - + printLttDebug = oldTrace.printLttDebug; - } - + } + /** - * Constructor, using C pointer.

+ * Constructor, using C pointer. + *

* * @param newPtr The pointer to an already opened LttTrace C structure. - * @param newPrintDebug Should the debug information be printed in the LTT C library - * + * @param newPrintDebug Should the debug information be printed in the LTT C + * library + * * @exception JniException * * @see org.eclipse.linuxtools.lttng.jni.common.Jni_C_Pointer_And_Library_Id @@ -207,35 +229,36 @@ public abstract class JniTrace extends Jni_C_Common { public JniTrace(Jni_C_Pointer_And_Library_Id newPtr, boolean newPrintDebug) throws JniException { thisTracePtr = newPtr; printLttDebug = newPrintDebug; - + // Populate our trace populateTraceInformation(); } - - + @Override - public void finalize() { - // If the trace is open, close it + public void finalize() { + // If the trace is open, close it if (thisTracePtr.getPointer() != NULL) { closeTrace(); } - + // Tell the C to free the allocated memory freeLibrary(); } - + /** - * Open an existing trace.

+ * Open an existing trace. + *

* - * The tracepath is a directory and needs to exist, otherwise - * a JniOpenTraceFailedException is throwed. + * The tracepath is a directory and needs to exist, otherwise a + * JniOpenTraceFailedException is throwed. * * @param newPath The directory of the trace to be opened * * @exception JniOpenTraceFailedException 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 open is called while a trace is already opened, we will try to + // close it first if (thisTracePtr.getPointer() != NULL) { closeTrace(); } @@ -244,98 +267,102 @@ public abstract class JniTrace extends Jni_C_Common { tracepath = newPath; openTrace(); } - + /** - * Open an existing trace.

+ * Open an existing trace. + *

* * The tracepath should have been set already, * - * @exception JniOpenTraceFailedException Thrown if the open failed + * @exception JniOpenTraceFailedException Thrown if the open failed */ public void openTrace() throws JniException { - - // Raise an exception if the tracepath is empty, otherwise open the trace + + // Raise an exception if the tracepath is empty, otherwise open the + // trace if (tracepath == "") { //$NON-NLS-1$ throw new JniTraceException("Tracepath is not set. (openTrace)"); //$NON-NLS-1$ } - + // If the file is already opened, close it first if (thisTracePtr.getPointer() != NULL) { closeTrace(); } - + // Initialization of the library is made here // It is very important that the id is kept! int newLibraryId = initializeLibrary(); - if ( newLibraryId != -1 ) { - // Call the LTT to open the trace - // Note that the libraryId is not yet and the pointer - long newPtr; - - if (isLiveTraceSupported()) { - try { - newPtr = ltt_openTraceLive(newLibraryId, tracepath, printLttDebug); - } catch (UnsatisfiedLinkError e) { - // JNI library doesn't support live trace read. Set flag for live trace support to false and - // open trace in offline mode. - setLiveTraceSupported(false); - newPtr = ltt_openTrace(newLibraryId, tracepath, printLttDebug); - } - } else { - newPtr = ltt_openTrace(newLibraryId, tracepath, printLttDebug); - } - - if (newPtr == NULL) { - thisTracePtr = new Jni_C_Pointer_And_Library_Id(); - throw new JniOpenTraceFailedException("Error while opening trace. Is the tracepath correct? (openTrace)"); //$NON-NLS-1$ - } - - // This is OUR pointer - thisTracePtr = new Jni_C_Pointer_And_Library_Id(newLibraryId, newPtr); - - // Populate the trace with LTT information - populateTraceInformation(); - } - else { - thisTracePtr = new Jni_C_Pointer_And_Library_Id(); - throw new JniTraceException("Failed to initialize library! Is the trace version supported?\n" + //$NON-NLS-1$ - "Make sure you have the correct LTTv library compiled. (openTrace)"); //$NON-NLS-1$ + if (newLibraryId != -1) { + // Call the LTT to open the trace + // Note that the libraryId is not yet and the pointer + long newPtr = NULL; + + try { + newPtr = ltt_openTraceLive(newLibraryId, tracepath, printLttDebug); + } catch (UnsatisfiedLinkError e) { + } + + if (newPtr == NULL) { + // JNI library doesn't support live trace read. Set flag for + // live trace support to false and + // open trace in offline mode. + isLiveTraceSupported = false; + newPtr = ltt_openTrace(newLibraryId, tracepath, printLttDebug); + } + + if (newPtr == NULL) { + thisTracePtr = new Jni_C_Pointer_And_Library_Id(); + throw new JniOpenTraceFailedException("Error while opening trace. Is the tracepath correct? (openTrace)"); //$NON-NLS-1$ + } + + // This is OUR pointer + thisTracePtr = new Jni_C_Pointer_And_Library_Id(newLibraryId, newPtr); + + // Populate the trace with LTT information + populateTraceInformation(); + } else { + thisTracePtr = new Jni_C_Pointer_And_Library_Id(); + throw new JniTraceException("Failed to initialize library! Is the trace version supported?\n" + //$NON-NLS-1$ + "Make sure you have the correct LTTv library compiled. (openTrace)"); //$NON-NLS-1$ } } - + /** - * Close a trace.

+ * Close a trace. + *

* * If the trace is already closed, will silently do nothing. */ public void closeTrace() { - + if (thisTracePtr.getPointer() != NULL) { ltt_closeTrace(thisTracePtr.getLibraryId(), thisTracePtr.getPointer()); - + // Clear the tracefile map tracefilesMap.clear(); tracefilesMap = null; - + // Clear the eventsHeap and make it points to null eventsHeap.clear(); eventsHeap = null; - + // Nullify the pointer thisTracePtr = new Jni_C_Pointer_And_Library_Id(); } } - + /** - * This function force the library to free its memory.

+ * This function force the library to free its memory. + *

* - * Note : No call to the library will work after this until ltt_initializeHandle is called again + * Note : No call to the library will work after this until + * ltt_initializeHandle is called again */ public void freeLibrary() { - ltt_freeHandle(thisTracePtr.getLibraryId()); + ltt_freeHandle(thisTracePtr.getLibraryId()); } - - /* + + /* * This function populates the trace data with data from LTT * * @throws JniException @@ -346,72 +373,76 @@ public abstract class JniTrace extends Jni_C_Common { } // Populate from the LTT library - tracepath = ltt_getTracepath(thisTracePtr.getLibraryId(), thisTracePtr.getPointer()); - cpuNumber = ltt_getCpuNumber(thisTracePtr.getLibraryId(), thisTracePtr.getPointer()); - archType = ltt_getArchType(thisTracePtr.getLibraryId(), thisTracePtr.getPointer()); + tracepath = ltt_getTracepath(thisTracePtr.getLibraryId(), thisTracePtr.getPointer()); + cpuNumber = ltt_getCpuNumber(thisTracePtr.getLibraryId(), thisTracePtr.getPointer()); + archType = ltt_getArchType(thisTracePtr.getLibraryId(), thisTracePtr.getPointer()); archVariant = ltt_getArchVariant(thisTracePtr.getLibraryId(), thisTracePtr.getPointer()); - archSize = ltt_getArchSize(thisTracePtr.getLibraryId(), thisTracePtr.getPointer()); + archSize = ltt_getArchSize(thisTracePtr.getLibraryId(), thisTracePtr.getPointer()); lttMajorVersion = ltt_getLttMajorVersion(thisTracePtr.getLibraryId(), thisTracePtr.getPointer()); lttMinorVersion = ltt_getLttMinorVersion(thisTracePtr.getLibraryId(), thisTracePtr.getPointer()); - flightRecorder = ltt_getFlightRecorder(thisTracePtr.getLibraryId(), thisTracePtr.getPointer()); - freqScale = ltt_getFreqScale(thisTracePtr.getLibraryId(), thisTracePtr.getPointer()); - startFreq = ltt_getStartFreq(thisTracePtr.getLibraryId(), thisTracePtr.getPointer()); + flightRecorder = ltt_getFlightRecorder(thisTracePtr.getLibraryId(), thisTracePtr.getPointer()); + freqScale = ltt_getFreqScale(thisTracePtr.getLibraryId(), thisTracePtr.getPointer()); + startFreq = ltt_getStartFreq(thisTracePtr.getLibraryId(), thisTracePtr.getPointer()); startTimestampCurrentCounter = ltt_getStartTimestampCurrentCounter(thisTracePtr.getLibraryId(), thisTracePtr.getPointer()); startMonotonic = ltt_getStartMonotonic(thisTracePtr.getLibraryId(), thisTracePtr.getPointer()); - // Creation of time is a bit different, we need to pass the object reference to C + // Creation of time is a bit different, we need to pass the object + // reference to C // - // *** NOTE : LTTv consider "raw startTime" (time without any frequency adjustement) to be default startTime - // So "startTimeNoAdjustement" is obtain throught "ltt_feedStartTime()" and - // "startTime" is obtained from ltt_feedStartTimeFromTimestampCurrentCounter() + // *** NOTE : LTTv consider "raw startTime" (time without any frequency + // adjustement) to be default startTime + // So "startTimeNoAdjustement" is obtain throught "ltt_feedStartTime()" + // and + // "startTime" is obtained from + // ltt_feedStartTimeFromTimestampCurrentCounter() startTimeNoAdjustement = new JniTime(); ltt_feedStartTime(thisTracePtr.getLibraryId(), thisTracePtr.getPointer(), startTimeNoAdjustement); - + startTime = new JniTime(); ltt_feedStartTimeFromTimestampCurrentCounter(thisTracePtr.getLibraryId(), thisTracePtr.getPointer(), startTime); // Call the fill up function for the tracefiles map - if ( tracefilesMap== null ) { + if (tracefilesMap == null) { tracefilesMap = new HashMap(); } ltt_feedAllTracefiles(thisTracePtr.getLibraryId(), thisTracePtr.getPointer()); - + // Now, obtain the trace "endTime" // Note that we discard "startTime" right away, as we already have it endTime = new JniTime(); ltt_feedTracefileTimeRange(thisTracePtr.getLibraryId(), thisTracePtr.getPointer(), new JniTime(), endTime); - + if (eventsHeap == null) { eventsHeap = new PriorityQueue(tracefilesMap.size()); } - + // 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() { currentEvent = null; eventsHeap.clear(); - + Object new_key = null; JniTracefile tmpTracefile = null; - + Iterator iterator = tracefilesMap.keySet().iterator(); - while( iterator.hasNext() ) { + while (iterator.hasNext()) { new_key = iterator.next(); - + tmpTracefile = tracefilesMap.get(new_key); - if ( tmpTracefile.getCurrentEvent().getEventState() == EOK ) { - eventsHeap.add( tmpTracefile.getCurrentEvent() ); + 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 @@ -419,34 +450,37 @@ public abstract class JniTrace extends Jni_C_Common { * catch all exceptions. * * @param tracefileName + * * @param tracefilePtr */ protected void addTracefileFromC(String tracefileName, long tracefilePtr) { - + JniTracefile newTracefile = null; - + // Create a new tracefile object and insert it in the map - // the tracefile fill itself with LTT data while being constructed + // the tracefile fill itself with LTT data while being constructed try { newTracefile = allocateNewJniTracefile(new Jni_C_Pointer_And_Library_Id(thisTracePtr.getLibraryId(), tracefilePtr), this); - getTracefilesMap().put( (tracefileName + newTracefile.getCpuNumber()), newTracefile); - } - catch(JniTracefileWithoutEventException e) { - if ( printLttDebug == true ) { - printlnC(thisTracePtr.getLibraryId(), "JniTracefile " + tracefileName + " has no event (addTracefileFromC). Ignoring."); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - catch(Exception e) { - if ( printLttDebug == true ) { - printlnC(thisTracePtr.getLibraryId(), "Failed to add tracefile " + tracefileName + " to tracefilesMap!(addTracefileFromC)\n\tException raised : " + e.toString() ); //$NON-NLS-1$ //$NON-NLS-2$ - } + getTracefilesMap().put((tracefileName + newTracefile.getCpuNumber()), newTracefile); + } catch (JniTracefileWithoutEventException e) { + if (printLttDebug == true) { + printlnC(thisTracePtr.getLibraryId(), "JniTracefile " + tracefileName + " has no event (addTracefileFromC). Ignoring."); //$NON-NLS-1$ //$NON-NLS-2$ + } + } catch (Exception e) { + if (printLttDebug == true) { + printlnC(thisTracePtr.getLibraryId(), + "Failed to add tracefile " + tracefileName + " to tracefilesMap!(addTracefileFromC)\n\tException raised : " + e.toString()); //$NON-NLS-1$ //$NON-NLS-2$ + } } } - + /** - * Return the top event in the events stack, determined by timestamp, in the trace (all the tracefiles).

+ * Return the top event in the events stack, determined by timestamp, in the + * trace (all the tracefiles). + *

* - * Note : If the events were read before, the top event and the event currently loaded (currentEvent) are most likely the same. + * Note : If the events were read before, the top event and the event + * currently loaded (currentEvent) are most likely the same. * * @return The top event in the stack or null if no event is available. * @@ -455,9 +489,11 @@ public abstract class JniTrace extends Jni_C_Common { public JniEvent findNextEvent() { return eventsHeap.peek(); } - + /** - * Return the next event in the events stack, determined by timestamp, in the trace (all the tracefiles).

+ * Return the next event in the events stack, determined by timestamp, in + * the trace (all the tracefiles). + *

* * @return The next event in the trace or null if no event is available. * @@ -466,48 +502,55 @@ public abstract class JniTrace extends Jni_C_Common { 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 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 - // NOTE : JniEvent.compareTo() compare by timestamp AND type, as 2 events of different type could have the same timestamp. + + // Otherwise, we need to make sure the timestamp of the event we got is + // not the same as the last "NextEvent" we requested + // NOTE : JniEvent.compareTo() compare by timestamp AND type, as 2 + // events of different type could have the same timestamp. // if( currentEvent != null ){ if (tmpEvent.equals(currentEvent)) { // 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 ) { + + // 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 event we just read as the "current event" currentEvent = tmpEvent; } - // If the event on top has different timestamp than the currentTimestamp, just save this timestamp as current + // If the event on top has different timestamp than the + // currentTimestamp, just save this timestamp as current else { currentEvent = tmpEvent; } - + return tmpEvent; } - + /** - * Read the next event on a certain tracefile.

+ * Read the next event on a certain tracefile. + *

* - * By calling this function make sure the "global" readNextEvent() stay synchronised. - * Calling readNextEvent() after this function will consider this tracefile moved and is then consistent. + * By calling this function make sure the "global" readNextEvent() stay + * synchronised. Calling readNextEvent() after this function will consider + * this tracefile moved and is then consistent. * - * @param targetTracefile The tracefile object to read from + * @param targetTracefile The tracefile object to read from * * @return The next event in the tracefile or null if no event is available. * @@ -516,136 +559,151 @@ public abstract class JniTrace extends Jni_C_Common { */ public JniEvent readNextEvent(JniTracefile targetTracefile) { JniEvent returnedEvent = null; - - // There is 2 special cases where we should read the CURRENT event, not the next one - // 1- The currentEvent is null --> We never read or we just seeked - // 2- The currentEvent is of another type --> We last read on a DIFFERENT tracefile - if ( (currentEvent == null) || - (currentEvent.getParentTracefile().equals(targetTracefile) == false) - ) { + + // There is 2 special cases where we should read the CURRENT event, not + // the next one + // 1- The currentEvent is null --> We never read or we just seeked + // 2- The currentEvent is of another type --> We last read on a + // DIFFERENT tracefile + if ((currentEvent == null) || (currentEvent.getParentTracefile().equals(targetTracefile) == false)) { returnedEvent = targetTracefile.getCurrentEvent(); // Save the event we read - currentEvent = returnedEvent; - } - else { - // Remove from the event related to this tracefile from the event heap, if it exists. - // WARNING : This only safe as long getCurrentEvent() never return "null" in any case. - eventsHeap.remove(targetTracefile.getCurrentEvent() ); - - // If status EOK, we can return the event, otherwise something wrong happen (out of range, read error, etc...) - if ( targetTracefile.readNextEvent() == EOK) { - returnedEvent = targetTracefile.getCurrentEvent(); - // Add back to the heap the read event - eventsHeap.add(returnedEvent); - } - // Save the event we read... - // Note : might be null if the read failed and it's ok - currentEvent = targetTracefile.getCurrentEvent(); + currentEvent = returnedEvent; + } else { + // Remove from the event related to this tracefile from the event + // heap, if it exists. + // WARNING : This only safe as long getCurrentEvent() never return + // "null" in any case. + eventsHeap.remove(targetTracefile.getCurrentEvent()); + + // If status EOK, we can return the event, otherwise something wrong + // happen (out of range, read error, etc...) + if (targetTracefile.readNextEvent() == EOK) { + returnedEvent = targetTracefile.getCurrentEvent(); + // Add back to the heap the read event + eventsHeap.add(returnedEvent); + } + // Save the event we read... + // Note : might be null if the read failed and it's ok + currentEvent = targetTracefile.getCurrentEvent(); } - - return returnedEvent; + + return returnedEvent; } - + /** - * Seek to a certain time but do not read the next event.

- * - * This only position the trace, it will not return anything.

- * - * @param seekTime The time where we want to seek to - * - * @see org.eclipse.linuxtools.lttng.jni.common.JniTime - */ + * Seek to a certain time but do not read the next event. + *

+ * + * This only position the trace, it will not return anything. + *

+ * + * @param seekTime The time where we want to seek to + * + * @see org.eclipse.linuxtools.lttng.jni.common.JniTime + */ public void seekToTime(JniTime seekTime) { - + // Invalidate the last read event currentEvent = null; - + Object tracefile_name = null; - Iterator iterator = tracefilesMap.keySet().iterator(); - - while (iterator.hasNext() ) { - // We seek to the given event for ALL tracefiles - tracefile_name = iterator.next(); - seekToTime(seekTime, tracefilesMap.get(tracefile_name)); - } - - populateEventHeap(); - } - + Iterator iterator = tracefilesMap.keySet().iterator(); + + while (iterator.hasNext()) { + // We seek to the given event for ALL tracefiles + tracefile_name = iterator.next(); + seekToTime(seekTime, tracefilesMap.get(tracefile_name)); + } + + populateEventHeap(); + } + /** - * Seek to a certain time on a certain tracefile but do not read the next event.

- * - * This only position the trace, it will not return anything.

- * - * @param targetTracefile The tracefile object to read from - * @param seekTime The time where we want to seek to - * - * @see org.eclipse.linuxtools.lttng.jni.JniTracefile - * @see org.eclipse.linuxtools.lttng.jni.common.JniTime - */ + * Seek to a certain time on a certain tracefile but do not read the + * next event. + *

+ * + * This only position the trace, it will not return anything. + *

+ * + * @param targetTracefile The tracefile object to read from + * @param seekTime The time where we want to seek to + * + * @see org.eclipse.linuxtools.lttng.jni.JniTracefile + * @see org.eclipse.linuxtools.lttng.jni.common.JniTime + */ public void seekToTime(JniTime seekTime, JniTracefile targetTracefile) { // Invalidate the current read event currentEvent = null; - - // Remove from the event related to this tracefile from the event heap, if it exists. - // WARNING : This is only safe as long getCurrentEvent() never return "null" in any case. - eventsHeap.remove(targetTracefile.getCurrentEvent() ); - + + // Remove from the event related to this tracefile from the event heap, + // if it exists. + // WARNING : This is only safe as long getCurrentEvent() never return + // "null" in any case. + eventsHeap.remove(targetTracefile.getCurrentEvent()); + // Perform the actual seek on the tracefile // Add the event to the heap if it succeed - if ( targetTracefile.seekToTime(seekTime) == EOK) { - // Add back to the heap the read event + if (targetTracefile.seekToTime(seekTime) == EOK) { + // Add back to the heap the read event eventsHeap.add(targetTracefile.getCurrentEvent()); } } - + /** - * Seek to a certain timestamp and read the next event. - *

- * 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 The event just after the seeked time or null if none available. - * - * @see org.eclipse.linuxtools.lttng.jni.JniEvent - * @see org.eclipse.linuxtools.lttng.jni.common.JniTime - */ - 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 timestamp and read the next event. + *

+ * 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 The event just after the seeked time or null if none available. + * + * @see org.eclipse.linuxtools.lttng.jni.JniEvent + * @see org.eclipse.linuxtools.lttng.jni.common.JniTime + */ + 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 timestamp on a certain tracefile and read the next event.

- * - * If no more events are available or an error happen, null will be returned. - * - * Calling readNextEvent() after this function will consider this tracefile moved and is then consistent.
- * - * @param targetTracefile The tracefile object to read from - * @param seekTime The time where we want to seek to - * - * @return The event just after the seeked time or null if none available. - * - * @see org.eclipse.linuxtools.lttng.jni.JniTracefile - * @see org.eclipse.linuxtools.lttng.jni.common.JniTime - * @see org.eclipse.linuxtools.lttng.jni.JniEvent - */ - public JniEvent seekAndRead(JniTime seekTime, JniTracefile targetTracefile) { + * Seek to a certain timestamp on a certain tracefile and read the next + * event. + *

+ * + * If no more events are available or an error happen, null will be + * returned. + * + * Calling readNextEvent() after this function will consider this tracefile + * moved and is then consistent.
+ * + * @param targetTracefile The tracefile object to read from + * @param seekTime The time where we want to seek to + * + * @return The event just after the seeked time or null if none available. + * + * @see org.eclipse.linuxtools.lttng.jni.JniTracefile + * @see org.eclipse.linuxtools.lttng.jni.common.JniTime + * @see org.eclipse.linuxtools.lttng.jni.JniEvent + */ + public JniEvent seekAndRead(JniTime seekTime, JniTracefile targetTracefile) { seekToTime(seekTime, targetTracefile); return readNextEvent(targetTracefile); } - + /** - * Get a certain tracefile from its given name.

+ * Get a certain tracefile from its given name. + *

* - * @param tracefileName The name of the tracefile. + * @param tracefileName The name of the tracefile. * * @return The tracefile found or null if none. * @@ -653,12 +711,13 @@ public abstract class JniTrace extends Jni_C_Common { */ public JniTracefile requestTracefileByName(String tracefileName) { return tracefilesMap.get(tracefileName); - } - + } + /** - * Get a certain event associated to a tracefile from the tracefile name.

+ * Get a certain event associated to a tracefile from the tracefile name. + *

* - * @param tracefileName The name of the trace file. + * @param tracefileName The name of the trace file. * * @return Event of the tracefile or null if none found. * @@ -676,8 +735,8 @@ public abstract class JniTrace extends Jni_C_Common { } return returnValue; - } - + } + // Access to class variable. Most of them doesn't have setter public String getTracepath() { return tracepath; @@ -728,7 +787,8 @@ public abstract class JniTrace extends Jni_C_Common { } /** - * Update trace file and file size information.

+ * Update trace file and file size information. + *

* * If the trace has any new events, fetch the new end time. */ @@ -740,11 +800,11 @@ public abstract class JniTrace extends Jni_C_Common { } } } - + public JniTime getStartTime() { return startTime; } - + public JniTime getEndTime() { return endTime; } @@ -752,13 +812,14 @@ public abstract class JniTrace extends Jni_C_Common { public JniTime getStartTimeNoAdjustement() { return startTimeNoAdjustement; } - + public HashMap getTracefilesMap() { return tracefilesMap; - } - + } + /** - * The timestamp of the last read event.

+ * The timestamp of the last read event. + *

* * Note : If no event is available, Long.MAX_VALUE is returned. * @@ -768,20 +829,20 @@ public abstract class JniTrace extends Jni_C_Common { */ public JniTime getCurrentEventTimestamp() { JniTime returnedTime = null; - - // If no event were read or we reach the last event in the trace, - // currentEvent will be null - if ( currentEvent != null ) { + + // If no event were read or we reach the last event in the trace, + // currentEvent will be null + if (currentEvent != null) { returnedTime = currentEvent.getEventTime(); - } - else { + } else { returnedTime = new JniTime(Long.MAX_VALUE); } return returnedTime; } - + /** - * Pointer to the LttTrace C structure.

+ * Pointer to the LttTrace C structure. + *

* * The pointer should only be used INTERNALY, do not use unless you * know what you are doing. @@ -792,7 +853,7 @@ public abstract class JniTrace extends Jni_C_Common { */ public Jni_C_Pointer_And_Library_Id getTracePtr() { return thisTracePtr; - } + } /** * Indicate whether a trace can be opened in live mode. @@ -802,18 +863,10 @@ public abstract class JniTrace extends Jni_C_Common { public boolean isLiveTraceSupported() { return isLiveTraceSupported; } - - /** - * Sets whether a trace can be opened in live mode. - * - * @param isSupported - */ - protected void setLiveTraceSupported(boolean isSupported) { - isLiveTraceSupported = isSupported; - } - + /** - * Return boolean value saying if the debug is enabled in LTT or not.

+ * Return boolean value saying if the debug is enabled in LTT or not. + *

* * Note : this need to be set at construction. * @@ -822,10 +875,11 @@ public abstract class JniTrace extends Jni_C_Common { public boolean isPrintingLttDebug() { return printLttDebug; } - + /** * Print information for all the tracefiles associated with this trace. - * Intended to debug

+ * Intended to debug + *

* * This function will call Ltt to print, so information printed will be the * one from the C structure, not the one populated in java. @@ -840,28 +894,28 @@ public abstract class JniTrace extends Jni_C_Common { tracefile = tracefilesMap.get(iterator.next()); tracefile.printTracefileInformation(); } - } - + } + /** - * Print information for this trace. - * Intended to debug

+ * Print information for this trace. Intended to debug + *

* * This function will call Ltt to print, so information printed will be the - * one from the C structure, not the one populated in java.

+ * one from the C structure, not the one populated in java. + *

*/ public void printTraceInformation() { ltt_printTrace(thisTracePtr.getLibraryId(), thisTracePtr.getPointer()); } - + /** - * toString() method. - * Intended to debug
+ * toString() method. Intended to debug
* * @return Attributes of the object concatenated in String */ @Override @SuppressWarnings("nls") - public String toString() { + public String toString() { String returnData = ""; returnData += "tracepath : " + tracepath + "\n"; returnData += "cpuNumber : " + cpuNumber + "\n"; @@ -884,48 +938,58 @@ public abstract class JniTrace extends Jni_C_Common { returnData += "endTime : " + endTime.getReferenceToString() + "\n"; returnData += " seconds : " + endTime.getSeconds() + "\n"; returnData += " nanoSeconds : " + endTime.getNanoSeconds() + "\n"; - returnData += "tracefilesMap : " + tracefilesMap.keySet() + "\n"; // Hack to avoid ending up with tracefilesMap.toString() + returnData += "tracefilesMap : " + tracefilesMap.keySet() + "\n"; // Hack + // to + // avoid + // ending + // up + // with + // tracefilesMap.toString() return returnData; } - - + // **************************** // **** ABSTRACT FUNCTIONS **** // You MUST override those in your version specific implementation - + /** - * Function place holder to load the correct C library.

+ * Function place holder to load the correct C library. + *

*
- * Can be as simple as calling ltt_initializeHandle(LIBRARY_NAME) with the correct .so instead of LIBRARY_NAME.
+ * Can be as simple as calling ltt_initializeHandle(LIBRARY_NAME) with the + * correct .so instead of LIBRARY_NAME.
* You may also want to perform some check or some additionnal validations.
*
* !! Override this with you version specific implementation.
* - * @return integer that is the library id, or -1 if the load was unsuccessful + * @return integer that is the library id, or -1 if the load was + * unsuccessful */ public abstract int initializeLibrary(); - - + /** - * Function place holder to allocate a new JniTracefile.

+ * Function place holder to allocate a new JniTracefile. + *

* - * JniTracefile constructor is non overridable so we need another overridable function to return the correct version of JniTracefile.
- * Effect of this function should be the same (allocate a fresh new JniTracefile)
+ * JniTracefile constructor is non overridable so we need another + * overridable function to return the correct version of JniTracefile.
+ * Effect of this function should be the same (allocate a fresh new + * JniTracefile)
*
* !! Override this with you version specific implementation.
* - * @param newPtr The pointer of an already opened LttTracefile C Structure - * @param newParentTrace The JniTrace parent of this tracefile. + * @param newPtr The pointer of an already opened LttTracefile C Structure + * @param newParentTrace The JniTrace parent of this tracefile. * - * @return The newly allocated JniTracefile of the correct version + * @return The newly allocated JniTracefile of the correct version * - * @throws JniException The construction (allocation) failed. + * @throws JniException The construction (allocation) failed. * * @see org.eclipse.linuxtools.lttng.jni.JniTracefile * @see org.eclipse.linuxtools.lttng.jni.common.Jni_C_Pointer_And_Library_Id * @see org.eclipse.linuxtools.lttng.jni.JniTrace */ public abstract JniTracefile allocateNewJniTracefile(Jni_C_Pointer_And_Library_Id newPtr, JniTrace newParentTrace) throws JniException; - + } diff --git a/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni_v2_6/JniTrace_v2_6.java b/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni_v2_6/JniTrace_v2_6.java index 99bfa28636..68698403ca 100644 --- a/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni_v2_6/JniTrace_v2_6.java +++ b/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni_v2_6/JniTrace_v2_6.java @@ -37,9 +37,6 @@ public class JniTrace_v2_6 extends JniTrace { */ protected JniTrace_v2_6() { super(); - // Set live trace supported for 2.6 to true by default. - // Will be set to false if open live trace fails. - setLiveTraceSupported(true); } public JniTrace_v2_6(String newpath) throws JniException { @@ -52,7 +49,7 @@ public class JniTrace_v2_6 extends JniTrace { public JniTrace_v2_6(JniTrace_v2_6 oldTrace) { super(oldTrace); - } + } public JniTrace_v2_6(Jni_C_Pointer_And_Library_Id newPtr, boolean newPrintDebug) throws JniException { super(newPtr, newPrintDebug); diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/tracecontrol/subsystems/TraceSubSystem.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/tracecontrol/subsystems/TraceSubSystem.java index 5450ed921a..97d7d069d7 100644 --- a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/tracecontrol/subsystems/TraceSubSystem.java +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/tracecontrol/subsystems/TraceSubSystem.java @@ -587,6 +587,11 @@ public class TraceSubSystem extends SubSystem implements ICommunicationsListener PauseTrace pauseAction = new PauseTrace(); pauseAction.setSelectedTraces(new ArrayList(Arrays.asList(traces))); pauseAction.run(null); + try { + Thread.sleep(2000); // allow time for target to pause traces before disconnecting the channel + } catch (InterruptedException e) { + e.printStackTrace(); + } } }); } diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/project/dialogs/messages.properties b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/project/dialogs/messages.properties index 717b96b99f..0511b2d7b3 100644 --- a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/project/dialogs/messages.properties +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/project/dialogs/messages.properties @@ -3,18 +3,9 @@ AddTraceWizard_windowTitle=Adding traces to experiment AddTraceWizardPage_columnHeader=Trace AddTraceWizardPage_description=Select the traces to add to the experiment AddTraceWizardPage_windowTitle=Select traces -ImportTraceWizard_LocationError=Error: Trace location is wrong. -ImportTraceWizard_LocationErrorMsg1=You cannot import your trace directly into " -ImportTraceWizard_LocationErrorMsg2=The trace has to be into a directory, like " -ImportTraceWizard_LocationErrorMsg3=Please adjust the location of the LTTng trace. ImportTraceWizardPage_BadTraceVersion=Error: Unrecognized trace version for ImportTraceWizardPage_BadTraceVersionMsg1=Verify that the directory is a valid LTTng trace directory. ImportTraceWizardPage_BadTraceVersionMsg2=Make sure the top directory is the trace itself and not any of its parent. -NewExperimentDialog_DialogTitle=LTTng Experiment -NewExperimentDialog_ExperimentLabel=Experiment name: -NewFolderDialog_errorTitle= -NewFolderDialog_internalError= -NewFolderDialog_progress= NewProjectWizard_Description=Create an LTTng Project NewProjectWizard_Title=LTTng Project TraceErrorDialog_DalogTitle=Trace Selection -- 2.34.1