diff --git a/userspace/engine/token_bucket.cpp b/userspace/engine/token_bucket.cpp index 1c30c649..955c2808 100644 --- a/userspace/engine/token_bucket.cpp +++ b/userspace/engine/token_bucket.cpp @@ -31,12 +31,18 @@ token_bucket::~token_bucket() { } -void token_bucket::init(double rate, double max_tokens) +void token_bucket::init(double rate, double max_tokens, uint64_t now) { m_rate = rate; m_max_tokens = max_tokens; m_tokens = max_tokens; - m_last_seen = sinsp_utils::get_current_time_ns(); + + if(now == 0) + { + now = sinsp_utils::get_current_time_ns(); + } + + m_last_seen = now; } bool token_bucket::claim(uint64_t now) diff --git a/userspace/engine/token_bucket.h b/userspace/engine/token_bucket.h index 2f767ef4..9bd91e1c 100644 --- a/userspace/engine/token_bucket.h +++ b/userspace/engine/token_bucket.h @@ -31,7 +31,7 @@ public: // // Initialize the token bucket and start accumulating tokens // - void init(double rate, double max_tokens); + void init(double rate, double max_tokens, uint64_t now = 0); // // Returns true if a token can be claimed. Also updates