Add some support for CPU profiling

This commit is contained in:
2021-12-17 16:21:56 -05:00
parent cfa6c28d34
commit 227a754b21
4 changed files with 33 additions and 1 deletions

View File

@@ -10,13 +10,26 @@
#include <cassert>
#include <algorithm>
#ifdef WIN32
#endif
#ifndef WIN32
#include <time.h>
#include <unistd.h>
#define stat _stat
#endif
namespace util {
int64_t profiling_clock() {
#ifdef WIN32
return 0.0;
#else
struct timespec ts;
assert(0 == clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts));
return int64_t(ts.tv_nsec) + (int64_t(ts.tv_sec)*int64_t(1000000000));
#endif
}
static bool ascii_isalpha(char c) {
return ((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z'));
}