diff options
author | Karsten Loesing <karsten.loesing@gmx.net> | 2009-07-27 16:23:53 +0200 |
---|---|---|
committer | Karsten Loesing <karsten.loesing@gmx.net> | 2009-07-27 16:23:53 +0200 |
commit | 7b716878cb6837756bd65ed788e5d8d89d8af56c (patch) | |
tree | 80839cd8fe6fdaf9bc471294821516aae462511f /src/common | |
parent | 2b0e8fb39f0ac9c0bfadc64102440843300fa9d7 (diff) | |
download | tor-7b716878cb6837756bd65ed788e5d8d89d8af56c.tar tor-7b716878cb6837756bd65ed788e5d8d89d8af56c.tar.gz |
Fix dirreq and cell stats on 32-bit architectures.
When determining how long directory requests take or how long cells spend
in queues, we were comparing timestamps on microsecond detail only to
convert results to second or millisecond detail later on. But on 32-bit
architectures this means that 2^31 microseconds only cover time
differences of up to 36 minutes. Instead, compare timestamps on
millisecond detail.
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/util.c | 21 | ||||
-rw-r--r-- | src/common/util.h | 1 |
2 files changed, 21 insertions, 1 deletions
diff --git a/src/common/util.c b/src/common/util.c index 0e7f59e62..234180c4d 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -1032,7 +1032,8 @@ tv_udiff(const struct timeval *start, const struct timeval *end) long secdiff = end->tv_sec - start->tv_sec; if (labs(secdiff+1) > LONG_MAX/1000000) { - log_warn(LD_GENERAL, "comparing times too far apart."); + log_warn(LD_GENERAL, "comparing times on microsecond detail too far " + "apart: %ld seconds", secdiff); return LONG_MAX; } @@ -1040,6 +1041,24 @@ tv_udiff(const struct timeval *start, const struct timeval *end) return udiff; } +/** Return the number of milliseconds elapsed between *start and *end. + */ +long +tv_mdiff(const struct timeval *start, const struct timeval *end) +{ + long mdiff; + long secdiff = end->tv_sec - start->tv_sec; + + if (labs(secdiff+1) > LONG_MAX/1000) { + log_warn(LD_GENERAL, "comparing times on millisecond detail too far " + "apart: %ld seconds", secdiff); + return LONG_MAX; + } + + mdiff = secdiff*1000L + (end->tv_usec - start->tv_usec) / 1000L; + return mdiff; +} + /** Yield true iff <b>y</b> is a leap-year. */ #define IS_LEAPYEAR(y) (!(y % 4) && ((y % 100) || !(y % 400))) /** Helper: Return the number of leap-days between Jan 1, y1 and Jan 1, y2. */ diff --git a/src/common/util.h b/src/common/util.h index 1c5643be3..c7741a64a 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -211,6 +211,7 @@ int base16_decode(char *dest, size_t destlen, const char *src, size_t srclen); /* Time helpers */ long tv_udiff(const struct timeval *start, const struct timeval *end); +long tv_mdiff(const struct timeval *start, const struct timeval *end); time_t tor_timegm(struct tm *tm); #define RFC1123_TIME_LEN 29 void format_rfc1123_time(char *buf, time_t t); |