| 1 | #ifndef _TIMED_CIRCLE_H_ |
|---|
| 2 | #define _TIMED_CIRCLE_H_ |
|---|
| 3 | |
|---|
| 4 | /* store hits for a given second in here. |
|---|
| 5 | * some bits of the logbits struct aren't used in the circle but |
|---|
| 6 | * it's better than making an entirely new struct */ |
|---|
| 7 | typedef struct logbits HIT; |
|---|
| 8 | |
|---|
| 9 | class Timed_Circle : public Circle |
|---|
| 10 | { |
|---|
| 11 | public: |
|---|
| 12 | |
|---|
| 13 | int create(unsigned int size); |
|---|
| 14 | int insert(struct logbits lb); |
|---|
| 15 | int walk(struct logbits **lb); |
|---|
| 16 | |
|---|
| 17 | void updatestats(void); |
|---|
| 18 | time_t oldest(void); |
|---|
| 19 | |
|---|
| 20 | double getreqcount(void) { return reqcount; } |
|---|
| 21 | double getbytecount(void) { return bytecount; } |
|---|
| 22 | double getsummary(int r_c) { return rc_summary[r_c]; } |
|---|
| 23 | |
|---|
| 24 | private: |
|---|
| 25 | int initbuckets(const unsigned int from, const unsigned int to); |
|---|
| 26 | void resetbucketstats(const unsigned int r); |
|---|
| 27 | |
|---|
| 28 | void garbagecollection(void); |
|---|
| 29 | |
|---|
| 30 | double reqcount, bytecount; |
|---|
| 31 | double rc_summary[6]; |
|---|
| 32 | |
|---|
| 33 | unsigned int bucketsize; /* how many buckets (seconds) ? */ |
|---|
| 34 | unsigned int bucketpos; /* which bucket are we using now? */ |
|---|
| 35 | |
|---|
| 36 | /* the timed_circle_struct is a set of buckets; each bucket contains |
|---|
| 37 | * data about hits for a given second. Each hit is stored in a |
|---|
| 38 | * HIT array inside the relevant bucket */ |
|---|
| 39 | struct timed_circle_struct |
|---|
| 40 | { |
|---|
| 41 | time_t time; /* second this bucket represents */ |
|---|
| 42 | |
|---|
| 43 | /* stats for the HITs array */ |
|---|
| 44 | double reqcount, bytecount; |
|---|
| 45 | double rc_summary[6]; |
|---|
| 46 | |
|---|
| 47 | unsigned int hitsize; /* how big is the array for hits? */ |
|---|
| 48 | unsigned int hitpos; /* how far along hits array we are */ |
|---|
| 49 | HIT *hits; /* hits for this second go into array */ |
|---|
| 50 | |
|---|
| 51 | } *tab; |
|---|
| 52 | |
|---|
| 53 | /* for walk() */ |
|---|
| 54 | unsigned int walk_bucketpos; |
|---|
| 55 | unsigned int walk_hitpos; |
|---|
| 56 | |
|---|
| 57 | }; |
|---|
| 58 | |
|---|
| 59 | #endif |
|---|