Added more timings

This commit is contained in:
Shoghi Cervantes 2014-07-12 15:23:06 +02:00
parent 9bdd294a66
commit 9a4ead54e3
9 changed files with 48 additions and 30 deletions

View File

@ -1753,35 +1753,10 @@ class Server{
$this->logger->info("Done (" . round(microtime(true) - \pocketmine\START_TIME, 3) . 's)! For help, type "help" or "?"'); $this->logger->info("Done (" . round(microtime(true) - \pocketmine\START_TIME, 3) . 's)! For help, type "help" or "?"');
//if(Utils::getOS() === "win"){ //Workaround less usleep() waste $this->tickProcessor();
// $this->tickProcessorWindows();
//}else{
$this->tickProcessor();
//}
$this->forceShutdown(); $this->forceShutdown();
} }
/*private function tickProcessorWindows(){
$lastLoop = 0;
while($this->isRunning){
foreach($this->interfaces as $interface){
if($interface->process()){
$lastLoop = 0;
}
}
$this->generationManager->handlePackets();
if(($ticks = $this->tick()) !== true){
++$lastLoop;
if($lastLoop > 8){
usleep(1000);
}
}else{
$lastLoop = 0;
}
}
}*/
public function checkTicks(){ public function checkTicks(){
if($this->getTicksPerSecond() < 12){ if($this->getTicksPerSecond() < 12){
$this->logger->warning("Can't keep up! Is the server overloaded?"); $this->logger->warning("Can't keep up! Is the server overloaded?");
@ -1885,13 +1860,17 @@ class Server{
private function tickProcessor(){ private function tickProcessor(){
$lastLoop = 0; $lastLoop = 0;
$connectionTimer = Timings::$connectionTimer;
while($this->isRunning){ while($this->isRunning){
$connectionTimer->startTiming();
foreach($this->interfaces as $interface){ foreach($this->interfaces as $interface){
if($interface->process()){ if($interface->process()){
$lastLoop = 0; $lastLoop = 0;
} }
} }
$connectionTimer->stopTiming();
$this->generationManager->handlePackets(); $this->generationManager->handlePackets();
++$lastLoop; ++$lastLoop;
@ -1913,22 +1892,29 @@ class Server{
} }
private function checkTickUpdates($currentTick){ private function checkTickUpdates($currentTick){
//TODO: move this to each Level
//Update entities that need update //Update entities that need update
if(count(Entity::$needUpdate) > 0){ if(count(Entity::$needUpdate) > 0){
Timings::$tickEntityTimer->startTiming();
foreach(Entity::$needUpdate as $id => $entity){ foreach(Entity::$needUpdate as $id => $entity){
if($entity->onUpdate() === false){ if($entity->onUpdate() === false){
unset(Entity::$needUpdate[$id]); unset(Entity::$needUpdate[$id]);
} }
} }
Timings::$tickEntityTimer->stopTiming();
} }
//Update tiles that need update //Update tiles that need update
if(count(Tile::$needUpdate) > 0){ if(count(Tile::$needUpdate) > 0){
Timings::$tickTileEntityTimer->startTiming();
foreach(Tile::$needUpdate as $id => $tile){ foreach(Tile::$needUpdate as $id => $tile){
if($tile->onUpdate() === false){ if($tile->onUpdate() === false){
unset(Tile::$needUpdate[$id]); unset(Tile::$needUpdate[$id]);
} }
} }
Timings::$tickTileEntityTimer->stopTiming();
} }
//TODO: Add level blocks //TODO: Add level blocks

View File

@ -33,6 +33,7 @@ use pocketmine\event\entity\EntityMotionEvent;
use pocketmine\event\entity\EntityMoveEvent; use pocketmine\event\entity\EntityMoveEvent;
use pocketmine\event\entity\EntitySpawnEvent; use pocketmine\event\entity\EntitySpawnEvent;
use pocketmine\event\entity\EntityTeleportEvent; use pocketmine\event\entity\EntityTeleportEvent;
use pocketmine\event\Timings;
use pocketmine\level\format\Chunk; use pocketmine\level\format\Chunk;
use pocketmine\level\Level; use pocketmine\level\Level;
use pocketmine\level\Position; use pocketmine\level\Position;
@ -669,6 +670,8 @@ abstract class Entity extends Position implements Metadatable{
return; return;
} }
Timings::$entityMoveTimer->startTiming();
$ox = $this->x; $ox = $this->x;
$oy = $this->y; $oy = $this->y;
$oz = $this->z; $oz = $this->z;
@ -832,6 +835,7 @@ abstract class Entity extends Position implements Metadatable{
//TODO: vehicle collision events (first we need to spawn them!) //TODO: vehicle collision events (first we need to spawn them!)
Timings::$entityMoveTimer->stopTiming();
} }

View File

@ -26,6 +26,7 @@ use pocketmine\event\entity\EntityDamageByEntityEvent;
use pocketmine\event\entity\EntityDamageEvent; use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\event\entity\EntityDeathEvent; use pocketmine\event\entity\EntityDeathEvent;
use pocketmine\event\entity\EntityRegainHealthEvent; use pocketmine\event\entity\EntityRegainHealthEvent;
use pocketmine\event\Timings;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\nbt\tag\Short; use pocketmine\nbt\tag\Short;
use pocketmine\network\protocol\EntityEventPacket; use pocketmine\network\protocol\EntityEventPacket;
@ -97,6 +98,12 @@ abstract class Living extends Entity implements Damageable{
} }
} }
public function entityBaseTick(){
Timings::$timerEntityBaseTick->startTiming();
parent::entityBaseTick();
Timings::$timerEntityBaseTick->stopTiming();
}
/** /**
* @return Item[] * @return Item[]
*/ */

View File

@ -447,13 +447,17 @@ class Level implements ChunkManager, Metadatable{
$X = null; $X = null;
$Z = null; $Z = null;
//Do chunk updates //Do block updates
$this->timings->doTickPending->startTiming();
while($this->updateQueue->count() > 0 and $this->updateQueue->current()["priority"] <= $currentTick){ while($this->updateQueue->count() > 0 and $this->updateQueue->current()["priority"] <= $currentTick){
$block = $this->getBlock($this->updateQueue->extract()["data"]); $block = $this->getBlock($this->updateQueue->extract()["data"]);
$block->onUpdate(self::BLOCK_UPDATE_SCHEDULED); $block->onUpdate(self::BLOCK_UPDATE_SCHEDULED);
} }
$this->timings->doTickPending->stopTiming();
$this->timings->doTickTiles->startTiming();
$this->tickChunks(); $this->tickChunks();
$this->timings->doTickTiles->stopTiming();
$this->processChunkRequest(); $this->processChunkRequest();
@ -1486,7 +1490,9 @@ class Level implements ChunkManager, Metadatable{
if($chunk instanceof Chunk){ if($chunk instanceof Chunk){
return true; return true;
}else{ }else{
$this->timings->syncChunkLoadTimer->startTiming();
$this->provider->loadChunk($x, $z); $this->provider->loadChunk($x, $z);
$this->timings->syncChunkLoadTimer->stopTiming();
return $this->provider->getChunk($x, $z) instanceof Chunk; return $this->provider->getChunk($x, $z) instanceof Chunk;
} }
@ -1514,10 +1520,13 @@ class Level implements ChunkManager, Metadatable{
if($safe === true and $this->isChunkInUse($x, $z)){ if($safe === true and $this->isChunkInUse($x, $z)){
return false; return false;
} }
$this->timings->doChunkUnload->startTiming();
$this->provider->unloadChunk($x, $z, $safe); $this->provider->unloadChunk($x, $z, $safe);
Cache::remove("world:" . $this->getID() . ":$x:$z"); Cache::remove("world:" . $this->getID() . ":$x:$z");
$this->timings->doChunkUnload->stopTiming();
return true; return true;
} }

View File

@ -117,7 +117,10 @@ class Anvil extends BaseLevelProvider{
$regionX = $regionZ = null; $regionX = $regionZ = null;
self::getRegionIndex($chunkX, $chunkZ, $regionX, $regionZ); self::getRegionIndex($chunkX, $chunkZ, $regionX, $regionZ);
$this->loadRegion($regionX, $regionZ); $this->loadRegion($regionX, $regionZ);
$this->level->timings->syncChunkLoadDataTimer->startTiming();
$chunk = $this->getRegion($regionX, $regionZ)->readChunk($chunkX - $regionX * 32, $chunkZ - $regionZ * 32, $create); //generate empty chunk if not loaded $chunk = $this->getRegion($regionX, $regionZ)->readChunk($chunkX - $regionX * 32, $chunkZ - $regionZ * 32, $create); //generate empty chunk if not loaded
$this->level->timings->syncChunkLoadDataTimer->stopTiming();
if($chunk instanceof Chunk){ if($chunk instanceof Chunk){
$this->chunks[$index] = $chunk; $this->chunks[$index] = $chunk;

View File

@ -116,13 +116,14 @@ class RegionLoader{
$this->writeLocationIndex($index); $this->writeLocationIndex($index);
}elseif($compression !== self::COMPRESSION_ZLIB and $compression !== self::COMPRESSION_GZIP){ }elseif($compression !== self::COMPRESSION_ZLIB and $compression !== self::COMPRESSION_GZIP){
trigger_error("Invalid compression type", E_USER_WARNING); trigger_error("Invalid compression type", E_USER_WARNING);
return false; return false;
} }
$nbt = new NBT(NBT::BIG_ENDIAN); $nbt = new NBT(NBT::BIG_ENDIAN);
$nbt->readCompressed(fread($this->filePointer, $length - 1), $compression); $nbt->readCompressed(fread($this->filePointer, $length - 1), $compression);
$chunk = $nbt->getData(); $chunk = $nbt->getData();
if(!isset($chunk->Level) or !($chunk->Level instanceof Compound)){ if(!isset($chunk->Level) or !($chunk->Level instanceof Compound)){
return false; return false;
} }

View File

@ -98,6 +98,7 @@ abstract class BaseChunk implements Chunk{
$this->biomeColors = array_fill(0, 256, Binary::readInt("\x00\x85\xb2\x4a")); $this->biomeColors = array_fill(0, 256, Binary::readInt("\x00\x85\xb2\x4a"));
} }
$this->getLevel()->getLevel()->timings->syncChunkLoadEntitiesTimer->startTiming();
foreach($entities as $nbt){ foreach($entities as $nbt){
if($nbt instanceof Compound){ if($nbt instanceof Compound){
if(!isset($nbt->id)){ if(!isset($nbt->id)){
@ -115,8 +116,9 @@ abstract class BaseChunk implements Chunk{
} }
} }
} }
$this->getLevel()->getLevel()->timings->syncChunkLoadEntitiesTimer->stopTiming();
$this->getLevel()->getLevel()->timings->syncChunkLoadTileEntitiesTimer->startTiming();
foreach($tiles as $nbt){ foreach($tiles as $nbt){
if($nbt instanceof Compound){ if($nbt instanceof Compound){
if(!isset($nbt->id)){ if(!isset($nbt->id)){
@ -135,6 +137,7 @@ abstract class BaseChunk implements Chunk{
} }
} }
} }
$this->getLevel()->getLevel()->timings->syncChunkLoadTileEntitiesTimer->stopTiming();
} }
public function getX(){ public function getX(){

View File

@ -25,6 +25,7 @@
*/ */
namespace pocketmine\tile; namespace pocketmine\tile;
use pocketmine\event\Timings;
use pocketmine\level\format\Chunk; use pocketmine\level\format\Chunk;
use pocketmine\level\Position; use pocketmine\level\Position;
use pocketmine\nbt\tag\Compound; use pocketmine\nbt\tag\Compound;
@ -57,6 +58,9 @@ abstract class Tile extends Position{
protected $lastUpdate; protected $lastUpdate;
protected $server; protected $server;
/** @var \pocketmine\event\TimingsHandler */
public $tickTimer;
public function __construct(Chunk $chunk, Compound $nbt){ public function __construct(Chunk $chunk, Compound $nbt){
$this->server = $chunk->getLevel()->getLevel()->getServer(); $this->server = $chunk->getLevel()->getLevel()->getServer();
$this->chunk = $chunk; $this->chunk = $chunk;
@ -72,6 +76,7 @@ abstract class Tile extends Position{
$this->chunk->addTile($this); $this->chunk->addTile($this);
$this->getLevel()->addTile($this); $this->getLevel()->addTile($this);
$this->tickTimer = Timings::getTileEntityTimings($this);
} }
public function getID(){ public function getID(){

@ -1 +1 @@
Subproject commit 577c371aa07bd2aa3cedc3b7d4bcdc1d54999c70 Subproject commit df53c0844231a2ddc340dcd13a77944ca8822d27