Hello,
New to Kamailio, first post on this ML. I'll probably ask dumb questions, please bear with me :)
Here goes the first one.
I would like to compute a time difference (with microseconds precision) when handling a stateless SIP request.
I looked into the core functions and modules but did not find anything suitable. Before I start implementing this by myself, I'd like to know if there's a simpler way.
Thanks for your help!
Regards, Nicolas.
This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message.
On Fri, 2020-09-25 at 13:54 +0000, Chaigneau, Nicolas wrote:
--snip I would like to compute a time difference (with microseconds precision) when handling a stateless SIP request. --snip
Welcome!
Take a look at: https://www.kamailio.org/wiki/cookbooks/5.4.x/pseudovariables#timeval
You can get down to the microsecond level.
--snip I would like to compute a time difference (with microseconds precision) when handling a stateless SIP request. --snip
Welcome!
Take a look at: https://www.kamailio.org/wiki/cookbooks/5.4.x/pseudovariables#timeval
You can get down to the microsecond level.
Thanks!
Looking at src\modules\pv\pv_time.c, it seems TV functions just use "gettimeofday". I was looking for a time difference based on a monotonically increasing clock (to avoid possible NTP drifting imprecision).
I've looked at the "benchmark" module which seems to do something like that, but I don't think I can use it for what I need...
Anyhow, I have another question. Using the TV I've come up with the following. This works, except that I don't know how to convert an int to a string padded with zeroes (e.g. 51 => "051"). Is there a transformation that allows to do that?
$var(start_time) = $TV(Sn); # allows to cache $TV(s) and $TV(u)
(...)
$var(end_time) = $TV(Sn); $var(end_s) = $TV(sn); $var(end_us) = $TV(un); $var(diff_us) = $var(end_us) - $TV(u) + (1000000 * ($var(end_s) - $TV(s)));
# convert this to ms (integer part) and us (fractional part) $var(diff_ms) = $var(diff_us) / 1000; $var(diff_us_f) = $var(diff_us) - (1000 * $var(diff_ms));
$var(diff_ms_us) = $var(diff_ms) + "." + $var(diff_us_f); # need to format on 3 digits... can we do the equivalent of sprintf("%03u") somehow ?
This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message.
Hello,
you could probably combine some string transformation to get the desired result.
If your requirements are related to accounting, the acc module might bei easier to use.
Cheers,
Henning
-- Henning Westerholt - https://skalatan.de/blog/ Kamailio services - https://skalatan.de/services ________________________________ From: sr-users sr-users-bounces@lists.kamailio.org on behalf of Chaigneau, Nicolas nicolas.chaigneau@capgemini.com Sent: Friday, September 25, 2020 6:34:30 PM To: Kamailio (SER) - Users Mailing List sr-users@lists.kamailio.org Subject: Re: [SR-Users] Computing a time difference when handling a stateless SIP request
--snip I would like to compute a time difference (with microseconds precision) when handling a stateless SIP request. --snip
Welcome!
Take a look at: https://www.kamailio.org/wiki/cookbooks/5.4.x/pseudovariables#timeval
You can get down to the microsecond level.
Thanks!
Looking at src\modules\pv\pv_time.c, it seems TV functions just use "gettimeofday". I was looking for a time difference based on a monotonically increasing clock (to avoid possible NTP drifting imprecision).
I've looked at the "benchmark" module which seems to do something like that, but I don't think I can use it for what I need...
Anyhow, I have another question. Using the TV I've come up with the following. This works, except that I don't know how to convert an int to a string padded with zeroes (e.g. 51 => "051"). Is there a transformation that allows to do that?
$var(start_time) = $TV(Sn); # allows to cache $TV(s) and $TV(u)
(...)
$var(end_time) = $TV(Sn); $var(end_s) = $TV(sn); $var(end_us) = $TV(un); $var(diff_us) = $var(end_us) - $TV(u) + (1000000 * ($var(end_s) - $TV(s)));
# convert this to ms (integer part) and us (fractional part) $var(diff_ms) = $var(diff_us) / 1000; $var(diff_us_f) = $var(diff_us) - (1000 * $var(diff_ms));
$var(diff_ms_us) = $var(diff_ms) + "." + $var(diff_us_f); # need to format on 3 digits... can we do the equivalent of sprintf("%03u") somehow ?
This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message.
_______________________________________________ Kamailio (SER) - Users Mailing List sr-users@lists.kamailio.org https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
route { $avp(proc_start) = $TV(Sn);
...
$avp(proc_start) = $TV(Sn);
$var(proc_diff) = ( ((( $(var(cur_time){s.select,0,.}{s.int}) - $(avp(proc_start){s.select,0,.}{s.int}) ) * 1000000) + ( $(var(cur_time){s.select,1,.}{s.int}) - $(avp(proc_start){s.select,1,.}{s.int}) ) / 1000) mod 1000 );
xlog("L_INFO", "Request processing time: $var(proc_diff) ms\n");
if(!t_relay()) sl_reply_error(); }
On 9/25/20 3:11 PM, Henning Westerholt wrote:
Hello,
you could probably combine some string transformation to get the desired result.
If your requirements are related to accounting, the acc module might bei easier to use.
Cheers,
Henning
-- Henning Westerholt - https://skalatan.de/blog/ Kamailio services - https://skalatan.de/services
*From:* sr-users sr-users-bounces@lists.kamailio.org on behalf of Chaigneau, Nicolas nicolas.chaigneau@capgemini.com *Sent:* Friday, September 25, 2020 6:34:30 PM *To:* Kamailio (SER) - Users Mailing List sr-users@lists.kamailio.org *Subject:* Re: [SR-Users] Computing a time difference when handling a stateless SIP request
--snip I would like to compute a time difference (with microseconds precision) when handling a stateless SIP request. --snip
Welcome!
Take a look at: https://www.kamailio.org/wiki/cookbooks/5.4.x/pseudovariables#timeval
You can get down to the microsecond level.
Thanks!
Looking at src\modules\pv\pv_time.c, it seems TV functions just use "gettimeofday". I was looking for a time difference based on a monotonically increasing clock (to avoid possible NTP drifting imprecision).
I've looked at the "benchmark" module which seems to do something like that, but I don't think I can use it for what I need...
Anyhow, I have another question. Using the TV I've come up with the following. This works, except that I don't know how to convert an int to a string padded with zeroes (e.g. 51 => "051"). Is there a transformation that allows to do that?
$var(start_time) = $TV(Sn); # allows to cache $TV(s) and $TV(u)
(...)
$var(end_time) = $TV(Sn); $var(end_s) = $TV(sn); $var(end_us) = $TV(un); $var(diff_us) = $var(end_us) - $TV(u) + (1000000 * ($var(end_s)
- $TV(s)));
# convert this to ms (integer part) and us (fractional part) $var(diff_ms) = $var(diff_us) / 1000; $var(diff_us_f) = $var(diff_us) - (1000 * $var(diff_ms));
$var(diff_ms_us) = $var(diff_ms) + "." + $var(diff_us_f); # need to format on 3 digits... can we do the equivalent of sprintf("%03u") somehow ?
This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message.
Kamailio (SER) - Users Mailing List sr-users@lists.kamailio.org https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
Kamailio (SER) - Users Mailing List sr-users@lists.kamailio.org https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
On 9/25/20 3:22 PM, Alex Balashov wrote:
route { $avp(proc_start) = $TV(Sn);
...
$avp(proc_start) = $TV(Sn);
^^^^^^^^^^^^^^^^
Copy and paste accident. That was meant to be:
$var(cur_time) = $TV(Sn);
-- Alex
On Fri, 2020-09-25 at 15:34 +0000, Chaigneau, Nicolas wrote:
--snip I would like to compute a time difference (with microseconds precision) when handling a stateless SIP request. --snip
Welcome!
Take a look at:
https://www.kamailio.org/wiki/cookbooks/5.4.x/pseudovariables#timeval
You can get down to the microsecond level.
Thanks!
Looking at src\modules\pv\pv_time.c, it seems TV functions just use "gettimeofday". I was looking for a time difference based on a monotonically increasing clock (to avoid possible NTP drifting imprecision).
I've looked at the "benchmark" module which seems to do something like that, but I don't think I can use it for what I need...
Anyhow, I have another question. Using the TV I've come up with the following. This works, except that I don't know how to convert an int to a string padded with zeroes (e.g. 51 => "051"). Is there a transformation that allows to do that?
$var(start_time) = $TV(Sn); # allows to cache $TV(s) and $TV(u)
(...)
$var(end_time) = $TV(Sn); $var(end_s) = $TV(sn); $var(end_us) = $TV(un); $var(diff_us) = $var(end_us) - $TV(u) + (1000000 * ($var(end_s) - $TV(s)));
# convert this to ms (integer part) and us (fractional part) $var(diff_ms) = $var(diff_us) / 1000; $var(diff_us_f) = $var(diff_us) - (1000 * $var(diff_ms));
$var(diff_ms_us) = $var(diff_ms) + "." + $var(diff_us_f); # need to format on 3 digits... can we do the equivalent of sprintf("%03u") somehow ?
You may also want to look at benchmarking: https://www.kamailio.org/docs/modules/stable/modules/benchmark.html
As for the data formatting, I'm sure you can accomplish what you'd like with transformations, but that being said, it might also be beneficial to just mark the info and then use an outside script or programs to calculate the data.
--fred
On 25.09.20 17:34, Chaigneau, Nicolas wrote:
--snip I would like to compute a time difference (with microseconds precision) when handling a stateless SIP request. --snip
Welcome!
Take a look at: https://www.kamailio.org/wiki/cookbooks/5.4.x/pseudovariables#timeval
You can get down to the microsecond level.
Thanks!
Looking at src\modules\pv\pv_time.c, it seems TV functions just use "gettimeofday". I was looking for a time difference based on a monotonically increasing clock (to avoid possible NTP drifting imprecision).
I've looked at the "benchmark" module which seems to do something like that, but I don't think I can use it for what I need...
Anyhow, I have another question. Using the TV I've come up with the following. This works, except that I don't know how to convert an int to a string padded with zeroes (e.g. 51 => "051"). Is there a transformation that allows to do that?
$var(start_time) = $TV(Sn); # allows to cache $TV(s) and $TV(u)
(...)
$var(end_time) = $TV(Sn); $var(end_s) = $TV(sn); $var(end_us) = $TV(un); $var(diff_us) = $var(end_us) - $TV(u) + (1000000 * ($var(end_s) - $TV(s)));
# convert this to ms (integer part) and us (fractional part) $var(diff_ms) = $var(diff_us) / 1000; $var(diff_us_f) = $var(diff_us) - (1000 * $var(diff_ms));
$var(diff_ms_us) = $var(diff_ms) + "." + $var(diff_us_f); # need to format on 3 digits... can we do the equivalent of sprintf("%03u") somehow ?
You can try with concatenating a variable set to "000" stripped by the length of milliseconds string with the value of the milliseconds string -- see the transformations cookbook for strip variant.
Also, useful for complex operations, have in mind that you can combine use of kamailio cfg scripting language with other embedded interpreters, such as app_jsdt, app_lua, app_python, ...
On the other hand, if you just want to log how long it takes to execute config for a request or a reply, then you can get it by tuning the value of core parameter:
* https://www.kamailio.org/wiki/cookbooks/5.4.x/core#latency_cfg_log
Cheers, Daniel
You can try with concatenating a variable set to "000" stripped by the length of milliseconds string with the value of the milliseconds string -- see the transformations cookbook for strip variant.
Also, useful for complex operations, have in mind that you can combine use of kamailio cfg scripting language with other embedded interpreters, such as app_jsdt, app_lua, app_python, ...
On the other hand, if you just want to log how long it takes to execute config for a request or a reply, then you can get it by tuning the value of core parameter:
* https://www.kamailio.org/wiki/cookbooks/5.4.x/core#latency_cfg_log
Cheers, Daniel
Thanks Daniel, this fully answers my question. :)
Regards, Nicolas.
This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message.