From 2596cfeb2a831397dca8e120a32cd1b6b6af099e Mon Sep 17 00:00:00 2001 From: Lukas Rothenberger Date: Thu, 17 Oct 2024 13:40:26 +0200 Subject: [PATCH] feat(profiler)[statistics]: profiling time --- DiscoPoP/llvm_hooks/doInitialization.cpp | 7 +++++++ rtlib/injected_functions/dp_finalize.cpp | 18 ++++++++++++++++++ rtlib/injected_functions/dp_func_entry.cpp | 2 ++ rtlib/runtimeFunctionsGlobals.cpp | 3 +++ rtlib/runtimeFunctionsGlobals.hpp | 4 ++++ 5 files changed, 34 insertions(+) diff --git a/DiscoPoP/llvm_hooks/doInitialization.cpp b/DiscoPoP/llvm_hooks/doInitialization.cpp index 64a648d94..00295c6df 100644 --- a/DiscoPoP/llvm_hooks/doInitialization.cpp +++ b/DiscoPoP/llvm_hooks/doInitialization.cpp @@ -36,6 +36,13 @@ bool DiscoPoP::doInitialization(Module &M) { if (stat(getenv("DOT_DISCOPOP_PROFILER"), &st2) == -1) { mkdir(getenv("DOT_DISCOPOP_PROFILER"), 0777); } + // prepare statistics directory if not present + struct stat st3 = {0}; + std::string tmp_str_2(getenv("DOT_DISCOPOP_PROFILER")); + tmp_str_2 += "/statistics"; + if (stat(tmp_str_2.data(), &st3) == -1) { + mkdir(tmp_str_2.data(), 0777); + } // prepare target directory if not present char const *tmp2 = getenv("DP_PROJECT_ROOT_DIR"); diff --git a/rtlib/injected_functions/dp_finalize.cpp b/rtlib/injected_functions/dp_finalize.cpp index b05fec996..1ca9bd124 100644 --- a/rtlib/injected_functions/dp_finalize.cpp +++ b/rtlib/injected_functions/dp_finalize.cpp @@ -25,6 +25,7 @@ #include #include #include +#include using namespace std; @@ -189,6 +190,23 @@ void __dp_finalize(LID lid) { delete out; + // output elapsed time for profiling + std::chrono::milliseconds time_elapsed = std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - statistics_profiling_start_time); +#ifdef __linux__ + // try to get an output file name w.r.t. the target application + // if it is not available, fall back to "Output.txt" + char *selfPath = new char[PATH_MAX]; + if (selfPath != nullptr) { + std::string tmp2(getenv("DOT_DISCOPOP_PROFILER")); + tmp2 += "/statistics/profiling_time.txt"; + std::ofstream stats_file; + stats_file.open(tmp2.data(), ios::out); + stats_file << std::to_string(time_elapsed.count()) << " ms\n"; + stats_file.flush(); + stats_file.close(); + } +#endif + dpInited = false; targetTerminated = true; // mark the target program has returned from main() diff --git a/rtlib/injected_functions/dp_func_entry.cpp b/rtlib/injected_functions/dp_func_entry.cpp index 0691507a6..a4f4013e9 100644 --- a/rtlib/injected_functions/dp_func_entry.cpp +++ b/rtlib/injected_functions/dp_func_entry.cpp @@ -25,6 +25,7 @@ #include #include #include +#include using namespace std; @@ -52,6 +53,7 @@ void __dp_func_entry(LID lid, int32_t isStart) { // This part should be executed only once. readRuntimeInfo(); timers = new Timers(); + statistics_profiling_start_time = std::chrono::high_resolution_clock::now(); #ifdef DP_INTERNAL_TIMER const auto timer = Timer(timers, TimerRegion::FUNC_ENTRY); #endif diff --git a/rtlib/runtimeFunctionsGlobals.cpp b/rtlib/runtimeFunctionsGlobals.cpp index a8a8f10d5..5ea2b3bb3 100644 --- a/rtlib/runtimeFunctionsGlobals.cpp +++ b/rtlib/runtimeFunctionsGlobals.cpp @@ -86,6 +86,9 @@ bool stop = false; // ONLY set stop to true if no more // be collected thread_local depMap *myMap = nullptr; +// statistics +std::chrono::high_resolution_clock::time_point statistics_profiling_start_time; + /******* END: parallelization section *******/ } // namespace __dp diff --git a/rtlib/runtimeFunctionsGlobals.hpp b/rtlib/runtimeFunctionsGlobals.hpp index 0da5fc242..4ca5c4b92 100644 --- a/rtlib/runtimeFunctionsGlobals.hpp +++ b/rtlib/runtimeFunctionsGlobals.hpp @@ -30,6 +30,7 @@ #include #include #include +#include extern bool USE_PERFECT; @@ -98,4 +99,7 @@ extern bool stop; // ONLY set stop to true if no more accessed // be collected extern thread_local depMap *myMap; +// statistics +extern std::chrono::high_resolution_clock::time_point statistics_profiling_start_time; + } // namespace __dp