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 "?"');
//if(Utils::getOS() === "win"){ //Workaround less usleep() waste
// $this->tickProcessorWindows();
//}else{
$this->tickProcessor();
//}
$this->tickProcessor();
$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(){
if($this->getTicksPerSecond() < 12){
$this->logger->warning("Can't keep up! Is the server overloaded?");
@ -1885,13 +1860,17 @@ class Server{
private function tickProcessor(){
$lastLoop = 0;
$connectionTimer = Timings::$connectionTimer;
while($this->isRunning){
$connectionTimer->startTiming();
foreach($this->interfaces as $interface){
if($interface->process()){
$lastLoop = 0;
}
}
$connectionTimer->stopTiming();
$this->generationManager->handlePackets();
++$lastLoop;
@ -1913,22 +1892,29 @@ class Server{
}
private function checkTickUpdates($currentTick){
//TODO: move this to each Level
//Update entities that need update
if(count(Entity::$needUpdate) > 0){
Timings::$tickEntityTimer->startTiming();
foreach(Entity::$needUpdate as $id => $entity){
if($entity->onUpdate() === false){
unset(Entity::$needUpdate[$id]);
}
}
Timings::$tickEntityTimer->stopTiming();
}
//Update tiles that need update
if(count(Tile::$needUpdate) > 0){
Timings::$tickTileEntityTimer->startTiming();
foreach(Tile::$needUpdate as $id => $tile){
if($tile->onUpdate() === false){
unset(Tile::$needUpdate[$id]);
}
}
Timings::$tickTileEntityTimer->stopTiming();
}
//TODO: Add level blocks

View File

@ -33,6 +33,7 @@ use pocketmine\event\entity\EntityMotionEvent;
use pocketmine\event\entity\EntityMoveEvent;
use pocketmine\event\entity\EntitySpawnEvent;
use pocketmine\event\entity\EntityTeleportEvent;
use pocketmine\event\Timings;
use pocketmine\level\format\Chunk;
use pocketmine\level\Level;
use pocketmine\level\Position;
@ -669,6 +670,8 @@ abstract class Entity extends Position implements Metadatable{
return;
}
Timings::$entityMoveTimer->startTiming();
$ox = $this->x;
$oy = $this->y;
$oz = $this->z;
@ -832,6 +835,7 @@ abstract class Entity extends Position implements Metadatable{
//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\EntityDeathEvent;
use pocketmine\event\entity\EntityRegainHealthEvent;
use pocketmine\event\Timings;
use pocketmine\math\Vector3;
use pocketmine\nbt\tag\Short;
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[]
*/

View File

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

View File

@ -117,7 +117,10 @@ class Anvil extends BaseLevelProvider{
$regionX = $regionZ = null;
self::getRegionIndex($chunkX, $chunkZ, $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
$this->level->timings->syncChunkLoadDataTimer->stopTiming();
if($chunk instanceof Chunk){
$this->chunks[$index] = $chunk;

View File

@ -116,13 +116,14 @@ class RegionLoader{
$this->writeLocationIndex($index);
}elseif($compression !== self::COMPRESSION_ZLIB and $compression !== self::COMPRESSION_GZIP){
trigger_error("Invalid compression type", E_USER_WARNING);
return false;
}
$nbt = new NBT(NBT::BIG_ENDIAN);
$nbt->readCompressed(fread($this->filePointer, $length - 1), $compression);
$chunk = $nbt->getData();
if(!isset($chunk->Level) or !($chunk->Level instanceof Compound)){
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->getLevel()->getLevel()->timings->syncChunkLoadEntitiesTimer->startTiming();
foreach($entities as $nbt){
if($nbt instanceof Compound){
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){
if($nbt instanceof Compound){
if(!isset($nbt->id)){
@ -135,6 +137,7 @@ abstract class BaseChunk implements Chunk{
}
}
}
$this->getLevel()->getLevel()->timings->syncChunkLoadTileEntitiesTimer->stopTiming();
}
public function getX(){

View File

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

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