events cycle count fix, reverse byte order fix
[lttv.git] / ltt / branches / poly / ltt / time.h
index 6622decea9f9f9a7c4dd70689cb7b3f414321787..7d925d1b48240854672371c1b72aff55231bf9cc 100644 (file)
@@ -23,6 +23,8 @@
 #include <ltt/compiler.h>
 #include <math.h>
 
+#include <ltt/ltt-types.h>
+
 typedef struct _LttTime {
   unsigned long tv_sec;
   unsigned long tv_nsec;
@@ -116,9 +118,9 @@ static inline double ltt_time_to_double(LttTime t1)
   if(t1.tv_sec > MAX_TV_SEC_TO_DOUBLE)
     g_warning("Precision loss in conversion LttTime to double");
 #endif //EXTRA_CHECK
-  return round(((double)((guint64)t1.tv_sec<<DOUBLE_SHIFT)
+  return ((double)((guint64)t1.tv_sec<<DOUBLE_SHIFT)
                   * (double)DOUBLE_SHIFT_CONST_MUL)
-                  + (double)t1.tv_nsec);
+                  + (double)t1.tv_nsec;
 }
 
 
@@ -140,7 +142,7 @@ static inline LttTime ltt_time_from_double(double t1)
   LttTime res;
   //res.tv_sec = t1/(double)NANOSECONDS_PER_SECOND;
   res.tv_sec = (guint64)(t1 * DOUBLE_SHIFT_CONST_DIV) >> DOUBLE_SHIFT;
-  res.tv_nsec = (round(t1) - (((guint64)res.tv_sec<<LTT_TIME_UINT_SHIFT))
+  res.tv_nsec = (t1 - (((guint64)res.tv_sec<<LTT_TIME_UINT_SHIFT))
                                * LTT_TIME_UINT_SHIFT_CONST);
   return res;
 }
@@ -213,7 +215,7 @@ static inline LttTime ltt_time_div(LttTime t1, double d)
 
 static inline guint64 ltt_time_to_uint64(LttTime t1)
 {
-  return (guint64)((t1.tv_sec*LTT_TIME_UINT_SHIFT_CONST) >> LTT_TIME_UINT_SHIFT)
+  return (((guint64)t1.tv_sec*LTT_TIME_UINT_SHIFT_CONST) << LTT_TIME_UINT_SHIFT)
                        + (guint64)t1.tv_nsec;
 }
 
@@ -246,4 +248,17 @@ static inline LttTime ltt_time_from_uint64(guint64 t1)
   return res;
 }
 
+inline LttTime ltt_get_time(LttTrace t, void *ptr)
+{
+  LttTime output;
+
+  output.tv_sec =
+    (guint64) (t->reverse_byte_order ? GUINT64_SWAP_LE_BE(ptr): ptr);
+  ptr += sizeof(guint64);
+  output.tv_nsec =
+    (guint64) (t->reverse_byte_order ? GUINT64_SWAP_LE_BE(ptr): ptr);
+
+  return output;
+}
+
 #endif // LTT_TIME_H
This page took 0.025065 seconds and 4 git commands to generate.