summaryrefslogtreecommitdiff
path: root/nacl/cpucycles/monotoniccpuinfo.c
diff options
context:
space:
mode:
Diffstat (limited to 'nacl/cpucycles/monotoniccpuinfo.c')
-rw-r--r--nacl/cpucycles/monotoniccpuinfo.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/nacl/cpucycles/monotoniccpuinfo.c b/nacl/cpucycles/monotoniccpuinfo.c
new file mode 100644
index 00000000..609c6305
--- /dev/null
+++ b/nacl/cpucycles/monotoniccpuinfo.c
@@ -0,0 +1,33 @@
1#include <time.h>
2#include <stdio.h>
3#include <unistd.h>
4#include <sys/time.h>
5#include <sys/types.h>
6#include <sys/sysctl.h>
7#include "osfreq.c"
8
9static double cpufrequency = 0;
10
11static void init(void)
12{
13 cpufrequency = osfreq();
14}
15
16long long cpucycles_monotoniccpuinfo(void)
17{
18 double result;
19 struct timespec t;
20 if (!cpufrequency) init();
21 clock_gettime(CLOCK_MONOTONIC,&t);
22 result = t.tv_nsec;
23 result *= 0.000000001;
24 result += (double) t.tv_sec;
25 result *= cpufrequency;
26 return result;
27}
28
29long long cpucycles_monotoniccpuinfo_persecond(void)
30{
31 if (!cpufrequency) init();
32 return cpufrequency;
33}