Advertisement
Guest User

Untitled

a guest
Sep 28th, 2011
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.95 KB | None | 0 0
  1.  
  2. class Plugin_Benchmark extends Zend_Controller_Plugin_Abstract {
  3.  
  4.    
  5.     protected $_routeStart;
  6.     protected $_routeEnd;
  7.    
  8.     protected $_dispatchLoopStart;
  9.     protected $_dispatchLoopEnd;
  10.    
  11.     protected $_dispatchStart;
  12.     protected $_dispatchEnd;
  13.    
  14.     protected $_speedAgentStart;
  15.     protected $_speedAgentEnd;
  16.    
  17.     public function __construct() {
  18.         $this->_speedAgentStart = microtime();
  19.     }
  20.    
  21.     public function generateSpeedReport() {
  22.         $this->_speedAgentEnd = microtime();
  23.    
  24.         $route = $this->_routeEnd - $this->_routeStart;
  25.         $dispatchLoop = $this->_dispatchLoopEnd - $this->_dispatchLoopStart;
  26.         $dispatch = $this->_dispatchEnd - $this->_dispatchStart;
  27.         $speedAgent = $this->_speedAgentEnd - $this->_speedAgentStart;
  28.  
  29.        
  30.        
  31.         $speedAgent = "<!-- \n Unit: Microseconds \n Routing: $route \n Dispatch : $dispatch \n Dispatch Loop: $dispatchLoop \n Total : $speedAgent \n !--> ";
  32.        
  33.         return $speedAgent;
  34.        
  35.     }
  36.    
  37.     public function routeStartup(Zend_Controller_Request_Abstract $request)
  38.     {
  39.         $this->_routeStart = microtime();
  40.     }
  41.  
  42.     public function routeShutdown(Zend_Controller_Request_Abstract $request)
  43.     {
  44.         $this->_routeEnd = microtime();
  45.     }
  46.  
  47.     public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
  48.     {
  49.         $this->_dispatchLoopStart = microtime();
  50.     }
  51.  
  52.     public function preDispatch(Zend_Controller_Request_Abstract $request)
  53.     {
  54.         $this->_dispatchStart = microtime();
  55.     }
  56.  
  57.     public function postDispatch(Zend_Controller_Request_Abstract $request)
  58.     {
  59.         $this->_dispatchEnd = microtime();
  60.     }
  61.  
  62.     public function dispatchLoopShutdown()
  63.     {
  64.         $this->_dispatchLoopEnd = microtime();
  65.        
  66.         $this->getResponse()
  67.              ->appendBody($this->generateSpeedReport() . $this->_order);
  68.     }
  69.    
  70.  
  71. }
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement