src_tests_sort_vector_CFLAGS = $(check_CFLAGS)
src_tests_sort_vector_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=log_config_get_int,--wrap=log_entry_is_earlier,--wrap=free
-src_tests_fd_info_SOURCES = src/tests/fd_info.c src/libdlogutil/fd_info.c
+src_tests_fd_info_SOURCES = src/tests/fd_info.c \
+ src/libdlogutil/fd_info.c \
+ src/libdlogutil/sort_vector.c \
+ src/shared/logcommon.c \
+ src/shared/logconfig.c \
+ src/shared/parsers.c \
+ src/shared/queued_entry_timestamp.c
src_tests_fd_info_CFLAGS = $(check_CFLAGS)
src_tests_fd_info_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=sort_vector_push,--wrap=malloc,--wrap=free,--wrap=close,--wrap=dlogutil_entry_get_timestamp,--wrap=log_should_print_line
int sort_vector_full(struct sort_vector *logs);
int sort_vector_used_size(struct sort_vector *logs);
void sort_vector_pop(struct sort_vector *logs);
+dlogutil_entry_s *sort_vector_pop_ret(struct sort_vector *logs);
void sort_vector_apply_config(struct sort_vector *logs, const struct log_config *config);
-int sort_vector_push(struct sort_vector *logs, dlogutil_entry_s *p, dlogutil_entry_cb callback, void *userdata);
+void sort_vector_push(struct sort_vector *logs, dlogutil_entry_s *p);
long sort_vector_time_span(struct sort_vector *logs);
int sort_vector_flush(struct sort_vector *logs, dlogutil_entry_cb callback, void *userdata, bool force);
}
int r;
+ dlogutil_entry_s *entry = NULL;
if (IS_VECTOR_SIZE_SORTABLE(logs->size)) {
struct timespec ts;
if (ts.tv_sec > logs->start.tv_sec || (ts.tv_sec == logs->start.tv_sec && ts.tv_nsec > logs->start.tv_nsec))
logs->old_logs_dumped = true;
- r = sort_vector_push(logs, temp, callback, userdata);
- } else {
- r = callback(temp, userdata);
- free(temp);
+ if (sort_vector_full(logs)) {
+ if (logs->dump == DLOGUTIL_MODE_CONTINUOUS || logs->dump == DLOGUTIL_MAX_DUMP_SIZE)
+ entry = sort_vector_pop_ret(logs);
+ else
+ sort_vector_pop(logs);
+ }
+
+ sort_vector_push(logs, temp);
+ } else
+ entry = temp;
+
+ if (entry) {
+ r = callback(entry, userdata);
+ free(entry);
}
return r;
logs->begin = (logs->begin + 1) % logs->size;
}
+dlogutil_entry_s *sort_vector_pop_ret(struct sort_vector *logs)
+{
+ assert(!sort_vector_empty(logs));
+ dlogutil_entry_s *const ret = logs->data[logs->begin];
+ logs->data[logs->begin] = NULL;
+ logs->begin = (logs->begin + 1) % logs->size;
+ return ret;
+}
+
int sort_vector_used_size(struct sort_vector *logs)
{
if (logs->end >= logs->begin)
* @details Push a log to the sorting container
* @param[in] p Pushee (taken ownership of)
* @param[in] logs Log sorting vector
- * @return 0 on success, -errno on failure
+ * @pre Vector not full
*/
-int sort_vector_push(struct sort_vector *logs, dlogutil_entry_s *p, dlogutil_entry_cb callback, void *userdata)
+void sort_vector_push(struct sort_vector *logs, dlogutil_entry_s *p)
{
assert(logs);
assert(logs->data);
assert(IS_VECTOR_SIZE_SORTABLE(logs->size));
assert(p);
-
- if (sort_vector_full(logs)) {
- if (logs->dump == DLOGUTIL_MODE_CONTINUOUS || logs->dump == DLOGUTIL_MAX_DUMP_SIZE) {
- const int r = callback(sort_vector_back(logs), userdata);
- if (r != 0)
- return r;
- }
- sort_vector_pop(logs);
- }
+ assert(!sort_vector_full(logs));
/* Insertion sort. Logs usually appear in order, so it makes a lot of sense to just iterate
* linearly from the end to try and find the correct index. The algorithm starts working
logs->data[i] = p;
logs->end = (logs->end + 1) % logs->size;
- return 0;
}
long sort_vector_time_span(struct sort_vector *logs)
}
static bool sv_pushed;
-static int sv_push_retval;
-int __wrap_sort_vector_push(struct sort_vector *logs, dlogutil_entry_s *p, dlogutil_entry_cb comp_callback, void *userdata)
+void __wrap_sort_vector_push(struct sort_vector *logs, dlogutil_entry_s *p)
{
assert(p == (dlogutil_entry_s *) 0xBADFEEL);
- assert(comp_callback == callback);
- assert(userdata == (struct log_file *) 0xDEFACED);
sv_pushed = true;
- return sv_push_retval;
}
struct fd_info G_fdi;
assert(!sv_flushed);
sv_pushed = false;
- sv_push_retval = -83;
- expect_free1 = &G_fdi;
- assert(-83 == fdi_push_log(&G_fdi, &sv, callback, (void *) 0xDEFACED, (dlogutil_filter_options_s *) 404));
- assert(sv_pushed);
- assert(!sv_flushed);
- sv_push_retval = 0;
-
sv.old_logs_dumped = false;
sv.start.tv_sec = 2;
sv.start.tv_nsec = 0;
memcpy(ent, fdi->ops->peek_entry(fdi), sizeof(dlogutil_entry_s));
struct fdi_internal *ii = fdi->priv_data;
ii->has_log = false;
- return sort_vector_push(logs, ent, callback, userdata);
+
+ int ret = 0;
+ if (sort_vector_full(logs)) {
+ if (logs->dump == DLOGUTIL_MODE_CONTINUOUS || logs->dump == DLOGUTIL_MAX_DUMP_SIZE)
+ ret = callback(sort_vector_pop_ret(logs), userdata);
+ else
+ sort_vector_pop(logs);
+ }
+ sort_vector_push(logs, ent);
+ return ret;
}
int main()
assert(ent2);
ent2->sec_sent_mono = 1;
ent2->nsec_sent_mono = (79 + i) * 10000000;
- sort_vector_push(&sv, ent2, callback, (void *)0xDDD);
+ sort_vector_push(&sv, ent2);
}
assert(sort_vector_time_span(&sv) == 110);
assert(ent3);
ent3->sec_sent_mono = 0;
ent3->nsec_sent_mono = 999999999;
- sort_vector_push(&sv, ent3, callback, (void *)0xDDD);
+ sort_vector_push(&sv, ent3);
assert(sort_vector_time_span(&sv) == 900);
struct fd_ops test_ops = {
assert(ent_future);
ent_future->sec_sent_mono = 2;
ent_future->nsec_sent_mono = 0;
- sort_vector_push(&sv, ent_future, callback, (void *)0xDDD);
+ sort_vector_push(&sv, ent_future);
written_logs = 0;
sort_vector_flush(&sv, callback, (void *)0xDDD, false);
assert(written_logs == 0);
struct log_file lf;
memset(&lf, 0, sizeof(struct log_file));
-#define ADD(x) assert(sort_vector_push(&sv, (dlogutil_entry_s *) x, callback, (void *)0xDA7A) == callback_ret)
+#define ADD(x) \
+ if (sort_vector_full(&sv)) \
+ total_flushed += (size_t) sort_vector_pop_ret(&sv); \
+ sort_vector_push(&sv, (dlogutil_entry_s *) x)
#define POP(x) \
free_total = 0; \
sort_vector_pop(&sv); \
assert((dlogutil_entry_s *) 20 == sort_vector_back(&sv));
assert(6 == sort_vector_used_size(&sv));
- callback_ret = 13;
- ADD(27);
- assert(20 == total_flushed);
- total_flushed = 0;
- /* ┌──┬──┬──┬──┬──┬──┬──┐
- * │33│40│41│ │20│24│25│
- * └──┴──┴──┴──┴──┴──┴──┘ */
- assert(!sort_vector_empty(&sv));
- assert(sort_vector_full(&sv));
- assert((dlogutil_entry_s *) 20 == sort_vector_back(&sv));
- assert(6 == sort_vector_used_size(&sv));
- callback_ret = 0;
-
#undef ADD
#undef POP