MT#56571 cfgt: route_log

Change-Id: Ic1f60cfb4626282a2bf296a9010c7ea9368d7413
mr11.4
Victor Seva 2 years ago
parent f6519f8dca
commit e31257606c

@ -49,6 +49,7 @@ sipwise/lcr-stats.patch
sipwise/dialog-support-profile_get_size-for-all-profiles.patch
### active development
sipwise/pv_headers-rework-pvh_remove_header_param-take-two.patch
sipwise/cfgt-route-log.patch
#
### Don't just put stuff in any order
### use gbp pq import/export tooling to help maintain patches

@ -0,0 +1,207 @@
From: Victor Seva <vseva@sipwise.com>
Date: Wed, 29 Mar 2023 12:12:54 +0200
Subject: cfgt: route log
---
src/modules/cfgt/cfgt_int.c | 39 ++++++++++++++++++++++++++++++++++++-
src/modules/cfgt/cfgt_int.h | 3 ++-
src/modules/cfgt/cfgt_mod.c | 4 +++-
src/modules/cfgt/doc/cfgt_admin.xml | 19 ++++++++++++++++++
4 files changed, 62 insertions(+), 3 deletions(-)
diff --git a/src/modules/cfgt/cfgt_int.c b/src/modules/cfgt/cfgt_int.c
index 683b39f..9470783 100644
--- a/src/modules/cfgt/cfgt_int.c
+++ b/src/modules/cfgt/cfgt_int.c
@@ -1,6 +1,6 @@
/**
*
- * Copyright (C) 2015 Victor Seva (sipwise.com)
+ * Copyright (C) 2015-2023 Victor Seva (sipwise.com)
*
* This file is part of Kamailio, a free SIP server.
*
@@ -22,6 +22,7 @@
#define _GNU_SOURCE
#include <stdio.h>
#include <sys/stat.h>
+#include <sys/time.h>
#include <dirent.h>
#include <string.h>
#include <errno.h>
@@ -45,6 +46,7 @@ str cfgt_hdr_prefix = {"NGCP%", 5};
str cfgt_basedir = {"/tmp", 4};
int cfgt_mask = CFGT_DP_ALL;
int cfgt_skip_unknown = 0;
+int cfgt_route_log = 0;
int not_sip = 0;
int _cfgt_get_filename(int msgid, str uuid, str *dest, int *dir);
@@ -462,6 +464,7 @@ int _cfgt_set_dump(struct sip_msg *msg, cfgt_node_p node, str *flow)
{
int len;
char v;
+ unsigned long int tdiff;
srjson_t *f, *vars;
if(node == NULL || flow == NULL)
@@ -493,6 +496,17 @@ int _cfgt_set_dump(struct sip_msg *msg, cfgt_node_p node, str *flow)
return -1;
}
+ if(node->route->duration.tv_usec > 0) {
+ tdiff = (node->route->duration.tv_sec) * 1000000
+ + (node->route->duration.tv_usec);
+ f = srjson_CreateNumber(&node->jdoc, tdiff);
+ if(f == NULL) {
+ LM_ERR("cannot create json object\n");
+ return -1;
+ }
+ srjson_AddItemToObject(&node->jdoc, vars, "execution_usec", f);
+ }
+
f = srjson_CreateObject(&node->jdoc);
if(f == NULL) {
LM_ERR("cannot create json object\n");
@@ -505,6 +519,21 @@ int _cfgt_set_dump(struct sip_msg *msg, cfgt_node_p node, str *flow)
return 0;
}
+static void _cfgt_log_route(cfgt_str_list_p route)
+{
+ unsigned long int tdiff;
+ if(!route) {
+ LM_BUG("empty route\n");
+ return;
+ }
+
+ if(route->duration.tv_usec > 0) {
+ tdiff = (route->duration.tv_sec) * 1000000 + (route->duration.tv_usec);
+ LM_WARN("[%.*s] exectime=%lu usec\n", route->s.len, route->s.s,
+ tdiff);
+ }
+}
+
void _cfgt_set_type(cfgt_str_list_p route, struct action *a)
{
switch(a->type) {
@@ -520,6 +549,8 @@ void _cfgt_set_type(cfgt_str_list_p route, struct action *a)
route->type = CFGT_DROP_E;
LM_DBG("set[%.*s]->CFGT_DROP_E\n", route->s.len, route->s.s);
}
+ gettimeofday(&route->end, NULL);
+ timersub(&route->end, &route->start, &route->duration);
break;
case ROUTE_T:
route->type = CFGT_ROUTE;
@@ -534,6 +565,8 @@ void _cfgt_set_type(cfgt_str_list_p route, struct action *a)
LM_DBG("[%.*s] already set to CFGT_DROP_E[%d]\n", route->s.len,
route->s.s, a->type);
}
+ gettimeofday(&route->end, NULL);
+ timersub(&route->end, &route->start, &route->duration);
break;
}
}
@@ -553,6 +586,7 @@ int _cfgt_add_routename(cfgt_node_p node, struct action *a, str *routename)
memset(node->route, 0, sizeof(cfgt_str_list_t));
node->flow_head = node->route;
node->route->type = CFGT_ROUTE;
+ gettimeofday(&node->route->start, NULL);
ret = 1;
} else {
LM_DBG("actual routename:[%.*s][%d]\n", node->route->s.len,
@@ -600,6 +634,7 @@ int _cfgt_add_routename(cfgt_node_p node, struct action *a, str *routename)
route->prev = node->route;
node->route->next = route;
node->route = route;
+ gettimeofday(&node->route->start, NULL);
_cfgt_set_type(node->route, a);
}
node->route->s.s = routename->s;
@@ -617,6 +652,8 @@ void _cfgt_del_routename(cfgt_node_p node)
}
LM_DBG("del route[%.*s]\n", node->route->s.len, node->route->s.s);
node->route = node->route->prev;
+ if(cfgt_route_log)
+ _cfgt_log_route(node->route->next);
pkg_free(node->route->next);
node->route->next = NULL;
}
diff --git a/src/modules/cfgt/cfgt_int.h b/src/modules/cfgt/cfgt_int.h
index 197e4bb..1564daa 100644
--- a/src/modules/cfgt/cfgt_int.h
+++ b/src/modules/cfgt/cfgt_int.h
@@ -1,6 +1,6 @@
/**
*
- * Copyright (C) 2015 Victor Seva (sipwise.com)
+ * Copyright (C) 2015-2023 Victor Seva (sipwise.com)
*
* This file is part of Kamailio, a free SIP server.
*
@@ -48,6 +48,7 @@ typedef struct _cfgt_str_list
{
str s;
enum _cfgt_action_type type;
+ struct timeval start, end, duration;
struct _cfgt_str_list *next, *prev;
} cfgt_str_list_t, *cfgt_str_list_p;
diff --git a/src/modules/cfgt/cfgt_mod.c b/src/modules/cfgt/cfgt_mod.c
index 10b0889..1d004ef 100644
--- a/src/modules/cfgt/cfgt_mod.c
+++ b/src/modules/cfgt/cfgt_mod.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2015 Victor Seva (sipwise.com)
+ * Copyright (C) 2015-2023 Victor Seva (sipwise.com)
*
* This file is part of Kamailio, a free SIP server.
*
@@ -43,6 +43,7 @@ extern int cfgt_mask;
extern str cfgt_basedir;
extern str cfgt_hdr_prefix;
extern int cfgt_skip_unknown;
+extern int cfgt_route_log;
/* clang-format off */
/*! \brief
* Exported functions
@@ -60,6 +61,7 @@ static param_export_t params[] = {
{"mask", INT_PARAM, &cfgt_mask},
{"callid_prefix", PARAM_STR, &cfgt_hdr_prefix},
{"skip_unknown", INT_PARAM, &cfgt_skip_unknown},
+ {"route_log", INT_PARAM, &cfgt_route_log},
{0, 0, 0}
};
diff --git a/src/modules/cfgt/doc/cfgt_admin.xml b/src/modules/cfgt/doc/cfgt_admin.xml
index 84d3df6..73f8565 100644
--- a/src/modules/cfgt/doc/cfgt_admin.xml
+++ b/src/modules/cfgt/doc/cfgt_admin.xml
@@ -163,6 +163,25 @@ modparam("cfgt", "callid_prefix", "TEST-ID%")
...
modparam("cfgt", "skip_unknown", "1")
...
+</programlisting>
+ </example>
+ </section>
+ <section id="cfg.p.route_log">
+ <title><varname>route_log</varname> (int)</title>
+ <para>
+ If enabled, value different from 0, cfgt will log (WARN) the execution time of routes.
+ </para>
+ <para>
+ <emphasis>
+ Default value is <quote>0</quote>, false.
+ </emphasis>
+ </para>
+ <example>
+ <title>Set <varname>route_log</varname> parameter</title>
+ <programlisting format="linespecific">
+...
+modparam("cfgt", "route_log", "1")
+...
</programlisting>
</example>
</section>
Loading…
Cancel
Save