eta
authorChristian Grothoff <christian@grothoff.org>
Sat, 29 Aug 2009 20:26:36 +0000 (20:26 +0000)
committerChristian Grothoff <christian@grothoff.org>
Sat, 29 Aug 2009 20:26:36 +0000 (20:26 +0000)
src/include/gnunet_time_lib.h
src/util/time.c

index b5da09cd83d59940493351eb15c38ab3d794e1f5..e4b9dd970640e81d532a54f77a2255b7f45e8151 100644 (file)
@@ -163,6 +163,22 @@ struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining (struct
                                                                 GNUNET_TIME_Absolute
                                                                 future);
 
+
+/**
+ * Calculate the estimate time of arrival/completion 
+ * for an operation.
+ *
+ * @param start when did the operation start?
+ * @param finished how much has been done?
+ * @param total how much must be done overall (same unit as for "finished")
+ * @return remaining duration for the operation,
+ *        assuming it continues at the same speed
+ */
+struct GNUNET_TIME_Relative GNUNET_TIME_calculate_eta (struct GNUNET_TIME_Absolute start,
+                                                      uint64_t finished,
+                                                      uint64_t total);
+
+
 /**
  * Compute the time difference between the given start and end times.
  * Use this function instead of actual subtraction to ensure that
index 85d8d0cd6d989eb4768be2d65c0ad91065ad7590..6b6be79170e71bbbe9675138ba90b1235665b78f 100644 (file)
@@ -238,6 +238,37 @@ GNUNET_TIME_relative_multiply (struct GNUNET_TIME_Relative rel,
   return ret;
 }
 
+
+/**
+ * Calculate the estimate time of arrival/completion 
+ * for an operation.
+ *
+ * @param start when did the operation start?
+ * @param finished how much has been done?
+ * @param total how much must be done overall (same unit as for "finished")
+ * @return remaining duration for the operation,
+ *        assuming it continues at the same speed
+ */
+struct GNUNET_TIME_Relative GNUNET_TIME_calculate_eta (struct GNUNET_TIME_Absolute start,
+                                                      uint64_t finished,
+                                                      uint64_t total)
+{
+  struct GNUNET_TIME_Relative dur;
+  double exp;
+  struct GNUNET_TIME_Relative ret;
+
+  GNUNET_break (finished > total);
+  if (finished >= total)
+    return GNUNET_TIME_UNIT_ZERO;
+  if (finished == 0)
+    return GNUNET_TIME_UNIT_FOREVER;
+  dur = GNUNET_TIME_absolute_get_duration (start);
+  exp = ((double)dur.value) * ((double) total) / ((double)finished);
+  ret.value = ((uint64_t) exp) - dur.value;
+  return ret;
+}
+
+
 /**
  * Add relative times together.
  *