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