summaryrefslogtreecommitdiff
path: root/src/rtapp_utils.h
blob: db71b4ae1fb80a54433c909167b147f3e6ae9c46 (plain)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#ifndef _TIMESPEC_UTILS_H_
#define _TIMESPEC_UTILS_H_

#include <time.h>
#include <math.h>
#include <stdio.h>
#include "rtapp_types.h"

#ifndef LOG_PREFIX
#define LOG_PREFIX "[rt-app] "
#endif
#ifndef LOG_LEVEL
#define LOG_LEVEL 50
#endif

#define LOG_LEVEL_DEBUG 100
#define LOG_LEVEL_INFO 50
#define LOG_LEVEL_ERROR 10
#define LOG_LEVEL_CRITICAL 10

/* This prepend a string to a message */
#define rtapp_log_to(where, level, msg, args...)			\
do {									\
    if (level <= LOG_LEVEL) {						\
        fprintf(where, LOG_PREFIX msg "\n", ##args);			\
    }									\
} while (0);

#define log_info(msg, args...)						\
do {									\
    rtapp_log_to(stderr, LOG_LEVEL_INFO, msg, ##args);			\
} while (0);

#define log_error(msg, args...)						\
do {									\
    rtapp_log_to(stderr, LOG_LEVEL_ERROR, msg, ##args);			\
} while (0);

#define log_debug(msg, args...)						\
do {									\
    rtapp_log_to(stderr, LOG_LEVEL_DEBUG, msg, ##args);			\
} while (0);

#define log_critical(msg, args...)					\
do {									\
    rtapp_log_to(stderr, LOG_LEVEL_CRITICAL, msg, ##args);		\
} while (0);

unsigned int 
timespec_to_msec(struct timespec *ts);

long 
timespec_to_lusec(struct timespec *ts);

unsigned long 
timespec_to_usec(struct timespec *ts);

struct timespec 
usec_to_timespec(unsigned long usec);

struct timespec 
usec_to_timespec(unsigned long usec);

struct timespec 
msec_to_timespec(unsigned int msec);

struct timespec 
timespec_add(struct timespec *t1, struct timespec *t2);

struct timespec 
timespec_sub(struct timespec *t1, struct timespec *t2);

int 
timespec_lower(struct timespec *what, struct timespec *than);

void
log_timing(FILE *handler, timing_point_t *t);

#endif // _TIMESPEC_UTILS_H_ 

/* vim: set ts=8 noexpandtab shiftwidth=8: */