Derecho  0.9
Distributed systems toolkit for RDMA
time.h
Go to the documentation of this file.
1 
2 #ifndef TIME_TIME_H
3 #define TIME_TIME_H
4 
5 #include <cstdint>
6 #include <sys/resource.h>
7 #include <time.h>
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif//__cplusplus
12 // Returns the number of nanoseconds since some fixed time in the past.
13 inline uint64_t get_time() {
14  struct timespec now;
15  clock_gettime(CLOCK_MONOTONIC, &now);
16  return now.tv_sec * 1000000000L + now.tv_nsec;
17 }
18 
19 // Returns the number of nanoseconds of CPU time that have been used by this
20 // process since some fixed time in the past.
21 inline uint64_t get_process_time() {
22  rusage usage;
23  getrusage(RUSAGE_SELF, &usage);
24  return (usage.ru_utime.tv_sec + usage.ru_stime.tv_sec) * 1000000000L + (usage.ru_utime.tv_usec + usage.ru_stime.tv_usec) * 1000L;
25 }
26 
27 #ifdef __cplusplus
28 }
29 #endif//__cplusplus
30 
31 #endif /* TIME_TIME_H */
uint64_t get_time()
Definition: time.h:13
uint64_t get_process_time()
Definition: time.h:21