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