Commit 92f03ddd authored by Nathan Bronson's avatar Nathan Bronson Committed by Facebook Github Bot

getrusage harness for CacheLocality

Summary:
This diff adds unit tests that print out the wall, user, and
system time for two backend implementations of CacheLocality gathering.

Reviewed By: yfeldblum

Differential Revision: D16547404

fbshipit-source-id: 5b5467965eb21bc50ad7248c0badd814edc71d68
parent 8deb4210
......@@ -17,6 +17,7 @@
#include <folly/concurrency/CacheLocality.h>
#include <folly/portability/GTest.h>
#include <folly/portability/SysResource.h>
#include <glog/logging.h>
#include <memory>
......@@ -999,6 +1000,39 @@ TEST(CacheLocality, LogSystem) {
}
}
#ifdef RUSAGE_THREAD
static uint64_t micros(struct timeval& tv) {
return static_cast<uint64_t>(tv.tv_sec) * 1000000 + tv.tv_usec;
}
template <typename F>
static void logRusageFor(std::string name, F func) {
struct rusage before;
getrusage(RUSAGE_THREAD, &before);
auto beforeNow = std::chrono::steady_clock::now();
func();
auto afterNow = std::chrono::steady_clock::now();
struct rusage after;
getrusage(RUSAGE_THREAD, &after);
LOG(INFO) << name << ": real: "
<< std::chrono::duration_cast<std::chrono::microseconds>(
afterNow - beforeNow)
.count()
<< " usec, user: "
<< (micros(after.ru_utime) - micros(before.ru_utime))
<< " usec, sys: "
<< (micros(after.ru_stime) - micros(before.ru_stime)) << " usec";
}
TEST(CacheLocality, BenchmarkProcCpuinfo) {
logRusageFor("readFromProcCpuinfo", CacheLocality::readFromProcCpuinfo);
}
TEST(CacheLocality, BenchmarkSysfs) {
logRusageFor("readFromSysfs", CacheLocality::readFromSysfs);
}
#endif
#if FOLLY_HAVE_LINUX_VDSO
TEST(Getcpu, VdsoGetcpu) {
unsigned cpu;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment