Split packet receive timings into decode and handle subcomponents

This commit is contained in:
Dylan K. Taylor 2022-07-24 21:16:52 +01:00
parent 2940547026
commit 42f9336f7a
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
2 changed files with 31 additions and 2 deletions

View File

@ -374,9 +374,8 @@ class NetworkSession{
throw new PacketHandlingException("Unexpected non-serverbound packet");
}
$timings = Timings::getReceiveDataPacketTimings($packet);
$timings = Timings::getDecodeDataPacketTimings($packet);
$timings->startTiming();
try{
$stream = PacketSerializer::decoder($buffer, 0, $this->packetSerializerContext);
try{
@ -388,7 +387,15 @@ class NetworkSession{
$remains = substr($stream->getBuffer(), $stream->getOffset());
$this->logger->debug("Still " . strlen($remains) . " bytes unread in " . $packet->getName() . ": " . bin2hex($remains));
}
}finally{
$timings->stopTiming();
}
$timings = Timings::getHandleDataPacketTimings($packet);
$timings->startTiming();
try{
//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
$ev = new DataPacketReceiveEvent($this, $packet);
$ev->call();
if(!$ev->isCancelled() && ($this->handler === null || !$packet->handle($this->handler))){

View File

@ -119,6 +119,12 @@ abstract class Timings{
public static $tileEntityTypeTimingMap = [];
/** @var TimingsHandler[] */
public static $packetReceiveTimingMap = [];
/** @var TimingsHandler[] */
private static array $packetDecodeTimingMap = [];
/** @var TimingsHandler[] */
private static array $packetHandleTimingMap = [];
/** @var TimingsHandler[] */
public static $packetSendTimingMap = [];
/** @var TimingsHandler[] */
@ -229,6 +235,22 @@ abstract class Timings{
return self::$packetReceiveTimingMap[$pid];
}
public static function getDecodeDataPacketTimings(ServerboundPacket $pk) : TimingsHandler{
$pid = $pk->pid();
return self::$packetDecodeTimingMap[$pid] ??= new TimingsHandler(
self::INCLUDED_BY_OTHER_TIMINGS_PREFIX . "Decode - " . $pk->getName() . " [0x" . dechex($pid) . "]",
self::getReceiveDataPacketTimings($pk)
);
}
public static function getHandleDataPacketTimings(ServerboundPacket $pk) : TimingsHandler{
$pid = $pk->pid();
return self::$packetHandleTimingMap[$pid] ??= new TimingsHandler(
self::INCLUDED_BY_OTHER_TIMINGS_PREFIX . "Handler - " . $pk->getName() . " [0x" . dechex($pid) . "]",
self::getReceiveDataPacketTimings($pk)
);
}
public static function getSendDataPacketTimings(ClientboundPacket $pk) : TimingsHandler{
$pid = $pk->pid();
if(!isset(self::$packetSendTimingMap[$pid])){