Skip to content

Commit c578d04

Browse files
committed
Merge remote-tracking branch 'origin/develop'
2 parents e7266f7 + e098717 commit c578d04

File tree

5 files changed

+60
-0
lines changed

5 files changed

+60
-0
lines changed

bin/llvm-kompile-clang

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ if $link; then
263263
"$LIBDIR"/libcollect.a
264264
"$LIBDIR"/libmeta.a
265265
"$LIBDIR"/libjson.a
266+
"$LIBDIR"/libtimer.a
266267
)
267268

268269
components=(

include/runtime/timer.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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

runtime/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ add_subdirectory(lto)
1919
add_subdirectory(meta)
2020
add_subdirectory(strings)
2121
add_subdirectory(util)
22+
add_subdirectory(timer)

runtime/timer/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
add_library( timer STATIC
2+
timer.cpp
3+
)
4+
5+
install(
6+
TARGETS timer
7+
ARCHIVE DESTINATION lib/kllvm
8+
)

runtime/timer/timer.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
}

0 commit comments

Comments
 (0)