src/registry_person.c
src/registry_person.h
src/registry_machine.c
- src/registry_machine.h src/registry_internals.c src/registry_init.c src/registry_db.c src/registry_log.c src/proc_uptime.c src/sys_devices_system_edac_mc.c src/plugin_proc_diskspace.c src/plugin_proc_diskspace.h src/simple_pattern.c src/simple_pattern.h)
+ src/registry_machine.h src/registry_internals.c src/registry_init.c src/registry_db.c src/registry_log.c src/proc_uptime.c src/sys_devices_system_edac_mc.c src/plugin_proc_diskspace.c src/plugin_proc_diskspace.h src/simple_pattern.c src/simple_pattern.h src/inlined.h)
set(APPS_PLUGIN_SOURCE_FILES
src/appconfig.c
add_executable(netdata ${NETDATA_SOURCE_FILES})
target_link_libraries (netdata m z uuid ${CMAKE_THREAD_LIBS_INIT})
-add_executable(apps.plugin ${APPS_PLUGIN_SOURCE_FILES})
+add_executable(apps.plugin ${APPS_PLUGIN_SOURCE_FILES} src/inlined.h)
target_link_libraries (apps.plugin m ${CMAKE_THREAD_LIBS_INIT})
AC_FUNC_STRERROR_R
AC_C__GENERIC
AC_C___ATOMIC
+AC_C_STMT_EXPR
AC_CHECK_SIZEOF([void *])
AC_CANONICAL_HOST
AC_HEADER_MAJOR
--- /dev/null
+# AC_C_STMT_EXPR
+# -------------
+# Define HAVE_STMT_EXPR if compiler has statement expressions.
+AN_IDENTIFIER([_Generic], [AC_C_STMT_EXPR])
+AC_DEFUN([AC_C_STMT_EXPR],
+[AC_CACHE_CHECK([for statement expressions], ac_cv_c_stmt_expr,
+[AC_COMPILE_IFELSE(
+ [AC_LANG_SOURCE(
+ [[int
+ main (int argc, char **argv)
+ {
+ int x = ({ int y = 1; y; });
+ return x;
+ }
+ ]])],
+ [ac_cv_c_stmt_expr=yes],
+ [ac_cv_c_stmt_expr=no])])
+if test $ac_cv_c_stmt_expr = yes; then
+ AC_DEFINE([HAVE_STMT_EXPR], 1,
+ [Define to 1 if compiler supports statement expressions.])
+fi
+])# AC_C_STMT_EXPR
+
eval.c eval.h \
global_statistics.c global_statistics.h \
health.c health.h \
+ inlined.h \
log.c log.h \
main.c main.h \
plugin_checks.c plugin_checks.h \
avl.c avl.h \
clocks.c clocks.h \
common.c common.h \
+ inlined.h \
log.c log.h \
procfile.c procfile.h \
web_buffer.c web_buffer.h \
}
*/
-
+/*
// http://isthe.com/chongo/tech/comp/fnv/#FNV-1a
uint32_t simple_hash(const char *name) {
unsigned char *s = (unsigned char *) name;
}
return hval;
}
+*/
/*
// http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx
long ticks;
if ((ticks = sysconf(_SC_CLK_TCK)) == -1) {
- perror("sysconf");
+ error("Cannot get system clock ticks");
}
hz = (unsigned int) ticks;
}
-
-int read_single_number_file(const char *filename, unsigned long long *result) {
- char buffer[1024 + 1];
-
- int fd = open(filename, O_RDONLY, 0666);
- if(unlikely(fd == -1)) return 1;
-
- ssize_t r = read(fd, buffer, 1024);
- if(unlikely(r == -1)) {
- close(fd);
- return 2;
- }
-
- close(fd);
- *result = strtoull(buffer, NULL, 0);
- return 0;
-}
#include "unit_test.h"
#include "ipc.h"
#include "backends.h"
+#include "inlined.h"
extern void netdata_fix_chart_id(char *s);
extern void netdata_fix_chart_name(char *s);
-extern uint32_t simple_hash(const char *name);
-extern uint32_t simple_uhash(const char *name);
-
extern void strreverse(char* begin, char* end);
extern char *mystrsep(char **ptr, char *s);
extern char *trim(char *s);
#endif
#endif
-extern int read_single_number_file(const char *filename, unsigned long long *result);
-
#endif /* NETDATA_COMMON_H */
--- /dev/null
+#ifndef NETDATA_INLINED_H
+#define NETDATA_INLINED_H
+
+#include "common.h"
+
+#ifdef HAVE_STMT_EXPR
+// GCC extension to define a function as a preprocessor macro
+
+#define simple_hash(name) ({ \
+ register unsigned char *__hash_source = (unsigned char *)(name); \
+ register uint32_t __hash_value = 0x811c9dc5; \
+ while (*__hash_source) { \
+ __hash_value *= 16777619; \
+ __hash_value ^= (uint32_t) *__hash_source++; \
+ } \
+ __hash_value; \
+})
+
+#define simple_uhash(name) ({ \
+ register unsigned char *__hash_source = (unsigned char *)(name); \
+ register uint32_t __hash_value = 0x811c9dc5, __hash_char; \
+ while ((__hash_char = *__hash_source++)) { \
+ if (unlikely(__hash_char >= 'A' && __hash_char <= 'Z')) \
+ __hash_char += 'a' - 'A'; \
+ __hash_value *= 16777619; \
+ __hash_value ^= __hash_char; \
+ } \
+ __hash_value; \
+})
+
+#else /* ! HAVE_STMT_EXPR */
+
+// for faster execution, allow the compiler to inline
+// these functions that are called to hash strings
+static inline uint32_t simple_hash(const char *name) {
+ register unsigned char *s = (unsigned char *) name;
+ register uint32_t hval = 0x811c9dc5;
+ while (*s) {
+ hval *= 16777619;
+ hval ^= (uint32_t) *s++;
+ }
+ return hval;
+}
+
+static inline uint32_t simple_uhash(const char *name) {
+ register unsigned char *s = (unsigned char *) name;
+ register uint32_t hval = 0x811c9dc5, c;
+ while ((c = *s++)) {
+ if (unlikely(c >= 'A' && c <= 'Z')) c += 'a' - 'A';
+ hval *= 16777619;
+ hval ^= c;
+ }
+ return hval;
+}
+
+#endif /* HAVE_STMT_EXPR */
+
+static inline int read_single_number_file(const char *filename, unsigned long long *result) {
+ char buffer[1024 + 1];
+
+ int fd = open(filename, O_RDONLY, 0666);
+ if(unlikely(fd == -1)) return 1;
+
+ ssize_t r = read(fd, buffer, 1024);
+ if(unlikely(r == -1)) {
+ close(fd);
+ return 2;
+ }
+
+ close(fd);
+ *result = strtoull(buffer, NULL, 0);
+ return 0;
+}
+
+#endif //NETDATA_INLINED_H