summaryrefslogtreecommitdiff
path: root/src/or/rephist.c
diff options
context:
space:
mode:
authorKarsten Loesing <karsten.loesing@gmx.net>2009-07-11 00:44:27 +0200
committerKarsten Loesing <karsten.loesing@gmx.net>2009-07-11 00:44:27 +0200
commitd1437245c77b930382f9b36355a3fa67d48ecb38 (patch)
tree1043fa7acc4ae8bac7f62ff9319ca45c953525e3 /src/or/rephist.c
parent7fb206e554db6290ed355cd7fda7d2bcfb23c89f (diff)
downloadtor-d1437245c77b930382f9b36355a3fa67d48ecb38.tar.gz
tor-d1437245c77b930382f9b36355a3fa67d48ecb38.zip
Simplify the math to round up to the next multiple of some value.
Diffstat (limited to 'src/or/rephist.c')
-rw-r--r--src/or/rephist.c22
1 files changed, 8 insertions, 14 deletions
diff --git a/src/or/rephist.c b/src/or/rephist.c
index ba363ba742..73dd1315ed 100644
--- a/src/or/rephist.c
+++ b/src/or/rephist.c
@@ -1404,10 +1404,8 @@ write_exit_stats(time_t when)
if (exit_bytes_read[i] + exit_bytes_written[i] > 0 &&
(total_bytes / (exit_bytes_read[i] + exit_bytes_written[i])
< EXIT_STATS_THRESHOLD)) {
- uint64_t num = b[i];
- num += EXIT_STATS_ROUND_UP_BYTES - 1;
- num /= EXIT_STATS_ROUND_UP_BYTES;
- num *= EXIT_STATS_ROUND_UP_BYTES;
+ uint64_t num = round_to_next_multiple_of(b[i],
+ EXIT_STATS_ROUND_UP_BYTES);
num /= 1024;
if (fprintf(out, "%s%d="U64_FORMAT,
comma++ ? "," : "", i,
@@ -1417,9 +1415,8 @@ write_exit_stats(time_t when)
other_bytes += b[i];
}
}
- other_bytes += EXIT_STATS_ROUND_UP_BYTES - 1;
- other_bytes /= EXIT_STATS_ROUND_UP_BYTES;
- other_bytes *= EXIT_STATS_ROUND_UP_BYTES;
+ other_bytes = round_to_next_multiple_of(other_bytes,
+ EXIT_STATS_ROUND_UP_BYTES);
other_bytes /= 1024;
if (fprintf(out, "%sother="U64_FORMAT"\n",
comma ? "," : "", other_bytes)<0)
@@ -1435,10 +1432,8 @@ write_exit_stats(time_t when)
if (exit_bytes_read[i] + exit_bytes_written[i] > 0 &&
(total_bytes / (exit_bytes_read[i] + exit_bytes_written[i])
< EXIT_STATS_THRESHOLD)) {
- uint32_t num = exit_streams[i];
- num += EXIT_STATS_ROUND_UP_STREAMS - 1;
- num /= EXIT_STATS_ROUND_UP_STREAMS;
- num *= EXIT_STATS_ROUND_UP_STREAMS;
+ uint32_t num = round_to_next_multiple_of(exit_streams[i],
+ EXIT_STATS_ROUND_UP_STREAMS);
if (fprintf(out, "%s%d=%d",
comma++ ? "," : "", i, num)<0)
goto done;
@@ -1446,9 +1441,8 @@ write_exit_stats(time_t when)
other_streams += exit_streams[i];
}
}
- other_streams += EXIT_STATS_ROUND_UP_STREAMS - 1;
- other_streams /= EXIT_STATS_ROUND_UP_STREAMS;
- other_streams *= EXIT_STATS_ROUND_UP_STREAMS;
+ other_streams = round_to_next_multiple_of(other_streams,
+ EXIT_STATS_ROUND_UP_STREAMS);
if (fprintf(out, "%sother=%d\n",
comma ? "," : "", other_streams)<0)
goto done;