1 #ifndef NETDATA_COMMON_H
2 #define NETDATA_COMMON_H 1
8 /* select the memory allocator, based on autoconf findings */
9 #if defined(ENABLE_JEMALLOC)
11 #if defined(HAVE_JEMALLOC_JEMALLOC_H)
12 #include <jemalloc/jemalloc.h>
17 #elif defined(ENABLE_TCMALLOC)
19 #include <google/tcmalloc.h>
21 #else /* !defined(ENABLE_JEMALLOC) && !defined(ENABLE_TCMALLOC) */
25 #endif /* __FreeBSD__ */
41 #include <arpa/inet.h>
42 #include <netinet/tcp.h>
44 #ifdef HAVE_NETINET_IN_H
45 #include <netinet/in.h>
68 #include <sys/prctl.h>
69 #endif /* __FreeBSD__ */
70 #include <sys/resource.h>
71 #include <sys/socket.h>
73 #include <sys/statvfs.h>
74 #include <sys/syscall.h>
76 #include <sys/types.h>
80 #include <uuid/uuid.h>
84 #include <sys/mkdev.h>
86 #ifdef MAJOR_IN_SYSMACROS
87 #include <sys/sysmacros.h>
94 #ifdef STORAGE_WITH_MATH
98 #if defined(HAVE_INTTYPES_H)
100 #elif defined(HAVE_STDINT_H)
104 #ifdef NETDATA_WITH_ZLIB
108 #if (SIZEOF_VOID_P == 8)
109 #define ENVIRONMENT64
110 #elif (SIZEOF_VOID_P == 4)
111 #define ENVIRONMENT32
113 #error "Cannot detect if this is a 32 or 64 bit CPU"
117 #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
123 #include "global_statistics.h"
124 #include "storage_number.h"
125 #include "web_buffer.h"
126 #include "web_buffer_svg.h"
130 #include "procfile.h"
131 #include "appconfig.h"
132 #include "dictionary.h"
133 #include "proc_self_mountinfo.h"
134 #include "plugin_checks.h"
135 #include "plugin_idlejitter.h"
136 #include "plugin_nfacct.h"
138 #include "plugin_proc.h"
140 #include "plugin_freebsd.h"
141 #endif /* __FreeBSD__ */
142 #include "plugin_tc.h"
143 #include "plugins_d.h"
149 #include "rrd2json.h"
151 #include "web_client.h"
152 #include "web_server.h"
154 #include "registry.h"
157 #include "unit_test.h"
160 #include "backends.h"
165 #define abs(x) ((x < 0)? -x : x)
167 extern void netdata_fix_chart_id(char *s);
168 extern void netdata_fix_chart_name(char *s);
170 extern uint32_t simple_hash(const char *name);
171 extern uint32_t simple_uhash(const char *name);
173 extern void strreverse(char* begin, char* end);
174 extern char *mystrsep(char **ptr, char *s);
175 extern char *trim(char *s);
177 extern char *strncpyz(char *dst, const char *src, size_t n);
178 extern int vsnprintfz(char *dst, size_t n, const char *fmt, va_list args);
179 extern int snprintfz(char *dst, size_t n, const char *fmt, ...) __attribute__ (( format (printf, 3, 4)));
181 // memory allocation functions that handle failures
182 #ifdef NETDATA_LOG_ALLOCATIONS
183 #define strdupz(s) strdupz_int(__FILE__, __FUNCTION__, __LINE__, s)
184 #define callocz(nmemb, size) callocz_int(__FILE__, __FUNCTION__, __LINE__, nmemb, size)
185 #define mallocz(size) mallocz_int(__FILE__, __FUNCTION__, __LINE__, size)
186 #define reallocz(ptr, size) reallocz_int(__FILE__, __FUNCTION__, __LINE__, ptr, size)
187 #define freez(ptr) freez_int(__FILE__, __FUNCTION__, __LINE__, ptr)
189 extern char *strdupz_int(const char *file, const char *function, const unsigned long line, const char *s);
190 extern void *callocz_int(const char *file, const char *function, const unsigned long line, size_t nmemb, size_t size);
191 extern void *mallocz_int(const char *file, const char *function, const unsigned long line, size_t size);
192 extern void *reallocz_int(const char *file, const char *function, const unsigned long line, void *ptr, size_t size);
193 extern void freez_int(const char *file, const char *function, const unsigned long line, void *ptr);
195 extern char *strdupz(const char *s);
196 extern void *callocz(size_t nmemb, size_t size);
197 extern void *mallocz(size_t size);
198 extern void *reallocz(void *ptr, size_t size);
199 extern void freez(void *ptr);
202 extern void json_escape_string(char *dst, const char *src, size_t size);
204 extern void *mymmap(const char *filename, size_t size, int flags, int ksm);
205 extern int savememory(const char *filename, void *mem, size_t size);
207 extern int fd_is_valid(int fd);
209 extern char *global_host_prefix;
210 extern int enable_ksm;
212 extern pid_t gettid(void);
214 extern int sleep_usec(usec_t usec);
216 extern char *fgets_trim_len(char *buf, size_t buf_size, FILE *fp, size_t *len);
218 extern int processors;
219 extern long get_system_cpus(void);
221 extern pid_t pid_max;
222 extern pid_t get_system_pid_max(void);
224 /* Number of ticks per second */
225 extern unsigned int hz;
226 extern void get_system_HZ(void);
229 /* fix for alpine linux */
230 #ifndef RUSAGE_THREAD
231 #ifdef RUSAGE_CHILDREN
232 #define RUSAGE_THREAD RUSAGE_CHILDREN
236 extern int read_single_number_file(const char *filename, unsigned long long *result);
238 #endif /* NETDATA_COMMON_H */