add drop fs caches to tools/perfect-cli

This commit is contained in:
Carl Pearson
2019-09-26 11:02:53 -05:00
parent 1b3cf604a8
commit a8d83417e8
3 changed files with 11 additions and 2 deletions

View File

@@ -116,7 +116,7 @@ See [tools/sync_drop_caches.cpp](tools/sync_drop_caches.cpp)
```
* `Result sync()`: flush filesystem caches to disk
* `Result drop_caches(DropCaches_t mode)`: remove file system caches
* `Result drop_caches(DropCaches_t mode = DropCaches_t(PAGECACHE | ENTRIES))`: remove file system caches
* `mode = PAGECACHE`: drop page caches
* `mode = ENTRIES`: drop dentries and inodes
* `mode = PAGECACHE | ENTRIES`: both

View File

@@ -24,7 +24,7 @@ Result sync() {
return Result::SUCCESS;
}
Result drop_caches(const DropCaches_t mode) {
Result drop_caches(const DropCaches_t mode = DropCaches_t(PAGECACHE | ENTRIES)) {
using detail::write_str;
const std::string path = "/proc/sys/vm/drop_caches";
if (mode & PAGECACHE & ENTRIES) {

View File

@@ -15,6 +15,7 @@
#include "perfect/cpu_turbo.hpp"
#include "perfect/os_perf.hpp"
#include "perfect/detail/os/linux.hpp"
#include "perfect/drop_caches.hpp"
// argv should be null-terminated
int fork_child(char *const *argv) {
@@ -72,6 +73,7 @@ int main(int argc, char **argv) {
bool aslr = false;
bool cpuTurbo = false;
bool maxOsPerf = true;
bool dropCaches = true;
std::vector<std::string> program;
@@ -83,6 +85,7 @@ int main(int argc, char **argv) {
auto cli = (shieldGroup,
option("--no-drop-cache").set(dropCaches, false).doc("do not drop filesystem caches"),
option("--no-max-perf").set(maxOsPerf, false).doc("do not max os perf"),
option("--no-aslr").set(aslr, false).doc("disable ASLR"),
option("--no-cpu-turbo").set(cpuTurbo, false).doc("disable CPU turbo"),
@@ -167,6 +170,12 @@ int main(int argc, char **argv) {
}
}
// handle file system caches
if (dropCaches) {
std::cerr << "clearing file system cache\n";
PERFECT(perfect::drop_caches());
}
// parent should return
std::cerr << "exec ";
for (size_t i = 0; i < args.size() - 1; ++i) {