/** * Add debugging information include queries and messages to output queue * * @param Util\Debug $debug */ protected function addDebug(Util\Debug $debug) { echo "level:\t" . $debug->getLevel() . PHP_EOL; echo "database:\t" . Util\Configuration::read('db.driver') . PHP_EOL; echo "time:\t" . $debug->getExecutionTime() . PHP_EOL; if ($uptime = Util\Debug::getUptime()) { echo "uptime:\t" . $uptime * 1000; } if ($load = Util\Debug::getLoadAvg()) { echo "load:\t" . implode(', ', $load) . PHP_EOL; } if ($commit = Util\Debug::getCurrentCommit()) { echo "commit-hash:\t" . $commit . PHP_EOL; } if ($version = phpversion()) { echo "php-version:\t" . $version . PHP_EOL; } foreach ($debug->getMessages() as $message) { echo "message:\t" . $message['message'] . PHP_EOL; // TODO add more information } foreach ($debug->getQueries() as $query) { echo "query:\t" . $query['sql'] . PHP_EOL; if (isset($query['parameters'])) { echo "\tparameters:\t" . implode(', ', $query['parameters']) . PHP_EOL; } } }
/** * Add debugging information include queries and messages to output queue * * @param Util\Debug $debug */ protected function addDebug(Util\Debug $debug) { echo '# level: ' . $debug->getLevel() . PHP_EOL; echo '# database: ' . Util\Configuration::read('db.driver') . PHP_EOL; echo '# time: ' . $debug->getExecutionTime() . PHP_EOL; if ($uptime = Util\Debug::getUptime()) { echo '# uptime: ' . $uptime * 1000; } if ($load = Util\Debug::getLoadAvg()) { echo '# load: ' . implode(', ', $load) . PHP_EOL; } if ($commit = Util\Debug::getCurrentCommit()) { echo '# commit-hash: ' . $commit; } if ($version = Util\Debug::getPhpVersion()) { echo '# php-version: ' . $version; } foreach ($debug->getMessages() as $message) { echo '# message: ' . $message['message'] . PHP_EOL; // TODO add more information } foreach ($debug->getQueries() as $query) { echo '# query: ' . $query['sql'] . PHP_EOL; if (isset($query['parameters'])) { echo "# \tparameters: " . implode(', ', $query['parameters']) . PHP_EOL; } } }
/** * @todo * @param string $capabilities * @param string $sub */ public function get($section = NULL) { $capabilities = array(); if (is_null($section) || $section == 'configuration') { $configuration = array('precision' => View\View::PRECISION, 'database' => Util\Configuration::read('db.driver'), 'debug' => Util\Configuration::read('debug'), 'devmode' => Util\Configuration::read('devmode')); if ($commit = Util\Debug::getCurrentCommit()) { $configuration['commit'] = $commit; } $capabilities['configuration'] = $configuration; } // db statistics - only if specifically requested if ($section == 'database') { $conn = $this->em->getConnection(); // get DBAL connection from EntityManager // estimate InnoDB tables to avoid performance penalty $rows = $conn->fetchAssoc('EXPLAIN SELECT COUNT(id) FROM data USE INDEX (PRIMARY)'); if (isset($rows['rows'])) { $rows = $rows['rows']; } else { // get correct values for MyISAM $rows = $conn->fetchColumn('SELECT COUNT(1) FROM data'); } // database disc space consumption $sql = 'SELECT SUM(data_length + index_length) ' . 'FROM information_schema.tables ' . 'WHERE table_schema = ?'; $size = $conn->fetchColumn($sql, array(Util\Configuration::read('db.dbname'))); $aggregation = Util\Configuration::read('aggregation'); $database = array('data_rows' => $rows, 'data_size' => $size, 'aggregation_enabled' => $aggregation ? 1 : 0); // aggregation table size if ($aggregation) { $agg_rows = $conn->fetchColumn('SELECT COUNT(1) FROM aggregate'); $database['aggregation_rows'] = $agg_rows; $database['aggregation_ratio'] = $agg_rows ? $rows / $agg_rows : 0; } $capabilities['database'] = $database; } if (is_null($section) || $section == 'formats') { $capabilities['formats'] = array_keys(Router::$viewMapping); } if (is_null($section) || $section == 'contexts') { $capabilities['contexts'] = array_keys(Router::$controllerMapping); } if (is_null($section) || $section == 'definitions') { // unresolved artifact from Symfony migration // if (!is_null($section)) { // only caching when we don't request dynamic informations // $this->view->setCaching('expires', time()+2*7*24*60*60); // cache for 2 weeks // } $capabilities['definitions']['entities'] = Definition\EntityDefinition::get(); $capabilities['definitions']['properties'] = Definition\PropertyDefinition::get(); } if (count($capabilities) == 0) { throw new \Exception('Invalid capability identifier: \'' . $section . '\''); } return array('capabilities' => $capabilities); }
/** * @param string $section select specific sub section for output */ public function get($section = NULL) { $capabilities = array(); if (is_null($section) || $section == 'configuration') { $configuration = array('precision' => View\View::PRECISION, 'database' => Util\Configuration::read('db.driver'), 'debug' => Util\Configuration::read('debug'), 'devmode' => Util\Configuration::read('devmode')); if ($commit = Util\Debug::getCurrentCommit()) { $configuration['commit'] = $commit; } $capabilities['configuration'] = $configuration; } // db statistics - only if specifically requested if ($section == 'database') { $conn = $this->em->getConnection(); // get DBAL connection from EntityManager // estimate InnoDB tables to avoid performance penalty $rows = $this->sqlCount($conn, 'data'); $size = $this->dbSize($conn, 'data'); $aggregation = Util\Configuration::read('aggregation'); $database = array('data_rows' => $rows, 'data_size' => $size, 'aggregation_enabled' => $aggregation ? 1 : 0); // aggregation table size if ($aggregation) { $agg_rows = $this->sqlCount($conn, 'aggregate'); $agg_size = $this->dbSize($conn, 'aggregate'); $database['aggregation_rows'] = $agg_rows; $database['aggregation_size'] = $agg_size; $database['aggregation_ratio'] = $agg_rows ? $rows / $agg_rows : 0; } $capabilities['database'] = $database; } if (is_null($section) || $section == 'formats') { $capabilities['formats'] = array_keys(Router::$viewMapping); } if (is_null($section) || $section == 'contexts') { $capabilities['contexts'] = array_keys(Router::$controllerMapping); } if (is_null($section) || $section == 'definitions') { // unresolved artifact from Symfony migration if (!is_null($section)) { // only caching when we don't request dynamic informations $this->view->setCaching('expires', time() + 2 * 7 * 24 * 60 * 60); // cache for 2 weeks } $capabilities['definitions']['entities'] = Definition\EntityDefinition::get(); $capabilities['definitions']['properties'] = Definition\PropertyDefinition::get(); } if (count($capabilities) == 0) { throw new \Exception('Invalid capability identifier: \'' . $section . '\''); } return array('capabilities' => $capabilities); }
/** * Add debugging information include queries and messages to output queue * * @param Util\Debug $debug */ protected function convertDebug(Util\Debug $debug) { $jsonDebug['level'] = $debug->getLevel(); if ($dbDriver = Util\Configuration::read('db.driver')) { $jsonDebug['database'] = $dbDriver; } $jsonDebug['time'] = $debug->getExecutionTime(); if ($uptime = Util\Debug::getUptime()) { $jsonDebug['uptime'] = $uptime * 1000; } if ($load = Util\Debug::getLoadAvg()) { $jsonDebug['load'] = $load; } if ($commit = Util\Debug::getCurrentCommit()) { $jsonDebug['commit-hash'] = $commit; } if ($version = phpversion()) { $jsonDebug['php-version'] = $version; } $jsonDebug['messages'] = $debug->getMessages(); // SQL statements if (count($statements = $debug->getQueries())) { $this->getSQLTimes($statements); $jsonDebug['sql'] = array('totalTime' => $this->sqlTotalTime, 'worstTime' => $this->sqlWorstTime, 'queries' => array_map(function ($q) { return array('sql' => Util\Debug::getParametrizedQuery($q['sql'], $q['params']), 'execTime' => $q['executionMS']); }, array_values($debug->getQueries()))); } return $jsonDebug; }
* A test for our JSON utility class * * @package tests * @copyright Copyright (c) 2011, The volkszaehler.org project * @license http://www.gnu.org/licenses/gpl.txt GNU Public License * @author Steffen Vogel <*****@*****.**> */ /* * This file is part of volkzaehler.org * * volkzaehler.org is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * any later version. * * volkzaehler.org is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>. */ define('VZ_DIR', realpath(__DIR__ . '/../..')); use Volkszaehler\Util; include VZ_DIR . '/lib/Util/Debug.php'; echo '<pre>'; echo print_r(Util\Debug::getLoadAvg(), TRUE); echo Util\Debug::getUptime() . "\n"; echo Util\Debug::getCurrentCommit(); echo '</pre>';
/** * Add debugging information include queries and messages to output queue * * @param Util\Debug $debug */ protected function addDebug(Util\Debug $debug) { $xmlDebug = $this->xmlDoc->createElement('debug'); $xmlDebug->setAttribute('level', $debug->getLevel()); $xmlDebug->appendChild($this->xmlDoc->createElement('time', $debug->getExecutionTime())); if ($uptime = Util\Debug::getUptime()) { $xmlDebug->appendChild($this->xmlDoc->createElement('uptime', $uptime * 1000)); } if ($load = Util\Debug::getLoadAvg()) { $xmlDebug->appendChild($this->xmlDoc->createElement('load', implode(', ', $load))); } if ($commit = Util\Debug::getCurrentCommit()) { $xmlDebug->appendChild($this->xmlDoc->createElement('commit-hash', $commit)); } if ($version = Util\Debug::getPhpVersion()) { $xmlDebug->appendChild($this->xmlDoc->createElement('php-version', $version)); } $xmlMessages = $this->xmlDoc->createElement('messages'); foreach ($debug->getMessages() as $message) { $xmlMessages->appendChild($this->convertMessage($message)); } $xmlDebug->appendChild($xmlMessages); $xmlDebug->appendChild($this->convertArray($debug->getQueries(), 'queries', 'query')); $this->xmlRoot->appendChild($xmlDebug); }
/** * Add debugging information include queries and messages to output queue * * @param Util\Debug $debug */ protected function addDebug(Util\Debug $debug) { $jsonDebug['level'] = $debug->getLevel(); if ($dbDriver = Util\Configuration::read('db.driver')) { $jsonDebug['database'] = $dbDriver; } $jsonDebug['time'] = $debug->getExecutionTime(); if ($uptime = Util\Debug::getUptime()) { $jsonDebug['uptime'] = $uptime * 1000; } if ($load = Util\Debug::getLoadAvg()) { $jsonDebug['load'] = $load; } if ($commit = Util\Debug::getCurrentCommit()) { $jsonDebug['commit-hash'] = $commit; } if ($version = phpversion()) { $jsonDebug['php-version'] = $version; } $jsonDebug['messages'] = $debug->getMessages(); // SQL statements $this->getSQLTimes($debug->getQueries()); $jsonDebug['sql'] = array('totalTime' => $this->sqlTotalTime, 'worstTime' => $this->sqlWorstTime, 'queries' => array_values($debug->getQueries())); $this->json['debug'] = $jsonDebug; }