rate_stat.h 729 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #ifndef __rate_stat_h_
  2. #define __rate_stat_h_
  3. #include "../common/cf_platform.h"
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. typedef struct
  8. {
  9. int sum;
  10. int sample;
  11. }rate_bucket_t;
  12. /*µ¥Î»Ê±¼ä´ø¿íͳ¼ÆÆ÷*/
  13. typedef struct
  14. {
  15. int64_t oldest_ts;
  16. int oldest_index;
  17. rate_bucket_t* buckets;
  18. int wnd_size;
  19. float scale;
  20. int accumulated_count;
  21. int sample_num;
  22. }rate_stat_t;
  23. void rate_stat_init(rate_stat_t* rate, int wnd_size, float scale);
  24. void rate_stat_destroy(rate_stat_t* rate);
  25. void rate_stat_reset(rate_stat_t* rate);
  26. void rate_stat_update(rate_stat_t* rate, size_t count, int64_t now_ts);
  27. int rate_stat_rate(rate_stat_t* rate, int64_t now_ts);
  28. #endif
  29. #ifdef __cplusplus
  30. }
  31. #endif