[or-cvs] [tor/master] Remove ./configure option for cell statistics.

Nick Mathewson nickm at seul.org
Wed Aug 26 15:36:39 UTC 2009


Author: Karsten Loesing <karsten.loesing at gmx.net>
Date: Fri, 14 Aug 2009 14:52:39 +0200
Subject: Remove ./configure option for cell statistics.
Commit: d97e95cb6242b94002854055a08c3190e731139b

---
 configure.in         |    7 ----
 src/or/circuitlist.c |    2 -
 src/or/config.c      |    6 ----
 src/or/main.c        |    4 --
 src/or/or.h          |   10 +-----
 src/or/relay.c       |   80 ++++++++++++++++++++++++++++++++++++++++---------
 src/or/rephist.c     |    2 -
 7 files changed, 66 insertions(+), 45 deletions(-)

diff --git a/configure.in b/configure.in
index df228ab..735a524 100644
--- a/configure.in
+++ b/configure.in
@@ -85,13 +85,6 @@ case $host in
      ;;
 esac
 
-AC_ARG_ENABLE(dirreq-stats,
-     AS_HELP_STRING(--enable-dirreq-stats, enable code for directories to collect per-country statistics))
-
-if test "$enable_dirreq_stats" = "yes"; then
-  AC_DEFINE(ENABLE_DIRREQ_STATS, 1, [Defined if we try to collect per-country statistics])
-fi
-
 AC_ARG_ENABLE(gcc-warnings,
      AS_HELP_STRING(--enable-gcc-warnings, enable verbose warnings))
 
diff --git a/src/or/circuitlist.c b/src/or/circuitlist.c
index 5a20e7e..04b1d8e 100644
--- a/src/or/circuitlist.c
+++ b/src/or/circuitlist.c
@@ -447,11 +447,9 @@ circuit_free(circuit_t *circ)
       rend_data_free(ocirc->rend_data);
   } else {
     or_circuit_t *ocirc = TO_OR_CIRCUIT(circ);
-#ifdef ENABLE_BUFFER_STATS
     /* Remember cell statistics for this circuit before deallocating. */
     if (get_options()->CellStatistics)
       add_circ_to_buffer_stats(circ, time(NULL));
-#endif
     mem = ocirc;
     memlen = sizeof(or_circuit_t);
     tor_assert(circ->magic == OR_CIRCUIT_MAGIC);
diff --git a/src/or/config.c b/src/or/config.c
index 0fc3af4..89c94b1 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -1424,16 +1424,10 @@ options_act(or_options_t *old_options)
                "Look for the exit-stats file that will first be written to "
                "the data directory in 24 hours from now.");
 
-#ifdef ENABLE_BUFFER_STATS
   if (options->CellStatistics)
     log_notice(LD_CONFIG, "Configured to measure cell statistics. Look "
                "for the buffer-stats file that will first be written to "
                "the data directory in 24 hours from now.");
-#else
-  if (options->CellStatistics)
-    log_warn(LD_CONFIG, "CellStatistics enabled, but Tor was built "
-             "without cell statistics support.");
-#endif
 
   if (options->EntryStatistics) {
     if (should_record_bridge_info(options)) {
diff --git a/src/or/main.c b/src/or/main.c
index 4969212..403ae93 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -830,9 +830,7 @@ run_scheduled_events(time_t now)
   static time_t time_to_clean_caches = 0;
   static time_t time_to_recheck_bandwidth = 0;
   static time_t time_to_check_for_expired_networkstatus = 0;
-#ifdef ENABLE_BUFFER_STATS
   static time_t time_to_dump_buffer_stats = 0;
-#endif
   static time_t time_to_retry_dns_init = 0;
   or_options_t *options = get_options();
   int i;
@@ -960,13 +958,11 @@ run_scheduled_events(time_t now)
     time_to_check_for_expired_networkstatus = now + CHECK_EXPIRED_NS_INTERVAL;
   }
 
-#ifdef ENABLE_BUFFER_STATS
   if (time_to_dump_buffer_stats < now) {
     if (get_options()->CellStatistics && time_to_dump_buffer_stats)
       dump_buffer_stats();
     time_to_dump_buffer_stats = now + DUMP_BUFFER_STATS_INTERVAL;
   }
-#endif
 
   /* Remove old information from rephist and the rend cache. */
   if (time_to_clean_caches < now) {
diff --git a/src/or/or.h b/src/or/or.h
index 5fed1cc..ff2e65c 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -20,9 +20,6 @@
 #ifndef INSTRUMENT_DOWNLOADS
 #define INSTRUMENT_DOWNLOADS 1
 #endif
-#ifndef ENABLE_BUFFER_STATS
-#define ENABLE_BUFFER_STATS 1
-#endif
 #endif
 
 #ifdef MS_WINDOWS
@@ -838,9 +835,7 @@ typedef struct var_cell_t {
 typedef struct packed_cell_t {
   struct packed_cell_t *next; /**< Next cell queued on this circuit. */
   char body[CELL_NETWORK_SIZE]; /**< Cell as packed for network. */
-#ifdef ENABLE_BUFFER_STATS
   struct timeval packed_timeval; /**< When was this cell packed? */
-#endif
 } packed_cell_t;
 
 /** A queue of cells on a circuit, waiting to be added to the
@@ -849,6 +844,7 @@ typedef struct cell_queue_t {
   packed_cell_t *head; /**< The first cell, or NULL if the queue is empty. */
   packed_cell_t *tail; /**< The last cell, or NULL if the queue is empty. */
   int n; /**< The number of cells in the queue. */
+  smartlist_t *insertion_times;
 } cell_queue_t;
 
 /** Beginning of a RELAY cell payload. */
@@ -2086,7 +2082,6 @@ typedef struct or_circuit_t {
   /** True iff this circuit was made with a CREATE_FAST cell. */
   unsigned int is_first_hop : 1;
 
-#ifdef ENABLE_BUFFER_STATS
   /** Number of cells that were removed from circuit queue; reset every
    * time when writing buffer stats to disk. */
   uint32_t processed_cells;
@@ -2095,7 +2090,6 @@ typedef struct or_circuit_t {
    * exit-ward queues of this circuit; reset every time when writing
    * buffer stats to disk. */
   uint64_t total_cell_waiting_time;
-#endif
 } or_circuit_t;
 
 /** Convert a circuit subtype to a circuit_t.*/
@@ -4121,11 +4115,9 @@ void hs_usage_note_fetch_successful(const char *service_id, time_t now);
 void hs_usage_write_statistics_to_file(time_t now);
 void hs_usage_free_all(void);
 
-#ifdef ENABLE_BUFFER_STATS
 #define DUMP_BUFFER_STATS_INTERVAL (24*60*60)
 void add_circ_to_buffer_stats(circuit_t *circ, time_t end_of_interval);
 void dump_buffer_stats(void);
-#endif
 
 /********************************* rendclient.c ***************************/
 
diff --git a/src/or/relay.c b/src/or/relay.c
index 63baabc..add8d4c 100644
--- a/src/or/relay.c
+++ b/src/or/relay.c
@@ -1612,16 +1612,48 @@ cell_queue_append(cell_queue_t *queue, packed_cell_t *cell)
   ++queue->n;
 }
 
+/** Number of cells added to a circuit queue including their insertion
+ * time on millisecond detail; used for buffer statistics. */
+typedef struct insertion_time_elem_t {
+  uint32_t insertion_time; /**< When were cells inserted (in ms starting
+                                at 0:00 of the current day)? */
+  unsigned counter; /**< How many cells were inserted? */
+} insertion_time_elem_t;
+
 /** Append a newly allocated copy of <b>cell</b> to the end of <b>queue</b> */
 void
 cell_queue_append_packed_copy(cell_queue_t *queue, const cell_t *cell)
 {
   packed_cell_t *copy = packed_cell_copy(cell);
-#ifdef ENABLE_BUFFER_STATS
-  /* Remember the exact time when this cell was put in the queue. */
-  if (get_options()->CellStatistics)
-    tor_gettimeofday(&copy->packed_timeval);
-#endif
+  /* Remember the time in millis when this cell was put in the queue. */
+  if (get_options()->CellStatistics) {
+    struct timeval now;
+    uint32_t added;
+    insertion_time_elem_t *last_elem = NULL;
+    int add_new_elem = 0;
+    tor_gettimeofday(&now);
+    added = now.tv_sec % 86400L * 1000L + now.tv_usec / 1000L;
+    if (!queue->insertion_times) {
+      queue->insertion_times = smartlist_create();
+    }
+    if (smartlist_len(queue->insertion_times) < 1) {
+      add_new_elem = 1;
+    } else {
+      last_elem = smartlist_get(queue->insertion_times,
+                      smartlist_len(queue->insertion_times) - 1);
+      if (last_elem->insertion_time == added)
+        last_elem->counter++;
+      else
+        add_new_elem = 1;
+    }
+    if (add_new_elem) {
+      insertion_time_elem_t *elem =
+          tor_malloc_zero(sizeof(insertion_time_elem_t));
+      elem->insertion_time = added;
+      elem->counter = 1;
+      smartlist_add(queue->insertion_times, elem);
+    }
+  }
   cell_queue_append(queue, copy);
 }
 
@@ -1638,6 +1670,11 @@ cell_queue_clear(cell_queue_t *queue)
   }
   queue->head = queue->tail = NULL;
   queue->n = 0;
+  if (queue->insertion_times) {
+    SMARTLIST_FOREACH(queue->insertion_times, void *, e, tor_free(e));
+    smartlist_free(queue->insertion_times);
+    queue->insertion_times = NULL;
+  }
 }
 
 /** Extract and return the cell at the head of <b>queue</b>; return NULL if
@@ -1831,20 +1868,33 @@ connection_or_flush_from_first_active_circuit(or_connection_t *conn, int max,
     packed_cell_t *cell = cell_queue_pop(queue);
     tor_assert(*next_circ_on_conn_p(circ,conn));
 
-#ifdef ENABLE_BUFFER_STATS
     /* Calculate the exact time that this cell has spent in the queue. */
     if (get_options()->CellStatistics && !CIRCUIT_IS_ORIGIN(circ)) {
-      struct timeval flushed_from_queue;
+      struct timeval now;
+      uint32_t flushed;
       uint32_t cell_waiting_time;
-      or_circuit_t *orcirc = TO_OR_CIRCUIT(circ);
-      tor_gettimeofday(&flushed_from_queue);
-      cell_waiting_time = (uint32_t)
-            tv_mdiff(&cell->packed_timeval, &flushed_from_queue);
-
-      orcirc->total_cell_waiting_time += cell_waiting_time;
-      orcirc->processed_cells++;
+      tor_gettimeofday(&now);
+      flushed = now.tv_sec % 86400L * 1000L + now.tv_usec / 1000L;
+      if (!queue->insertion_times ||
+          smartlist_len(queue->insertion_times) < 1) {
+        log_warn(LD_BUG, "Cannot determine insertion time of cell.");
+      } else {
+        or_circuit_t *orcirc = TO_OR_CIRCUIT(circ);
+        insertion_time_elem_t *elem = smartlist_get(
+            queue->insertion_times, 0);
+        cell_waiting_time = (flushed + 86400000L - elem->insertion_time) %
+                            86400000L;
+        elem->counter--;
+        if (elem->counter < 1) {
+// TODO this operation is really expensive! write own queue impl?
+//          smartlist_del(queue->insertion_times, 0);
+          smartlist_remove(queue->insertion_times, elem);
+          tor_free(elem);
+        }
+        orcirc->total_cell_waiting_time += cell_waiting_time;
+        orcirc->processed_cells++;
+      }
     }
-#endif
 
     /* If we just flushed our queue and this circuit is used for a
      * tunneled directory request, possibly advance its state. */
diff --git a/src/or/rephist.c b/src/or/rephist.c
index 0d370a3..abfd477 100644
--- a/src/or/rephist.c
+++ b/src/or/rephist.c
@@ -2620,7 +2620,6 @@ hs_usage_write_statistics_to_file(time_t now)
 
 /*** cell statistics ***/
 
-#ifdef ENABLE_BUFFER_STATS
 /** Start of the current buffer stats interval. */
 time_t start_of_buffer_stats_interval;
 
@@ -2787,5 +2786,4 @@ dump_buffer_stats(void)
   tor_free(str);
 #undef SHARES
 }
-#endif
 
-- 
1.5.6.5




More information about the tor-commits mailing list