record() public static method

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.
public static record ( string $message = null ) : boolean
$message string Message to identify this memory point.
return boolean
示例#1
0
 /**
  * Return an array of events to listen to.
  *
  * @return array
  */
 public function implementedEvents()
 {
     $before = function ($name) {
         return function () use($name) {
             DebugTimer::start($name, __d('debug_kit', $name));
         };
     };
     $after = function ($name) {
         return function () use($name) {
             DebugTimer::stop($name);
         };
     };
     $both = function ($name) use($before, $after) {
         return [['priority' => 0, 'callable' => $before('Event: ' . $name)], ['priority' => 999, 'callable' => $after('Event: ' . $name)]];
     };
     return ['Controller.initialize' => [['priority' => 0, 'callable' => function () {
         DebugMemory::record(__d('debug_kit', 'Controller initialization'));
     }], ['priority' => 0, 'callable' => $before('Event: Controller.initialize')], ['priority' => 999, 'callable' => $after('Event: Controller.initialize')]], 'Controller.startup' => [['priority' => 0, 'callable' => $before('Event: Controller.startup')], ['priority' => 999, 'callable' => $after('Event: Controller.startup')], ['priority' => 999, 'callable' => function () {
         DebugMemory::record(__d('debug_kit', 'Controller action start'));
         DebugTimer::start(__d('debug_kit', 'Controller action'));
     }]], 'Controller.beforeRender' => [['priority' => 0, 'callable' => function () {
         DebugTimer::stop(__d('debug_kit', 'Controller action'));
     }], ['priority' => 0, 'callable' => $before('Event: Controller.beforeRender')], ['priority' => 999, 'callable' => $after('Event: Controller.beforeRender')], ['priority' => 999, 'callable' => function () {
         DebugMemory::record(__d('debug_kit', 'View Render start'));
         DebugTimer::start(__d('debug_kit', 'View Render start'));
     }]], 'View.beforeRender' => $both('View.beforeRender'), 'View.afterRender' => $both('View.afterRender'), 'View.beforeLayout' => $both('View.beforeLayout'), 'View.afterLayout' => $both('View.afterLayout'), 'View.beforeRenderFile' => [['priority' => 0, 'callable' => function ($event, $filename) {
         DebugTimer::start(__d('debug_kit', 'Render {0}', $filename));
     }]], 'View.afterRenderFile' => [['priority' => 0, 'callable' => function ($event, $filename) {
         DebugTimer::stop(__d('debug_kit', 'Render {0}', $filename));
     }]], 'Controller.shutdown' => [['priority' => 0, 'callable' => $before('Event: Controller.shutdown')], ['priority' => 0, 'callable' => function () {
         DebugTimer::stop(__d('debug_kit', 'View Render start'));
         DebugMemory::record(__d('debug_kit', 'Controller shutdown'));
     }], ['priority' => 999, 'callable' => $after('Event: Controller.shutdown')]]];
 }
示例#2
0
 /**
  * test making memory use markers.
  *
  * @return void
  */
 public function testMemorySettingAndGetting()
 {
     DebugMemory::clear();
     $result = DebugMemory::record('test marker');
     $this->assertTrue($result);
     $result = DebugMemory::getAll(true);
     $this->assertEquals(count($result), 1);
     $this->assertTrue(isset($result['test marker']));
     $this->assertTrue(is_numeric($result['test marker']));
     $result = DebugMemory::getAll();
     $this->assertTrue(empty($result));
     DebugMemory::record('test marker');
     DebugMemory::record('test marker');
     $result = DebugMemory::getAll();
     $this->assertEquals(count($result), 2);
     $this->assertTrue(isset($result['test marker']));
     $this->assertTrue(isset($result['test marker #2']));
 }