forked from googleprojectzero/functionsimsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththreadtimer.cpp
33 lines (28 loc) · 838 Bytes
/
threadtimer.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
#include <chrono>
#include <cstdarg>
#include <cstdio>
#include <thread>
#include "threadtimer.hpp"
namespace profile {
#ifdef PROFILE
static thread_local std::chrono::time_point<
std::chrono::high_resolution_clock> timepoint;
void ResetClock() {
timepoint = std::chrono::high_resolution_clock::now();
}
void ClockCheckpoint(const char* format, ...) {
va_list args;
auto microseconds = std::chrono::duration_cast<
std::chrono::microseconds>(std::chrono::high_resolution_clock::now() -
timepoint);
printf("[Thread %d Profiling: %ld microseconds] ",
std::this_thread::get_id(), microseconds);
va_start(args, format);
vprintf(format, args);
timepoint = std::chrono::high_resolution_clock::now();
}
#else
void ResetClock() {};
void ClockCheckpoint(const char* format, ...) {};
#endif
} // namespace profile