artdaq_mfextensions  v1_05_00
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, int64_t timespan);
27 
34  bool reach_limit(std::string const& name, timeval tm);
35 
40  void use(bool flag) { in_use_ = flag; }
41 
42 private:
43  std::string name_;
44  regex_t expr_;
45  smatch_t what_;
46  int limit_;
47  int64_t timespan_;
48  int64_t last_window_start_;
49  int count_;
50  bool in_use_;
51 };
52 
53 #endif // artdaq_mfextensions_extensions_throttle_hh
void use(bool flag)
Enable or disable this throttle
Definition: throttle.hh:40
throttle(std::string const &name, int limit, int64_t 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:6