GenisysPro  for Minecraft PE/Windows 10 v1.1.x
Feature-rich server software for Minecraft PE and Windows 10 Edition
TimingsHandler Class Reference

Public Member Functions

 __construct ($name, TimingsHandler $parent=null)
 
 startTiming ()
 
 stopTiming ()
 
 reset ()
 
 remove ()
 

Static Public Member Functions

static printTimings ($fp)
 
static reload ()
 
static tick ($measure=true)
 

Constructor & Destructor Documentation

◆ __construct()

__construct (   $name,
TimingsHandler  $parent = null 
)
Parameters
string$name
TimingsHandler$parent
50  {
51  $this->name = $name;
52  if($parent !== null){
53  $this->parent = $parent;
54  }
55 
56  self::$HANDLERS[spl_object_hash($this)] = $this;
57  }

Member Function Documentation

◆ printTimings()

static printTimings (   $fp)
static
Parameters
$fp
62  {
63  fwrite($fp, "Minecraft" . PHP_EOL);
64 
65  foreach(self::$HANDLERS as $timings){
66  $time = $timings->totalTime;
67  $count = $timings->count;
68  if($count === 0){
69  continue;
70  }
71 
72  $avg = $time / $count;
73 
74  fwrite($fp, " " . $timings->name . " Time: " . round($time * 1000000000) . " Count: " . $count . " Avg: " . round($avg * 1000000000) . " Violations: " . $timings->violations . PHP_EOL);
75  }
76 
77  fwrite($fp, "# Version " . Server::getInstance()->getVersion() . PHP_EOL);
78  fwrite($fp, "# " . Server::getInstance()->getName() . " " . Server::getInstance()->getPocketMineVersion() . PHP_EOL);
79 
80  $entities = 0;
81  $livingEntities = 0;
82  foreach(Server::getInstance()->getLevels() as $level){
83  $entities += count($level->getEntities());
84  foreach($level->getEntities() as $e){
85  if($e instanceof Living){
86  ++$livingEntities;
87  }
88  }
89  }
90 
91  fwrite($fp, "# Entities " . $entities . PHP_EOL);
92  fwrite($fp, "# LivingEntities " . $livingEntities . PHP_EOL);
93  }

◆ reload()

static reload ( )
static
95  {
96  if(Server::getInstance()->getPluginManager()->useTimings()){
97  foreach(self::$HANDLERS as $timings){
98  $timings->reset();
99  }
100  TimingsCommand::$timingStart = microtime(true);
101  }
102  }

◆ remove()

remove ( )
168  {
169  unset(self::$HANDLERS[spl_object_hash($this)]);
170  }

◆ reset()

reset ( )
158  {
159  $this->count = 0;
160  $this->curCount = 0;
161  $this->violations = 0;
162  $this->curTickTotal = 0;
163  $this->totalTime = 0;
164  $this->start = 0;
165  $this->timingDepth = 0;
166  }

◆ startTiming()

startTiming ( )
131  {
132  if(PluginManager::$useTimings and ++$this->timingDepth === 1){
133  $this->start = microtime(true);
134  if($this->parent !== null and ++$this->parent->timingDepth === 1){
135  $this->parent->start = $this->start;
136  }
137  }
138  }

◆ stopTiming()

stopTiming ( )
140  {
142  if(--$this->timingDepth !== 0 or $this->start === 0){
143  return;
144  }
145 
146  $diff = microtime(true) - $this->start;
147  $this->totalTime += $diff;
148  $this->curTickTotal += $diff;
149  ++$this->curCount;
150  ++$this->count;
151  $this->start = 0;
152  if($this->parent !== null){
153  $this->parent->stopTiming();
154  }
155  }
156  }

◆ tick()

static tick (   $measure = true)
static
Parameters
bool$measure
107  {
109  if($measure){
110  foreach(self::$HANDLERS as $timings){
111  if($timings->curTickTotal > 0.05){
112  $timings->violations += round($timings->curTickTotal / 0.05);
113  }
114  $timings->curTickTotal = 0;
115  $timings->curCount = 0;
116  $timings->timingDepth = 0;
117  }
118  }else{
119  foreach(self::$HANDLERS as $timings){
120  $timings->totalTime -= $timings->curTickTotal;
121  $timings->count -= $timings->curCount;
122 
123  $timings->curTickTotal = 0;
124  $timings->curCount = 0;
125  $timings->timingDepth = 0;
126  }
127  }
128  }
129  }

The documentation for this class was generated from the following file: