1 #ifndef NETDATA_COMMON_H
2 #define NETDATA_COMMON_H 1
20 #include <arpa/inet.h>
21 #include <netinet/in.h>
22 #include <netinet/tcp.h>
36 #include <sys/prctl.h>
37 #include <sys/resource.h>
38 #include <sys/socket.h>
40 #include <sys/statvfs.h>
41 #include <sys/syscall.h>
43 #include <sys/types.h>
47 #include <uuid/uuid.h>
49 #ifdef STORAGE_WITH_MATH
53 #if defined(HAVE_INTTYPES_H)
55 #elif defined(HAVE_STDINT_H)
59 #ifdef NETDATA_WITH_ZLIB
64 #define GCC_VERSION (__GNUC__ * 10000 \
65 + __GNUC_MINOR__ * 100 \
66 + __GNUC_PATCHLEVEL__)
68 // test for gcc version < 4.1.2
69 // to disable gcc atomic operations
70 #if GCC_VERSION < 40102
71 #define NETDATA_NO_ATOMIC_INSTRUCTIONS 1
74 #if __x86_64__ || __ppc64__
81 #define NETDATA_NO_ATOMIC_INSTRUCTIONS 1
87 #include "global_statistics.h"
88 #include "storage_number.h"
89 #include "web_buffer.h"
90 #include "web_buffer_svg.h"
95 #include "appconfig.h"
96 #include "dictionary.h"
97 #include "proc_self_mountinfo.h"
98 #include "plugin_checks.h"
99 #include "plugin_idlejitter.h"
100 #include "plugin_nfacct.h"
101 #include "plugin_proc.h"
102 #include "plugin_tc.h"
103 #include "plugins_d.h"
109 #include "rrd2json.h"
111 #include "web_client.h"
112 #include "web_server.h"
114 #include "registry.h"
117 #include "unit_test.h"
122 #define abs(x) ((x < 0)? -x : x)
124 extern unsigned long long usec_dt(struct timeval *now, struct timeval *old);
125 extern unsigned long long timeval_usec(struct timeval *tv);
127 // #define usec_dt(now, last) (((((now)->tv_sec * 1000000ULL) + (now)->tv_usec) - (((last)->tv_sec * 1000000ULL) + (last)->tv_usec)))
129 extern void netdata_fix_chart_id(char *s);
130 extern void netdata_fix_chart_name(char *s);
132 extern uint32_t simple_hash(const char *name);
133 extern uint32_t simple_uhash(const char *name);
135 extern void strreverse(char* begin, char* end);
136 extern char *mystrsep(char **ptr, char *s);
137 extern char *trim(char *s);
139 extern char *strncpyz(char *dst, const char *src, size_t n);
140 extern int vsnprintfz(char *dst, size_t n, const char *fmt, va_list args);
141 extern int snprintfz(char *dst, size_t n, const char *fmt, ...) __attribute__ (( format (printf, 3, 4)));
143 // memory allocation functions that handle failures
144 extern char *strdupz(const char *s);
145 extern void *callocz(size_t nmemb, size_t size);
146 extern void *mallocz(size_t size);
147 extern void freez(void *ptr);
148 extern void *reallocz(void *ptr, size_t size);
150 extern void *mymmap(const char *filename, size_t size, int flags, int ksm);
151 extern int savememory(const char *filename, void *mem, size_t size);
153 extern int fd_is_valid(int fd);
155 extern char *global_host_prefix;
156 extern int enable_ksm;
158 /* Number of ticks per second */
159 extern unsigned int hz;
160 extern void get_HZ(void);
162 extern pid_t gettid(void);
164 extern unsigned long long time_usec(void);
165 extern int sleep_usec(unsigned long long usec);
167 extern char *fgets_trim_len(char *buf, size_t buf_size, FILE *fp, size_t *len);
169 /* fix for alpine linux */
170 #ifndef RUSAGE_THREAD
171 #ifdef RUSAGE_CHILDREN
172 #define RUSAGE_THREAD RUSAGE_CHILDREN
176 #endif /* NETDATA_COMMON_H */