More accurate ping and handling all packet types properly
This commit is contained in:
+12
-12
@@ -21,9 +21,9 @@ public class PacketStatistics {
|
|||||||
receivedBytes += size;
|
receivedBytes += size;
|
||||||
receivedPackets ++;
|
receivedPackets ++;
|
||||||
|
|
||||||
receivedPacketList.add(new DataPoint(packet.getCreatedNanotime() / 1000L, packet.getSize()));
|
receivedPacketList.add(new DataPoint(packet.getCreatedNanotime(), packet.getSize()));
|
||||||
|
|
||||||
long t = System.currentTimeMillis() - 60_000L;
|
long t = System.nanoTime() - 60_000_000_000L;
|
||||||
receivedPacketList.removeIf(x -> x.getTime() < t);
|
receivedPacketList.removeIf(x -> x.getTime() < t);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,10 +33,10 @@ public class PacketStatistics {
|
|||||||
sentBytes += size;
|
sentBytes += size;
|
||||||
sentPackets ++;
|
sentPackets ++;
|
||||||
|
|
||||||
sentPacketList.add(new DataPoint(packet.getCreatedNanotime() / 1000L, packet.getSize()));
|
sentPacketList.add(new DataPoint(packet.getCreatedNanotime(), packet.getSize()));
|
||||||
|
|
||||||
// Remove oldest
|
// Remove oldest
|
||||||
long t = System.currentTimeMillis() - 60_000L;
|
long t = System.nanoTime() - 60_000_000_000L;
|
||||||
sentPacketList.removeIf(x -> x.getTime() < t);
|
sentPacketList.removeIf(x -> x.getTime() < t);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,7 +49,7 @@ public class PacketStatistics {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getSentPacketsLastSecond() {
|
public int getSentPacketsLastSecond() {
|
||||||
long now = System.currentTimeMillis() - 1_000L;
|
long now = System.currentTimeMillis() - 1_000_000_000L;
|
||||||
|
|
||||||
return (int) sentPacketList.stream()
|
return (int) sentPacketList.stream()
|
||||||
.filter(x -> x.getTime() >= now)
|
.filter(x -> x.getTime() >= now)
|
||||||
@@ -57,7 +57,7 @@ public class PacketStatistics {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getSentPacketsLastMinute() {
|
public int getSentPacketsLastMinute() {
|
||||||
long now = System.currentTimeMillis() - 60_000L;
|
long now = System.currentTimeMillis() - 1_000_000_000L;
|
||||||
|
|
||||||
return (int) sentPacketList.stream()
|
return (int) sentPacketList.stream()
|
||||||
.filter(x -> x.getTime() >= now)
|
.filter(x -> x.getTime() >= now)
|
||||||
@@ -69,7 +69,7 @@ public class PacketStatistics {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getReceivedPacketsLastSecond() {
|
public int getReceivedPacketsLastSecond() {
|
||||||
long now = System.currentTimeMillis() - 1_000L;
|
long now = System.currentTimeMillis() - 1_000_000_000L;
|
||||||
|
|
||||||
return (int) receivedPacketList.stream()
|
return (int) receivedPacketList.stream()
|
||||||
.filter(x -> x.getTime() >= now)
|
.filter(x -> x.getTime() >= now)
|
||||||
@@ -77,7 +77,7 @@ public class PacketStatistics {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getReceivedPacketsLastMinute() {
|
public int getReceivedPacketsLastMinute() {
|
||||||
long now = System.currentTimeMillis() - 60_000L;
|
long now = System.currentTimeMillis() - 60_000_000_000L;
|
||||||
|
|
||||||
return (int) receivedPacketList.stream()
|
return (int) receivedPacketList.stream()
|
||||||
.filter(x -> x.getTime() >= now)
|
.filter(x -> x.getTime() >= now)
|
||||||
@@ -90,7 +90,7 @@ public class PacketStatistics {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getSentBytesLastMinute() {
|
public int getSentBytesLastMinute() {
|
||||||
long now = System.currentTimeMillis() - 60_000L;
|
long now = System.currentTimeMillis() - 60_000_000_000L;
|
||||||
|
|
||||||
return sentPacketList.stream()
|
return sentPacketList.stream()
|
||||||
.filter(x -> x.getTime() >= now)
|
.filter(x -> x.getTime() >= now)
|
||||||
@@ -100,7 +100,7 @@ public class PacketStatistics {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getSentBytesLastSecond() {
|
public int getSentBytesLastSecond() {
|
||||||
long now = System.currentTimeMillis() - 1_000L;
|
long now = System.currentTimeMillis() - 1_000_000_000L;
|
||||||
|
|
||||||
return sentPacketList.stream()
|
return sentPacketList.stream()
|
||||||
.filter(x -> x.getTime() >= now)
|
.filter(x -> x.getTime() >= now)
|
||||||
@@ -110,7 +110,7 @@ public class PacketStatistics {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getReceivedBytesLastMinute() {
|
public int getReceivedBytesLastMinute() {
|
||||||
long now = System.currentTimeMillis() - 60_000L;
|
long now = System.currentTimeMillis() - 60_000_000_000L;
|
||||||
|
|
||||||
return receivedPacketList.stream()
|
return receivedPacketList.stream()
|
||||||
.filter(x -> x.getTime() >= now)
|
.filter(x -> x.getTime() >= now)
|
||||||
@@ -120,7 +120,7 @@ public class PacketStatistics {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getReceivedBytesLastSecond() {
|
public int getReceivedBytesLastSecond() {
|
||||||
long now = System.currentTimeMillis() - 1_000L;
|
long now = System.currentTimeMillis() - 1_000_000_000L;
|
||||||
|
|
||||||
return receivedPacketList.stream()
|
return receivedPacketList.stream()
|
||||||
.filter(x -> x.getTime() >= now)
|
.filter(x -> x.getTime() >= now)
|
||||||
|
|||||||
+2
-2
@@ -112,9 +112,9 @@ public class LocalTeamspeakClientSocket
|
|||||||
|
|
||||||
Pair<Double, Double> ping = getPing();
|
Pair<Double, Double> ping = getPing();
|
||||||
response.add(new CommandSingleParameter("connection_ping",
|
response.add(new CommandSingleParameter("connection_ping",
|
||||||
Integer.toString((int)(double)ping.getKey())));
|
Double.toString(Math.round(ping.getKey() * 1000D * 1000D) / 1000D)));
|
||||||
response.add(new CommandSingleParameter("connection_ping_deviation",
|
response.add(new CommandSingleParameter("connection_ping_deviation",
|
||||||
Integer.toString((int)(double)ping.getValue())));
|
Double.toString(Math.round(ping.getValue() * 1000D * 1000D) / 1000D)));
|
||||||
|
|
||||||
for (PacketKind kind : PacketKind.values()) {
|
for (PacketKind kind : PacketKind.values()) {
|
||||||
PacketStatistics stats = getStatistics(kind);
|
PacketStatistics stats = getStatistics(kind);
|
||||||
|
|||||||
@@ -143,9 +143,7 @@ public class ServerConnectionTest {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onChannelSubscribed(ChannelSubscribedEvent e) {
|
public void onChannelSubscribed(ChannelSubscribedEvent e) {
|
||||||
System.err.println("doing");
|
|
||||||
client.setNickname("EEEE" + (new Random().nextInt(1000)));
|
|
||||||
System.err.println("done");
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user