Exemplo n.º 1
0
 /**
  * Starts the execution. Root path is passed to avoid recalculation.
  *
  */
 public static function execute()
 {
     // Register autoloader:
     spl_autoload_register(array('\\Sifo\\Bootstrap', 'includeFile'));
     // Set paths:
     self::$root = ROOT_PATH;
     self::$application = dirname(__FILE__);
     Benchmark::getInstance()->timingStart();
     self::dispatch(self::$script_controller);
     Benchmark::getInstance()->timingStop();
 }
Exemplo n.º 2
0
 /**
  * Rewrite Query to init some debug parameters.
  * @param $query_filters
  * @param $sphinx_indexes
  * @param string $comment
  * @return bool
  */
 public function Query($query_filters, $sphinx_indexes, $comment = "")
 {
     Benchmark::getInstance()->timingStart('search');
     $sphinx_results = $this->sphinx->Query($query_filters, $sphinx_indexes, $comment);
     $sphinx_time = Benchmark::getInstance()->timingCurrentToRegistry('search');
     $debug_sphinx = array("tag" => $comment, "query" => $query_filters, "connection" => $this->sphinx_config['config_file'], "indexes" => $sphinx_indexes, "resultset" => $sphinx_results, "time" => $sphinx_time, "error" => $this->sphinx->_error, "controller" => $this->getCallerClass());
     $debug_sphinx = array_merge($debug_sphinx, $this->query_context);
     $this->query_debug['queries'][$this->query_debug['current_query']] = $debug_sphinx;
     $this->query_debug['time'] = $sphinx_time;
     $this->query_debug['error'] = $this->sphinx->_error;
     $this->query_debug['tag'] = $comment;
     $this->query_debug['total_found'] = $sphinx_results['total_found'];
     $this->query_debug['returned_rows'] = isset($sphinx_results['matches']) ? count($sphinx_results['matches']) : 0;
     Debug::push('searches', $this->query_debug);
     unset($this->query_debug);
     $this->query_debug['current_query'] = 0;
     return $sphinx_results;
 }
Exemplo n.º 3
0
 /**
  * Stops the timer for the bench.
  * @param string $key Identifier that you used to start the bench.
  * @param string $label Text that will be shown in the benchmarks table.
  */
 protected function stopBench($key, $label)
 {
     Debug::subSet('benchmarks', $label, Benchmark::getInstance()->timingCurrent($key));
 }
Exemplo n.º 4
0
 /**
  * Set Query Debug. Used in '__call' method. It checks if dev mode is enabled and then stores debug data in registry.
  *
  * @param $resultset
  * @param $tag
  * @param $method
  * @param $read_operation
  * @param $error
  * @return void
  */
 protected function queryDebug($resultset, $tag, $method, $read_operation, $error)
 {
     if (!Domains::getInstance()->getDebugMode()) {
         return false;
     }
     $query = self::$adodb[self::$destination_type]->_querySQL;
     $query_time = Benchmark::getInstance()->timingCurrentToRegistry('db_queries');
     $debug_query = array("tag" => $tag, "sql" => in_array($method, array('Affected_Rows', 'Insert_ID')) ? $method : $query, "type" => $read_operation ? 'read' : 'write', "destination" => self::$destination_type, "host" => self::$adodb[self::$destination_type]->host, "database" => self::$adodb[self::$destination_type]->database, "user" => self::$adodb[self::$destination_type]->user, "controller" => get_class($this), "resultset" => is_integer($resultset) ? array(array($method => $resultset)) : $resultset, "time" => $query_time, "error" => isset($error) ? $error : false, "duplicated" => false);
     if ($debug_query['type'] == 'read') {
         $debug_query['rows_num'] = count($resultset);
     } else {
         $debug_query['rows_num'] = 0;
         if ($method != 'close') {
             $debug_query['rows_num'] = self::$adodb[self::$destination_type]->Affected_Rows();
         }
     }
     // Check duplicated queries.
     $queries_executed = Debug::get('executed_queries');
     if (!empty($queries_executed) && isset($queries_executed[$debug_query['sql']])) {
         $debug_query['duplicated'] = true;
         Debug::push('duplicated_queries', 1);
     }
     Debug::subSet('executed_queries', $debug_query['sql'], 1);
     // Save query info in debug and add query errors if it's necessary.
     Debug::push('queries', $debug_query);
     if (isset($error)) {
         Debug::push('queries_errors', $error);
     }
 }
Exemplo n.º 5
0
 public function testBenchmark()
 {
     // skip PHPUnit dots alignment problem
     print "\n";
     Yii::import('ext.Benchmark');
     $bench = Benchmark::getInstance();
     // expected FALSE, since there's no active mark in progress
     $this->assertFalse($bench->cutoff());
     // start benchmarking batch
     $bench->start('Benchmark testing');
     // a simple loop
     for ($i = 1; $i <= 5; $i++) {
         $this->assertTrue($bench->mark('First operation'));
         usleep(100);
         // 'mark' with optional text parameter
         $this->assertTrue($bench->mark('Second operation', $i));
         usleep(20000);
         $this->assertTrue($bench->cutoff());
     }
     // see how well lock/save/load stuff works
     $bench->lock_marks();
     for ($i = 1; $i <= 2; $i++) {
         for ($j = 1; $j <= 5; $j++) {
             $bench->mark('Third operation', "of the {$i} run");
             usleep(100);
             $bench->cutoff();
         }
         $bench->save('/tmp', $i);
     }
     $bench->load('/tmp');
     // finalize benchmarking batch and print out some results
     $bench->kaput();
     /*
     
     Expected output: 
     
      --- Benchmark testing ---
     2012-06-24 17:06:31
     [    0.0003] First operation
     [    0.0211] Second operation 1
     [    0.0002] First operation
     [    0.0211] Second operation 2
     [    0.0002] First operation
     [    0.0211] Second operation 3
     [    0.0002] First operation
     [    0.0212] Second operation 4
     [    0.0002] First operation
     [    0.0212] Second operation 5
     [    0.0002] Third operation of the 1 run
     [    0.0002] Third operation of the 1 run
     [    0.0002] Third operation of the 1 run
     [    0.0002] Third operation of the 1 run
     [    0.0002] Third operation of the 1 run
     [    0.0002] Third operation of the 2 run
     [    0.0002] Third operation of the 2 run
     [    0.0002] Third operation of the 2 run
     [    0.0002] Third operation of the 2 run
     [    0.0002] Third operation of the 2 run
     
     Benchmark testing totals:
     memory: 8.85MB
     peak  : 9.02MB
     [    0.1120] Execution time
     [    0.0002] 0.0011 / 5 First operation
     [    0.0211] 0.1057 / 5 Second operation
     [    0.0002] 0.0020 / 10 Third operation
     --- kaput ---
     */
 }
Exemplo n.º 6
0
 /**
  * Starts the execution. Root path is passed to avoid recalculation.
  *
  * @param $instance_name
  * @param string $controller_name Optional, a controller to execute. If null the router will be used to determine it.
  *
  * @internal param string $root Path to root.
  *
  */
 public static function execute($instance_name, $controller_name = null)
 {
     // Set paths:
     self::$root = ROOT_PATH;
     self::$application = dirname(__FILE__);
     self::$instance = $instance_name;
     // Include files:
     self::includeRequiredFiles();
     self::autoload();
     Benchmark::getInstance()->timingStart();
     self::dispatch($controller_name);
     Benchmark::getInstance()->timingStop();
 }