Timings: fixed receivePacket timer showing 2x the actual number of received packets

This commit is contained in:
Dylan K. Taylor 2023-03-11 19:12:48 +00:00
parent 328b87fc18
commit b13e97de3d
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -431,8 +431,12 @@ class NetworkSession{
throw new PacketHandlingException("Unexpected non-serverbound packet"); throw new PacketHandlingException("Unexpected non-serverbound packet");
} }
$timings = Timings::getDecodeDataPacketTimings($packet); $timings = Timings::getReceiveDataPacketTimings($packet);
$timings->startTiming(); $timings->startTiming();
try{
$decodeTimings = Timings::getDecodeDataPacketTimings($packet);
$decodeTimings->startTiming();
try{ try{
$stream = PacketSerializer::decoder($buffer, 0, $this->packetSerializerContext); $stream = PacketSerializer::decoder($buffer, 0, $this->packetSerializerContext);
try{ try{
@ -445,11 +449,11 @@ class NetworkSession{
$this->logger->debug("Still " . strlen($remains) . " bytes unread in " . $packet->getName() . ": " . bin2hex($remains)); $this->logger->debug("Still " . strlen($remains) . " bytes unread in " . $packet->getName() . ": " . bin2hex($remains));
} }
}finally{ }finally{
$timings->stopTiming(); $decodeTimings->stopTiming();
} }
$timings = Timings::getHandleDataPacketTimings($packet); $handlerTimings = Timings::getHandleDataPacketTimings($packet);
$timings->startTiming(); $handlerTimings->startTiming();
try{ try{
//TODO: I'm not sure DataPacketReceiveEvent should be included in the handler timings, but it needs to be //TODO: I'm not sure DataPacketReceiveEvent should be included in the handler timings, but it needs to be
//included for now to ensure the receivePacket timings are counted the way they were before //included for now to ensure the receivePacket timings are counted the way they were before
@ -458,6 +462,9 @@ class NetworkSession{
if(!$ev->isCancelled() && ($this->handler === null || !$packet->handle($this->handler))){ if(!$ev->isCancelled() && ($this->handler === null || !$packet->handle($this->handler))){
$this->logger->debug("Unhandled " . $packet->getName() . ": " . base64_encode($stream->getBuffer())); $this->logger->debug("Unhandled " . $packet->getName() . ": " . base64_encode($stream->getBuffer()));
} }
}finally{
$handlerTimings->stopTiming();
}
}finally{ }finally{
$timings->stopTiming(); $timings->stopTiming();
} }