Module: kamailio
Branch: master
Commit: 626a8bf3e6cbc6dbdf11de0e6f8737f08c79a0bb
URL: 
https://github.com/kamailio/kamailio/commit/626a8bf3e6cbc6dbdf11de0e6f8737f08c79a0bb

Author: Daniel-Constantin Mierla <[email protected]>
Committer: Daniel-Constantin Mierla <[email protected]>
Date: 2019-04-05T08:56:42+02:00

app_jsdt: use system time to compute execution duration

---

Modified: src/modules/app_jsdt/app_jsdt_api.c

---

Diff:  
https://github.com/kamailio/kamailio/commit/626a8bf3e6cbc6dbdf11de0e6f8737f08c79a0bb.diff
Patch: 
https://github.com/kamailio/kamailio/commit/626a8bf3e6cbc6dbdf11de0e6f8737f08c79a0bb.patch

---

diff --git a/src/modules/app_jsdt/app_jsdt_api.c 
b/src/modules/app_jsdt/app_jsdt_api.c
index 8ecd62c46b..abd54215da 100644
--- a/src/modules/app_jsdt/app_jsdt_api.c
+++ b/src/modules/app_jsdt/app_jsdt_api.c
@@ -1347,29 +1347,34 @@ int sr_kemi_jsdt_exec_func(duk_context *J, int eidx)
 {
        sr_kemi_t *ket;
        int ret;
-       unsigned int ms = 0;
+       struct timeval tvb, tve;
+       struct timezone tz;
+       unsigned int tdiff;
        int sline = 0;
 
        ket = sr_kemi_jsdt_export_get(eidx);
-       if(unlikely(cfg_get(core, core_cfg, latency_limit_action)>0)) {
-                       ms = TICKS_TO_MS(get_ticks_raw());
+       if(unlikely(cfg_get(core, core_cfg, latency_limit_action)>0)
+                       && is_printable(cfg_get(core, core_cfg, latency_log))) {
+               gettimeofday(&tvb, &tz);
        }
 
        ret = sr_kemi_jsdt_exec_func_ex(J, ket);
 
-       if(unlikely(cfg_get(core, core_cfg, latency_limit_action)>0)) {
-               ms = TICKS_TO_MS(get_ticks_raw()) - ms;
-               if(ms >= cfg_get(core, core_cfg, latency_limit_action)
-                               && is_printable(cfg_get(core, core_cfg, 
latency_log))) {
+       if(unlikely(cfg_get(core, core_cfg, latency_limit_action)>0)
+                       && is_printable(cfg_get(core, core_cfg, latency_log))) {
+               gettimeofday(&tve, &tz);
+               tdiff = (tve.tv_sec - tvb.tv_sec) * 1000000
+                                  + (tve.tv_usec - tvb.tv_usec);
+               if(tdiff >= cfg_get(core, core_cfg, latency_limit_action)) {
                        duk_inspect_callstack_entry(J, -1);
                        duk_get_prop_string(J, -1, "lineNumber");
                        sline = (int)duk_to_int(J, -1);
                        duk_pop_2(J);
                        LOG(cfg_get(core, core_cfg, latency_log),
                                        "alert - action KSR.%s%s%s(...)"
-                                       " took too long [%u ms] (line: %d)\n",
+                                       " took too long [%u us] (line: %d)\n",
                                        (ket->mname.len>0)?ket->mname.s:"",
-                                       (ket->mname.len>0)?".":"", 
ket->fname.s, ms, sline);
+                                       (ket->mname.len>0)?".":"", 
ket->fname.s, tdiff, sline);
                }
        }
 


_______________________________________________
Kamailio (SER) - Development Mailing List
[email protected]
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to