/**
  * Start an benchmarking timer.
  *
  * @param string $name The name of the timer to start.
  * @param string $message A message for your timer
  * @return boolean Always true
  */
 public static function start($name = null, $message = null)
 {
     $start = microtime(true);
     if (!$name) {
         $named = false;
         $calledFrom = debug_backtrace();
         $_name = $name = Debugger::trimpath($calledFrom[0]['file']) . ' line ' . $calledFrom[0]['line'];
     } else {
         $named = true;
     }
     if (!$message) {
         $message = $name;
     }
     $_name = $name;
     $i = 1;
     while (isset(self::$_timers[$name])) {
         $i++;
         $name = $_name . ' #' . $i;
     }
     if ($i > 1) {
         $message .= ' #' . $i;
     }
     self::$_timers[$name] = array('start' => $start, 'message' => $message, 'named' => $named);
     return true;
 }
Exemplo n.º 2
0
 /**
  * Stores a memory point in the internal tracker.
  * Takes a optional message name which can be used to identify the memory point.
  * If no message is supplied a debug_backtrace will be done to identify the memory point.
  *
  * @param string $message Message to identify this memory point.
  * @return bool
  */
 public static function record($message = null)
 {
     $memoryUse = self::getCurrent();
     if (!$message) {
         $named = false;
         $trace = debug_backtrace();
         $message = Debugger::trimpath($trace[0]['file']) . ' line ' . $trace[0]['line'];
     }
     if (isset(self::$_points[$message])) {
         $originalMessage = $message;
         $i = 1;
         while (isset(self::$_points[$message])) {
             $i++;
             $message = $originalMessage . ' #' . $i;
         }
     }
     self::$_points[$message] = $memoryUse;
     return true;
 }