Skip to content

Commit

Permalink
feat(profiler)[statistics]: profiling time
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasrothenberger committed Oct 23, 2024
1 parent 284c32c commit 2596cfe
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 0 deletions.
7 changes: 7 additions & 0 deletions DiscoPoP/llvm_hooks/doInitialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
18 changes: 18 additions & 0 deletions rtlib/injected_functions/dp_finalize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <mutex>
#include <set>
#include <string>
#include <chrono>

using namespace std;

Expand Down Expand Up @@ -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::milliseconds>(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()

Expand Down
2 changes: 2 additions & 0 deletions rtlib/injected_functions/dp_func_entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <mutex>
#include <set>
#include <string>
#include <chrono>

using namespace std;

Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions rtlib/runtimeFunctionsGlobals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions rtlib/runtimeFunctionsGlobals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <tuple>
#include <unordered_map>
#include <utility>
#include <chrono>

extern bool USE_PERFECT;

Expand Down Expand Up @@ -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

0 comments on commit 2596cfe

Please sign in to comment.