summaryrefslogtreecommitdiff
path: root/src/common/util.c
diff options
context:
space:
mode:
authorKarsten Loesing <karsten.loesing@gmx.net>2009-07-27 16:23:53 +0200
committerKarsten Loesing <karsten.loesing@gmx.net>2009-07-27 16:23:53 +0200
commit7b716878cb6837756bd65ed788e5d8d89d8af56c (patch)
tree80839cd8fe6fdaf9bc471294821516aae462511f /src/common/util.c
parent2b0e8fb39f0ac9c0bfadc64102440843300fa9d7 (diff)
downloadtor-7b716878cb6837756bd65ed788e5d8d89d8af56c.tar.gz
tor-7b716878cb6837756bd65ed788e5d8d89d8af56c.zip
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/util.c')
-rw-r--r--src/common/util.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/common/util.c b/src/common/util.c
index 0e7f59e620..234180c4d4 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. */