Tor  0.4.6.0-alpha-dev
bw_array_st.h
Go to the documentation of this file.
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-2020, 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. */
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? */
46  /** How many values in maxima/totals have been set ever? */
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) */
NUM_SECS_ROLLING_MEASURE
#define NUM_SECS_ROLLING_MEASURE
Definition: bw_array_st.h:17
bw_array_t::next_period
time_t next_period
Definition: bw_array_st.h:42
bw_array_t::max_total
uint64_t max_total
Definition: bw_array_st.h:36
bw_array_t::cur_obs_idx
int cur_obs_idx
Definition: bw_array_st.h:32
bw_array_t::total_obs
uint64_t total_obs
Definition: bw_array_st.h:34
bw_array_t::next_max_idx
int next_max_idx
Definition: bw_array_st.h:45
bw_array_t::maxima
uint64_t maxima[NUM_TOTALS]
Definition: bw_array_st.h:51
bw_array_t
Definition: bw_array_st.h:28
NUM_TOTALS
#define NUM_TOTALS
Definition: bw_array_st.h:23
bw_array_t::num_maxes_set
int num_maxes_set
Definition: bw_array_st.h:47
bw_array_t::obs
uint64_t obs[NUM_SECS_ROLLING_MEASURE]
Definition: bw_array_st.h:31
bw_array_t::totals
uint64_t totals[NUM_TOTALS]
Definition: bw_array_st.h:54
bw_array_t::cur_obs_time
time_t cur_obs_time
Definition: bw_array_st.h:33
bw_array_t::total_in_period
uint64_t total_in_period
Definition: bw_array_st.h:38