Elgg  Version 6.1
Timer.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg;
4 
10 class Timer {
11  const MARKER_BEGIN = ':begin';
12  const MARKER_END = ':end';
13 
14  private $times = [];
15 
22  public function begin(array $keys) {
23  $this->getTreeNode($keys)[self::MARKER_BEGIN] = microtime(true);
24  }
25 
32  public function end(array $keys) {
33  $this->getTreeNode($keys)[self::MARKER_END] = microtime(true);
34  }
35 
42  public function hasEnded(array $keys) {
43  $node = $this->getTreeNode($keys);
44  return isset($node[self::MARKER_END]);
45  }
46 
52  public function getTimes() {
53  return $this->times;
54  }
55 
62  private function &getTreeNode(array $keys) {
63  $arr =& $this->times;
64 
65  foreach ($keys as $key) {
66  if (!isset($arr[$key])) {
67  $arr[$key] = [];
68  }
69 
70  $arr =& $arr[$key];
71  }
72 
73  return $arr;
74  }
75 }
begin(array $keys)
Record the start time of a period.
Definition: Timer.php:22
getTimes()
Get the tree of recorded start/end times.
Definition: Timer.php:52
Capture timing info for profiling.
Definition: Timer.php:10
$keys
Definition: access.php:31
end(array $keys)
Record the end time of a period.
Definition: Timer.php:32
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
Definition: summary.php:44
hasEnded(array $keys)
Has the end of the period been recorded?
Definition: Timer.php:42