File tree 5 files changed +60
-0
lines changed 5 files changed +60
-0
lines changed Original file line number Diff line number Diff line change @@ -263,6 +263,7 @@ if $link; then
263
263
" $LIBDIR " /libcollect.a
264
264
" $LIBDIR " /libmeta.a
265
265
" $LIBDIR " /libjson.a
266
+ " $LIBDIR " /libtimer.a
266
267
)
267
268
268
269
components=(
Original file line number Diff line number Diff line change
1
+ #ifndef TIMER_H
2
+ #define TIMER_H
3
+
4
+ #include < chrono>
5
+
6
+ // Macro to register a new timer.
7
+ // Timers are implemented using the std::chrono::high_resolution_clock.
8
+ // The unit should be one of the duration types provided in std::chrono,
9
+ // e.g. seconds, microseconds, etc.
10
+ #define REGISTER_TIMER (name, unit ) \
11
+ static std::chrono::high_resolution_clock::time_point name##_clock_start; \
12
+ static std::chrono::high_resolution_clock::time_point name##_clock_stop; \
13
+ void name##_timer_start() { \
14
+ name##_clock_start = std::chrono::high_resolution_clock::now (); \
15
+ } \
16
+ void name##_timer_stop() { \
17
+ name##_clock_stop = std::chrono::high_resolution_clock::now (); \
18
+ } \
19
+ uint64_t name##_timer_measurement() { \
20
+ return std::chrono::duration_cast<std::chrono::unit>( \
21
+ name##_clock_stop - name##_clock_start) \
22
+ .count (); \
23
+ }
24
+
25
+ #endif // TIMER_H
Original file line number Diff line number Diff line change @@ -19,3 +19,4 @@ add_subdirectory(lto)
19
19
add_subdirectory (meta)
20
20
add_subdirectory (strings )
21
21
add_subdirectory (util)
22
+ add_subdirectory (timer)
Original file line number Diff line number Diff line change
1
+ add_library ( timer STATIC
2
+ timer.cpp
3
+ )
4
+
5
+ install (
6
+ TARGETS timer
7
+ ARCHIVE DESTINATION lib/kllvm
8
+ )
Original file line number Diff line number Diff line change
1
+ #include < fstream>
2
+
3
+ #include " runtime/header.h"
4
+ #include " runtime/timer.h"
5
+
6
+ REGISTER_TIMER (hook, nanoseconds);
7
+
8
+ extern " C" {
9
+
10
+ block *hook_TIMER_timerStart (void ) {
11
+ hook_timer_start ();
12
+
13
+ return dot_k ();
14
+ }
15
+
16
+ block *hook_TIMER_timerStop (void ) {
17
+ hook_timer_stop ();
18
+
19
+ std::ofstream times_file;
20
+ times_file.open (" hook_times.txt" , std::ios_base::app);
21
+ times_file << hook_timer_measurement () << std::endl;
22
+
23
+ return dot_k ();
24
+ }
25
+ }
You can’t perform that action at this time.
0 commit comments