25 const DEFAULT_WATCH =
'default';
35 public function __construct(Logger $logger)
37 $this->logger = $logger;
39 $this->startTime = $this->getTimestamp();
40 $this->watchTimes = array(self::DEFAULT_WATCH => $this->startTime);
48 public function tic($watch = self::DEFAULT_WATCH)
50 $this->watchTimes[$watch] = $this->getTimestamp();
57 public function toc($text, $watch = self::DEFAULT_WATCH)
59 if (! array_key_exists($watch, $this->watchTimes)) {
60 $watch = self::DEFAULT_WATCH;
61 $text .=
" using watch '$watch'";
62 }
else if (empty($text)) {
63 $text =
"Using watch '$watch'";
74 $endTime = $this->getTimestamp();
85 $this->logger->debug(sprintf(
"%s (%.3fms)", $text, ($endTime - $startTime) * 1000));
86 $this->startTime = $endTime;
89 protected function getTimestamp()
91 return microtime(
true);
logWithStartTime($text, $startTime)
tic($watch=self::DEFAULT_WATCH)
start stopwatch timer
logWithStartAndEndTime($text, $startTime, $endTime)
toc($text, $watch=self::DEFAULT_WATCH)