This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
laforge gerrit-no-reply at lists.osmocom.orglaforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/20306 )
Change subject: WIP: add rate_ctr_group to log_target
......................................................................
WIP: add rate_ctr_group to log_target
This way we account for the number of dropped log messages at
write_queue overflow. However, log targets have no numerical
ID and hence we're not able to extract them in a reasonable manner.
Change-Id: I89b696311b823267e05d6a3e85b92c1784b220ed
---
M include/osmocom/core/logging.h
M src/logging.c
M tests/ctrl/ctrl_test.c
3 files changed, 43 insertions(+), 3 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/06/20306/1
diff --git a/include/osmocom/core/logging.h b/include/osmocom/core/logging.h
index 94788af..410a95e 100644
--- a/include/osmocom/core/logging.h
+++ b/include/osmocom/core/logging.h
@@ -10,6 +10,7 @@
#include <stdbool.h>
#include <osmocom/core/defs.h>
#include <osmocom/core/linuxlist.h>
+#include <osmocom/core/rate_ctr.h>
/*! Maximum number of logging contexts */
#define LOG_MAX_CTX 8
@@ -350,6 +351,9 @@
enum log_filename_type print_filename2;
/* Where on a log line to put the source file info. */
enum log_filename_pos print_filename_pos;
+
+ /* Rate counters related to this target */
+ struct rate_ctr_group *ctrg;
};
/* use the above macros */
diff --git a/src/logging.c b/src/logging.c
index 952c350..8f52a43 100644
--- a/src/logging.c
+++ b/src/logging.c
@@ -59,6 +59,8 @@
#include <osmocom/core/timer.h>
#include <osmocom/core/select.h>
#include <osmocom/core/write_queue.h>
+#include <osmocom/core/stats.h>
+#include <osmocom/core/rate_ctr.h>
#include <osmocom/vty/logging.h> /* for LOGGING_STR. */
@@ -81,6 +83,25 @@
void *tall_log_ctx = NULL;
LLIST_HEAD(osmo_log_target_list);
+enum tgt_ctr {
+ TGT_CTR_LOG_COUNT,
+ TGT_CTR_REOPEN_COUNT,
+ TGT_CTR_DROP_COUNT,
+};
+static const struct rate_ctr_desc log_target_ctr_description[] = {
+ { "writes", "Log write count" },
+ { "repoens", "Re-open count " },
+ { "drops", "Log writes dropped due to overflow" },
+};
+static const struct rate_ctr_group_desc log_target_ctrg_desc = {
+ .group_name_prefix = "log:target",
+ .group_description = "Log Target Statistics",
+ .num_ctr = ARRAY_SIZE(log_target_ctr_description),
+ .ctr_desc = log_target_ctr_description,
+ .class_id = OSMO_STATS_CLASS_GLOBAL,
+};
+
+
#if (!EMBEDDED)
/*! This mutex must be held while using osmo_log_target_list or any of its
log_targets in a multithread program. Prevents race conditions between threads
@@ -636,6 +657,8 @@
if (!should_log_to_target(tar, subsys, level))
continue;
+ rate_ctr_inc(&tar->ctrg->ctr[TGT_CTR_LOG_COUNT]);
+
/* According to the manpage, vsnprintf leaves the value of ap
* in undefined state. Since _output uses vsnprintf and it may
* be called several times, we have to pass a copy of ap. */
@@ -880,6 +903,7 @@
int line, int cont, const char *format, va_list ap)
{
struct msgb *msg;
+ int rc;
OSMO_ASSERT(target->tgt_file.wqueue);
msg = msgb_alloc_c(target->tgt_file.wqueue, MAX_LOG_SIZE, "log_file_msg");
@@ -891,10 +915,14 @@
* and call _file_wq_write_cb() */
rc = _output_buf((char *)msgb_data(msg), msgb_tailroom(msg), target, subsys, level, file, line, cont, format, ap);
msgb_put(msg, rc);
- osmo_wqueue_enqueue_quiet(target->tgt_file.wqueue, msg);
+ rc = osmo_wqueue_enqueue_quiet(target->tgt_file.wqueue, msg);
+ if (rc < 0)
+ rate_ctr_inc(&target->ctrg->ctr[TGT_CTR_DROP_COUNT]);
}
#endif
+static int log_target_ctrg_idx = 0;
+
/*! Create a new log target skeleton
* \returns dynamically-allocated log target
* This funcition allocates a \ref log_target and initializes it
@@ -919,6 +947,12 @@
talloc_free(target);
return NULL;
}
+ target->ctrg = rate_ctr_group_alloc(target, &log_target_ctrg_desc, log_target_ctrg_idx++);
+ if (!target->ctrg) {
+ talloc_free(target->categories);
+ talloc_free(target);
+ return NULL;
+ }
INIT_LLIST_HEAD(&target->entry);
@@ -1189,6 +1223,7 @@
}
#endif
+ rate_ctr_group_free(target->ctrg);
talloc_free(target);
}
@@ -1225,6 +1260,7 @@
return rc;
}
+ rate_ctr_inc(&target->ctrg->ctr[TGT_CTR_REOPEN_COUNT]);
return 0;
}
diff --git a/tests/ctrl/ctrl_test.c b/tests/ctrl/ctrl_test.c
index b46e9ac..06e5d2c 100644
--- a/tests/ctrl/ctrl_test.c
+++ b/tests/ctrl/ctrl_test.c
@@ -478,8 +478,8 @@
test_deferred_cmd();
- /* Expecting root ctx + msgb root ctx + 5 logging elements */
- if (talloc_total_blocks(ctx) != 7) {
+ /* Expecting root ctx + msgb root ctx + 6 logging elements */
+ if (talloc_total_blocks(ctx) != 8) {
talloc_report_full(ctx, stdout);
OSMO_ASSERT(false);
}
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/20306
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I89b696311b823267e05d6a3e85b92c1784b220ed
Gerrit-Change-Number: 20306
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge at osmocom.org>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200927/e2d2d0ac/attachment.htm>