sapling/eden/fs/utils/test/ProcessAccessLogBenchmark.cpp
Chad Austin 4c1ad47d20 replace folly::Baton in existing benchmarks with StartingGate
Summary:
Now that we have a standardized StartingGate for benchmarks, use it
everywhere we used to use folly::Baton.

(Note: this ignores all push blocking failures!)

Differential Revision: D13012244

fbshipit-source-id: 5841ab74cfa408e87d021fe5591557e79e677e5c
2018-11-13 15:27:51 -08:00

60 lines
1.6 KiB
C++

/*
* Copyright (c) 2018-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
#include "eden/fs/utils/ProcessAccessLog.h"
#include <folly/Benchmark.h>
#include "eden/fs/benchharness/Bench.h"
#include "eden/fs/utils/ProcessNameCache.h"
using namespace facebook::eden;
/**
* A high but realistic amount of contention.
*/
constexpr size_t kThreadCount = 4;
BENCHMARK(ProcessAccessLog_repeatedly_add_self, iters) {
folly::BenchmarkSuspender suspender;
auto processNameCache = std::make_shared<ProcessNameCache>();
ProcessAccessLog processAccessLog{processNameCache};
std::vector<std::thread> threads;
StartingGate gate{kThreadCount};
size_t remainingIterations = iters;
size_t totalIterations = 0;
for (size_t i = 0; i < kThreadCount; ++i) {
size_t remainingThreads = kThreadCount - i;
size_t assignedIterations = remainingIterations / remainingThreads;
remainingIterations -= assignedIterations;
totalIterations += assignedIterations;
threads.emplace_back(
[&processAccessLog, &gate, assignedIterations, myPid = getpid()] {
gate.wait();
for (size_t j = 0; j < assignedIterations; ++j) {
processAccessLog.recordAccess(myPid);
}
});
}
CHECK_EQ(totalIterations, iters);
suspender.dismiss();
// Now wake the threads.
gate.waitThenOpen();
// Wait until they're done.
for (auto& thread : threads) {
thread.join();
}
}