From bf10a9471979e1eaae4d12aa20e4bea45cfb7506 Mon Sep 17 00:00:00 2001 From: Vukasin Milovanovic Date: Fri, 29 Apr 2022 16:41:22 -0700 Subject: [PATCH] Flush output streams before creating a process to drop caches (#10762) Small improvement for the `try_drop_l3_cache` feature in cuIO benchmarks. Prevents unflushed output from the original process from intermingling with the output from the `popen` process. Authors: - Vukasin Milovanovic (https://github.com/vuule) Approvers: - https://github.com/nvdbaranec - Bradley Dice (https://github.com/bdice) URL: https://github.com/rapidsai/cudf/pull/10762 --- cpp/benchmarks/io/cuio_common.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cpp/benchmarks/io/cuio_common.cpp b/cpp/benchmarks/io/cuio_common.cpp index 7d356263220..da64c1bbf3c 100644 --- a/cpp/benchmarks/io/cuio_common.cpp +++ b/cpp/benchmarks/io/cuio_common.cpp @@ -16,6 +16,7 @@ #include +#include #include #include #include @@ -145,6 +146,8 @@ std::vector segments_in_chunk(int num_segments, int num_chunks, // Executes the command and returns stderr output std::string exec_cmd(std::string_view cmd) { + // Prevent the output from the command from mixing with the original process' output + std::fflush(nullptr); // Switch stderr and stdout to only capture stderr auto const redirected_cmd = std::string{"( "}.append(cmd).append(" 3>&2 2>&1 1>&3) 2>/dev/null"); std::unique_ptr pipe(popen(redirected_cmd.c_str(), "r"), pclose);