summaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2022-02-18 10:42:02 +0100
committerGitHub <noreply@github.com>2022-02-18 10:42:02 +0100
commit52d6a2d5221c4a4f7aafad8c771704388621ce50 (patch)
treef3980b953b58dcd76765e63d3716471a7d4ae63c /vespalib
parent589ed1bd7d92e9d67f7a052519cb9c6ceca7d28a (diff)
parentcc34e970770e668048e65c4bf2eb946b05fb014e (diff)
Merge pull request #21266 from vespa-engine/balder/add-method-to-get-default-timer-frequency
Add a base vespa timer frequency that is used as a base to control po…
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/tests/time/time_test.cpp4
-rw-r--r--vespalib/src/vespa/vespalib/util/time.cpp18
-rw-r--r--vespalib/src/vespa/vespalib/util/time.h5
3 files changed, 27 insertions, 0 deletions
diff --git a/vespalib/src/tests/time/time_test.cpp b/vespalib/src/tests/time/time_test.cpp
index 0bef18ddc0d..c2858308006 100644
--- a/vespalib/src/tests/time/time_test.cpp
+++ b/vespalib/src/tests/time/time_test.cpp
@@ -64,4 +64,8 @@ TEST(TimeTest, conversion_of_max) {
EXPECT_EQ(9223372036.8547764, vespalib::to_s(vespalib::duration::max()));
}
+TEST(TimeTest, default_timer_frequency_is_1000_hz) {
+ EXPECT_EQ(1000u, getVespaTimerHz());
+}
+
GTEST_MAIN_RUN_ALL_TESTS()
diff --git a/vespalib/src/vespa/vespalib/util/time.cpp b/vespalib/src/vespa/vespalib/util/time.cpp
index b5c019b4a27..bcc289489ea 100644
--- a/vespalib/src/vespa/vespalib/util/time.cpp
+++ b/vespalib/src/vespa/vespalib/util/time.cpp
@@ -3,6 +3,9 @@
#include "time.h"
#include <thread>
+#include <vespa/log/log.h>
+
+LOG_SETUP(".vespalib.time");
namespace vespalib {
system_time
@@ -12,6 +15,21 @@ to_utc(steady_time ts) {
return system_time(std::chrono::duration_cast<system_time::duration>(nowUtc.time_since_epoch() - nowSteady.time_since_epoch() + ts.time_since_epoch()));
}
+uint32_t
+getVespaTimerHz() {
+ const char * vespa_timer_hz = getenv("VESPA_TIMER_HZ");
+ if (vespa_timer_hz != nullptr) {
+ try {
+ size_t idx(0);
+ uint32_t tmp = std::stoi(vespa_timer_hz, &idx, 0);
+ return std::max(1u, std::min(1000u, tmp));
+ } catch (const std::exception & e) {
+ LOG(warning, "Parsing environment VESPA_TIMER_HZ='%s' failed with exception: %s", vespa_timer_hz, e.what());
+ }
+ }
+ return 1000u;
+}
+
namespace {
string
diff --git a/vespalib/src/vespa/vespalib/util/time.h b/vespalib/src/vespa/vespalib/util/time.h
index f19d71afb32..dbbae862a8d 100644
--- a/vespalib/src/vespa/vespalib/util/time.h
+++ b/vespalib/src/vespa/vespalib/util/time.h
@@ -88,4 +88,9 @@ public:
static void waitAtLeast(duration dur, bool busyWait);
};
+/**
+ * The default frequency (1000hz) for vespa timer, with environment override VESPA_TIMER_HZ capped to [1..1000]
+ */
+uint32_t getVespaTimerHz();
+
}