/**
  * Collects data
  *
  * @param TimeDataCollector $timeCollector
  * @return array
  */
 protected function collectData(TimeDataCollector $timeCollector = null)
 {
     $stmts = array();
     $total_duration = 0;
     $total_mem = 0;
     $failed = 0;
     $i = 0;
     $queries = $this->db->getQueries();
     $limit = DebugBar::config()->query_limit;
     $showDb = count(array_unique(array_map(function ($stmt) {
         return $stmt['database'];
     }, $queries))) > 1;
     foreach ($queries as $stmt) {
         $i++;
         $total_duration += $stmt['duration'];
         $total_mem += $stmt['memory'];
         if (!$stmt['success']) {
             $failed++;
         }
         if ($limit && $i > $limit) {
             $stmts[] = array('sql' => "Only the first {$limit} queries are shown");
             break;
         }
         $stmts[] = array('sql' => $stmt['short_query'], 'row_count' => $stmt['rows'], 'params' => $stmt['select'] ? $stmt['select'] : null, 'duration' => $stmt['duration'], 'duration_str' => $this->getDataFormatter()->formatDuration($stmt['duration']), 'memory' => $stmt['memory'], 'memory_str' => $this->getDataFormatter()->formatBytes($stmt['memory']), 'is_success' => $stmt['success'], 'database' => $showDb ? $stmt['database'] : null, 'source' => $stmt['source']);
         if ($timeCollector !== null) {
             $timeCollector->addMeasure($stmt['short_query'], $stmt['start_time'], $stmt['end_time']);
         }
     }
     return array('nb_statements' => count($queries), 'nb_failed_statements' => $failed, 'statements' => $stmts, 'accumulated_duration' => $total_duration, 'accumulated_duration_str' => $this->getDataFormatter()->formatDuration($total_duration), 'memory_usage' => $total_mem, 'memory_usage_str' => $this->getDataFormatter()->formatBytes($total_mem));
 }
 /**
  * Convert a single statement information into a javascript parsable array.
  *
  * @param array $stmt The statement information.
  *
  * @return array
  */
 protected function convertStatement($stmt)
 {
     $newstmt = array('sql' => $stmt['realquery'], 'row_count' => isset($stmt['return_count']) ? $stmt['return_count'] : $stmt['affected_count'], 'prepared_stmt' => $stmt['query'], 'params' => (object) $stmt['params'], 'duration' => $stmt['duration'], 'duration_str' => $this->getDataFormatter()->formatDuration($stmt['duration']), 'is_success' => true, 'error_code' => 0, 'error_message' => '');
     if ($this->timeCollector !== null) {
         $this->timeCollector->addMeasure($stmt['query'], $stmt['timeStart'], $stmt['timeStop']);
     }
     return $newstmt;
 }
 /**
  * Adds a template.
  *
  * @param \Template $template The message.
  *
  * @return void
  */
 public function parseTemplate(\Template $template)
 {
     if (self::$timeCollector) {
         self::$timeCollector->startMeasure($template->getName(), 'Parse: ' . $template->getName());
         self::$timeCollector->stopMeasure($template->getName());
     }
     self::$collector->addTemplate($template);
 }
 public function __construct($requestStartTime = null)
 {
     parent::__construct($requestStartTime);
     if (class_exists('\\Cubex\\Cassandra\\ColumnFamily')) {
         EventManager::listen(\Cubex\Cassandra\ColumnFamily::QUERY_EVENT, [$this, "getQuery"]);
     }
 }
 public function __construct($requestStartTime = null)
 {
     parent::__construct($requestStartTime);
     EventManager::listen(EventManager::CUBEX_TIMETRACK_START, [$this, "trackStart"]);
     EventManager::listen(EventManager::CUBEX_TIMETRACK_END, [$this, "trackEnd"]);
     //$this->addMeasure("Starting Project", PHP_START, microtime(true));
     $this->startMeasure("project.dispatch", "Dispatching Project");
 }
 /**
  * {@inheritDoc}
  */
 public function __construct()
 {
     $time = new TimeDataCollector(microtime(true));
     $time->startMeasure('Debugger active.');
     $messages = new MessagesCollector();
     $phpInfo = new PhpInfoCollector();
     $request = new RequestDataCollector();
     $memory = new MemoryCollector();
     $exception = new ExceptionsCollector();
     $this->addCollector($messages)->addCollector($time)->addCollector($phpInfo)->addCollector($request)->addCollector($memory)->addCollector($exception);
     if (isset($GLOBALS['debugger-panels'])) {
         foreach ($GLOBALS['debugger-panels'] as $panelFunc) {
             $collector = $panelFunc($this);
             if ($collector) {
                 $this->addCollector($collector);
             }
         }
     }
 }
 /**
  * Stop the measurement.
  *
  * @param RequestInterface  $request
  * @param ResponseInterface $response
  * @param Exception         $error
  *
  * @throws DebugBarException
  */
 protected function stopMeasure(RequestInterface $request, ResponseInterface $response = null, Exception $error = null)
 {
     $name = $this->createTimelineID($request);
     if (!isset($this->startedMeasures[$name])) {
         throw new DebugBarException("Failed stopping measure '{$name}' because it hasn't been started");
     }
     $start = $this->startedMeasures[$name];
     $end = microtime(true);
     $params = $this->getParameters($request, $response, $error);
     $this->timeline->addMeasure($this->createTimelineMessage($request, $response), $start, $end, $params, 'guzzle');
     unset($this->startedMeasures[$name]);
 }
 public function collect()
 {
     foreach ($GLOBALS['timers'] as $name => &$timer) {
         if (isset($timer['start'])) {
             timer_stop($name);
         }
         foreach ($timer['measures'] as $measure) {
             call_user_func_array(array($this, 'addMeasure'), $measure);
         }
     }
     return parent::collect();
 }
 /**
  * Generic hook logging facility.
  *
  * @param string $hookName The hook name.
  *
  * @param array  $params   The parameters.
  *
  * @param bool   $starting Flag determining if we are entering the hook or exiting.
  *
  * @return void
  */
 protected function processHook($hookName, $params, $starting)
 {
     if (!$starting) {
         if (self::$timeCollector->hasStartedMeasure($hookName)) {
             self::$timeCollector->stopMeasure($hookName);
         }
         return;
     }
     if (self::$timeCollector && $hookName !== 'initializeSystem') {
         if (!self::$timeCollector->hasStartedMeasure($hookName)) {
             self::$timeCollector->startMeasure($hookName, $hookName);
         }
     }
     $exception = new \ErrorException();
     $stack = $exception->getTrace();
     $information = array('caller' => str_replace(TL_ROOT, 'TL_ROOT', $stack[1]['file']) . '#' . $stack[1]['line'], '$GLOBALS[\'TL_HOOKS\'][\'' . $hookName . '\']' => $this->createHookList($GLOBALS['TL_HOOKS'][$hookName]), 'parameters' => $this->prepareParams($hookName, $params));
     $this->log($information, $hookName);
 }
Exemple #10
0
 public function collect()
 {
     $data = parent::collect();
     $data['nb_measures'] = count($data['measures']);
     return $data;
 }
Exemple #11
0
 /**
  * Collects data from a single TraceablePDO instance
  *
  * @param TraceablePDO $pdo
  * @param TimeDataCollector $timeCollector
  * @return array
  */
 protected function collectPDO(TraceablePDO $pdo, TimeDataCollector $timeCollector = null)
 {
     $stmts = array();
     foreach ($pdo->getExecutedStatements() as $stmt) {
         $stmts[] = array('sql' => $this->renderSqlWithParams ? $stmt->getSqlWithParams($this->sqlQuotationChar) : $stmt->getSql(), 'row_count' => $stmt->getRowCount(), 'stmt_id' => $stmt->getPreparedId(), 'prepared_stmt' => $stmt->getSql(), 'params' => (object) $stmt->getParameters(), 'duration' => $stmt->getDuration(), 'duration_str' => $this->getDataFormatter()->formatDuration($stmt->getDuration()), 'memory' => $stmt->getMemoryUsage(), 'memory_str' => $this->getDataFormatter()->formatBytes($stmt->getMemoryUsage()), 'end_memory' => $stmt->getEndMemory(), 'end_memory_str' => $this->getDataFormatter()->formatBytes($stmt->getEndMemory()), 'is_success' => $stmt->isSuccess(), 'error_code' => $stmt->getErrorCode(), 'error_message' => $stmt->getErrorMessage());
         if ($timeCollector !== null) {
             $timeCollector->addMeasure($stmt->getSql(), $stmt->getStartTime(), $stmt->getEndTime());
         }
     }
     return array('nb_statements' => count($stmts), 'nb_failed_statements' => count($pdo->getFailedExecutedStatements()), 'accumulated_duration' => $pdo->getAccumulatedStatementsDuration(), 'accumulated_duration_str' => $this->getDataFormatter()->formatDuration($pdo->getAccumulatedStatementsDuration()), 'memory_usage' => $pdo->getMemoryUsage(), 'memory_usage_str' => $this->getDataFormatter()->formatBytes($pdo->getPeakMemoryUsage()), 'peak_memory_usage' => $pdo->getPeakMemoryUsage(), 'peak_memory_usage_str' => $this->getDataFormatter()->formatBytes($pdo->getPeakMemoryUsage()), 'statements' => $stmts);
 }
 public function __construct($requestStartTime = null)
 {
     parent::__construct($requestStartTime);
     EventManager::listen(EventManager::CUBEX_QUERY, [$this, "getQuery"]);
 }
 /**
  * @param float $start
  * @param float $end
  * @param \Psr\Http\Message\RequestInterface $request
  * @param \Psr\Http\Message\ResponseInterface $response
  */
 public function add($start, $end, RequestInterface $request, ResponseInterface $response = null)
 {
     $description = $this->describe($request, $response);
     $params = $this->getParameters($request, $response);
     $this->timeline->addMeasure($description, $start, $end, $params, 'guzzle');
 }