-
Notifications
You must be signed in to change notification settings - Fork 48
/
periodic_calls.cpp
51 lines (40 loc) · 1.35 KB
/
periodic_calls.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#ifdef RECKLESS_ENABLE_TRACE_LOG
#include <performance_log/trace_log.hpp>
#include <fstream>
#endif
#include <performance_log/performance_log.hpp>
#include <iostream>
#include <unistd.h>
#include LOG_INCLUDE
char c = 'A';
float pi = 3.1415;
int main()
{
unlink("log.txt");
performance_log::logger<4096, performance_log::rdtscp_cpuid_clock> performance_log;
{
LOG_INIT(6000);
performance_log::rdtscp_cpuid_clock::bind_cpu(0);
for(int i=0; i!=2500; ++i) {
usleep(1000);
struct timespec busywait_start;
clock_gettime(CLOCK_REALTIME, &busywait_start);
struct timespec busywait_end = busywait_start;
while( (busywait_end.tv_sec - busywait_start.tv_sec)*1000000 + busywait_end.tv_nsec - busywait_start.tv_nsec < 1000 )
clock_gettime(CLOCK_REALTIME, &busywait_end);
auto start = performance_log.start();
LOG(c, i, pi);
performance_log.stop(start);
}
performance_log::rdtscp_cpuid_clock::unbind_cpu();
LOG_CLEANUP();
}
for(auto sample : performance_log) {
std::cout << sample.start << ' ' << sample.stop << std::endl;
}
#ifdef RECKLESS_ENABLE_TRACE_LOG
std::ofstream trace_log("trace_log.txt", std::ios::trunc);
reckless::detail::g_trace_log.save(trace_log);
#endif
return 0;
}