artdaq_mfextensions  v1_02_02
throttle.hh
1 #ifndef artdaq_mfextensions_extensions_throttle_hh
2 #define artdaq_mfextensions_extensions_throttle_hh
3 
4 #include <string>
5 
6 #include <sys/time.h>
7 
8 #include <boost/regex.hpp>
9 
10 typedef boost::regex regex_t;
11 typedef boost::smatch smatch_t;
12 
17 class throttle
18 {
19 public:
26  throttle(std::string const& name, int limit, long timespan);
27 
34  bool reach_limit(std::string const& name, timeval tm);
35 
36  void use(bool flag) { in_use_ = flag; }
37 
38 private:
39  std::string name_;
40  regex_t expr_;
41  smatch_t what_;
42  int limit_;
43  long timespan_;
44  long last_window_start_;
45  int count_;
46  bool in_use_;
47 };
48 
49 #endif //artdaq_mfextensions_extensions_throttle_hh
throttle(std::string const &name, int limit, long timespan)
Throttle messages using a regular expression if they occurr above a certain frequency ...
Definition: throttle.cc:3
Throttle messages based on name and time limits. Separate from MessageFacility limiting.
Definition: throttle.hh:17
bool reach_limit(std::string const &name, timeval tm)
Determine whether the name has reached the throttling limit
Definition: throttle.cc:13