/**
  * Test save timers
  *
  * @return void
  */
 public function testSaveTimers()
 {
     $timers = DebugTimer::getAll();
     $this->assertEquals(count($timers), 1);
     $article = $this->Article->newEntity(['user_id' => 1, 'title' => 'test', 'body' => 'test']);
     $this->Article->save($article);
     $result = DebugTimer::getAll();
     $this->assertEquals(count($result), 2);
 }
 /**
  * Wrapper around _isAuthorized to allow for timing
  *
  * @param array $user an array of user data. Can also be null
  * @param string $action The action to check access for
  * @return bool whether or not the user is authorized for access
  */
 public function isAuthorized($user, $action)
 {
     $timerExists = Configure::read('debug') && class_exists('\\DebugKit\\DebugTimer');
     if ($timerExists) {
         \DebugKit\DebugTimer::start(get_called_class() . '->isAuthorized()');
     }
     $return = $this->performCheck($user, $action);
     if ($timerExists) {
         \DebugKit\DebugTimer::stop(get_called_class() . '->isAuthorized()');
     }
     return $return;
 }
예제 #3
0
파일: Client.php 프로젝트: dorxy/debug_http
 /**
  * Helper method for doing non-GET requests.
  *
  * @param string $method  HTTP method.
  * @param string $url     URL to request.
  * @param mixed  $data    The request body.
  * @param array  $options The options to use. Contains auth, proxy etc.
  *
  * @return \Cake\Network\Http\Response
  */
 protected function _doRequest($method, $url, $data, $options)
 {
     $request = $this->_createRequest($method, $url, $data, $options);
     $timerKey = 'debug_http.call.' . $url;
     if (Configure::read('debug')) {
         DebugTimer::start($timerKey, $method . ' ' . $url);
     }
     $response = $this->send($request, $options);
     if (Configure::read('debug')) {
         DebugTimer::stop($timerKey);
         ClientCallPanel::addCall($request, $response, DebugTimer::elapsedTime($timerKey));
     }
     return $response;
 }
예제 #4
0
 /**
  * @param $identifier
  * @param array $parameters
  * @param null $context
  * @throws MacroException
  * @return mixed
  */
 public function runMacro($identifier, array $parameters = [], $context = null, array $options = [])
 {
     $options = Hash::merge(['validate' => false], $options);
     if (Plugin::loaded('DebugKit')) {
         DebugTimer::start(__d('macro', 'Macro: {0}', $identifier));
     }
     $macroParts = explode('::', $identifier);
     $name = $macroParts[0];
     $method = isset($macroParts[1]) ? $macroParts[1] : 'run';
     $this->getMacroRegistry()->reset();
     $config = [];
     /** @var Macro $macro */
     try {
         $macro = $this->getMacroRegistry()->load($name, $config);
         if ($context) {
             $macro->context($context);
         }
     } catch (MacroException $missing) {
         if (!$options['validate']) {
             throw $missing;
         }
         return $missing;
     }
     $callable = [$macro, $method];
     if (!is_callable($callable)) {
         $exception = new MissingMacroMethodException('Unknown method \'' . $method . '\' in macro ' . get_class($macro));
         if (!$options['validate']) {
             throw $exception;
         }
         return $exception;
     }
     $result = call_user_func_array($callable, $parameters);
     $elapsedTime = null;
     if (Plugin::loaded('DebugKit')) {
         $elapsedTime = DebugTimer::elapsedTime(__d('macro', 'Macro: {0}', $identifier), 10) * 1000;
         DebugTimer::stop(__d('macro', 'Macro: {0}', $identifier));
     }
     DebugMacro::record($identifier, $parameters, $context, $options, $result, $elapsedTime);
     if ($options['validate']) {
         return true;
     }
     return $result;
 }
예제 #5
0
 /**
  * afterSave, stop the timer started from a save.
  *
  * @param Cake\Event\Event $event The afterSave event
  * @return void
  */
 public function afterSave(Event $event)
 {
     $alias = $event->subject()->alias();
     DebugTimer::stop($alias . '_save');
 }
예제 #6
0
 /**
  * Get the summary for the panel.
  *
  * @return string
  */
 public function summary()
 {
     $time = Number::precision(DebugTimer::requestTime(), 2) . ' s';
     $memory = Number::toReadableSize(DebugMemory::getPeak());
     return "{$time} / {$memory}";
 }
예제 #7
0
 /**
  * {@inheritDoc}
  */
 public function clearGroup($group)
 {
     $this->_track('delete');
     DebugTimer::start('Cache.clearGroup ' . $group);
     $result = $this->_engine->clearGroup($group);
     DebugTimer::stop('Cache.clearGroup ' . $group);
     return $result;
 }
예제 #8
0
 /**
  * Test that methods are proxied.
  *
  * @return void
  */
 public function testProxyMethodsTimers()
 {
     $this->engine->read('key');
     $this->engine->write('key', 'value');
     $this->engine->delete('key');
     $this->engine->increment('key');
     $this->engine->decrement('key');
     $result = DebugTimer::getAll();
     $this->assertCount(6, $result);
     $this->assertArrayHasKey('Cache.read key', $result);
     $this->assertArrayHasKey('Cache.write key', $result);
     $this->assertArrayHasKey('Cache.delete key', $result);
     $this->assertArrayHasKey('Cache.increment key', $result);
     $this->assertArrayHasKey('Cache.decrement key', $result);
 }
예제 #9
0
 /**
  * Leave $profile.
  *
  * @param \Twig_Profiler_Profile $profile Profile.
  *
  * @return void
  */
 public function leave(\Twig_Profiler_Profile $profile)
 {
     parent::leave($profile);
     $name = 'Twig Template: ' . substr($profile->getName(), strlen(ROOT) + 1);
     DebugTimer::stop($name);
 }
예제 #10
0
 /**
  * test getting all the set timers.
  *
  * @return void
  */
 public function testGetTimers()
 {
     DebugTimer::start('test1', 'this is my first test');
     DebugTimer::stop('test1');
     usleep(50);
     DebugTimer::start('test2');
     DebugTimer::stop('test2');
     $timers = DebugTimer::getAll();
     $this->assertEquals(3, count($timers));
     $this->assertTrue(is_float($timers['test1']['time']));
     $this->assertTrue(isset($timers['test1']['message']));
     $this->assertTrue(isset($timers['test2']['message']));
 }