1 #ifndef NETDATA_COMMON_H
2 #define NETDATA_COMMON_H 1
9 #include <jemalloc/jemalloc.h>
11 #undef HAVE_C_MALLINFO
13 #include <google/tcmalloc.h>
15 #undef HAVE_C_MALLINFO
32 #include <arpa/inet.h>
33 #include <netinet/in.h>
34 #include <netinet/tcp.h>
48 #include <sys/prctl.h>
49 #include <sys/resource.h>
50 #include <sys/socket.h>
52 #include <sys/statvfs.h>
53 #include <sys/syscall.h>
55 #include <sys/types.h>
59 #include <uuid/uuid.h>
61 #ifdef STORAGE_WITH_MATH
65 #if defined(HAVE_INTTYPES_H)
67 #elif defined(HAVE_STDINT_H)
71 #ifdef NETDATA_WITH_ZLIB
75 #if (SIZEOF_VOID_P == 8)
77 #elif (SIZEOF_VOID_P == 4)
80 #error "Cannot detect if this is a 32 or 64 bit CPU"
84 #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
89 #include "global_statistics.h"
90 #include "storage_number.h"
91 #include "web_buffer.h"
92 #include "web_buffer_svg.h"
97 #include "appconfig.h"
98 #include "dictionary.h"
99 #include "proc_self_mountinfo.h"
100 #include "plugin_checks.h"
101 #include "plugin_idlejitter.h"
102 #include "plugin_nfacct.h"
103 #include "plugin_proc.h"
104 #include "plugin_tc.h"
105 #include "plugins_d.h"
111 #include "rrd2json.h"
113 #include "web_client.h"
114 #include "web_server.h"
116 #include "registry.h"
119 #include "unit_test.h"
124 #define abs(x) ((x < 0)? -x : x)
126 extern unsigned long long usec_dt(struct timeval *now, struct timeval *old);
127 extern unsigned long long timeval_usec(struct timeval *tv);
129 // #define usec_dt(now, last) (((((now)->tv_sec * 1000000ULL) + (now)->tv_usec) - (((last)->tv_sec * 1000000ULL) + (last)->tv_usec)))
131 extern void netdata_fix_chart_id(char *s);
132 extern void netdata_fix_chart_name(char *s);
134 extern uint32_t simple_hash(const char *name);
135 extern uint32_t simple_uhash(const char *name);
137 extern void strreverse(char* begin, char* end);
138 extern char *mystrsep(char **ptr, char *s);
139 extern char *trim(char *s);
141 extern char *strncpyz(char *dst, const char *src, size_t n);
142 extern int vsnprintfz(char *dst, size_t n, const char *fmt, va_list args);
143 extern int snprintfz(char *dst, size_t n, const char *fmt, ...) __attribute__ (( format (printf, 3, 4)));
145 // memory allocation functions that handle failures
146 #ifdef NETDATA_LOG_ALLOCATIONS
147 #define strdupz(s) strdupz_int(__FILE__, __FUNCTION__, __LINE__, s)
148 #define callocz(nmemb, size) callocz_int(__FILE__, __FUNCTION__, __LINE__, nmemb, size)
149 #define mallocz(size) mallocz_int(__FILE__, __FUNCTION__, __LINE__, size)
150 #define reallocz(ptr, size) reallocz_int(__FILE__, __FUNCTION__, __LINE__, ptr, size)
151 #define freez(ptr) freez_int(__FILE__, __FUNCTION__, __LINE__, ptr)
153 extern char *strdupz_int(const char *file, const char *function, const unsigned long line, const char *s);
154 extern void *callocz_int(const char *file, const char *function, const unsigned long line, size_t nmemb, size_t size);
155 extern void *mallocz_int(const char *file, const char *function, const unsigned long line, size_t size);
156 extern void *reallocz_int(const char *file, const char *function, const unsigned long line, void *ptr, size_t size);
157 extern void freez_int(const char *file, const char *function, const unsigned long line, void *ptr);
159 extern char *strdupz(const char *s);
160 extern void *callocz(size_t nmemb, size_t size);
161 extern void *mallocz(size_t size);
162 extern void *reallocz(void *ptr, size_t size);
163 extern void freez(void *ptr);
166 extern void *mymmap(const char *filename, size_t size, int flags, int ksm);
167 extern int savememory(const char *filename, void *mem, size_t size);
169 extern int fd_is_valid(int fd);
171 extern char *global_host_prefix;
172 extern int enable_ksm;
174 extern pid_t gettid(void);
176 extern unsigned long long time_usec(void);
177 extern int sleep_usec(unsigned long long usec);
179 extern char *fgets_trim_len(char *buf, size_t buf_size, FILE *fp, size_t *len);
181 extern int processors;
182 extern long get_system_cpus(void);
184 extern pid_t pid_max;
185 extern pid_t get_system_pid_max(void);
187 /* Number of ticks per second */
188 extern unsigned int hz;
189 extern void get_system_HZ(void);
192 /* fix for alpine linux */
193 #ifndef RUSAGE_THREAD
194 #ifdef RUSAGE_CHILDREN
195 #define RUSAGE_THREAD RUSAGE_CHILDREN
199 extern int read_single_number_file(const char *filename, unsigned long long *result);
201 #endif /* NETDATA_COMMON_H */