diff options
author | Christian Grothoff <christian@grothoff.org> | 2009-08-29 20:26:36 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2009-08-29 20:26:36 +0000 |
commit | 61b1c378568bbf7ca7cb1a51d2f1920d5d36fd26 (patch) | |
tree | 443822505cde9ff0288f0f995b5afcb804e5198a /src/util/time.c | |
parent | 987d988f588eae28c8c97c651cdd7cc0d81159c8 (diff) | |
download | gnunet-61b1c378568bbf7ca7cb1a51d2f1920d5d36fd26.tar.gz gnunet-61b1c378568bbf7ca7cb1a51d2f1920d5d36fd26.zip |
eta
Diffstat (limited to 'src/util/time.c')
-rw-r--r-- | src/util/time.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/util/time.c b/src/util/time.c index 85d8d0cd6..6b6be7917 100644 --- a/src/util/time.c +++ b/src/util/time.c | |||
@@ -238,6 +238,37 @@ GNUNET_TIME_relative_multiply (struct GNUNET_TIME_Relative rel, | |||
238 | return ret; | 238 | return ret; |
239 | } | 239 | } |
240 | 240 | ||
241 | |||
242 | /** | ||
243 | * Calculate the estimate time of arrival/completion | ||
244 | * for an operation. | ||
245 | * | ||
246 | * @param start when did the operation start? | ||
247 | * @param finished how much has been done? | ||
248 | * @param total how much must be done overall (same unit as for "finished") | ||
249 | * @return remaining duration for the operation, | ||
250 | * assuming it continues at the same speed | ||
251 | */ | ||
252 | struct GNUNET_TIME_Relative GNUNET_TIME_calculate_eta (struct GNUNET_TIME_Absolute start, | ||
253 | uint64_t finished, | ||
254 | uint64_t total) | ||
255 | { | ||
256 | struct GNUNET_TIME_Relative dur; | ||
257 | double exp; | ||
258 | struct GNUNET_TIME_Relative ret; | ||
259 | |||
260 | GNUNET_break (finished > total); | ||
261 | if (finished >= total) | ||
262 | return GNUNET_TIME_UNIT_ZERO; | ||
263 | if (finished == 0) | ||
264 | return GNUNET_TIME_UNIT_FOREVER; | ||
265 | dur = GNUNET_TIME_absolute_get_duration (start); | ||
266 | exp = ((double)dur.value) * ((double) total) / ((double)finished); | ||
267 | ret.value = ((uint64_t) exp) - dur.value; | ||
268 | return ret; | ||
269 | } | ||
270 | |||
271 | |||
241 | /** | 272 | /** |
242 | * Add relative times together. | 273 | * Add relative times together. |
243 | * | 274 | * |