summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fastos/src/vespa/fastos/timestamp.h1
-rw-r--r--staging_vespalib/src/tests/clock/.gitignore1
-rw-r--r--staging_vespalib/src/tests/clock/CMakeLists.txt6
-rw-r--r--staging_vespalib/src/tests/clock/clock_benchmark.cpp53
-rw-r--r--staging_vespalib/src/tests/clock/clock_test.cpp2
5 files changed, 62 insertions, 1 deletions
diff --git a/fastos/src/vespa/fastos/timestamp.h b/fastos/src/vespa/fastos/timestamp.h
index 79d6ef5eed6..a38c02e7302 100644
--- a/fastos/src/vespa/fastos/timestamp.h
+++ b/fastos/src/vespa/fastos/timestamp.h
@@ -128,6 +128,7 @@ public:
}
UTCTimeStamp toUTC() const;
std::string toString() const { return _timeStamp.toString(); };
+ const TimeStamp & raw() const { return _timeStamp; }
private:
TimeStamp _timeStamp;
};
diff --git a/staging_vespalib/src/tests/clock/.gitignore b/staging_vespalib/src/tests/clock/.gitignore
index 1826ba1563b..b0fcd343176 100644
--- a/staging_vespalib/src/tests/clock/.gitignore
+++ b/staging_vespalib/src/tests/clock/.gitignore
@@ -2,3 +2,4 @@
Makefile
clock_test
staging_vespalib_clock_test_app
+staging_vespalib_clock_benchmark_app
diff --git a/staging_vespalib/src/tests/clock/CMakeLists.txt b/staging_vespalib/src/tests/clock/CMakeLists.txt
index e62ef47e18a..825c0ae36cb 100644
--- a/staging_vespalib/src/tests/clock/CMakeLists.txt
+++ b/staging_vespalib/src/tests/clock/CMakeLists.txt
@@ -1,4 +1,10 @@
# Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+vespa_add_executable(staging_vespalib_clock_benchmark_app TEST
+ SOURCES
+ clock_benchmark.cpp
+ DEPENDS
+ staging_vespalib
+)
vespa_add_executable(staging_vespalib_clock_test_app TEST
SOURCES
clock_test.cpp
diff --git a/staging_vespalib/src/tests/clock/clock_benchmark.cpp b/staging_vespalib/src/tests/clock/clock_benchmark.cpp
new file mode 100644
index 00000000000..49eac95de66
--- /dev/null
+++ b/staging_vespalib/src/tests/clock/clock_benchmark.cpp
@@ -0,0 +1,53 @@
+// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include <vespa/vespalib/util/clock.h>
+#include <cassert>
+#include <vector>
+
+using vespalib::Clock;
+using fastos::TimeStamp;
+
+struct Sampler : public FastOS_Runnable {
+ Sampler(Clock & clock, fastos::SteadyTimeStamp end) :
+ _samples(0),
+ _clock(clock),
+ _theEnd(end)
+ { }
+ void Run(FastOS_ThreadInterface *, void *) override {
+ printf("Starting at %s with doom at %s\n", _clock.getTimeNSAssumeRunning().toString().c_str(), _theEnd.toString().c_str());
+ for (_samples = 0; (_clock.getTimeNSAssumeRunning() < _theEnd) && (_samples < 40000000000l); _samples++) {
+
+ }
+ printf("Took %ld clock samples at %s\n", _samples, _clock.getTimeNSAssumeRunning().toString().c_str());
+ }
+ uint64_t _samples;
+ const Clock & _clock;
+ fastos::SteadyTimeStamp _theEnd;
+ FastOS_ThreadInterface * _thread;
+};
+void sample() {
+
+}
+
+int
+main(int , char *argv[])
+{
+ long frequency = atoll(argv[1]);
+ int numThreads = atoi(argv[2]);
+ Clock clock(1.0/frequency);
+ FastOS_ThreadPool pool(0x10000);
+ assert(pool.NewThread(&clock, nullptr) != nullptr);
+
+ std::vector<std::unique_ptr<Sampler>> threads;
+ threads.reserve(numThreads);
+ for (int i(0); i < numThreads; i++) {
+ threads.push_back(std::make_unique<Sampler>(clock, fastos::ClockSteady::now() + 10*TimeStamp::SEC));
+ Sampler * sampler = threads[i].get();
+ sampler->_thread = pool.NewThread(threads[i].get(), nullptr);
+ }
+ for (const auto & sampler : threads) {
+ sampler->_thread->Join();
+ }
+ pool.Close();
+ clock.stop();
+}
diff --git a/staging_vespalib/src/tests/clock/clock_test.cpp b/staging_vespalib/src/tests/clock/clock_test.cpp
index 45f17bbba92..c8c93272e85 100644
--- a/staging_vespalib/src/tests/clock/clock_test.cpp
+++ b/staging_vespalib/src/tests/clock/clock_test.cpp
@@ -20,7 +20,7 @@ Test::Main()
Clock clock(0.050);
FastOS_ThreadPool pool(0x10000);
- ASSERT_TRUE(pool.NewThread(&clock, NULL) != NULL);
+ ASSERT_TRUE(pool.NewThread(&clock, nullptr) != nullptr);
fastos::SteadyTimeStamp start = clock.getTimeNS();
FastOS_Thread::Sleep(5000);
fastos::SteadyTimeStamp stop = clock.getTimeNS();