LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Command line (ping) numbers precision (https://www.linuxquestions.org/questions/linux-newbie-8/command-line-ping-numbers-precision-4175478464/)

Buiosu 09-25-2013 05:00 AM

Command line (ping) numbers precision
 
Hello,

on my Ubuntu Server 13.04 64b (only command line) when I'm pinging another network entity I have one digit after decimal separator for rtt, like this:
Code:

64 bytes from 10.10.10.2: icmp_seq=962 ttl=62 time=18.5 ms
(though summarized min/avg/max rtt is displayed with three digits after separator).

I need to have result with higher precision of rtt time, e.g.:
Code:

64 bytes from 10.10.10.2: icmp_seq=962 ttl=62 time=18.467 ms
How can I adjust this display precision?
Should I look for some locales or elsewhere?

I apologize, I'm a total newbie I agree. It's urgent for me however (MSc thesis measurements), and I didn't know how to explicitly google it (decimals, separators, precision, resolution, ping, linux, command line - all combined in many ways).

Regards.

rtmistler 09-25-2013 07:50 AM

LOL! It just works for me.

Sorry for that. I think it's merely the version of ping, took me a bit, I assumed "-v", then "--version", but it's Capital-V "ping -V", down at the bottom.

The other option is to grab the ping source and rewrite it to print with greater precision. I'd try to just get the correct copy of ping to suit your needs.

Make sure the one you're using is not derived from Busybox, that may be your problem.

Code:

ping 127.0.0.1
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.039 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.027 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.024 ms
64 bytes from 127.0.0.1: icmp_seq=4 ttl=64 time=0.025 ms
^C
--- 127.0.0.1 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 2997ms
rtt min/avg/max/mdev = 0.024/0.028/0.039/0.008 ms

ping -h
Usage: ping [-LRUbdfnqrvVaA] [-c count] [-i interval] [-w deadline]
            [-p pattern] [-s packetsize] [-t ttl] [-I interface or address]
            [-M mtu discovery hint] [-S sndbuf]
            [ -T timestamp option ] [ -Q tos ] [hop1 ...] destination

which ping
/bin/ping

ls -l /bin/ping
-rwsr-xr-x 1 root root 34756 2010-03-11 18:12 /bin/ping

ping -V
ping utility, iputils-sss20071127

Added: I'm using Ubuntu 12.10, so I guess they changed it for release 13. Not nice of them.

Buiosu 09-25-2013 08:06 AM

I've got iputils-sss20101006. So I'll connect it to the Internet and look for updates maybe (despite your version is older).
Regards.

zhjim 09-25-2013 08:29 AM

Two ideas here. Either use the -D switch which prints the time with nanoseconds before each line. You maybe have to use the -i option to turn of wait intervall between packets. Or just subtract 1 seconds. Check man page for better overview.
Code:

[1380115547.971681] 64 bytes from 127.0.0.1: icmp_req=1 ttl=56 time=18.3 ms
[1380115547.989950] 64 bytes from 127.0.0.1: icmp_req=2 ttl=56 time=18.2 ms

Or you could use -c 1 option to just send one packet and then use the average numbers.

Buiosu 09-25-2013 09:31 AM

Rtmistler, I've downgraded iputils-ping to your version but it didn't change anything.
I'll probably have to go on with zhjim's solution (-D +math) or to simply deal with smaller precision, while the issue remains unknown... But I'm still curious what is going on. ;)

Regards.

rtmistler 09-25-2013 09:49 AM

Here's your problem. From the iputils-s20101006 package, ping_common.c, function gather_statistics():

Code:

                if (timing) {
                        if (triptime >= 100000)
                                printf(" time=%ld ms", triptime/1000);
                        else if (triptime >= 10000)
                                printf(" time=%ld.%01ld ms", triptime/1000,
                                      (triptime%1000)/100);
                        else if (triptime >= 1000)
                                printf(" time=%ld.%02ld ms", triptime/1000,
                                      (triptime%1000)/10);
                        else
                                printf(" time=%ld.%03ld ms", triptime/1000,
                                      triptime%1000);
                }

Your triptime is in excess of 10 mS so it's giving single digit precision in the print statement. To achieve greater precision in that case you would have to get rid of the "/100" and just use (triptime%1000) and change the %01ld to be %03ld.

Buiosu 09-26-2013 04:48 AM

[Solved] Command line (ping) numbers precision
 
Thanks a lot for your investigation! :)


All times are GMT -5. The time now is 12:38 AM.