mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-30 07:09:56 +00:00
Timings: added timers for player data I/O
This commit is contained in:
parent
37ace19857
commit
4d42f0c3db
@ -519,30 +519,32 @@ class Server{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getOfflinePlayerData(string $name) : ?CompoundTag{
|
public function getOfflinePlayerData(string $name) : ?CompoundTag{
|
||||||
$name = strtolower($name);
|
return Timings::$syncPlayerDataLoad->time(function() use ($name) : ?CompoundTag{
|
||||||
$path = $this->getPlayerDataPath($name);
|
$name = strtolower($name);
|
||||||
|
$path = $this->getPlayerDataPath($name);
|
||||||
|
|
||||||
if(file_exists($path)){
|
if(file_exists($path)){
|
||||||
$contents = @file_get_contents($path);
|
$contents = @file_get_contents($path);
|
||||||
if($contents === false){
|
if($contents === false){
|
||||||
throw new \RuntimeException("Failed to read player data file \"$path\" (permission denied?)");
|
throw new \RuntimeException("Failed to read player data file \"$path\" (permission denied?)");
|
||||||
}
|
}
|
||||||
$decompressed = @zlib_decode($contents);
|
$decompressed = @zlib_decode($contents);
|
||||||
if($decompressed === false){
|
if($decompressed === false){
|
||||||
$this->logger->debug("Failed to decompress raw player data for \"$name\"");
|
$this->logger->debug("Failed to decompress raw player data for \"$name\"");
|
||||||
$this->handleCorruptedPlayerData($name);
|
$this->handleCorruptedPlayerData($name);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
try{
|
try{
|
||||||
return (new BigEndianNbtSerializer())->read($decompressed)->mustGetCompoundTag();
|
return (new BigEndianNbtSerializer())->read($decompressed)->mustGetCompoundTag();
|
||||||
}catch(NbtDataException $e){ //zlib decode error / corrupt data
|
}catch(NbtDataException $e){ //zlib decode error / corrupt data
|
||||||
$this->logger->debug("Failed to decode NBT data for \"$name\": " . $e->getMessage());
|
$this->logger->debug("Failed to decode NBT data for \"$name\": " . $e->getMessage());
|
||||||
$this->handleCorruptedPlayerData($name);
|
$this->handleCorruptedPlayerData($name);
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
return null;
|
||||||
return null;
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function saveOfflinePlayerData(string $name, CompoundTag $nbtTag) : void{
|
public function saveOfflinePlayerData(string $name, CompoundTag $nbtTag) : void{
|
||||||
@ -554,13 +556,15 @@ class Server{
|
|||||||
$ev->call();
|
$ev->call();
|
||||||
|
|
||||||
if(!$ev->isCancelled()){
|
if(!$ev->isCancelled()){
|
||||||
$nbt = new BigEndianNbtSerializer();
|
Timings::$syncPlayerDataSave->time(function() use ($name, $ev) : void{
|
||||||
try{
|
$nbt = new BigEndianNbtSerializer();
|
||||||
file_put_contents($this->getPlayerDataPath($name), zlib_encode($nbt->write(new TreeRoot($ev->getSaveData())), ZLIB_ENCODING_GZIP));
|
try{
|
||||||
}catch(\ErrorException $e){
|
file_put_contents($this->getPlayerDataPath($name), zlib_encode($nbt->write(new TreeRoot($ev->getSaveData())), ZLIB_ENCODING_GZIP));
|
||||||
$this->logger->critical($this->getLanguage()->translateString("pocketmine.data.saveError", [$name, $e->getMessage()]));
|
}catch(\ErrorException $e){
|
||||||
$this->logger->logException($e);
|
$this->logger->critical($this->getLanguage()->translateString("pocketmine.data.saveError", [$name, $e->getMessage()]));
|
||||||
}
|
$this->logger->logException($e);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,6 +107,11 @@ abstract class Timings{
|
|||||||
/** @var TimingsHandler */
|
/** @var TimingsHandler */
|
||||||
public static $craftingDataCacheRebuildTimer;
|
public static $craftingDataCacheRebuildTimer;
|
||||||
|
|
||||||
|
/** @var TimingsHandler */
|
||||||
|
public static $syncPlayerDataLoad;
|
||||||
|
/** @var TimingsHandler */
|
||||||
|
public static $syncPlayerDataSave;
|
||||||
|
|
||||||
/** @var TimingsHandler[] */
|
/** @var TimingsHandler[] */
|
||||||
public static $entityTypeTimingMap = [];
|
public static $entityTypeTimingMap = [];
|
||||||
/** @var TimingsHandler[] */
|
/** @var TimingsHandler[] */
|
||||||
@ -155,6 +160,9 @@ abstract class Timings{
|
|||||||
self::$permissibleCalculationTimer = new TimingsHandler("Permissible Calculation");
|
self::$permissibleCalculationTimer = new TimingsHandler("Permissible Calculation");
|
||||||
self::$permissionDefaultTimer = new TimingsHandler("Default Permission Calculation");
|
self::$permissionDefaultTimer = new TimingsHandler("Default Permission Calculation");
|
||||||
|
|
||||||
|
self::$syncPlayerDataLoad = new TimingsHandler("Player Data Load");
|
||||||
|
self::$syncPlayerDataSave = new TimingsHandler("Player Data Save");
|
||||||
|
|
||||||
self::$entityMoveTimer = new TimingsHandler(self::INCLUDED_BY_OTHER_TIMINGS_PREFIX . "entityMove");
|
self::$entityMoveTimer = new TimingsHandler(self::INCLUDED_BY_OTHER_TIMINGS_PREFIX . "entityMove");
|
||||||
self::$playerCheckNearEntitiesTimer = new TimingsHandler(self::INCLUDED_BY_OTHER_TIMINGS_PREFIX . "checkNearEntities");
|
self::$playerCheckNearEntitiesTimer = new TimingsHandler(self::INCLUDED_BY_OTHER_TIMINGS_PREFIX . "checkNearEntities");
|
||||||
self::$tickEntityTimer = new TimingsHandler(self::INCLUDED_BY_OTHER_TIMINGS_PREFIX . "tickEntity");
|
self::$tickEntityTimer = new TimingsHandler(self::INCLUDED_BY_OTHER_TIMINGS_PREFIX . "tickEntity");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user