point-source / dart_ping

Multi-platform network ping utility for Dart
30 stars 13 forks source link

PingSummary shows unexpected duration #58

Open rdivanji opened 8 months ago

rdivanji commented 8 months ago

If I call Ping(google.com, count: 5) and listen for events, each individual PingResponse notes <25ms time, however the PingSummary shows a total of ~4000ms. Where does this time come from? Using this on Android API 33 emulator with version 9.0.1.

image
point-source commented 8 months ago

Here is the output if I run the equivalent command on a terminal within the android emulator:

~ $ ping -O -n -W 2 -i 1 -t 255 -c 5 google.com
PING google.com (172.217.14.110) 56(84) bytes of data.
64 bytes from 172.217.14.110: icmp_seq=1 ttl=255 time=4.83 ms
64 bytes from 172.217.14.110: icmp_seq=2 ttl=255 time=16.5 ms
64 bytes from 172.217.14.110: icmp_seq=3 ttl=255 time=6.15 ms
64 bytes from 172.217.14.110: icmp_seq=4 ttl=255 time=9.43 ms
64 bytes from 172.217.14.110: icmp_seq=5 ttl=255 time=5.02 ms

--- google.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4014ms
rtt min/avg/max/mdev = 4.837/8.392/16.503/4.378 ms

Notice that they have very similar timings and that the summary shows a total time of 4014. This is using the native ping binary in the Android OS, not using my library or any dart/flutter code at all.

The reason for this is that the version of iputils-ping that Android uses is reporting the total time that the whole ping process took rather than the sum of all pings. More information about this here and also here. I believe this is the intended behavior by the iputils-ping developers.

If you would like to reproduce this yourself, you can install a terminal emulator (such as Termux) on your Android system and run this command: ping -O -n -W 2 -i 1 -t 255 -c 5 google.com

This is equivalent to the dart_ping library running Ping(google.com, count: 5) and can be displayed by doing this in your code:

final ping = Ping(google.com, count: 5);
print(ping.command); // Displays the exact command that will be run in a background shell / process
rdivanji commented 8 months ago

I see, thanks for pointing this out. I ran the command on my MacOS terminal and it does not show the total time this way. Is it possible, using a custom parser for example, to grab the last line that shows the min/max/mdev or would the most feasible way be calculating that all manually using the individual PingResponse values?

point-source commented 8 months ago

Yes, it could be retrieved. Just haven't put the effort in to do it since it varies across platforms and I wasn't sure if anyone needed it. Would have to create regex strings that work on each platform and then integrate. Happy to do this as time allows or will also accept a PR that does this. If this is something you would like to have, could you do a PR or open a new ticket for it? Thanks!

rdivanji commented 8 months ago

It's not something I need immediately since I can just manually calculate the timings, but seems like it'll be something fun to look in to. I'll give it my best shot