From c6953e810b3f524272484d939bbce9cba6af01a5 Mon Sep 17 00:00:00 2001 From: Mark Stemm Date: Thu, 8 Dec 2016 10:59:47 -0800 Subject: [PATCH] Use sinsp utils version of get time. sinsp_utils::get_current_time_ns() has the same purpose as get_epoch_ns(), and now that we're including the token bucket in falco_engine, it's easy to package the dependency. So use that function instead. --- userspace/engine/token_bucket.cpp | 13 +++---------- userspace/engine/token_bucket.h | 3 --- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/userspace/engine/token_bucket.cpp b/userspace/engine/token_bucket.cpp index c1ae9b0c..93f04924 100644 --- a/userspace/engine/token_bucket.cpp +++ b/userspace/engine/token_bucket.cpp @@ -19,6 +19,7 @@ along with falco. If not, see . #include #include +#include "utils.h" #include "token_bucket.h" token_bucket::token_bucket() @@ -35,14 +36,14 @@ void token_bucket::init(uint32_t rate, uint32_t max_tokens) m_rate = rate; m_max_tokens = max_tokens; m_tokens = max_tokens; - m_last_seen = get_epoch_ns(); + m_last_seen = sinsp_utils::get_current_time_ns(); } bool token_bucket::claim() { // Determine the number of tokens gained. Delta between // last_seen and now, divided by the rate. - uint64_t now = get_epoch_ns(); + uint64_t now = sinsp_utils::get_current_time_ns(); uint64_t tokens_gained = (now - m_last_seen) / (m_rate * 1000000000); m_last_seen = now; @@ -68,11 +69,3 @@ bool token_bucket::claim() return true; } - -uint64_t token_bucket::get_epoch_ns() -{ - struct timeval tv; - gettimeofday(&tv, NULL); - - return tv.tv_sec * (uint64_t) 1000000000 + (tv.tv_usec * 1000); -} diff --git a/userspace/engine/token_bucket.h b/userspace/engine/token_bucket.h index f9f62e00..b9c0d8b9 100644 --- a/userspace/engine/token_bucket.h +++ b/userspace/engine/token_bucket.h @@ -40,9 +40,6 @@ public: bool claim(); private: - // Utility function to get the time in nanoseconds since the epoch. - uint64_t get_epoch_ns(); - // // The number of tokens generated per second. //