[OpenSIPS-Users] time going backwards?
Gregory Massel
greg at switchtel.co.za
Sat Jun 26 17:37:19 EST 2021
Per https://www.opensips.org/Documentation/Script-CoreVar-3-1
<https://www.opensips.org/Documentation/Script-CoreVar-3-1>
$Tsm - reference to current microseconds _*of the current second*_
This means that if the second counter cycles up, the microsecond counter
will cycle back to zero and you'll get a negative.
e.g. Let's assume that at the time of the first reading of $Tsm it is
12:00:00.99999 and, at the time of the second reading, it's
12:00:01.00003, then you'll get a result of -0.99996, because you're
looking at the fraction of a second in isolation to the second counter.
So you probably need something like:
$var(t0s) = $Ts;
$var(t0ms) = $Tsm;
$var(node_number) = route(get_my_node_number);
$var(dur) = (($Ts - $var(t0s))*1000000) + $Tsm - $var(t0ms);
Note: I'm not sure whether the syntax above is correct (I've never tried
to do arithmetic operations within OpenSIPS), but the basic idea is there.
--Greg
On 2021-06-25 22:01, Kingsley Tart wrote:
> Hi,
>
> For testing, this code at the top of my route script:
>
> $var(t0) = $Tsm;
> $var(node_number) = route(get_my_node_number);
> $var(dur) = $Tsm - $var(t0);
> xlog("My node number is $var(node_number) and it took $var(dur) microsecconds to find out\n");
>
> has just logged this:
>
> Jun 25 20:55:01 [598]: My node number is -1 and it took 65 microsecconds to find out
> Jun 25 20:55:03 [598]: My node number is -1 and it took 67 microsecconds to find out
> Jun 25 20:55:05 [598]: My node number is -1 and it took 64 microsecconds to find out
> Jun 25 20:55:05 [578]: My node number is -1 and it took 602523 microsecconds to find out
> Jun 25 20:55:06 [579]: My node number is -1 and it took -79396 microsecconds to find out
> Jun 25 20:55:07 [598]: My node number is -1 and it took 63 microsecconds to find out
> Jun 25 20:55:07 [580]: My node number is -1 and it took -455503 microsecconds to find out
> Jun 25 20:55:07 [579]: My node number is -1 and it took 108 microsecconds to find out
> Jun 25 20:55:09 [598]: My node number is -1 and it took 78 microsecconds to find out
> Jun 25 20:55:11 [598]: My node number is -1 and it took 68 microsecconds to find out
> Jun 25 20:55:13 [598]: My node number is -1 and it took 66 microsecconds to find out
> Jun 25 20:55:15 [598]: My node number is -1 and it took 68 microsecconds to find out
> Jun 25 20:55:17 [598]: My node number is -1 and it took 65 microsecconds to find out
> Jun 25 20:55:18 [578]: My node number is -1 and it took 107 microsecconds to find out
> Jun 25 20:55:19 [598]: My node number is -1 and it took 71 microsecconds to find out
>
> which is weird because time seems to have gone backwards a couple of times.
>
> Using OpenSIPS 3.1.2 in a VM running Debian 10, with the host being a
> CentOS 7 machine running Qemu KVM.
>
> Any idea what's happening here?
>
> Cheers,
> Kingsley.
>
>
> _______________________________________________
> Users mailing list
> Users at lists.opensips.org
> http://lists.opensips.org/cgi-bin/mailman/listinfo/users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opensips.org/pipermail/users/attachments/20210626/e59bf5ce/attachment.html>
More information about the Users
mailing list