]> arthur.barton.de Git - netdata.git/blob - src/common.h
replace `time_usec()` calls by `now_realtime_usec()`
[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 /* select the memory allocator, based on autoconf findings */
9 #if defined(ENABLE_JEMALLOC)
10
11 #if defined(HAVE_JEMALLOC_JEMALLOC_H)
12 #include <jemalloc/jemalloc.h>
13 #else
14 #include <malloc.h>
15 #endif
16
17 #elif defined(ENABLE_TCMALLOC)
18
19 #include <google/tcmalloc.h>
20
21 #else /* !defined(ENABLE_JEMALLOC) && !defined(ENABLE_TCMALLOC) */
22
23 #ifndef __FreeBSD__
24 #include <malloc.h>
25 #endif /* __FreeBSD__ */
26
27 #endif
28
29 #include <pthread.h>
30 #include <errno.h>
31
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <stdarg.h>
35 #include <stddef.h>
36
37 #include <ctype.h>
38 #include <string.h>
39 #include <strings.h>
40
41 #include <arpa/inet.h>
42 #include <netinet/in.h>
43 #include <netinet/tcp.h>
44
45 #include <dirent.h>
46 #include <fcntl.h>
47 #include <getopt.h>
48 #include <grp.h>
49 #include <pwd.h>
50 #include <locale.h>
51
52 #include <netdb.h>
53 #include <poll.h>
54 #include <signal.h>
55 #include <syslog.h>
56 #include <sys/mman.h>
57 #ifndef __FreeBSD__
58 #include <sys/prctl.h>
59 #endif /* __FreeBSD__ */
60 #include <sys/resource.h>
61 #include <sys/socket.h>
62 #include <sys/stat.h>
63 #include <sys/statvfs.h>
64 #include <sys/syscall.h>
65 #include <sys/time.h>
66 #include <sys/types.h>
67 #include <sys/wait.h>
68 #include <time.h>
69 #include <unistd.h>
70 #include <uuid/uuid.h>
71
72 /*
73 #include <mntent.h>
74 */
75
76 #ifdef STORAGE_WITH_MATH
77 #include <math.h>
78 #endif
79
80 #if defined(HAVE_INTTYPES_H)
81 #include <inttypes.h>
82 #elif defined(HAVE_STDINT_H)
83 #include <stdint.h>
84 #endif
85
86 #ifdef NETDATA_WITH_ZLIB
87 #include <zlib.h>
88 #endif
89
90 #if (SIZEOF_VOID_P == 8)
91 #define ENVIRONMENT64
92 #elif (SIZEOF_VOID_P == 4)
93 #define ENVIRONMENT32
94 #else
95 #error "Cannot detect if this is a 32 or 64 bit CPU"
96 #endif
97
98 #ifdef __GNUC__
99 #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
100 #endif // __GNUC__
101
102 #include "avl.h"
103 #include "log.h"
104 #include "global_statistics.h"
105 #include "storage_number.h"
106 #include "web_buffer.h"
107 #include "web_buffer_svg.h"
108 #include "url.h"
109 #include "popen.h"
110
111 #include "procfile.h"
112 #include "appconfig.h"
113 #include "dictionary.h"
114 #include "proc_self_mountinfo.h"
115 #include "plugin_checks.h"
116 #include "plugin_idlejitter.h"
117 #include "plugin_nfacct.h"
118 #ifndef __FreeBSD__
119 #include "plugin_proc.h"
120 #else
121 #include "plugin_freebsd.h"
122 #endif /* __FreeBSD__ */
123 #include "plugin_tc.h"
124 #include "plugins_d.h"
125
126 #include "clocks.h"
127 #include "eval.h"
128 #include "health.h"
129
130 #include "rrd.h"
131 #include "rrd2json.h"
132
133 #include "web_client.h"
134 #include "web_server.h"
135
136 #include "registry.h"
137 #include "daemon.h"
138 #include "main.h"
139 #include "unit_test.h"
140
141 #include "ipc.h"
142 #include "backends.h"
143
144 #ifdef abs
145 #undef abs
146 #endif
147 #define abs(x) ((x < 0)? -x : x)
148
149 extern void netdata_fix_chart_id(char *s);
150 extern void netdata_fix_chart_name(char *s);
151
152 extern uint32_t simple_hash(const char *name);
153 extern uint32_t simple_uhash(const char *name);
154
155 extern void strreverse(char* begin, char* end);
156 extern char *mystrsep(char **ptr, char *s);
157 extern char *trim(char *s);
158
159 extern char *strncpyz(char *dst, const char *src, size_t n);
160 extern int  vsnprintfz(char *dst, size_t n, const char *fmt, va_list args);
161 extern int  snprintfz(char *dst, size_t n, const char *fmt, ...) __attribute__ (( format (printf, 3, 4)));
162
163 // memory allocation functions that handle failures
164 #ifdef NETDATA_LOG_ALLOCATIONS
165 #define strdupz(s) strdupz_int(__FILE__, __FUNCTION__, __LINE__, s)
166 #define callocz(nmemb, size) callocz_int(__FILE__, __FUNCTION__, __LINE__, nmemb, size)
167 #define mallocz(size) mallocz_int(__FILE__, __FUNCTION__, __LINE__, size)
168 #define reallocz(ptr, size) reallocz_int(__FILE__, __FUNCTION__, __LINE__, ptr, size)
169 #define freez(ptr) freez_int(__FILE__, __FUNCTION__, __LINE__, ptr)
170
171 extern char *strdupz_int(const char *file, const char *function, const unsigned long line, const char *s);
172 extern void *callocz_int(const char *file, const char *function, const unsigned long line, size_t nmemb, size_t size);
173 extern void *mallocz_int(const char *file, const char *function, const unsigned long line, size_t size);
174 extern void *reallocz_int(const char *file, const char *function, const unsigned long line, void *ptr, size_t size);
175 extern void freez_int(const char *file, const char *function, const unsigned long line, void *ptr);
176 #else
177 extern char *strdupz(const char *s);
178 extern void *callocz(size_t nmemb, size_t size);
179 extern void *mallocz(size_t size);
180 extern void *reallocz(void *ptr, size_t size);
181 extern void freez(void *ptr);
182 #endif
183
184 extern void *mymmap(const char *filename, size_t size, int flags, int ksm);
185 extern int savememory(const char *filename, void *mem, size_t size);
186
187 extern int fd_is_valid(int fd);
188
189 extern char *global_host_prefix;
190 extern int enable_ksm;
191
192 extern pid_t gettid(void);
193
194 extern int sleep_usec(unsigned long long usec);
195
196 extern char *fgets_trim_len(char *buf, size_t buf_size, FILE *fp, size_t *len);
197
198 extern int processors;
199 extern long get_system_cpus(void);
200
201 extern pid_t pid_max;
202 extern pid_t get_system_pid_max(void);
203
204 /* Number of ticks per second */
205 extern unsigned int hz;
206 extern void get_system_HZ(void);
207
208
209 /* fix for alpine linux */
210 #ifndef RUSAGE_THREAD
211 #ifdef RUSAGE_CHILDREN
212 #define RUSAGE_THREAD RUSAGE_CHILDREN
213 #endif
214 #endif
215
216 extern int read_single_number_file(const char *filename, unsigned long long *result);
217
218 #endif /* NETDATA_COMMON_H */