Module: kamailio
Branch: master
Commit: 1205869ffd9c7e16a4f299b020f0bc90a2d4fcd7
URL: 
https://github.com/kamailio/kamailio/commit/1205869ffd9c7e16a4f299b020f0bc90a2d4fcd7

Author: Victor Seva <vs...@sipwise.com>
Committer: Victor Seva <linuxman...@torreviejawireless.org>
Date: 2023-05-25T00:16:12+02:00

core: pv_cache_dump

related to #3440

---

Modified: src/core/cfg_core.c
Modified: src/core/cfg_core.h
Modified: src/core/pvapi.c
Modified: src/core/pvapi.h

---

Diff:  
https://github.com/kamailio/kamailio/commit/1205869ffd9c7e16a4f299b020f0bc90a2d4fcd7.diff
Patch: 
https://github.com/kamailio/kamailio/commit/1205869ffd9c7e16a4f299b020f0bc90a2d4fcd7.patch

---

diff --git a/src/core/cfg_core.c b/src/core/cfg_core.c
index 52629bd9022..982cd6c92ea 100644
--- a/src/core/cfg_core.c
+++ b/src/core/cfg_core.c
@@ -55,6 +55,7 @@
 #include "sock_ut.h"
 #include "cfg/cfg.h"
 #include "cfg_core.h"
+#include "pvapi.h"
 
 struct cfg_group_core default_core_cfg = {
                L_WARN,         /*!<  print only msg. < L_WARN */
@@ -121,6 +122,7 @@ struct cfg_group_core default_core_cfg = {
                0,         /*!< latency limit db */
                0,         /*!< latency limit action */
                0,         /*!< latency limit cfg */
+               0,         /*!< pv_cache_dump */
                2048,  /*!< pv_cache_limit */
                0          /*!< pv_cache_action */
 };
@@ -336,6 +338,8 @@ cfg_def_t core_cfg_def[] = {
                                "limit in ms for alerting on time consuming 
config actions"},
                {"latency_limit_cfg", CFG_VAR_INT | CFG_ATOMIC, 0, 0, 0, 0,
                                "limit in ms for alerting on time consuming 
config execution"},
+               {"pv_cache_dump", CFG_VAR_INT, 0, 0, 0, pv_cache_dump_cb,
+                               "dump process pv cache, parameter: pid_number"},
                {"pv_cache_limit", CFG_VAR_INT | CFG_ATOMIC, 0, 0, 0, 0,
                                "limit to alert if too many vars in pv cache"},
                {"pv_cache_action", CFG_VAR_INT | CFG_ATOMIC, 0, 0, 0, 0,
diff --git a/src/core/cfg_core.h b/src/core/cfg_core.h
index e0f5c357073..18dc3b059f7 100644
--- a/src/core/cfg_core.h
+++ b/src/core/cfg_core.h
@@ -112,6 +112,7 @@ struct cfg_group_core
        int latency_limit_db;     /*!< alert limit of running db commands */
        int latency_limit_action; /*!< alert limit of running cfg actions */
        int latency_limit_cfg;    /*!< alert limit of running cfg routing 
script */
+       int pv_cache_dump;       /*!< dump process pv cache, parameter: 
pid_number */
        int pv_cache_limit;      /*!< alert limit of having too many vars in pv 
cache */
        int pv_cache_action; /*!< action to be taken on pv cache limit */
 };
diff --git a/src/core/pvapi.c b/src/core/pvapi.c
index 37a872b9575..0bb20367ba5 100644
--- a/src/core/pvapi.c
+++ b/src/core/pvapi.c
@@ -90,6 +90,38 @@ pv_cache_t **pv_cache_get_table(void)
        return NULL;
 }
 
+static void pv_cache_dump(int level)
+{
+       int i;
+       pv_cache_t *pvi = NULL;
+
+       if(_pv_cache_set == 0) {
+               LM_DBG("PV cache not initialized\n");
+               return;
+       }
+
+       for(i = 0; i < PV_CACHE_SIZE; i++) {
+               pvi = _pv_cache[i];
+               while(pvi) {
+                       LOG(level, "pvar [%.*s] found in cache[%d]\n", 
pvi->pvname.len,
+                                       pvi->pvname.s, i);
+                       pvi = pvi->next;
+               }
+       }
+}
+
+/* Dumps pv cache.
+ * Per-child process callback that is called
+ * when pv_cache_dump cfg var is changed.
+ */
+void pv_cache_dump_cb(str *gname, str *name)
+{
+       if(cfg_get(core, core_cfg, pv_cache_dump) == my_pid()) {
+               pv_cache_dump(cfg_get(core, core_cfg, memlog));
+               cfg_get(core, core_cfg, pv_cache_dump) = 0;
+       }
+}
+
 /**
  * @brief Check if a char is valid according to the PV syntax
  * @param c checked char
diff --git a/src/core/pvapi.h b/src/core/pvapi.h
index 729bcf307f0..9cea1a803d4 100644
--- a/src/core/pvapi.h
+++ b/src/core/pvapi.h
@@ -22,6 +22,7 @@
 
 #ifndef __pvapi_h__
 #define __pvapi_h__
+#include "str.h"
 
 int pv_init_api(void);
 void pv_destroy_api(void);
@@ -34,6 +35,7 @@ int pv_get_buffer_size(void);
 int pv_get_buffer_slots(void);
 void pv_set_buffer_size(int n);
 void pv_set_buffer_slots(int n);
+void pv_cache_dump_cb(str *gname, str *name);
 
 #endif /*__pvapi_h__*/
 

_______________________________________________
Kamailio (SER) - Development Mailing List
To unsubscribe send an email to sr-dev-le...@lists.kamailio.org

Reply via email to