diff options
author | Nick Mathewson <nickm@torproject.org> | 2004-08-07 05:13:55 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2004-08-07 05:13:55 +0000 |
commit | 28a6d0901f82514e818f9fc522986fc0299e8ace (patch) | |
tree | 093ef9047761da9951e2540162c42cffb8ed2869 /src/or/rephist.c | |
parent | 3de630ec678df36244d8c693a54cc5c24f615c4f (diff) | |
download | tor-28a6d0901f82514e818f9fc522986fc0299e8ace.tar tor-28a6d0901f82514e818f9fc522986fc0299e8ace.tar.gz |
Handle loop initialization for bandwidth tracking properly
svn:r2190
Diffstat (limited to 'src/or/rephist.c')
-rw-r--r-- | src/or/rephist.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/or/rephist.c b/src/or/rephist.c index c766dd320..4de57ac86 100644 --- a/src/or/rephist.c +++ b/src/or/rephist.c @@ -360,6 +360,8 @@ static void commit_max(bw_array_t *b) { ++b->num_maxes_set; /* Reset max_total. */ b->max_total = 0; + /* Reset total_in_period. */ + b->total_in_period = 0; } /** Shift the current observation time of 'b' forward by one second. @@ -449,7 +451,6 @@ void rep_hist_note_bytes_written(int num_bytes, time_t when) { */ void rep_hist_note_bytes_read(int num_bytes, time_t when) { /* if we're smart, we can make this func and the one above share code */ - add_obs(read_array, when, num_bytes); } @@ -508,8 +509,14 @@ char *rep_hist_get_bandwidth_lines(void) sprintf(cp, "opt %s-history %s (%d s)", r?"read":"write", t, NUM_SECS_BW_SUM_INTERVAL); cp += strlen(cp); - for (i=b->num_maxes_set+1,n=0; n<b->num_maxes_set; ++n,++i) { - if (i >= NUM_TOTALS) i -= NUM_TOTALS; + + if (b->num_maxes_set < b->next_max_idx) + i = 0; + else + i = b->next_max_idx; + + for (n=0; n<b->num_maxes_set; ++n,++i) { + while (i >= NUM_TOTALS) i -= NUM_TOTALS; if (n==(b->num_maxes_set-1)) sprintf(cp, "%d", b->totals[i]); else |