bw_array_st.h (2311B)
1 /* Copyright (c) 2001 Matej Pfajfar. 2 * Copyright (c) 2001-2004, Roger Dingledine. 3 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson. 4 * Copyright (c) 2007-2021, The Tor Project, Inc. */ 5 /* See LICENSE for licensing information */ 6 7 /** 8 * @file bw_array_st.h 9 * @brief Declaration for bw_array_t structure and related constants 10 **/ 11 12 #ifndef TOR_FEATURE_STATS_BW_ARRAY_ST_H 13 #define TOR_FEATURE_STATS_BW_ARRAY_ST_H 14 15 /** For how many seconds do we keep track of individual per-second bandwidth 16 * totals? */ 17 #define NUM_SECS_ROLLING_MEASURE 10 18 /** How large are the intervals for which we track and report bandwidth use? */ 19 #define NUM_SECS_BW_SUM_INTERVAL (24*60*60) 20 /** How far in the past do we remember and publish bandwidth use? */ 21 #define NUM_SECS_BW_SUM_IS_VALID (5*24*60*60) 22 /** How many bandwidth usage intervals do we remember? (derived) */ 23 #define NUM_TOTALS (NUM_SECS_BW_SUM_IS_VALID/NUM_SECS_BW_SUM_INTERVAL) 24 25 /** Structure to track bandwidth use, and remember the maxima for a given 26 * time period. 27 */ 28 struct bw_array_t { 29 /** Observation array: Total number of bytes transferred in each of the last 30 * NUM_SECS_ROLLING_MEASURE seconds. This is used as a circular array. */ 31 uint64_t obs[NUM_SECS_ROLLING_MEASURE]; 32 int cur_obs_idx; /**< Current position in obs. */ 33 time_t cur_obs_time; /**< Time represented in obs[cur_obs_idx] */ 34 uint64_t total_obs; /**< Total for all members of obs except 35 * obs[cur_obs_idx] */ 36 uint64_t max_total; /**< Largest value that total_obs has taken on in the 37 * current period. */ 38 uint64_t total_in_period; /**< Total bytes transferred in the current 39 * period. */ 40 41 /** When does the next period begin? */ 42 time_t next_period; 43 /** Where in 'maxima' should the maximum bandwidth usage for the current 44 * period be stored? */ 45 int next_max_idx; 46 /** How many values in maxima/totals have been set ever? */ 47 int num_maxes_set; 48 /** Circular array of the maximum 49 * bandwidth-per-NUM_SECS_ROLLING_MEASURE usage for the last 50 * NUM_TOTALS periods */ 51 uint64_t maxima[NUM_TOTALS]; 52 /** Circular array of the total bandwidth usage for the last NUM_TOTALS 53 * periods */ 54 uint64_t totals[NUM_TOTALS]; 55 }; 56 57 #endif /* !defined(TOR_FEATURE_STATS_BW_ARRAY_ST_H) */