From c357e4b61e51db4e6ba474e120ed353fe9dbe138 Mon Sep 17 00:00:00 2001 From: William Bourque Date: Tue, 16 Mar 2010 16:53:51 +0000 Subject: [PATCH] Added better comments and slight changes in the mecanisms that get the version number of a trace --- .../linuxtools/lttng/jni/JniEvent.java | 39 ++-- .../linuxtools/lttng/jni/JniMarker.java | 24 ++- .../linuxtools/lttng/jni/JniMarkerField.java | 5 +- .../linuxtools/lttng/jni/JniParser.java | 9 +- .../linuxtools/lttng/jni/JniTrace.java | 78 +++++--- .../linuxtools/lttng/jni/JniTracefile.java | 67 +++++-- .../linuxtools/lttng/jni/Jni_C_Common.java | 3 +- .../linuxtools/lttng/jni/common/JniTime.java | 13 +- .../lttng/jni/common/Jni_C_Constant.java | 7 +- .../lttng/jni/common/Jni_C_Pointer.java | 12 +- .../lttng/jni/factory/JniTraceFactory.java | 58 +++++- .../lttng/jni/factory/JniTraceVersion.java | 168 ++++++++++++++++-- 12 files changed, 400 insertions(+), 83 deletions(-) diff --git a/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/JniEvent.java b/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/JniEvent.java index d4ccc981a7..5a84e4f52f 100644 --- a/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/JniEvent.java +++ b/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/JniEvent.java @@ -114,9 +114,9 @@ public abstract class JniEvent extends Jni_C_Common implements Comparable newMarkersMap, JniTracefile newParentTracefile) throws JniException { @@ -153,9 +153,9 @@ public abstract class JniEvent extends Jni_C_Common implements Comparable * - * @return LTT read status, as defined in Jni_C_Common + * @return LTT read status, as defined in Jni_C_Constant * - * @see org.eclipse.linuxtools.lttng.jni.common.eclipse.linuxtools.lttng.jni.Jni_C_Common + * @see org.eclipse.linuxtools.lttng.jni.common.Jni_C_Constant */ public int seekToTime(JniTime seekTime) { // Ask Ltt to read the next event for this particular tracefile @@ -201,9 +201,9 @@ public abstract class JniEvent extends Jni_C_Common implements Comparable * - * @return LTT read status, as defined in Jni_C_Common + * @return LTT read status, as defined in Jni_C_Constant * - * @see org.eclipse.linuxtools.lttng.jni.common.eclipse.linuxtools.lttng.jni.Jni_C_Common + * @see org.eclipse.linuxtools.lttng.jni.common.Jni_C_Constant */ public int seekOrFallBack(JniTime seekTime) { // Save the old time @@ -231,9 +231,9 @@ public abstract class JniEvent extends Jni_C_Common implements Comparable which is the parsedContent objects and their name as key. * - * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniParser + * @see org.eclipse.linuxtools.lttng.jni.JniParser */ public HashMap parseAllFields() { return JniParser.parseAllFields(this); @@ -364,7 +364,7 @@ public abstract class JniEvent extends Jni_C_Common implements Comparable + *
+ * JniMarkerField constructor is non overridable so we need another overridable function to return the correct version of JniMarkerField.
+ * Effect of this function should be the same (allocate a fresh new JniMarkerField).
+ *
+ * !! Override this with you version specific implementation.
+ * + * @param newMarkerFieldPtr The pointer of an already opened marker_field C Structure + * + * @return The newly allocated JniMarkerField of the correct version + * + * @throws JniException The construction (allocation) failed. + * + * @see org.eclipse.linuxtools.lttng.jni.common.Jni_C_Pointer + * @see org.eclipse.linuxtools.lttng.jni.JniMarkerField + */ public abstract JniMarkerField allocateNewJniMarkerField(Jni_C_Pointer newMarkerFieldPtr) throws JniException; } diff --git a/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/JniMarkerField.java b/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/JniMarkerField.java index d5458d5d7d..3af403f90e 100644 --- a/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/JniMarkerField.java +++ b/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/JniMarkerField.java @@ -61,6 +61,8 @@ public abstract class JniMarkerField extends Jni_C_Common * @param newMarkerFieldPtr Pointer to a C marker_field structure * * @exception JniException + * + * @see org.eclipse.linuxtools.lttng.jni.common.Jni_C_Pointer */ public JniMarkerField(Jni_C_Pointer newMarkerFieldPtr) throws JniException { thisMarkerFieldPtr = newMarkerFieldPtr; @@ -99,7 +101,7 @@ public abstract class JniMarkerField extends Jni_C_Common * * @return The actual (long converted) pointer or NULL * - * @see org.eclipse.linuxtools.lttng.jni.common.eclipse.linuxtools.lttng.jni.Jni_C_Pointer + * @see org.eclipse.linuxtools.lttng.jni.common.Jni_C_Pointer */ public Jni_C_Pointer getMarkerFieldPtr() { return thisMarkerFieldPtr; @@ -137,4 +139,5 @@ public abstract class JniMarkerField extends Jni_C_Common return returnData; } + } diff --git a/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/JniParser.java b/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/JniParser.java index 0a32f21332..cc3bb22f95 100644 --- a/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/JniParser.java +++ b/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/JniParser.java @@ -52,7 +52,7 @@ public abstract class JniParser extends Jni_C_Common * * @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.eclipse.linuxtools.lttng.jni.JniEvent + * @see org.eclipse.linuxtools.lttng.jni.JniEvent */ static public Object parseField(JniEvent eventToParse, int fieldPosition) { @@ -80,7 +80,7 @@ public abstract class JniParser extends Jni_C_Common * * @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.eclipse.linuxtools.lttng.jni.JniEvent + * @see org.eclipse.linuxtools.lttng.jni.JniEvent */ static public Object parseField(JniEvent eventToParse, String fieldName) { @@ -106,7 +106,7 @@ public abstract class JniParser extends Jni_C_Common * @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.eclipse.linuxtools.lttng.jni.JniEvent + * @see org.eclipse.linuxtools.lttng.jni.JniEvent */ static public HashMap parseAllFields(JniEvent eventToParse) { HashMap markerFieldData = eventToParse.requestEventMarker().getMarkerFieldsHashMap(); @@ -283,6 +283,7 @@ public abstract class JniParser extends Jni_C_Common } + /** * ParsedObjectContent

* @@ -299,4 +300,4 @@ class ParsedObjectContent { public void setData(Object newData) { parsedData = newData; } -} \ No newline at end of file +} 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 8ecbe09e6b..43918e5bbd 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 @@ -11,7 +11,6 @@ package org.eclipse.linuxtools.lttng.jni; * William Bourque (wbourque@gmail.com) - Initial API and implementation *******************************************************************************/ - import java.util.HashMap; import java.util.Iterator; import java.util.PriorityQueue; @@ -46,7 +45,7 @@ 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) private int cpuNumber = 0; private long archType = 0; @@ -190,7 +189,7 @@ public abstract class JniTrace extends Jni_C_Common { * * @exception JniException * - * @see org.eclipse.linuxtools.lttng.jni.common.eclipse.linuxtools.lttng.jni.Jni_C_Pointer + * @see org.eclipse.linuxtools.lttng.jni.common.Jni_C_Pointer */ public JniTrace(Jni_C_Pointer newPtr, boolean newPrintDebug) throws JniException { thisTracePtr = newPtr; @@ -425,7 +424,7 @@ public abstract class JniTrace extends Jni_C_Common { * * @return The top event in the stack or null if no event is available. * - * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniEvent + * @see org.eclipse.linuxtools.lttng.jni.JniEvent */ public JniEvent findNextEvent() { return eventsHeap.peek(); @@ -436,7 +435,7 @@ public abstract class JniTrace extends Jni_C_Common { * * @return The next event in the trace or null if no event is available. * - * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniEvent + * @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 @@ -485,8 +484,8 @@ public abstract class JniTrace extends Jni_C_Common { * * @return The next event in the tracefile or null if no event is available. * - * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniTracefile - * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniEvent + * @see org.eclipse.linuxtools.lttng.jni.JniTracefile + * @see org.eclipse.linuxtools.lttng.jni.JniEvent */ public JniEvent readNextEvent(JniTracefile targetTracefile) { JniEvent returnedEvent = null; @@ -527,7 +526,7 @@ public abstract class JniTrace extends Jni_C_Common { * * @param seekTime The time where we want to seek to * - * @see org.eclipse.linuxtools.lttng.jni.common.eclipse.linuxtools.lttng.jni.JniTime + * @see org.eclipse.linuxtools.lttng.jni.common.JniTime */ public void seekToTime(JniTime seekTime) { @@ -554,8 +553,8 @@ public abstract class JniTrace extends Jni_C_Common { * @param targetTracefile The tracefile object to read from * @param seekTime The time where we want to seek to * - * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniTracefile - * @see org.eclipse.linuxtools.lttng.jni.common.eclipse.linuxtools.lttng.jni.JniTime + * @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 @@ -582,8 +581,8 @@ public abstract class JniTrace extends Jni_C_Common { * * @return The event just after the seeked time or null if none available. * - * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniEvent - * @see org.eclipse.linuxtools.lttng.jni.common.eclipse.linuxtools.lttng.jni.JniTime + * @see org.eclipse.linuxtools.lttng.jni.JniEvent + * @see org.eclipse.linuxtools.lttng.jni.common.JniTime */ public JniEvent seekAndRead(JniTime seekTime) { JniEvent returnedEvent = null; @@ -602,14 +601,14 @@ public abstract class JniTrace extends Jni_C_Common { * * Calling readNextEvent() after this function will consider this tracefile moved and is then consistent.
* - * @param tracefileName The tracefile object to read from + * @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.eclipse.linuxtools.lttng.jni.JniTracefile - * @see org.eclipse.linuxtools.lttng.jni.common.eclipse.linuxtools.lttng.jni.JniTime - * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniEvent + * @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); @@ -623,7 +622,7 @@ public abstract class JniTrace extends Jni_C_Common { * * @return The tracefile found or null if none. * - * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniTracefile + * @see org.eclipse.linuxtools.lttng.jni.JniTracefile */ public JniTracefile requestTracefileByName(String tracefileName) { return tracefilesMap.get(tracefileName); @@ -636,7 +635,7 @@ public abstract class JniTrace extends Jni_C_Common { * * @return Event of the tracefile or null if none found. * - * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniEvent + * @see org.eclipse.linuxtools.lttng.jni.JniEvent */ public JniEvent requestEventByName(String tracefileName) { JniEvent returnValue = null; @@ -724,7 +723,7 @@ public abstract class JniTrace extends Jni_C_Common { * * @return Time of the last event read * - * @see org.eclipse.linuxtools.lttng.jni.common.eclipse.linuxtools.lttng.jni.JniTime + * @see org.eclipse.linuxtools.lttng.jni.common.JniTime */ public JniTime getCurrentEventTimestamp() { JniTime returnedTime = null; @@ -748,7 +747,7 @@ public abstract class JniTrace extends Jni_C_Common { * * @return The actual (long converted) pointer or NULL. * - * @see org.eclipse.linuxtools.lttng.jni.common.eclipse.linuxtools.lttng.jni.Jni_C_Pointer + * @see org.eclipse.linuxtools.lttng.jni.common.Jni_C_Pointer */ public Jni_C_Pointer getTracePtr() { return thisTracePtr; @@ -772,7 +771,7 @@ public abstract class JniTrace extends Jni_C_Common { * This function will call Ltt to print, so information printed will be the * one from the C structure, not the one populated in java. * - * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniTracefile + * @see org.eclipse.linuxtools.lttng.jni.JniTracefile */ public void printAllTracefilesInformation() { JniTracefile tracefile = null; @@ -839,8 +838,43 @@ public abstract class JniTrace extends Jni_C_Common { return returnData; } + + // **************************** + // **** ABSTRACT FUNCTIONS **** + // You MUST override those in your version specific implementation + + /** + * 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.
+ * You may also want to perform some check or some additionnal validations.
+ *
+ * !! Override this with you version specific implementation.
+ * + * @return boolean saying if the initialization was successful. + */ public abstract boolean initializeLibrary(); + + /** + * 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)
+ *
+ * !! 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. + * + * @return The newly allocated JniTracefile of the correct version + * + * @throws JniException The construction (allocation) failed. + * + * @see org.eclipse.linuxtools.lttng.jni.JniTracefile + * @see org.eclipse.linuxtools.lttng.jni.common.Jni_C_Pointer + * @see org.eclipse.linuxtools.lttng.jni.JniTrace + */ public abstract JniTracefile allocateNewJniTracefile(Jni_C_Pointer newPtr, JniTrace newParentTrace) throws JniException; -} \ No newline at end of file +} diff --git a/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/JniTracefile.java b/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/JniTracefile.java index 1262a32709..869d23414b 100644 --- a/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/JniTracefile.java +++ b/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/JniTracefile.java @@ -159,12 +159,13 @@ public abstract class JniTracefile extends Jni_C_Common { /** * Constructor, using C pointer.

* - * @param newPtr The pointer of an already opened LttTracefile C Structure + * @param newPtr The pointer of an already opened LttTracefile C Structure + * @param newParentTrace The JniTrace parent of this tracefile. * * @exception JniException * - * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniTrace - * @see org.eclipse.linuxtools.lttng.jni.common.eclipse.linuxtools.lttng.jni.Jni_C_Pointer + * @see org.eclipse.linuxtools.lttng.jni.JniTrace + * @see org.eclipse.linuxtools.lttng.jni.common.Jni_C_Pointer */ public JniTracefile(Jni_C_Pointer newPtr, JniTrace newParentTrace) throws JniException { thisTracefilePtr = newPtr; @@ -185,9 +186,9 @@ public abstract class JniTracefile extends Jni_C_Common { * * Note : If the read succeed, the event will be populated.

* - * @return LTT read status, as defined in Jni_C_Common + * @return LTT read status, as defined in Jni_C_Constant * - * @see org.eclipse.linuxtools.lttng.jni.common.eclipse.linuxtools.lttng.jni.Jni_C_Common + * @see org.eclipse.linuxtools.lttng.jni.common.Jni_C_Constant */ public int readNextEvent() { return currentEvent.readNextEvent(); @@ -200,9 +201,9 @@ public abstract class JniTracefile extends Jni_C_Common { * * @param seekTime The timestamp where to seek. * - * @return LTT read status, as defined in Jni_C_Common + * @return LTT read status, as defined in Jni_C_Constant * - * @see org.eclipse.linuxtools.lttng.jni.common.eclipse.linuxtools.lttng.jni.Jni_C_Common + * @see org.eclipse.linuxtools.lttng.jni.common.Jni_C_Constant */ public int seekToTime(JniTime seekTime) { return currentEvent.seekToTime(seekTime); @@ -384,7 +385,7 @@ public abstract class JniTracefile extends Jni_C_Common { * * @return The parent trace * - * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniTrace + * @see org.eclipse.linuxtools.lttng.jni.JniTrace */ public JniTrace getParentTrace() { return parentTrace; @@ -398,7 +399,7 @@ public abstract class JniTracefile extends Jni_C_Common { * * @return The actual (long converted) pointer or NULL. * - * @see org.eclipse.linuxtools.lttng.jni.common.eclipse.linuxtools.lttng.jni.Jni_C_Pointer + * @see org.eclipse.linuxtools.lttng.jni.common.Jni_C_Pointer */ public Jni_C_Pointer getTracefilePtr() { return thisTracefilePtr; @@ -465,8 +466,52 @@ public abstract class JniTracefile extends Jni_C_Common { } + // **************************** + // **** ABSTRACT FUNCTIONS **** + // You MUST override those in your version specific implementation + + + /** + * Function place holder to allocate a new JniEvent.

+ *
+ * JniEvent constructor is non overridable so we need another overridable function to return the correct version of JniEvent.
+ * Effect of this function should be the same (allocate a fresh new JniEvent).
+ *
+ * !! Override this with you version specific implementation.
+ * + * @param newEventPtr The pointer of an already opened LttEvent C Structure + * @param newMarkersMap An already populated HashMap of JniMarker objects for this new event + * @param newParentTracefile The JniTrace parent of this tracefile. + * + * @return The newly allocated JniEvent of the correct version + * + * @throws JniException The construction (allocation) failed. + * + * @see org.eclipse.linuxtools.lttng.jni.JniEvent + * @see org.eclipse.linuxtools.lttng.jni.common.Jni_C_Pointer + * @see org.eclipse.linuxtools.lttng.jni.JniMarker + * @see org.eclipse.linuxtools.lttng.jni.JniTracefile + */ public abstract JniEvent allocateNewJniEvent(Jni_C_Pointer newEventPtr, HashMap newMarkersMap, JniTracefile newParentTracefile) throws JniException; - public abstract JniMarker allocateNewJniMarker(Jni_C_Pointer newMarkerPtr) throws JniException; + + + /** + * Function place holder to allocate a new JniMarker.

+ *
+ * JniMarker constructor is non overridable so we need another overridable function to return the correct version of JniMarker.
+ * Effect of this function should be the same (allocate a fresh new JniMarker).
+ *
+ * !! Override this with you version specific implementation.
+ * + * @param newMarkerPtr The pointer of an already opened marker_info C Structure + * + * @return The newly allocated JniMarker of the correct version + * + * @throws JniException The construction (allocation) failed. + * + * @see org.eclipse.linuxtools.lttng.jni.JniMarker + * @see org.eclipse.linuxtools.lttng.jni.common.Jni_C_Pointer + */ + public abstract JniMarker allocateNewJniMarker(Jni_C_Pointer newMarkerPtr) throws JniException; } - diff --git a/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/Jni_C_Common.java b/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/Jni_C_Common.java index 9531cbf159..eb4d38f5b0 100644 --- a/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/Jni_C_Common.java +++ b/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/Jni_C_Common.java @@ -48,4 +48,5 @@ public abstract class Jni_C_Common extends Jni_C_Constant { public void printlnC(String msg) { printC(msg + "\n"); } -} \ No newline at end of file + +} diff --git a/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/common/JniTime.java b/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/common/JniTime.java index 27960f4a2a..dc6d2827eb 100644 --- a/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/common/JniTime.java +++ b/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/common/JniTime.java @@ -1,6 +1,15 @@ package org.eclipse.linuxtools.lttng.jni.common; - - +/******************************************************************************* + * 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 + *******************************************************************************/ /** * JniTime diff --git a/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/common/Jni_C_Constant.java b/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/common/Jni_C_Constant.java index 652f80f4c1..b6bc19540d 100644 --- a/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/common/Jni_C_Constant.java +++ b/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/common/Jni_C_Constant.java @@ -11,7 +11,6 @@ package org.eclipse.linuxtools.lttng.jni.common; * William Bourque (wbourque@gmail.com) - Initial API and implementation *******************************************************************************/ - /** * Jni_C_Common *

@@ -30,6 +29,12 @@ public abstract class Jni_C_Constant { // Timestamps are in nanoseconds, this const ease up the math public static final long NANO = 1000000000; + /** + * Default constructor + */ + public Jni_C_Constant() { + } + /** * "Alternate" .toString()

* diff --git a/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/common/Jni_C_Pointer.java b/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/common/Jni_C_Pointer.java index 0d2d91c942..0dca5ded52 100644 --- a/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/common/Jni_C_Pointer.java +++ b/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/common/Jni_C_Pointer.java @@ -1,5 +1,15 @@ package org.eclipse.linuxtools.lttng.jni.common; - +/******************************************************************************* + * 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 + *******************************************************************************/ /** * Jni_C_Pointer diff --git a/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/factory/JniTraceFactory.java b/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/factory/JniTraceFactory.java index 75dac8f9fb..ac15628331 100644 --- a/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/factory/JniTraceFactory.java +++ b/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/factory/JniTraceFactory.java @@ -1,4 +1,15 @@ package org.eclipse.linuxtools.lttng.jni.factory; +/******************************************************************************* + * 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 + *******************************************************************************/ import org.eclipse.linuxtools.lttng.jni.JniTrace; import org.eclipse.linuxtools.lttng.jni.exception.JniException; @@ -7,34 +18,63 @@ import org.eclipse.linuxtools.lttng.jni_v2_3.JniTrace_v2_3; import org.eclipse.linuxtools.lttng.jni_v2_5.JniTrace_v2_5; import org.eclipse.linuxtools.lttng.jni_v2_6.JniTrace_v2_6; +/** + * JniTraceFactory + *

+ * This class factory is responsible of returning the correct JniTrace implementation from a (valid) trace path.

+ * + * The different version supported are listed below and the same version string are expected to be returned by JniTraceVersion.
+ * Each version need a different Lttv library so each need its liblttvtraceread-X.Y.so installed and available on the system. + * + */ public class JniTraceFactory { + // *** + // Version string of the supported library version + // These will be used in the switch below to find the correct version + // *** static final String TraceVersion_v2_3 = "2.3"; static final String TraceVersion_v2_5 = "2.5"; static final String TraceVersion_v2_6 = "2.6"; + /* + * Default constructor is forbidden + */ private JniTraceFactory(){ - // Default constructor is forbidden } + /** + * Factory function : return the correct version of the JniTrace from a given path

+ * NOTE : The correct Lttv library (liblttvtraceread-X.Y.so) need to be installed and accessible otherwise this + * function will return an Exception. + * + * If the path is wrong or if the library is not supported (bad version or missing library) an Exception will be throwed. + * + * @param path Path of the trace we want to open + * @param show_debug Should JniTrace print debug or not? + * + * @return a newly allocated JniTrace of the correct version + * + * @throws JniException + */ static public JniTrace getJniTrace(String path, boolean show_debug) throws JniException { try { JniTraceVersion traceVersion = new JniTraceVersion(path); - if ( traceVersion.toString().equals(TraceVersion_v2_6) ) { - return new JniTrace_v2_6(path); + if ( traceVersion.getVersionAsString().equals(TraceVersion_v2_6) ) { + return new JniTrace_v2_6(path, show_debug); } - else if ( traceVersion.toString().equals(TraceVersion_v2_5) ) { - return new JniTrace_v2_5(path); + else if ( traceVersion.getVersionAsString().equals(TraceVersion_v2_5) ) { + return new JniTrace_v2_5(path, show_debug); } - else if ( traceVersion.toString().equals(TraceVersion_v2_3) ) { - return new JniTrace_v2_3(path); + else if ( traceVersion.getVersionAsString().equals(TraceVersion_v2_3) ) { + return new JniTrace_v2_3(path, show_debug); } else { String errMsg = "\nERROR : Unrecognized/unsupported trace version." + - "\nLibrary reported a trace version " + traceVersion.toString() + "." + - "\nMake sure you installed the Lttv library that support this version (look for liblttvtraceread-" + traceVersion.toString() + ".so).\n"; + "\nLibrary reported a trace version " + traceVersion.getVersionAsString() + "." + + "\nMake sure you installed the Lttv library that support this version (look for liblttvtraceread-" + traceVersion.getVersionAsString() + ".so).\n"; throw new JniException(errMsg); } } diff --git a/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/factory/JniTraceVersion.java b/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/factory/JniTraceVersion.java index 75a1a26429..dbaf9889c5 100644 --- a/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/factory/JniTraceVersion.java +++ b/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/factory/JniTraceVersion.java @@ -1,41 +1,118 @@ package org.eclipse.linuxtools.lttng.jni.factory; +/******************************************************************************* + * 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 + *******************************************************************************/ +import org.eclipse.linuxtools.lttng.jni.exception.JniException; import org.eclipse.linuxtools.lttng.jni.exception.JniTraceVersionException; +/** + * JniTraceVersion + *

+ * This class is responsible of returning the correct version number of a trace at a certain given path.

+ * + * The class will call the C library to get the correct version number from the trace.

+ * + * Lttv library loader (liblttvtraceread_loader.so) and the default Lttv library (liblttvtraceread.so) must be installed on system and available to java. + * + */ public class JniTraceVersion { + // Native access functions protected native void ltt_getTraceVersion(String tracepath); protected native void ltt_setLibraryPath(String ldLibraryPath); + // Variables to store version number private int majorNumber = 0; private int minorNumber = 0; + // To store the given tracepath private String tracepath = ""; - + + // Was the trace read already? + private boolean wasTraceRead = false; + + /** + * Default constructor.

+ * + * Do nothing, readVersionFromTrace(path) will need to be called by the user + */ public JniTraceVersion() { // Nothing to do } + /** + * Constructor that takes a tracepath parameter.

+ * + * This constructor read the version number from the trace, so it might throw. + * + * @param newTracepath The directory of the trace to read. + * + * @exception JniException If the library can not be loaded,if the path is wrong or if something go wrong during the read. + */ public JniTraceVersion(String newTracepath) throws JniTraceVersionException { // Read the version number from the trace - readVersionNumber(newTracepath); + readVersionFromTrace(newTracepath); } + /** + * Copy constructor. + * + * @param oldVersion A reference to the JniTraceVersion to copy. + */ public JniTraceVersion(JniTraceVersion oldVersion) { majorNumber = oldVersion.majorNumber; minorNumber = oldVersion.minorNumber; } + /* + * Read the version from the (already set) tracepath.

+ * + * This version is used internally and will silently dismiss any exceptions. + * + */ + private void readVersionNumberNofail() { + try { + readVersionFromTrace(tracepath); + } + catch(JniTraceVersionException e) { } + } + + /** + * Read the version from the (already set) tracepath.

+ * + * This function throw if the library can not be loaded, if the path is wrong or if something go wrong during the read. + * + */ public void readVersionNumber() throws JniTraceVersionException { - readVersionNumber(tracepath); + readVersionFromTrace(tracepath); } - public void readVersionNumber(String tracepath) throws JniTraceVersionException { + /** + * Read the version from a given tracepath.

+ * MajorVersion and MinorVersion should be set after a successful execution of this function.
+ * + * This function throw if the library can not be loaded,if the path is wrong or if something go wrong during the read. + * + */ + public void readVersionFromTrace(String newTracepath) throws JniTraceVersionException { // Verify that the tracepath isn't obliviously wrong (null or empty) - if ( (tracepath == null) || (tracepath.equals("") ) ) { + if ( (newTracepath == null) || (newTracepath.equals("") ) ) { throw new JniTraceVersionException("ERROR : Tracepath is null or empty! (readVersionNumber)"); } + else { + // Otherwise set the path in case it was changed + tracepath = newTracepath; + } try { // Load the C library here. @@ -44,47 +121,116 @@ public class JniTraceVersion { // Assuming the C library loaded correctly, call the JNI here. ltt_getTraceVersion(tracepath); + + // We can now assume that the trace was read + wasTraceRead = true; } + // The library was unable to load -> Lttv not installed or bad version of it? catch (java.lang.UnsatisfiedLinkError e) { - throw new JniTraceVersionException("ERROR : Could not get trace version. Is the library missing?\n" + - " Make sure you setted either \"java.library.path\" or \"LD_LIBRARY_PATH\" (readVersionNumber)"); + throw new JniTraceVersionException("\nERROR : Could not get trace version. Is the library missing?" + + "\nMake sure you setted either \"java.library.path\" or \"LD_LIBRARY_PATH\" (readVersionNumber)\n"); } + // Something else failed -> Possibly a bad tracepath was given catch (Exception e) { - throw new JniTraceVersionException("ERROR : Call to ltt_getTraceVersion failed. (readVersionNumber)"); + throw new JniTraceVersionException("\nERROR : Call to ltt_getTraceVersion failed. (readVersionNumber)\n"); } } - + /** + * Get major version number of the trace.

+ * Note : readVersionFromTrace() will be called if it wasn't done but exception will be silently ignored. + * + * @return major version + */ public int getMajor() { + if ( wasTraceRead == false ) { + readVersionNumberNofail(); + } + return majorNumber; } + /** + * Get minor version number of the trace.

+ * Note : readVersionFromTrace() will be called if it wasn't done but exception will be silently ignored. + * + * @return minor version + */ public int getMinor() { + if ( wasTraceRead == false ) { + readVersionNumberNofail(); + } + return minorNumber; } + /** + * Get full version number of the trace.

+ * Note : readVersionFromTrace() will be called if it wasn't done but exception will be silently ignored. + * + * @return Full Version as float + */ public float getVersionAsFloat() { + if ( wasTraceRead == false ) { + readVersionNumberNofail(); + } + return ((float)majorNumber + ((float)minorNumber)/10); } + /** + * Get full version number of the trace.

+ * Note : readVersionFromTrace() will be called if it wasn't done but exception will be silently ignored. + * + * @return Full Version as string + */ + public String getVersionAsString() { + if ( wasTraceRead == false ) { + readVersionNumberNofail(); + } + + return majorNumber + "." + minorNumber; + } + + /** + * Get for the current tracepath + * + * @return The tracepath was are currently using. + */ public String getTracepath() { return tracepath; } + /** + * Set for the tracepath.

+ * NOTE : Changing this will reset the version number currently loaded. + * NOTE2 : readVersionFromTrace() will be called but exception will be silently ignored. + * + * @param newtracepath The net tracepath + */ public void setTracepath(String newtracepath) { + majorNumber = 0; + minorNumber = 0; + wasTraceRead = false; tracepath = newtracepath; + + // Call the read function. This will fill up all the number if it goes well. + readVersionNumberNofail(); } - + /* + * This function is be called from the C side to assign the version number the Java variable. + */ @SuppressWarnings("unused") private void setTraceVersionFromC(int newMajor, int newMinor) { majorNumber = newMajor; minorNumber = newMinor; } + @Override public String toString() { - return majorNumber + "." + minorNumber; + return "JniTraceVersion [" + majorNumber + "." + minorNumber + "]"; } } -- 2.34.1