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/in.h>
43 #include <netinet/tcp.h>
58 #include <sys/prctl.h>
59 #endif /* __FreeBSD__ */
60 #include <sys/resource.h>
61 #include <sys/socket.h>
63 #include <sys/statvfs.h>
64 #include <sys/syscall.h>
66 #include <sys/types.h>
70 #include <uuid/uuid.h>
76 #ifdef STORAGE_WITH_MATH
80 #if defined(HAVE_INTTYPES_H)
82 #elif defined(HAVE_STDINT_H)
86 #ifdef NETDATA_WITH_ZLIB
90 #if (SIZEOF_VOID_P == 8)
92 #elif (SIZEOF_VOID_P == 4)
95 #error "Cannot detect if this is a 32 or 64 bit CPU"
99 #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
104 #include "global_statistics.h"
105 #include "storage_number.h"
106 #include "web_buffer.h"
107 #include "web_buffer_svg.h"
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"
119 #include "plugin_proc.h"
121 #include "plugin_freebsd.h"
122 #endif /* __FreeBSD__ */
123 #include "plugin_tc.h"
124 #include "plugins_d.h"
130 #include "rrd2json.h"
132 #include "web_client.h"
133 #include "web_server.h"
135 #include "registry.h"
138 #include "unit_test.h"
141 #include "backends.h"
146 #define abs(x) ((x < 0)? -x : x)
148 extern unsigned long long usec_dt(struct timeval *now, struct timeval *old);
149 extern unsigned long long timeval_usec(struct timeval *tv);
151 // #define usec_dt(now, last) (((((now)->tv_sec * 1000000ULL) + (now)->tv_usec) - (((last)->tv_sec * 1000000ULL) + (last)->tv_usec)))
153 extern void netdata_fix_chart_id(char *s);
154 extern void netdata_fix_chart_name(char *s);
156 extern uint32_t simple_hash(const char *name);
157 extern uint32_t simple_uhash(const char *name);
159 extern void strreverse(char* begin, char* end);
160 extern char *mystrsep(char **ptr, char *s);
161 extern char *trim(char *s);
163 extern char *strncpyz(char *dst, const char *src, size_t n);
164 extern int vsnprintfz(char *dst, size_t n, const char *fmt, va_list args);
165 extern int snprintfz(char *dst, size_t n, const char *fmt, ...) __attribute__ (( format (printf, 3, 4)));
167 // memory allocation functions that handle failures
168 #ifdef NETDATA_LOG_ALLOCATIONS
169 #define strdupz(s) strdupz_int(__FILE__, __FUNCTION__, __LINE__, s)
170 #define callocz(nmemb, size) callocz_int(__FILE__, __FUNCTION__, __LINE__, nmemb, size)
171 #define mallocz(size) mallocz_int(__FILE__, __FUNCTION__, __LINE__, size)
172 #define reallocz(ptr, size) reallocz_int(__FILE__, __FUNCTION__, __LINE__, ptr, size)
173 #define freez(ptr) freez_int(__FILE__, __FUNCTION__, __LINE__, ptr)
175 extern char *strdupz_int(const char *file, const char *function, const unsigned long line, const char *s);
176 extern void *callocz_int(const char *file, const char *function, const unsigned long line, size_t nmemb, size_t size);
177 extern void *mallocz_int(const char *file, const char *function, const unsigned long line, size_t size);
178 extern void *reallocz_int(const char *file, const char *function, const unsigned long line, void *ptr, size_t size);
179 extern void freez_int(const char *file, const char *function, const unsigned long line, void *ptr);
181 extern char *strdupz(const char *s);
182 extern void *callocz(size_t nmemb, size_t size);
183 extern void *mallocz(size_t size);
184 extern void *reallocz(void *ptr, size_t size);
185 extern void freez(void *ptr);
188 extern void *mymmap(const char *filename, size_t size, int flags, int ksm);
189 extern int savememory(const char *filename, void *mem, size_t size);
191 extern int fd_is_valid(int fd);
193 extern char *global_host_prefix;
194 extern int enable_ksm;
196 extern pid_t gettid(void);
198 extern unsigned long long time_usec(void);
199 extern int sleep_usec(unsigned long long usec);
201 extern char *fgets_trim_len(char *buf, size_t buf_size, FILE *fp, size_t *len);
203 extern int processors;
204 extern long get_system_cpus(void);
206 extern pid_t pid_max;
207 extern pid_t get_system_pid_max(void);
209 /* Number of ticks per second */
210 extern unsigned int hz;
211 extern void get_system_HZ(void);
214 /* fix for alpine linux */
215 #ifndef RUSAGE_THREAD
216 #ifdef RUSAGE_CHILDREN
217 #define RUSAGE_THREAD RUSAGE_CHILDREN
221 extern int read_single_number_file(const char *filename, unsigned long long *result);
223 #endif /* NETDATA_COMMON_H */