Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
.gitignore | 4 +-
configure.ac | 21 ++++++-
include/qb/qbatomic.h | 1 +
include/qb/qbconfig.h.in | 31 ++++++++
include/qb/qblog.h | 26 ++++---
lib/Makefile.am | 3 +-
lib/log.c | 167 ++++++++++++++++++++++++---------------------
lib/log_dcs.c | 170 ++++++++++++++++++++++++++++++++++++++++++++++
lib/log_int.h | 13 +++-
tests/Makefile.am | 8 ++-
tests/bench-log.c | 5 +-
tests/make-log-test | 32 +++++++++
12 files changed, 386 insertions(+), 95 deletions(-)
create mode 100644 include/qb/qbconfig.h.in
create mode 100644 lib/log_dcs.c
create mode 100755 tests/make-log-test
diff --git a/.gitignore b/.gitignore
index f0924db..fbfb225 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,8 +9,8 @@
*.pc
Makefile
Makefile.in
-include/config.h
-include/config.h.in
+include/config.*
+include/qb/qbconfig.h
include/stamp-h1
aclocal.m4
autom4te.cache/
diff --git a/configure.ac b/configure.ac
index 8366888..2e6bf5b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -10,7 +10,7 @@ AC_INIT([libqb],
AM_INIT_AUTOMAKE([-Wno-portability])
AC_CONFIG_SRCDIR([lib/ringbuffer.c])
-AC_CONFIG_HEADERS([include/config.h])
+AC_CONFIG_HEADERS([include/config.h include/qb/qbconfig.h])
LT_PREREQ([2.2.6])
LT_INIT
@@ -354,6 +354,25 @@ fi
AM_CONDITIONAL(USE_TIMERFD, [test "x$ac_cv_func_timerfd_create" = xyes])
+# --- callsite sections ---
+if test "x${GCC}" = xyes; then
+ AC_MSG_CHECKING([whether GCC supports __attribute__((section())])
+ AC_TRY_LINK([],
+ [static int my_var __attribute__((section("__verbose"))) = 5;
+ if (my_var == 5) return 0;
+ else return -1;
+ ],
+ [gcc_has_attribute_section=yes],
+ [gcc_has_attribute_section=no])
+
+ AC_MSG_RESULT($gcc_has_attribute_section)
+ if test $gcc_has_attribute_section = yes; then
+ AC_DEFINE([QB_HAVE_ATTRIBUTE_SECTION], 1,
+ [Enabling code using __attribute__((section))])
+ PACKAGE_FEATURES="$PACKAGE_FEATURES attribute-section"
+ fi
+fi
+
# --- ansi ---
if test "x${enable_ansi}" = xyes && \
cc_supports_flag -std=iso9899:199409 ; then
diff --git a/include/qb/qbatomic.h b/include/qb/qbatomic.h
index 2d0a060..968fe31 100644
--- a/include/qb/qbatomic.h
+++ b/include/qb/qbatomic.h
@@ -33,6 +33,7 @@ extern "C" {
#include <stdint.h>
#include <qb/qbdefs.h>
+#include <qb/qbconfig.h>
/**
* @file
diff --git a/include/qb/qbconfig.h.in b/include/qb/qbconfig.h.in
new file mode 100644
index 0000000..254e0f8
--- /dev/null
+++ b/include/qb/qbconfig.h.in
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2011 Red Hat, Inc.
+ *
+ * All rights reserved.
+ *
+ * Author: Angus Salkeld <asalkeld(a)redhat.com>
+ *
+ * libqb is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * libqb is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with libqb. If not, see <
http://www.gnu.org/licenses/>.
+ */
+
+#ifndef QB_CONFIG_H_DEFINED
+#define QB_CONFIG_H_DEFINED
+
+/* need atomic memory barrier */
+#undef QB_ATOMIC_OP_MEMORY_BARRIER_NEEDED
+
+/* Enabling code using __attribute__((section)) */
+#undef QB_HAVE_ATTRIBUTE_SECTION
+
+#endif /* QB_CONFIG_H_DEFINED */
diff --git a/include/qb/qblog.h b/include/qb/qblog.h
index 161c3ec..b5da37d 100644
--- a/include/qb/qblog.h
+++ b/include/qb/qblog.h
@@ -32,6 +32,11 @@ extern "C" {
#include <stdlib.h>
#include <errno.h>
#include <syslog.h>
+#include <qb/qbconfig.h>
+
+#ifdef S_SPLINT_S
+#undef QB_HAVE_ATTRIBUTE_SECTION
+#endif /* S_SPLINT_S */
/**
* @file qblog.h
@@ -224,6 +229,7 @@ struct qb_log_callsite {
} __attribute__((aligned(8)));
/* will be assigned by ld linker magic */
+#ifdef QB_HAVE_ATTRIBUTE_SECTION
extern struct qb_log_callsite __start___verbose[];
extern struct qb_log_callsite __stop___verbose[];
@@ -231,7 +237,9 @@ extern struct qb_log_callsite __stop___verbose[];
void name(void); \
void name(void) { assert(__start___verbose != __stop___verbose); } \
void __attribute__ ((constructor)) name(void);
-
+#else
+#define QB_LOG_INIT_DATA(name)
+#endif
/**
* Internal function: use qb_log() or qb_logt()
@@ -281,7 +289,7 @@ void qb_log_from_external_source(const char *function,
* @param fmt usual printf style format specifiers
* @param args usual printf style args
*/
-#ifndef S_SPLINT_S
+#ifdef QB_HAVE_ATTRIBUTE_SECTION
#define qb_logt(priority, tags, fmt, args...) do { \
static struct qb_log_callsite descriptor \
__attribute__((section("__verbose"), aligned(8))) = \
@@ -289,8 +297,12 @@ void qb_log_from_external_source(const char *function,
qb_log_real_(&descriptor, ##args); \
} while(0)
#else
-#define qb_logt
-#endif
+#define qb_logt(priority, tags, fmt, args...) do { \
+ char _log_buf_[256]; \
+ snprintf(_log_buf_, 256, fmt, ##args); \
+ qb_log_from_external_source( __func__, __FILE__, fmt, priority, __LINE__, tags,
_log_buf_); \
+ } while(0)
+#endif /* QB_HAVE_ATTRIBUTE_SECTION */
/**
* This is the main function to generate a log message.
@@ -299,12 +311,7 @@ void qb_log_from_external_source(const char *function,
* @param fmt usual printf style format specifiers
* @param args usual printf style args
*/
-#ifndef S_SPLINT_S
#define qb_log(priority, fmt, args...) qb_logt(priority, 0, fmt, ##args)
-#else
-#define qb_log
-#endif
-
/**
* This is similar to perror except it goes into the logging system.
@@ -321,7 +328,6 @@ void qb_log_from_external_source(const char *function,
#else
#define qb_perror
#endif
-
#define QB_LOG_SYSLOG 0
#define QB_LOG_STDERR 1
#define QB_LOG_BLACKBOX 2
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 4ba3793..8d795e0 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -41,7 +41,8 @@ libqb_la_LDFLAGS = -version-info 4:1:4
source_to_lint = util.c hdb.c ringbuffer.c ringbuffer_helper.c array.c \
loop.c loop_poll.c loop_job.c \
ipcc.c ipcs.c ipc_posix_mq.c ipc_sysv_mq.c ipc_shm.c ipc_us.c \
- log.c log_thread.c log_blackbox.c log_file.c log_syslog.c log_format.c
+ log.c log_thread.c log_blackbox.c log_file.c log_syslog.c \
+ log_format.c log_dcs.c
libqb_la_SOURCES = $(source_to_lint)
if USE_TIMERFD
else
diff --git a/lib/log.c b/lib/log.c
index 5b66bfd..f0f88b5 100644
--- a/lib/log.c
+++ b/lib/log.c
@@ -27,9 +27,11 @@
#include <qb/qblist.h>
#include <qb/qblog.h>
#include <qb/qbutil.h>
+#include <qb/qbarray.h>
#include "log_int.h"
static struct qb_log_target conf[32];
+static int32_t in_logger = QB_FALSE;
static QB_LIST_DECLARE(active_targets);
static QB_LIST_DECLARE(tags_head);
@@ -84,62 +86,8 @@ static int32_t _cs_matches_filter_(struct qb_log_callsite *cs,
return match;
}
-/*
- * 1 alloc a new callsite
- * 2 apply correct targets based on current filters
- * 3 pass onto qb_log_real_()
- *
- * Later:
- * if (cs < __start___verbose in && cs > __stop___verbose) {
- * free(cs)
- * }
- */
-void qb_log_from_external_source(const char *function,
- const char *filename,
- const char *format,
- uint8_t priority,
- uint32_t lineno,
- uint32_t tags,
- const char *msg)
-{
- struct qb_log_callsite *cs = calloc(1, sizeof(struct qb_log_callsite));
- struct qb_log_target *t;
- struct qb_log_filter *flt;
-
- cs->function = function;
- cs->filename = filename;
- cs->format = format;
- cs->priority = priority;
- cs->lineno = lineno;
- cs->tags = tags;
-
- qb_list_for_each_entry(t, &active_targets, active_list) {
- qb_list_for_each_entry(flt, &t->filter_head, list) {
- if (_cs_matches_filter_(cs,
- flt->type,
- flt->text,
- flt->priority)) {
- qb_bit_set(cs->targets, t->pos);
- break;
- }
- }
- }
- qb_log_real_(cs, msg);
-}
-
-static void qb_log_external_source_free(struct qb_log_callsite *cs)
+static void _log_real_msg(struct qb_log_callsite *cs, const char *msg)
{
- if (qb_bit_is_set(cs->tags, QB_LOG_TAG_EXTERNAL_BIT)) {
- free(cs);
- }
-}
-
-void qb_log_real_(struct qb_log_callsite *cs, ...)
-{
- va_list ap;
- char buf[COMBINE_BUFFER_SIZE];
- size_t len;
- static int32_t in_logger = 0;
int32_t found_threaded;
struct qb_log_target *t;
struct timeval tv;
@@ -149,20 +97,11 @@ void qb_log_real_(struct qb_log_callsite *cs, ...)
}
in_logger = QB_TRUE;
- va_start(ap, cs);
- len = vsnprintf(buf, COMBINE_BUFFER_SIZE, cs->format, ap);
- va_end(ap);
-
- if (buf[len - 1] == '\n') {
- buf[len - 1] = '\0';
- len -= 1;
- }
-
gettimeofday(&tv, NULL);
if (old_internal_log_fn) {
if (qb_bit_is_set(cs->tags, QB_LOG_TAG_LIBQB_MSG_BIT)) {
- old_internal_log_fn(cs->filename, cs->lineno, cs->priority, buf);
+ old_internal_log_fn(cs->filename, cs->lineno, cs->priority, msg);
}
}
@@ -178,14 +117,12 @@ void qb_log_real_(struct qb_log_callsite *cs, ...)
}
} else {
if (qb_bit_is_set(cs->targets, t->pos) && t->logger) {
- t->logger(t, cs, tv.tv_sec, buf);
+ t->logger(t, cs, tv.tv_sec, msg);
}
}
}
if (found_threaded) {
- qb_log_thread_log_post(cs, tv.tv_sec, buf);
- } else {
- qb_log_external_source_free(cs);
+ qb_log_thread_log_post(cs, tv.tv_sec, msg);
}
in_logger = QB_FALSE;
}
@@ -203,7 +140,68 @@ void qb_log_thread_log_write(struct qb_log_callsite *cs,
t->logger(t, cs, timestamp, buffer);
}
}
- qb_log_external_source_free(cs);
+}
+
+void qb_log_from_external_source(const char *function,
+ const char *filename,
+ const char *format,
+ uint8_t priority,
+ uint32_t lineno,
+ uint32_t tags,
+ const char *msg)
+{
+ struct qb_log_target *t;
+ struct qb_log_filter *flt;
+ struct qb_log_callsite *cs;
+ int32_t new_dcs = QB_FALSE;
+
+ cs = qb_log_dcs_get(&new_dcs, function, filename,
+ format, priority, lineno, tags);
+ assert(cs != NULL);
+
+ if (new_dcs) {
+ qb_list_for_each_entry(t, &active_targets, active_list) {
+ qb_list_for_each_entry(flt, &t->filter_head, list) {
+ if (_cs_matches_filter_(cs,
+ flt->type,
+ flt->text,
+ flt->priority)) {
+ qb_bit_set(cs->targets, t->pos);
+ break;
+ }
+ }
+ }
+ if (tags != 0) {
+ qb_list_for_each_entry(flt, &tags_head, list) {
+ if (_cs_matches_filter_(cs,
+ flt->type,
+ flt->text,
+ flt->priority)) {
+ cs->tags = tags;
+ break;
+ }
+ }
+ }
+
+ }
+ _log_real_msg(cs, msg);
+}
+
+void qb_log_real_(struct qb_log_callsite *cs, ...)
+{
+ va_list ap;
+ char buf[COMBINE_BUFFER_SIZE];
+ size_t len;
+
+ va_start(ap, cs);
+ len = vsnprintf(buf, COMBINE_BUFFER_SIZE, cs->format, ap);
+ va_end(ap);
+
+ if (buf[len - 1] == '\n') {
+ buf[len - 1] = '\0';
+ len -= 1;
+ }
+ _log_real_msg(cs, buf);
}
void qb_log_callsites_register(struct qb_log_callsite *_start, struct qb_log_callsite
*_stop)
@@ -255,6 +253,9 @@ void qb_log_callsites_dump(void)
printf(" start %p - stop %p\n", sect->start, sect->stop);
printf("filename lineno targets tags\n");
for (cs = sect->start; cs < sect->stop; cs++) {
+ if (cs->lineno == 0) {
+ break;
+ }
printf("%12s %6d %16d %16d\n", cs->filename, cs->lineno,
cs->targets, cs->tags);
}
@@ -353,6 +354,9 @@ static void _log_filter_apply(struct callsite_section *sect,
struct qb_log_callsite *cs;
for (cs = sect->start; cs < sect->stop; cs++) {
+ if (cs->lineno == 0) {
+ break;
+ }
if (c == QB_LOG_FILTER_CLEAR_ALL) {
qb_bit_clear(cs->targets, t);
@@ -412,6 +416,7 @@ int32_t qb_log_filter_ctl(int32_t t, enum qb_log_filter_conf c,
return 0;
}
+#ifdef QB_HAVE_ATTRIBUTE_SECTION
static int32_t
_log_so_walk_callback(struct dl_phdr_info *info, size_t size, void *data)
{
@@ -450,11 +455,14 @@ done:
}
return 0;
}
+#endif /* QB_HAVE_ATTRIBUTE_SECTION */
void qb_log_init(const char *name, int32_t facility, int32_t priority)
{
int32_t i;
+ qb_log_dcs_init();
+
for (i = 0; i < 32; i++) {
conf[i].pos = i;
conf[i].debug = QB_FALSE;
@@ -468,8 +476,10 @@ void qb_log_init(const char *name, int32_t facility, int32_t
priority)
conf[QB_LOG_SYSLOG].state = QB_LOG_STATE_ENABLED;
qb_list_add(&conf[QB_LOG_SYSLOG].active_list, &active_targets);
+#ifdef QB_HAVE_ATTRIBUTE_SECTION
qb_log_callsites_register(__start___verbose, __stop___verbose);
dl_iterate_phdr(_log_so_walk_callback, NULL);
+#endif /* QB_HAVE_ATTRIBUTE_SECTION */
conf[QB_LOG_STDERR].state = QB_LOG_STATE_DISABLED;
conf[QB_LOG_BLACKBOX].state = QB_LOG_STATE_DISABLED;
@@ -494,11 +504,6 @@ void qb_log_fini(void)
qb_log_thread_stop();
- qb_list_for_each_safe(iter, next, &callsite_sections) {
- s = qb_list_entry(iter, struct callsite_section, list);
- qb_list_del(iter);
- free(s);
- }
qb_list_for_each_safe(iter, next, &active_targets) {
t = qb_list_entry(iter, struct qb_log_target, active_list);
_log_target_disable(t);
@@ -509,6 +514,12 @@ void qb_log_fini(void)
free(flt);
}
}
+ qb_log_dcs_fini();
+ qb_list_for_each_safe(iter, next, &callsite_sections) {
+ s = qb_list_entry(iter, struct callsite_section, list);
+ qb_list_del(iter);
+ free(s);
+ }
qb_list_for_each_safe(iter, next, &tags_head) {
flt = qb_list_entry(iter, struct qb_log_filter, list);
qb_list_del(iter);
@@ -569,11 +580,13 @@ static void _log_target_disable(struct qb_log_target *t)
if (t->state != QB_LOG_STATE_ENABLED) {
return;
}
+ t->state = QB_LOG_STATE_DISABLED;
+ qb_list_del(&t->active_list);
if (t->close) {
+ in_logger = QB_TRUE;
t->close(t);
+ in_logger = QB_FALSE;
}
- t->state = QB_LOG_STATE_DISABLED;
- qb_list_del(&t->active_list);
}
int32_t qb_log_ctl(int32_t t, enum qb_log_conf c, int32_t arg)
diff --git a/lib/log_dcs.c b/lib/log_dcs.c
new file mode 100644
index 0000000..0bac375
--- /dev/null
+++ b/lib/log_dcs.c
@@ -0,0 +1,170 @@
+/*
+ * Copyright (C) 2011 Red Hat, Inc.
+ *
+ * All rights reserved.
+ *
+ * Author: Angus Salkeld <asalkeld(a)redhat.com>
+ *
+ * libqb is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * libqb is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with libqb. If not, see <
http://www.gnu.org/licenses/>.
+ */
+#include "os_base.h"
+#include <ctype.h>
+#include <link.h>
+#include <stdarg.h>
+
+#include <qb/qbdefs.h>
+#include <qb/qblist.h>
+#include <qb/qblog.h>
+#include <qb/qbutil.h>
+#include <qb/qbarray.h>
+#include "log_int.h"
+
+static qb_array_t *lookup_arr = NULL;
+static qb_array_t *callsite_arr = NULL;
+static uint32_t callsite_arr_next = 0;
+static uint32_t callsite_num_bins = 0;
+static uint32_t callsite_elems_per_bin = 0;
+
+struct callsite_list {
+ struct qb_log_callsite *cs;
+ struct qb_list_head list;
+};
+
+
+static void _log_register_callsites(void)
+{
+ struct qb_log_callsite* start;
+ struct qb_log_callsite* stop;
+ int32_t b;
+ int32_t rc;
+ uint32_t num_bins = qb_array_num_bins_get(callsite_arr);
+
+ for (b = callsite_num_bins; b < num_bins; b++) {
+ /* get the first element in the bin */
+ rc = qb_array_index(callsite_arr,
+ b * callsite_elems_per_bin,
+ (void**)&start);
+ if (rc == 0) {
+ stop = &start[callsite_elems_per_bin];
+ qb_log_callsites_register(start, stop);
+ }
+ }
+ callsite_num_bins = num_bins;
+}
+
+static struct qb_log_callsite *
+_log_dcs_new_cs(const char *function,
+ const char *filename,
+ const char *format,
+ uint8_t priority,
+ uint32_t lineno,
+ uint32_t tags)
+{
+ struct qb_log_callsite *cs;
+ int32_t rc;
+
+ if (qb_array_index(callsite_arr, callsite_arr_next, (void**)&cs) < 0) {
+ rc = qb_array_grow(callsite_arr, callsite_arr_next + 255);
+ assert(rc == 0);
+ rc = qb_array_index(callsite_arr, callsite_arr_next, (void**)&cs);
+ assert(rc == 0);
+ assert(cs != NULL);
+ callsite_arr_next++;
+ _log_register_callsites();
+ }
+
+ cs->function = function;
+ cs->filename = filename;
+ cs->format = format;
+ cs->priority = priority;
+ cs->lineno = lineno;
+ cs->tags = tags;
+
+ return cs;
+}
+
+struct qb_log_callsite *
+qb_log_dcs_get(int32_t *newly_created,
+ const char *function,
+ const char *filename,
+ const char *format,
+ uint8_t priority,
+ uint32_t lineno,
+ uint32_t tags)
+{
+ int32_t rc;
+ struct qb_log_callsite *cs;
+ struct callsite_list *csl_head;
+ struct callsite_list *csl_next;
+ struct callsite_list *csl;
+ struct qb_list_head *iter = NULL;
+
+ rc = qb_array_index(lookup_arr, lineno, (void**)&csl_head);
+ if (rc < 0) {
+ rc = qb_array_grow(lookup_arr, lineno + 255);
+ assert(rc == 0);
+ rc = qb_array_index(lookup_arr, lineno, (void**)&csl_head);
+ assert(rc == 0);
+ }
+ if (csl_head->cs == NULL) {
+ csl_head->cs = _log_dcs_new_cs(function, filename, format,
+ priority, lineno, tags);
+ cs = csl_head->cs;
+ qb_list_init(&csl_head->list);
+ *newly_created = QB_TRUE;
+ } else {
+ csl_next = csl_head;
+ do {
+ csl = csl_next;
+ if (strcmp(filename, csl->cs->filename) == 0) {
+ cs = csl->cs;
+ break;
+ }
+ if (iter == NULL) {
+ iter = csl_head->list.next;
+ } else {
+ iter = iter->next;
+ }
+ csl_next = qb_list_entry(iter, struct callsite_list, list);
+ } while (iter != &csl_head->list);
+ if (cs == NULL) {
+ /*
+ * create new list entry
+ */
+ csl_next = calloc(1, sizeof(struct callsite_list));
+ csl_next->cs = _log_dcs_new_cs(function, filename, format,
+ priority, lineno, tags);
+ cs = csl_next->cs;
+ qb_list_init(&csl_next->list);
+ qb_list_add(&csl_next->list, &csl_head->list);
+ *newly_created = QB_TRUE;
+ }
+ }
+ return cs;
+}
+
+
+void qb_log_dcs_init(void)
+{
+ lookup_arr = qb_array_create(256, sizeof(struct callsite_list));
+ callsite_arr = qb_array_create(256, sizeof(struct callsite_list));
+
+ callsite_elems_per_bin = qb_array_elems_per_bin_get(callsite_arr);
+ _log_register_callsites();
+}
+
+void qb_log_dcs_fini(void)
+{
+}
+
diff --git a/lib/log_int.h b/lib/log_int.h
index 34f82e0..e73d5d0 100644
--- a/lib/log_int.h
+++ b/lib/log_int.h
@@ -70,7 +70,6 @@ struct qb_log_filter {
struct qb_list_head list;
};
-
struct qb_log_record {
struct qb_log_callsite *cs;
time_t timestamp;
@@ -78,6 +77,7 @@ struct qb_log_record {
struct qb_list_head list;
};
+
#define TIME_STRING_SIZE 64
#define COMBINE_BUFFER_SIZE 512
@@ -102,5 +102,16 @@ void qb_log_thread_log_write(struct qb_log_callsite *cs,
time_t current_time,
const char *buffer);
+void qb_log_dcs_init(void);
+void qb_log_dcs_fini(void);
+struct qb_log_callsite *qb_log_dcs_get(int32_t *newly_created,
+ const char *function,
+ const char *filename,
+ const char *format,
+ uint8_t priority,
+ uint32_t lineno,
+ uint32_t tags);
+
+
#endif /* _QB_LOG_INT_H_ */
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 6f591f1..ea07801 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -48,7 +48,7 @@ simple_log_SOURCES = simple-log.c $(top_builddir)/include/qb/qblog.h
simple_log_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include
simple_log_LDADD = -lrt $(top_builddir)/lib/libqb.la
-bench_log_SOURCES = bench-log.c $(top_builddir)/include/qb/qblog.h
+bench_log_SOURCES = bench-log.c write_logs.c $(top_builddir)/include/qb/qblog.h
bench_log_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include
bench_log_LDADD = -lrt $(top_builddir)/lib/libqb.la
@@ -57,7 +57,7 @@ EXTRA_DIST = check_resources.sh
TESTS = check_array check_rb check_loop check_ipc check_resources.sh
-check_PROGRAMS = check_array check_rb check_loop check_ipc
+check_PROGRAMS = check_array check_rb check_log check_loop check_ipc
check_SCRIPTS = check_resources.sh
check_array_SOURCES = check_array.c $(top_builddir)/include/qb/qbarray.h
@@ -76,5 +76,9 @@ check_ipc_SOURCES = check_ipc.c $(top_builddir)/include/qb/qbipcc.h
$(top_buildd
check_ipc_CFLAGS = @CHECK_CFLAGS@ -I$(top_srcdir)/include
check_ipc_LDADD = $(top_builddir)/lib/libqb.la -lrt @CHECK_LIBS@
+check_log_SOURCES = check_log.c $(top_builddir)/include/qb/qblog.h
+check_log_CFLAGS = @CHECK_CFLAGS@ -I$(top_srcdir)/include
+check_log_LDADD = $(top_builddir)/lib/libqb.la -lrt @CHECK_LIBS@
+
endif
diff --git a/tests/bench-log.c b/tests/bench-log.c
index 80c167a..7bbbcb8 100644
--- a/tests/bench-log.c
+++ b/tests/bench-log.c
@@ -28,7 +28,7 @@
#include <qb/qbdefs.h>
#include <qb/qblog.h>
-#define ITERATIONS 10000000
+#define ITERATIONS 50000
static struct timeval tv1, tv2, tv_elapsed;
@@ -94,6 +94,9 @@ int main (void)
qb_log(LOG_DEBUG, "%s%s%s", "RecordA", "RecordB",
"RecordC");
}
bm_finish ("qb_log 3 arguments:");
+ bm_start();
+ log_dict_words();
+ bm_finish ("qb_log /usr/share/dict/words:");
/* this will close the ringbuffer
*/
diff --git a/tests/make-log-test b/tests/make-log-test
new file mode 100755
index 0000000..46110c9
--- /dev/null
+++ b/tests/make-log-test
@@ -0,0 +1,32 @@
+#!/bin/sh
+
+line=
+count=0
+total=50000
+echo "#include <stdio.h>"
+echo "#include <qb/qblog.h>"
+echo "void log_dict_words(void) {"
+
+while read w
+do
+ if [ $count -eq 0 ]
+ then
+ line=" qb_log(LOG_DEBUG, \"%d : %s %s %s\", $total"
+ fi
+ line="$line, \"$w\""
+ let count="$count+1"
+ if [ $count -eq 3 ]
+ then
+ line="$line );"
+ count=0
+ let total="$total-1"
+ echo $line
+ if [ $total -eq 0 ]
+ then
+ echo "}"
+ exit 0
+ fi
+ fi
+done < /usr/share/dict/words
+
+
--
1.7.4