From 8434caf5890e98a06b36a7ad17b19c45ae46a922 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Sun, 1 Apr 2012 16:24:39 -0700 Subject: [PATCH] qa: test_rewrite_latency Tool to measure latency of overwriting a single block. Signed-off-by: Sage Weil --- src/Makefile.am | 4 +++ src/test/test_rewrite_latency.cc | 46 ++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 src/test/test_rewrite_latency.cc diff --git a/src/Makefile.am b/src/Makefile.am index a37392d436fcf..c14b0e80cb33c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -177,6 +177,10 @@ test_mutate_SOURCES = test/test_mutate.cc test_mutate_LDADD = libglobal.la librados.la $(PTHREAD_LIBS) -lm $(CRYPTO_LIBS) $(EXTRALIBS) bin_DEBUGPROGRAMS += test_mutate +test_rewrite_latency_SOURCES = test/test_rewrite_latency.cc +test_rewrite_latency_LDADD = libcommon.la $(PTHREAD_LIBS) -lm $(CRYPTO_LIBS) $(EXTRALIBS) +bin_DEBUGPROGRAMS += test_rewrite_latency + testmsgr_SOURCES = testmsgr.cc testmsgr_LDADD = $(LIBGLOBAL_LDA) bin_DEBUGPROGRAMS += testmsgr diff --git a/src/test/test_rewrite_latency.cc b/src/test/test_rewrite_latency.cc new file mode 100644 index 0000000000000..5b006f9cde56d --- /dev/null +++ b/src/test/test_rewrite_latency.cc @@ -0,0 +1,46 @@ + +#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(NULL); + ::pwrite(fd, fn, strlen(fn), 0); + utime_t lat = ceph_clock_now(NULL); + 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; + } + } + } +} -- 2.39.5