From 50794fd47ea9910c7a1c7b7f20107603badc49bf Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Sun, 31 Jul 2011 18:16:24 +0200 Subject: [PATCH] moved statistics and library versions from capabilities to debugging section --- lib/Controller/CapabilitiesController.php | 11 ------- lib/Util/Debug.php | 4 +++ lib/View/CSV.php | 31 ++++++++----------- lib/View/JSON.php | 36 ++++++++++------------- lib/View/XML.php | 5 ++++ 5 files changed, 38 insertions(+), 49 deletions(-) diff --git a/lib/Controller/CapabilitiesController.php b/lib/Controller/CapabilitiesController.php index 62950b2..1953c97 100644 --- a/lib/Controller/CapabilitiesController.php +++ b/lib/Controller/CapabilitiesController.php @@ -54,17 +54,6 @@ class CapabilitiesController extends Controller { $capabilities['configuration'] = $configuration; } - if (is_null($section) || $section == 'statistics') { // TODO database statistics - $statistics = array(); - - if ($load = Util\Debug::getLoadAvg()) $statistics['load'] = $load; - if ($uptime = Util\Debug::getUptime()) $statistics['uptime'] = $uptime*1000; - if ($commit = Util\Debug::getCurrentCommit()) $statistics['commit-hash'] = $commit; - if ($version = phpversion()) $statistics['php-version'] = $version; - - $capabilities['statistics'] = $statistics; - } - if (is_null($section) || $section == 'formats') { $capabilities['formats'] = array_keys(\Volkszaehler\Router::$viewMapping); } diff --git a/lib/Util/Debug.php b/lib/Util/Debug.php index 9507efe..6541418 100644 --- a/lib/Util/Debug.php +++ b/lib/Util/Debug.php @@ -147,6 +147,10 @@ class Debug { } } + public static function getPhpVersion() { + return phpversion(); + } + /** * Get average server load * diff --git a/lib/View/CSV.php b/lib/View/CSV.php index 83b73f4..13fa993 100644 --- a/lib/View/CSV.php +++ b/lib/View/CSV.php @@ -78,8 +78,14 @@ class CSV extends View { * @param Util\Debug $debug */ protected function addDebug(Util\Debug $debug) { - echo '# time: ' . $debug->getExecutionTime() . PHP_EOL; + 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 @@ -141,23 +147,12 @@ class CSV extends View { echo '# uuid: ' . $interpreter->getEntity()->getUuid() . PHP_EOL; - if (isset($from)) - echo '# from: ' . $from . PHP_EOL; - - if (isset($to)) - echo '# to: ' . $to . PHP_EOL; - - if (isset($min)) - echo '# min: ' . $min[0] . ' => ' . $min[1] . PHP_EOL; - - if (isset($max)) - echo '# max: ' . $max[0] . ' => ' . $max[1] . PHP_EOL; - - if (isset($average)) - echo '# average: ' . View::formatNumber($average) . PHP_EOL; - - if (isset($consumption)) - echo '# consumption: ' . View::formatNumber($consumption) . PHP_EOL; + if (isset($from)) echo '# from: ' . $from . PHP_EOL; + if (isset($to)) echo '# to: ' . $to . PHP_EOL; + if (isset($min)) echo '# min: ' . $min[0] . ' => ' . $min[1] . PHP_EOL; + if (isset($max)) echo '# max: ' . $max[0] . ' => ' . $max[1] . PHP_EOL; + if (isset($average)) echo '# average: ' . View::formatNumber($average) . PHP_EOL; + if (isset($consumption)) echo '# consumption: ' . View::formatNumber($consumption) . PHP_EOL; echo '# rows: ' . $interpreter->getRowCount() . PHP_EOL; diff --git a/lib/View/JSON.php b/lib/View/JSON.php index fda900b..df9e8a3 100644 --- a/lib/View/JSON.php +++ b/lib/View/JSON.php @@ -129,8 +129,15 @@ class JSON extends View { * @param Util\Debug $debug */ protected function addDebug(Util\Debug $debug) { - $jsonDebug['time'] = $debug->getExecutionTime(); $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 = Util\Debug::getPhpVersion()) $jsonDebug['php-version'] = $version; + $jsonDebug['messages'] = $debug->getMessages(); $jsonDebug['queries'] = array_values($debug->getQueries()); @@ -189,26 +196,15 @@ class JSON extends View { $from = $interpreter->getFrom(); $to = $interpreter->getTo(); - $this->json['data']['uuid'] = $interpreter->getEntity()->getUuid(); - if (isset($from)) - $this->json['data']['from'] = $from; + $this->json['data']['uuid'] = $interpreter->getEntity()->getUuid(); + if (isset($from)) $this->json['data']['from'] = $from; + if (isset($to)) $this->json['data']['to'] = $to; + if (isset($min)) $this->json['data']['min'] = $min; + if (isset($max)) $this->json['data']['max'] = $max; + if (isset($average)) $this->json['data']['average'] = View::formatNumber($average); + if (isset($consumption)) $this->json['data']['consumption'] = View::formatNumber($consumption); - if (isset($to)) - $this->json['data']['to'] = $to; - - if (isset($min)) - $this->json['data']['min'] = $min; - - if (isset($max)) - $this->json['data']['max'] = $max; - - if (isset($average)) - $this->json['data']['average'] = View::formatNumber($average); - - if (isset($consumption)) - $this->json['data']['consumption'] = View::formatNumber($consumption); - - $this->json['data']['rows'] = $interpreter->getRowCount(); + $this->json['data']['rows'] = $interpreter->getRowCount(); if (($interpreter->getTupleCount() > 0 || is_null($interpreter->getTupleCount())) && count($data) > 0) $this->json['data']['tuples'] = $data; diff --git a/lib/View/XML.php b/lib/View/XML.php index 26139ca..c340bae 100644 --- a/lib/View/XML.php +++ b/lib/View/XML.php @@ -166,6 +166,11 @@ class XML extends View { $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) {