]> arthur.barton.de Git - netdata.git/blob - src/common.h
detect compiler atomic instructions using autoconf
[netdata.git] / src / common.h
1 #ifndef NETDATA_COMMON_H
2 #define NETDATA_COMMON_H 1
3
4 #ifdef HAVE_CONFIG_H
5 #include <config.h>
6 #endif
7
8 #include <pthread.h>
9 #include <errno.h>
10
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <stdarg.h>
14 #include <stddef.h>
15
16 #include <ctype.h>
17 #include <string.h>
18 #include <strings.h>
19
20 #include <arpa/inet.h>
21 #include <netinet/in.h>
22 #include <netinet/tcp.h>
23
24 #include <dirent.h>
25 #include <fcntl.h>
26 #include <getopt.h>
27 #include <grp.h>
28 #include <pwd.h>
29 #include <locale.h>
30 #include <malloc.h>
31 #include <netdb.h>
32 #include <poll.h>
33 #include <signal.h>
34 #include <syslog.h>
35 #include <sys/mman.h>
36 #include <sys/prctl.h>
37 #include <sys/resource.h>
38 #include <sys/socket.h>
39 #include <sys/stat.h>
40 #include <sys/statvfs.h>
41 #include <sys/syscall.h>
42 #include <sys/time.h>
43 #include <sys/types.h>
44 #include <sys/wait.h>
45 #include <time.h>
46 #include <unistd.h>
47 #include <uuid/uuid.h>
48
49 #ifdef STORAGE_WITH_MATH
50 #include <math.h>
51 #endif
52
53 #if defined(HAVE_INTTYPES_H)
54 #include <inttypes.h>
55 #elif defined(HAVE_STDINT_H)
56 #include <stdint.h>
57 #endif
58
59 #ifdef NETDATA_WITH_ZLIB
60 #include <zlib.h>
61 #endif
62
63 #ifdef __GNUC__
64 #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
65
66 #if __x86_64__ || __ppc64__
67 #define ENVIRONMENT64
68 #else
69 #define ENVIRONMENT32
70 #endif
71
72 #else // !__GNUC__
73 #define NETDATA_NO_ATOMIC_INSTRUCTIONS 1
74 #define ENVIRONMENT32
75 #endif // __GNUC__
76
77 #include "avl.h"
78 #include "log.h"
79 #include "global_statistics.h"
80 #include "storage_number.h"
81 #include "web_buffer.h"
82 #include "web_buffer_svg.h"
83 #include "url.h"
84 #include "popen.h"
85
86 #include "procfile.h"
87 #include "appconfig.h"
88 #include "dictionary.h"
89 #include "proc_self_mountinfo.h"
90 #include "plugin_checks.h"
91 #include "plugin_idlejitter.h"
92 #include "plugin_nfacct.h"
93 #include "plugin_proc.h"
94 #include "plugin_tc.h"
95 #include "plugins_d.h"
96
97 #include "eval.h"
98 #include "health.h"
99
100 #include "rrd.h"
101 #include "rrd2json.h"
102
103 #include "web_client.h"
104 #include "web_server.h"
105
106 #include "registry.h"
107 #include "daemon.h"
108 #include "main.h"
109 #include "unit_test.h"
110
111 #ifdef abs
112 #undef abs
113 #endif
114 #define abs(x) ((x < 0)? -x : x)
115
116 extern unsigned long long usec_dt(struct timeval *now, struct timeval *old);
117 extern unsigned long long timeval_usec(struct timeval *tv);
118
119 // #define usec_dt(now, last) (((((now)->tv_sec * 1000000ULL) + (now)->tv_usec) - (((last)->tv_sec * 1000000ULL) + (last)->tv_usec)))
120
121 extern void netdata_fix_chart_id(char *s);
122 extern void netdata_fix_chart_name(char *s);
123
124 extern uint32_t simple_hash(const char *name);
125 extern uint32_t simple_uhash(const char *name);
126
127 extern void strreverse(char* begin, char* end);
128 extern char *mystrsep(char **ptr, char *s);
129 extern char *trim(char *s);
130
131 extern char *strncpyz(char *dst, const char *src, size_t n);
132 extern int  vsnprintfz(char *dst, size_t n, const char *fmt, va_list args);
133 extern int  snprintfz(char *dst, size_t n, const char *fmt, ...) __attribute__ (( format (printf, 3, 4)));
134
135 // memory allocation functions that handle failures
136 extern char *strdupz(const char *s);
137 extern void *callocz(size_t nmemb, size_t size);
138 extern void *mallocz(size_t size);
139 extern void freez(void *ptr);
140 extern void *reallocz(void *ptr, size_t size);
141
142 extern void *mymmap(const char *filename, size_t size, int flags, int ksm);
143 extern int savememory(const char *filename, void *mem, size_t size);
144
145 extern int fd_is_valid(int fd);
146
147 extern char *global_host_prefix;
148 extern int enable_ksm;
149
150 extern pid_t gettid(void);
151
152 extern unsigned long long time_usec(void);
153 extern int sleep_usec(unsigned long long usec);
154
155 extern char *fgets_trim_len(char *buf, size_t buf_size, FILE *fp, size_t *len);
156
157 extern int processors;
158 extern long get_system_cpus(void);
159
160 extern pid_t pid_max;
161 extern pid_t get_system_pid_max(void);
162
163 /* Number of ticks per second */
164 extern unsigned int hz;
165 extern void get_system_HZ(void);
166
167
168 /* fix for alpine linux */
169 #ifndef RUSAGE_THREAD
170 #ifdef RUSAGE_CHILDREN
171 #define RUSAGE_THREAD RUSAGE_CHILDREN
172 #endif
173 #endif
174
175 #endif /* NETDATA_COMMON_H */