aboutsummaryrefslogtreecommitdiff
path: root/src/zen/bench.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/zen/bench.cpp')
-rw-r--r--src/zen/bench.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/zen/bench.cpp b/src/zen/bench.cpp
index 614454ed5..2332ce1b8 100644
--- a/src/zen/bench.cpp
+++ b/src/zen/bench.cpp
@@ -119,6 +119,53 @@ EmptyStandByList()
} // namespace zen::bench::util
+#elif ZEN_PLATFORM_LINUX
+
+# include <fcntl.h>
+# include <unistd.h>
+
+namespace zen::bench::util {
+
+void
+EmptyStandByList()
+{
+ sync();
+
+ int Fd = open("/proc/sys/vm/drop_caches", O_WRONLY);
+ if (Fd < 0)
+ {
+ throw std::runtime_error("Failed to open /proc/sys/vm/drop_caches (are you running as root?)");
+ }
+
+ if (write(Fd, "3", 1) != 1)
+ {
+ close(Fd);
+ throw std::runtime_error("Failed to write to /proc/sys/vm/drop_caches");
+ }
+
+ close(Fd);
+}
+
+} // namespace zen::bench::util
+
+#elif ZEN_PLATFORM_MAC
+
+# include <cstdlib>
+
+namespace zen::bench::util {
+
+void
+EmptyStandByList()
+{
+ int Result = system("/usr/sbin/purge");
+ if (Result != 0)
+ {
+ throw std::runtime_error("Failed to run /usr/sbin/purge (are you running as root?)");
+ }
+}
+
+} // namespace zen::bench::util
+
#else
namespace zen::bench::util {