pespin has uploaded this change for review.

View Change

pcap-client: Move stats to its own file

Further stats groups will be added, so move it to a separate file for
easier handing.

Change-Id: I4b5ecdd6f9b0c646dd03ca3bc7fa24624fb9fcbc
---
M include/osmo-pcap/osmo_pcap_client.h
M src/Makefile.am
M src/osmo_client_core.c
M src/osmo_client_main.c
A src/osmo_client_stats.c
5 files changed, 74 insertions(+), 31 deletions(-)

git pull ssh://gerrit.osmocom.org:29418/osmo-pcap refs/changes/73/39173/1
diff --git a/include/osmo-pcap/osmo_pcap_client.h b/include/osmo-pcap/osmo_pcap_client.h
index 8ad5ffa..8b7c06e 100644
--- a/include/osmo-pcap/osmo_pcap_client.h
+++ b/include/osmo-pcap/osmo_pcap_client.h
@@ -28,13 +28,14 @@
#include <osmocom/core/linuxlist.h>
#include <osmocom/core/select.h>
#include <osmocom/core/timer.h>
+#include <osmocom/core/rate_ctr.h>
#include <osmocom/core/write_queue.h>

struct rate_ctr_group;

#define WQUEUE_MAXLEN_DEFAULT 1000

-enum {
+enum pcap_client_ctr {
CLIENT_CTR_CONNECT,
CLIENT_CTR_BYTES,
CLIENT_CTR_PKTS,
@@ -47,6 +48,7 @@
CLIENT_CTR_P_DROP,
CLIENT_CTR_P_IFDROP,
};
+extern const struct rate_ctr_group_desc pcap_client_ctr_group_desc;

enum osmo_pcap_protocol {
PROTOCOL_OSMOPCAP,
diff --git a/src/Makefile.am b/src/Makefile.am
index 8c2c968..b35227c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -19,6 +19,7 @@
osmo_client_core.c \
osmo_client_vty.c \
osmo_client_network.c \
+ osmo_client_stats.c \
osmo_tls.c \
$(NULL)

diff --git a/src/osmo_client_core.c b/src/osmo_client_core.c
index bde40d3..d111fca 100644
--- a/src/osmo_client_core.c
+++ b/src/osmo_client_core.c
@@ -302,7 +302,18 @@
INIT_LLIST_HEAD(&client->handles);
INIT_LLIST_HEAD(&client->conns);

+ /* initialize the stats interface */
+ client->ctrg = rate_ctr_group_alloc(pcap_client, &pcap_client_ctr_group_desc, 0);
+ if (!client->ctrg) {
+ LOGP(DCLIENT, LOGL_ERROR, "Failed to allocate rate ctr\n");
+ goto ret_free;
+ }
+
return client;
+
+ret_free:
+ talloc_free(client);
+ return NULL;
}

void osmo_client_conn_free(struct osmo_pcap_client_conn *conn)
diff --git a/src/osmo_client_main.c b/src/osmo_client_main.c
index 3fa0ae4..1fedce1 100644
--- a/src/osmo_client_main.c
+++ b/src/osmo_client_main.c
@@ -52,29 +52,6 @@
void *tall_cli_ctx;
struct osmo_pcap_client *pcap_client;

-
-static const struct rate_ctr_desc pcap_client_ctr_desc[] = {
- [CLIENT_CTR_CONNECT] = { "server:connect", "Connects to the server" },
- [CLIENT_CTR_BYTES] = { "captured:bytes", "Captured bytes " },
- [CLIENT_CTR_PKTS] = { "captured:pkts", "Captured packets " },
- [CLIENT_CTR_2BIG] = { "bpf:too_big", "Captured data too big " },
- [CLIENT_CTR_NOMEM] = { "client:no_mem", "No memory available " },
- [CLIENT_CTR_QERR] = { "client:queue_err", "Can not queue data " },
- [CLIENT_CTR_PERR] = { "client:pcap_err", "libpcap error " },
- [CLIENT_CTR_WERR] = { "client:write_err", "Write error " },
- [CLIENT_CTR_P_RECV] = { "pcap:recv", "PCAP received packets " },
- [CLIENT_CTR_P_DROP] = { "pcap:drop", "PCAP dropped packets " },
- [CLIENT_CTR_P_IFDROP] = { "pcap:ifdrop", "iface dropped packets " },
-};
-
-static const struct rate_ctr_group_desc pcap_client_ctr_group_desc = {
- .group_name_prefix = "pcap:client",
- .group_description = "PCAP Client statistics",
- .num_ctr = ARRAY_SIZE(pcap_client_ctr_desc),
- .ctr_desc = pcap_client_ctr_desc,
- .class_id = OSMO_STATS_CLASS_GLOBAL,
-};
-
static struct vty_app_info vty_info = {
.name = "OsmoPCAPClient",
.version = PACKAGE_VERSION,
@@ -261,13 +238,6 @@
exit(1);
}

- /* initialize the stats interface */
- pcap_client->ctrg = rate_ctr_group_alloc(pcap_client, &pcap_client_ctr_group_desc, 0);
- if (!pcap_client->ctrg) {
- LOGP(DCLIENT, LOGL_ERROR, "Failed to allocate rate ctr\n");
- exit(1);
- }
-
/* Default conn, always present. */
pcap_client->conn = osmo_client_conn_alloc(pcap_client, "default");

diff --git a/src/osmo_client_stats.c b/src/osmo_client_stats.c
new file mode 100644
index 0000000..9fde091
--- /dev/null
+++ b/src/osmo_client_stats.c
@@ -0,0 +1,59 @@
+/*
+ * osmo-pcap-client code
+ *
+ * (C) 2024 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
+ * (C) 2011-2016 by Holger Hans Peter Freyther <holger@moiji-mobile.com>
+ * (C) 2011 by On-Waves
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <osmocom/core/rate_ctr.h>
+#include <osmocom/core/stats.h>
+#include <osmocom/core/talloc.h>
+#include <osmocom/core/utils.h>
+
+#include <osmocom/vty/logging.h>
+#include <osmocom/vty/telnet_interface.h>
+#include <osmocom/vty/stats.h>
+#include <osmocom/vty/misc.h>
+
+#include <osmo-pcap/common.h>
+#include <osmo-pcap/osmo_pcap_client.h>
+
+#include "osmopcapconfig.h"
+
+static const struct rate_ctr_desc pcap_client_ctr_desc[] = {
+ [CLIENT_CTR_CONNECT] = { "server:connect", "Connects to the server" },
+ [CLIENT_CTR_BYTES] = { "captured:bytes", "Captured bytes " },
+ [CLIENT_CTR_PKTS] = { "captured:pkts", "Captured packets " },
+ [CLIENT_CTR_2BIG] = { "bpf:too_big", "Captured data too big " },
+ [CLIENT_CTR_NOMEM] = { "client:no_mem", "No memory available " },
+ [CLIENT_CTR_QERR] = { "client:queue_err", "Can not queue data " },
+ [CLIENT_CTR_PERR] = { "client:pcap_err", "libpcap error " },
+ [CLIENT_CTR_WERR] = { "client:write_err", "Write error " },
+ [CLIENT_CTR_P_RECV] = { "pcap:recv", "PCAP received packets " },
+ [CLIENT_CTR_P_DROP] = { "pcap:drop", "PCAP dropped packets " },
+ [CLIENT_CTR_P_IFDROP] = { "pcap:ifdrop", "iface dropped packets " },
+};
+
+const struct rate_ctr_group_desc pcap_client_ctr_group_desc = {
+ .group_name_prefix = "pcap:client",
+ .group_description = "PCAP Client statistics",
+ .num_ctr = ARRAY_SIZE(pcap_client_ctr_desc),
+ .ctr_desc = pcap_client_ctr_desc,
+ .class_id = OSMO_STATS_CLASS_GLOBAL,
+};

To view, visit change 39173. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: osmo-pcap
Gerrit-Branch: master
Gerrit-Change-Id: I4b5ecdd6f9b0c646dd03ca3bc7fa24624fb9fcbc
Gerrit-Change-Number: 39173
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin@sysmocom.de>