-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Time Hooks for measuring semantics performance (#1131)
This PR introduces `hook_timer_start` and `hook_timer_stop`, which can be used to measure the execution time of an instruction or an entire semantics by getting the current timestamp when starting the timer and then when stopping it, we get the current timestamp again, and save the difference into a default file `hooks_time.txt` in the current directory. --------- Co-authored-by: Theodoros Kasampalis <[email protected]>
- Loading branch information
1 parent
670ad8f
commit e098717
Showing
5 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifndef TIMER_H | ||
#define TIMER_H | ||
|
||
#include <chrono> | ||
|
||
// Macro to register a new timer. | ||
// Timers are implemented using the std::chrono::high_resolution_clock. | ||
// The unit should be one of the duration types provided in std::chrono, | ||
// e.g. seconds, microseconds, etc. | ||
#define REGISTER_TIMER(name, unit) \ | ||
static std::chrono::high_resolution_clock::time_point name##_clock_start; \ | ||
static std::chrono::high_resolution_clock::time_point name##_clock_stop; \ | ||
void name##_timer_start() { \ | ||
name##_clock_start = std::chrono::high_resolution_clock::now(); \ | ||
} \ | ||
void name##_timer_stop() { \ | ||
name##_clock_stop = std::chrono::high_resolution_clock::now(); \ | ||
} \ | ||
uint64_t name##_timer_measurement() { \ | ||
return std::chrono::duration_cast<std::chrono::unit>( \ | ||
name##_clock_stop - name##_clock_start) \ | ||
.count(); \ | ||
} | ||
|
||
#endif // TIMER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
add_library( timer STATIC | ||
timer.cpp | ||
) | ||
|
||
install( | ||
TARGETS timer | ||
ARCHIVE DESTINATION lib/kllvm | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <fstream> | ||
|
||
#include "runtime/header.h" | ||
#include "runtime/timer.h" | ||
|
||
REGISTER_TIMER(hook, nanoseconds); | ||
|
||
extern "C" { | ||
|
||
block *hook_TIMER_timerStart(void) { | ||
hook_timer_start(); | ||
|
||
return dot_k(); | ||
} | ||
|
||
block *hook_TIMER_timerStop(void) { | ||
hook_timer_stop(); | ||
|
||
std::ofstream times_file; | ||
times_file.open("hook_times.txt", std::ios_base::app); | ||
times_file << hook_timer_measurement() << std::endl; | ||
|
||
return dot_k(); | ||
} | ||
} |