Just (ab)use any other time function like "time"

tic() { TICFILE=$(mktemp); rm $TICFILE; mkfifo $TICFILE; ((TIME=$(time
cat $TICFILE 2>&1 | sed -rne '/real/{s/^real[[:blank:]]*//;p}'); echo
"$TIME">$TICFILE ) & )2>/dev/null; }
toc() { echo -n >$TICFILE; awk "BEGIN { print $(cat $TICFILE | sed -e
's/m/ * 60 +/;s/s//') }"; rm $TICFILE; }

$ tic
$ do something...
$ toc

Or you can save toc output to a var as

$ TIME=$(toc)

Ex:

root@router:~# tic; sleep 3; toc
3.01
root@router:~# tic; find / > /dev/null; toc
1.4

If lua can use module socket (package luasocket, normally not
installed), you could use:

root@router:~# lua -l"socket" -e 'print("Milliseconds: " ..
socket.gettime()*1000)'
Milliseconds: 1353642672185.1

And maybe other solutions using other sources...

Regards,
---
     Luiz Angelo Daros de Luca, Me.
            luizl...@gmail.com


2012/11/22 Gabriel <gto...@inti.gob.ar>:
> Hi,
>
> I'm using TP-Link WR741ND routers with openwrt, and I want to log some debug
> files, to know for example how many packets have been transmitted in a
> period of time. For that purpose I use while loops and log the results. The
> problem is that I couldn't find how to use a good time reference to measure
> the time periods. In a PC I can use the date command with nanoseconds
> resolution, but in openwrt it seems that it's not possible to get more
> resolution than 1 second, at least with the date command. I'd like to know
> if there's a way to get a resolution of at least milliseconds in user space.
> I've read in some posts that the problem with routers is that most of them
> don't have RTCs, but with ticks relative to processor's clock i'd be OK.
> I've also read here:
>
> https://forum.openwrt.org/viewtopic.php?id=21965
>
> people recommending to write a specific timer function, but i wanted to be
> sure that there's no a simple way.
>
> Regards
>
> Gabriel
> _______________________________________________
> openwrt-devel mailing list
> openwrt-devel@lists.openwrt.org
> https://lists.openwrt.org/mailman/listinfo/openwrt-devel
_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to