forked from sumerc/yappi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
timing.h
60 lines (44 loc) · 1.26 KB
/
timing.h
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
52
53
54
55
56
57
58
#include "config.h"
#ifndef YTIMING_H
#define YTIMING_H
#if defined(_WINDOWS)
#include <windows.h>
#define USE_CLOCK_TYPE_GETTHREADTIMES
#elif defined(_MACH)
#include <mach/mach.h>
#include <mach/thread_info.h>
#define USE_CLOCK_TYPE_THREADINFO
#elif defined(_UNIX)
#include <time.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/resource.h>
/*
Policy of clock usage on *nix systems is as follows:
1) If clock_gettime() is possible, then use it, it has nanosecond
resolution. It is available in >Linux 2.6.0.
2) If get_rusage() is possible use that. >Linux 2.6.26 and Solaris have that.
*/
#if (defined(_POSIX_THREAD_CPUTIME) && defined(LIB_RT_AVAILABLE))
#define USE_CLOCK_TYPE_CLOCKGETTIME
#elif (defined(RUSAGE_THREAD) || defined(RUSAGE_LWP))
#define USE_CLOCK_TYPE_RUSAGE
#if defined(RUSAGE_LWP)
#define RUSAGE_WHO RUSAGE_LWP
#elif defined(RUSAGE_THREAD)
#define RUSAGE_WHO RUSAGE_THREAD
#else
#error "No OS API found for getting cpu time per thread."
#endif
#endif
#endif
typedef enum
{
WALL_CLOCK = 0x00,
CPU_CLOCK = 0x01,
}clock_type_t;
long long tickcount(void);
double tickfactor(void);
int set_timing_clock_type(clock_type_t type);
clock_type_t get_timing_clock_type(void);
#endif