-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfns.h
55 lines (50 loc) · 1.28 KB
/
fns.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
void warn(char*, ...);
void logmsg(char*);
void logerr(char*);
char* va(char*, ...);
void dprint(int, char*, ...);
void vawarn(char*, va_list);
void vadebug(char*, char*, va_list);
void initlog(void);
char* error(void);
char* estrdup(char*);
void* erealloc(void*, usize, usize);
void* emalloc(usize);
#define panic(x) {warn((x)); abort();}
void errmsg(char*, ...);
int errstr(char*, uint);
vlong μsec(void);
void lsleep(vlong);
void sysquit(void);
void quit(void);
void initsys(void);
void xsrand(u64int);
float xfrand(void);
u32int xlrand(void);
u32int xnrand(u32int);
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
void newthread(void (*)(void*), void (*)(void*), void*, void*, char*, uint);
void* threadstore(void*);
#define DPRINT(x,...) do{ \
if((debug&(x)) != 0) \
dprint((x), __VA_ARGS__); \
}while(0)
/* FIXME: get something better */
#define CLK0(c) if((debug & Debugperf) != 0){ \
(c).t = μsec(); \
if((c).t0 == 0) \
(c).t0 = (c).t; \
(c).n++; \
}
#define CLK1(c) if((debug & Debugperf) != 0){ \
vlong _t = μsec(); \
(c).s += (_t - (c).t) / 1000000.0; \
(c).n++; \
if(_t - (c).t0 >= PerfΔt){ \
(c).t0 = _t; \
_t = (vlong)(((c).s / (c).n) * 1000000.0); \
warn("[perf] %s: avg %lld μs over %lld samples\n", \
(c).lab, _t, (c).n); \
} \
}