![]() |
Bitcoin Core 31.0.0
P2P Digital Currency
|
Fixed window rate limiter for logging. More...
#include <logging.h>
Classes | |
| struct | Stats |
| Keeps track of an individual source location and how many available bytes are left for logging from it. More... | |
Public Types | |
| enum class | Status { UNSUPPRESSED , NEWLY_SUPPRESSED , STILL_SUPPRESSED } |
| Suppression status of a source log location. More... | |
| using | SchedulerFunction = std::function<void(std::function<void()>, std::chrono::milliseconds)> |
Public Member Functions | |
| Status | Consume (const SourceLocation &source_loc, const std::string &str) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex) |
Consumes source_loc's available bytes corresponding to the size of the (formatted) str and returns its status. | |
| void | Reset () EXCLUSIVE_LOCKS_REQUIRED(!m_mutex) |
| Resets all usage to zero. Called periodically by the scheduler. | |
| bool | SuppressionsActive () const |
| Returns true if any log locations are currently being suppressed. | |
Static Public Member Functions | |
| static std::shared_ptr< LogRateLimiter > | Create (SchedulerFunction &&scheduler_func, uint64_t max_bytes, std::chrono::seconds reset_window) |
Public Attributes | |
| const uint64_t | m_max_bytes |
| Maximum number of bytes logged per location per window. | |
| const std::chrono::seconds | m_reset_window |
| Interval after which the window is reset. | |
Private Member Functions | |
| std::unordered_map< SourceLocation, Stats, SourceLocationHasher, SourceLocationEqual > m_source_locations | GUARDED_BY (m_mutex) |
| Stats for each source location that has attempted to log something. | |
| LogRateLimiter (uint64_t max_bytes, std::chrono::seconds reset_window) | |
Private Attributes | |
| StdMutex | m_mutex |
| std::atomic< bool > | m_suppression_active {false} |
| Whether any log locations are suppressed. Cached view on m_source_locations for performance reasons. | |
| using BCLog::LogRateLimiter::SchedulerFunction = std::function<void(std::function<void()>, std::chrono::milliseconds)> |
|
strong |
|
private |
Definition at line 376 of file logging.cpp.
| BCLog::LogRateLimiter::Status BCLog::LogRateLimiter::Consume | ( | const SourceLocation & | source_loc, |
| const std::string & | str ) |
Consumes source_loc's available bytes corresponding to the size of the (formatted) str and returns its status.
Definition at line 391 of file logging.cpp.
|
static |
| scheduler_func | Callable object used to schedule resetting the window. The first parameter is the function to be executed, and the second is the reset_window interval. |
| max_bytes | Maximum number of bytes that can be logged for each source location. |
| reset_window | Time window after which the stats are reset. |
Definition at line 379 of file logging.cpp.
|
private |
Stats for each source location that has attempted to log something.
| void BCLog::LogRateLimiter::Reset | ( | ) |
Resets all usage to zero. Called periodically by the scheduler.
Definition at line 555 of file logging.cpp.
|
inline |
| const uint64_t BCLog::LogRateLimiter::m_max_bytes |
| const std::chrono::seconds BCLog::LogRateLimiter::m_reset_window |