From e6918187568dbd01842d8d1d2c808ce16a894239 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 21 Apr 2024 13:54:28 +0200 Subject: Adding upstream version 18.2.2. Signed-off-by: Daniel Baumann --- src/test/test_rewrite_latency.cc | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/test/test_rewrite_latency.cc (limited to 'src/test/test_rewrite_latency.cc') diff --git a/src/test/test_rewrite_latency.cc b/src/test/test_rewrite_latency.cc new file mode 100644 index 000000000..348c8dde5 --- /dev/null +++ b/src/test/test_rewrite_latency.cc @@ -0,0 +1,47 @@ + +#include +#include +#include + +#include "include/utime.h" +#include "common/Clock.h" +#include "common/errno.h" + +using namespace std; + +int main(int argc, const char **argv) +{ + const char *fn = argv[1]; + multimap latency; + unsigned max = 10; + + int fd = ::open(fn, O_CREAT|O_RDWR, 0644); + if (fd < 1) { + int err = errno; + cerr << "failed to open " << fn << " with " << cpp_strerror(err) << std::endl; + return -1; + } + + while (true) { + utime_t now = ceph_clock_now(); + int r = ::pwrite(fd, fn, strlen(fn), 0); + ceph_assert(r >= 0); + utime_t lat = ceph_clock_now(); + lat -= now; + utime_t oldmin; + if (!latency.empty()) + oldmin = latency.begin()->first; + latency.insert(make_pair(lat, now)); + utime_t newmin = latency.begin()->first; + while (latency.size() > max) + latency.erase(latency.begin()); + if (oldmin == newmin) { + cout << "latency\tat" << std::endl; + for (multimap::reverse_iterator p = latency.rbegin(); + p != latency.rend(); + ++p) { + cout << p->first << "\t" << p->second << std::endl; + } + } + } +} -- cgit v1.2.3