-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.c
51 lines (43 loc) · 996 Bytes
/
log.c
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
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <errno.h>
#include <stdint.h>
#include <time.h>
#include <stdarg.h>
#include <math.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <pthread.h>
#include <semaphore.h>
#include <sys/wait.h>
#include "log.h"
uint64_t zero = 0;
uint64_t get_ms_time() {
uint64_t ms; // Milliseconds
time_t s; // Seconds
struct timespec spec;
clock_gettime(CLOCK_REALTIME, &spec);
s = spec.tv_sec;
ms = spec.tv_nsec / 1000000; // Convert nanoseconds to milliseconds
if (ms > 999) {
s++;
ms = 0;
}
ms+=s*1000;
return ms;
}
void Log(char* msg, ...)
{
if (zero == 0) {
zero = get_ms_time();
}
uint32_t t = get_ms_time() - zero;
fprintf(stderr, "%09d ", t);
va_list args;
va_start(args, msg);
vfprintf(stderr, msg, args);
va_end(args);
}