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(a)lists.kamailio.org> on behalf of
Chaigneau, Nicolas <nicolas.chaigneau(a)capgemini.com>
*Sent:* Friday, September 25, 2020 6:34:30 PM
*To:* Kamailio (SER) - Users Mailing List <sr-users(a)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(a)lists.kamailio.org
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
_______________________________________________
Kamailio (SER) - Users Mailing List
sr-users(a)lists.kamailio.org
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
--
Alex Balashov | Principal | Evariste Systems LLC
Tel: +1-706-510-6800 / +1-800-250-5920 (toll-free)
Web: