summaryrefslogtreecommitdiff
path: root/src/or/relay.c
diff options
context:
space:
mode:
authorKarsten Loesing <karsten.loesing@gmx.net>2009-07-05 19:53:25 +0200
committerKarsten Loesing <karsten.loesing@gmx.net>2009-07-05 19:53:25 +0200
commitb493a2ccb97e00f4fe3acb5c59c941c2babaeebb (patch)
treeeec79d7610ffc84657bfed515cfd948970377e39 /src/or/relay.c
parent4d6af73db88e409764f43fc6cdaa432d667becf3 (diff)
downloadtor-b493a2ccb97e00f4fe3acb5c59c941c2babaeebb.tar.gz
tor-b493a2ccb97e00f4fe3acb5c59c941c2babaeebb.zip
If configured, write cell statistics to disk periodically.
Diffstat (limited to 'src/or/relay.c')
-rw-r--r--src/or/relay.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/or/relay.c b/src/or/relay.c
index 3ce05c8858..e5ba6f4035 100644
--- a/src/or/relay.c
+++ b/src/or/relay.c
@@ -1592,7 +1592,13 @@ cell_queue_append(cell_queue_t *queue, packed_cell_t *cell)
void
cell_queue_append_packed_copy(cell_queue_t *queue, const cell_t *cell)
{
- cell_queue_append(queue, packed_cell_copy(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
+ cell_queue_append(queue, copy);
}
/** Remove and free every cell in <b>queue</b>. */
@@ -1801,6 +1807,19 @@ 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;
+ uint32_t cell_waiting_time;
+ or_circuit_t *orcirc = TO_OR_CIRCUIT(circ);
+ tor_gettimeofday(&flushed_from_queue);
+ cell_waiting_time = (uint32_t)
+ (tv_udiff(&cell->packed_timeval, &flushed_from_queue) / 1000);
+ orcirc->total_cell_waiting_time += cell_waiting_time;
+ orcirc->processed_cells++;
+ }
+#endif
connection_write_to_buf(cell->body, CELL_NETWORK_SIZE, TO_CONN(conn));
packed_cell_free(cell);