Author: dr Date: Fri Feb 1 15:16:31 2008 New Revision: 7273 Log: - Fixed issue #12427: Changed output rendering of the debug formatter to not include a stylesheet by default, but instead the formatter now includes easy overridable CSS classes.
Added: trunk/Debug/docs/example_stylesheet.txt (with props) trunk/Debug/tests/formatters/output/ trunk/Debug/tests/formatters/output/output.html (with props) Modified: trunk/Debug/ChangeLog trunk/Debug/docs/img/debug_tutorial_recursive_timers.png trunk/Debug/docs/img/debug_tutorial_timers.png trunk/Debug/docs/tutorial.txt trunk/Debug/docs/tutorial_recursive_timers.php trunk/Debug/docs/tutorial_timers.php trunk/Debug/src/formatters/html_formatter.php trunk/Debug/src/structs/timer.php trunk/Debug/src/writers/memory_writer.php trunk/Debug/tests/formatters/html_formatter_data_structures.php trunk/Debug/tests/formatters/html_formatter_test.php Modified: trunk/Debug/ChangeLog ============================================================================== --- trunk/Debug/ChangeLog [iso-8859-1] (original) +++ trunk/Debug/ChangeLog [iso-8859-1] Fri Feb 1 15:16:31 2008 @@ -1,3 +1,11 @@ +1.1.1 - [RELEASEDATE] +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +- Fixed issue #12427: Changed output rendering of the debug formatter to not + include a stylesheet by default, but instead the formatter now includes easy + overridable CSS classes. + + 1.1 - Monday 02 July 2007 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Added: trunk/Debug/docs/example_stylesheet.txt ============================================================================== --- trunk/Debug/docs/example_stylesheet.txt (added) +++ trunk/Debug/docs/example_stylesheet.txt [iso-8859-1] Fri Feb 1 15:16:31 2008 @@ -1,0 +1,78 @@ + + + .ezc-debug-output .group-header, .ezc-debug-output .debugheader + { + text-align: left; + background-color: #dddddd; + } + + .ezc-debug-output .group-header th, .ezc-debug-output .debugheader th + { + border-top: solid 1px gray; + } + + .ezc-debug-output td.source + { + font-weight: bold; + } + + .ezc-debug-output th, .ezc-debug-output td + { + padding-left: 0.5em; + padding-right: 0.5em; + } + + .ezc-debug-output tr.totals + { + text-align: left; + font-weight: bold; + background-color: #eeeeee; + } + + .ezc-debug-output td.tp-elapsed, .ezc-debug-output td.tp-percent, .ezc-debug-output td.tp-average + { + text-align: right; + } + + .ezc-debug-output td.tp-count + { + text-align: center; + } + + .ezc-debug-output td.tp-empty + { + display: none; + } + + .ezc-debug-output tr.switch + { + font-style: italic; + font-size: 90%; + } + + .ezc-debug-output tr.switch td.tp-name + { + padding-left: 2em; + } + + .ezc-debug-output table + { + margin-bottom: 2em; + border: 1px solid gray; + border-spacing: 0; + } + + .ezc-debug-output span.verbosity1 + { + color: #ff0000; + } + + .ezc-debug-output span.verbosity2 + { + color: #dd6622; + } + + .ezc-debug-output span.verbosity3 + { + color: #fc8f1c; + } Propchange: trunk/Debug/docs/example_stylesheet.txt ------------------------------------------------------------------------------ svn:eol-style = native Modified: trunk/Debug/docs/img/debug_tutorial_recursive_timers.png ============================================================================== Binary files - no diff available. Modified: trunk/Debug/docs/img/debug_tutorial_timers.png ============================================================================== Binary files - no diff available. Modified: trunk/Debug/docs/tutorial.txt ============================================================================== --- trunk/Debug/docs/tutorial.txt [iso-8859-1] (original) +++ trunk/Debug/docs/tutorial.txt [iso-8859-1] Fri Feb 1 15:16:31 2008 @@ -90,7 +90,8 @@ .. include:: tutorial_timers.php :literal: -The output is as follows: +The output is as follows (if the CSS stylesheet is used that is available +through "Example Stylesheet" in the menu): .. image:: img/debug_tutorial_timers.png @@ -114,7 +115,8 @@ .. include:: tutorial_recursive_timers.php :literal: -The resulting output is as follows: +The resulting output is as follows (if the CSS stylesheet is used that is available +through "Example Stylesheet" in the menu): .. image:: img/debug_tutorial_recursive_timers.png Modified: trunk/Debug/docs/tutorial_recursive_timers.php ============================================================================== --- trunk/Debug/docs/tutorial_recursive_timers.php [iso-8859-1] (original) +++ trunk/Debug/docs/tutorial_recursive_timers.php [iso-8859-1] Fri Feb 1 15:16:31 2008 @@ -1,3 +1,4 @@ +<style type="text/css">@import url("example_stylesheet.txt");</style> <?php require_once 'tutorial_autoload.php'; Modified: trunk/Debug/docs/tutorial_timers.php ============================================================================== --- trunk/Debug/docs/tutorial_timers.php [iso-8859-1] (original) +++ trunk/Debug/docs/tutorial_timers.php [iso-8859-1] Fri Feb 1 15:16:31 2008 @@ -1,3 +1,4 @@ +<style type="text/css">@import url("example_stylesheet.txt");</style> <?php require_once 'tutorial_autoload.php'; Modified: trunk/Debug/src/formatters/html_formatter.php ============================================================================== --- trunk/Debug/src/formatters/html_formatter.php [iso-8859-1] (original) +++ trunk/Debug/src/formatters/html_formatter.php [iso-8859-1] Fri Feb 1 15:16:31 2008 @@ -56,12 +56,10 @@ */ public function generateOutput( array $writerData, array $timerData ) { - $str = ''; - $str .= "<style type=\"text/css\">[EMAIL PROTECTED] url(\"debug.css\");\n</style>\n\n"; - $str .= "<table cellspacing='0'>\n"; - + $str = '<div class="ezc-debug-output">'; $str .= $this->getLog( $writerData ); $str .= $this->getTimingsAccumulator( $timerData ); + $str .= "</div>\n"; return $str; } @@ -73,19 +71,22 @@ */ public function getLog( array $writerData ) { - $str = ''; + $str = "<table class='log'>\n"; foreach ( $writerData as $w ) { - $str .= "<tr>\n"; - $str .= "\t<td class='debugheader' valign='top'>"; - $str .= "<b><font color=\"". ( isset( $this->verbosityColors[$w->verbosity]) ? $this->verbosityColors[$w->verbosity] : "" )."\">"; - $str .= $w->verbosity; - $str .= ":</font>{$w->source}::{$w->category}</b></td>\n"; - $str .= "\t<td class='debugheader' valign='top'>{$w->datetime}</td>\n"; - $str .= "</tr>\n"; - $str .= "<tr>\n"; - $str .= "\t<td class='debugbody' colspan='2'><pre>\n{$w->message}\n\t</pre></td>\n"; - $str .= "</tr>\n"; + $color = isset( $this->verbosityColors[$w->verbosity]) ? $this->verbosityColors[$w->verbosity] : ""; + $date = date( 'Y-m-d H:i:s O', $w->datetime ); + $str .= <<<ENDT +<tr class='debugheader'> + <td class='source'> + <span class='verbosity{$w->verbosity}'>{$w->verbosity}: {$w->source}::{$w->category}</span> + </td> + <td class='date'>{$date}</td> +</tr> +<tr class='debugbody'> + <td colspan='2'>{$w->message}</td> +</tr> +ENDT; } $str .= "</table>\n"; @@ -104,56 +105,75 @@ if ( sizeof( $groups ) > 0 ) { - $str = "<table style='border: 1px dashed black;' cellspacing='0'>\n<tr><th> Timings</th><th> Elapsed</th>". - "<th> Percent</th><th> Count</th><th> Average</th></tr>\n"; - - $isFirst = true; + $str = <<<ENDT +<table class='accumulator'> + <tr> + <th>Timings</th> + <th>Elapsed</th> + <th>Percent</th> + <th>Count</th> + <th>Average</th> + </tr> + +ENDT; + foreach ( $groups as $groupName => $group ) { - if ( !$isFirst ) - { - $str .= "<tr><td> </td></tr>"; - $str .= "\n"; - } - else - { - $isFirst = false; - } - - $str .= "<tr><td class='timingpoint1'><b>$groupName</b></td><td class='timingpoint1'> </td><td class='timingpoint1'> </td>". - "<td class='timingpoint1'> </td><td class='timingpoint1'> </td></tr>\n"; + $str .= <<<ENDT + <tr class='group-header'> + <th colspan='5'>{$groupName}</th> + </tr> + +ENDT; // Calculate the total time. foreach ( $group->elements as $name => $element ) { - $str .= "<tr><td class='timingpoint1'>$name</td>" . - "<td class='timingpoint1'>" . sprintf( '%.5f', $element->elapsedTime ) . "</td>" . - "<td class='timingpoint1' align='right'>". sprintf( '%.2f', (100 * ($element->elapsedTime / $group->elapsedTime ) ) ) ."</td>" . - "<td class='timingpoint1' align='right'>{$element->count}</td>" . - "<td class='timingpoint1' align='right'>" . sprintf( '%.5f', ( $element->elapsedTime / $element->count ) ) . - "</td></tr>\n"; - + $elapsedTime = sprintf( '%.5f', $element->elapsedTime ); + $percent = sprintf( '%.2f', (100 * ($element->elapsedTime / $group->elapsedTime ) ) ); + $average = sprintf( '%.5f', ( $element->elapsedTime / $element->count ) ); + $str .= <<<ENDT + <tr class='group'> + <td class='tp-name'>{$name}</td> + <td class='tp-elapsed'>{$elapsedTime}</td> + <td class='tp-percent'>{$percent} %</td> + <td class='tp-count'>{$element->count}</td> + <td class='tp-average'>{$average}</td> + </tr> + +ENDT; foreach ( $element->switchTime as $switch ) { - $elapsedTime = $switch->time - $element->startTime; - - $str .= "<tr><td class='timingpoint1'> {$switch->name}</td>" . - "<td class='timingpoint1'>" . sprintf( '%.5f', $elapsedTime ) . "</td>" . - "<td class='timingpoint1' align='right'>". sprintf( '%.2f', (100 * ($elapsedTime / $group->elapsedTime ) ) ) ."</td>" . - "<td class='timingpoint1' align='right'>-</td>" . - "<td class='timingpoint1' align='right'>-</td></tr>\n"; + $elapsedTime = sprintf( '%.5f', $switch->time - $element->startTime ); + $percent = sprintf( '%.2f', ( 100 * ( $elapsedTime / $group->elapsedTime ) ) ); + + $str .= <<<ENDT + <tr class='switch'> + <td class='tp-name'>{$switch->name}</td> + <td class='tp-elapsed'>{$elapsedTime}</td> + <td class='tp-percent'>{$percent} %</td> + <td class='tp-empty'>-</td> + <td class='tp-empty'>-</td> + </tr> + +ENDT; } } - $str .= "\n"; if ( $group->count > 1 ) { - $str .= "<tr><td class='timingpoint1'><b>Total:</b></td>" . - "<td class='timingpoint1'>" . sprintf( '%.5f', $group->elapsedTime ) . "</td>" . - "<td class='timingpoint1' align='right'>100.00</td>" . - "<td class='timingpoint1' align='right'>{$group->count}</td>" . - "<td class='timingpoint1' align='right'>" . sprintf( '%.5f', ( $group->elapsedTime / $group->count ) ) . - "</td></tr>\n"; + $elapsedTime = sprintf( '%.5f', $group->elapsedTime ); + $average = sprintf( '%.5f', ( $group->elapsedTime / $group->count ) ); + $str .= <<<ENDT + <tr class='totals'> + <th class='tp-total'>Total:</th> + <td class='tp-elapsed'>{$elapsedTime}</td> + <td class='tp-percent'>100.00 %</td> + <td class='tp-count'>{$group->count}</td> + <td class='tp-average'>{$average}</td> + </tr> + +ENDT; } } Modified: trunk/Debug/src/structs/timer.php ============================================================================== --- trunk/Debug/src/structs/timer.php [iso-8859-1] (original) +++ trunk/Debug/src/structs/timer.php [iso-8859-1] Fri Feb 1 15:16:31 2008 @@ -85,7 +85,46 @@ * * @var int */ - public $stopNumber; + public $stopNumber; + + /** + * Constructs a new ezcDebugSwitchTimerStruct + * + * @param string $name + */ + public function __construct( $name = null, $source = null, $group = null, $switchTime = null, $startTime = null, $stopTime = null, $elapsedTime = null, $startNumber = null, $stopNumber = null ) + { + $this->name = $name; + $this->source = $source; + $this->group = $group; + $this->switchTime = $switchTime; + $this->startTime = $startTime; + $this->stopTime = $stopTime; + $this->elapsedTime = $elapsedTime; + $this->startNumber = $startNumber; + $this->stopNumber = $stopNumber; + } + + /** + * Returns a new instance of this class with the data specified by $array. + * + * $array contains all the data members of this class in the form: + * array('member_name'=>value). + * + * __set_state makes this class exportable with var_export. + * var_export() generates code, that calls this method when it + * is parsed with PHP. + * + * @param array(string=>mixed) + * @return ezcDebugSwitchTimerStruct + */ + static public function __set_state( array $array ) + { + return new ezcDebugTimerStruct( + $array['name'], $array['source'], $array['group'], $array['switchTime'], $array['startTime'], + $array['stopTime'], $array['elapsedTime'], $array['startNumber'], $array['stopNumber'] + ); + } } ?> Modified: trunk/Debug/src/writers/memory_writer.php ============================================================================== --- trunk/Debug/src/writers/memory_writer.php [iso-8859-1] (original) +++ trunk/Debug/src/writers/memory_writer.php [iso-8859-1] Fri Feb 1 15:16:31 2008 @@ -63,7 +63,7 @@ $log->severity = $severity; $log->source = $source; $log->category = $category; - $log->datetime = date( 'M d H:i:s' ); + $log->datetime = time(); if ( is_array( $extraInfo ) ) { Modified: trunk/Debug/tests/formatters/html_formatter_data_structures.php ============================================================================== --- trunk/Debug/tests/formatters/html_formatter_data_structures.php [iso-8859-1] (original) +++ trunk/Debug/tests/formatters/html_formatter_data_structures.php [iso-8859-1] Fri Feb 1 15:16:31 2008 @@ -24,7 +24,7 @@ $log1->source = "content"; $log1->category = "sql"; $log1->verbosity = 1; - $log1->datetime = "Oct 05 2005 12:04:20"; + $log1->datetime = 1201870191; $log2 = new ezcDebugStructure(); $log2->message = "SELECT DISTINCT ezdiscountrule.id\n FROM ezdiscountrule,\n ezuser_discountrule\n WHERE ezuser_discountrule.contentobject_id = '10' AND\n". @@ -32,34 +32,114 @@ $log2->source = "content"; $log2->category = "sql"; $log2->verbosity = 2; - $log2->datetime = "Oct 05 2005 12:04:25"; + $log2->datetime = 1201870191; return array( $log1, $log2 ); } public function getTimeStructure() { - $time = new ezcDebugTimer(); - $time->startTimer("Script", "html_reporter_test", "script"); - - if ( true != false ) $i_do_something = false; - - $time->startTimer("Timing module", "content", "module"); - - if ( true != false ) $i_do_something = true; - - $this->mySQLFunction($time); - $this->mySQLFunction($time); - $this->mySQLFunction($time); - - $this->anotherMySQLFunction($time); - $this->anotherMySQLFunction($time); - - $time->stopTimer("Timing module"); - - $time->stopTimer("Script"); - - return $time->getTimeData(); + $time = array ( + 0 => + ezcDebugTimerStruct::__set_state(array( + 'name' => 'my query', + 'source' => NULL, + 'group' => 'html_reporter_test', + 'switchTime' => + array ( + ), + 'startTime' => 1201870820.6352, + 'stopTime' => 1201870820.6352, + 'elapsedTime' => 1.9073486328125E-5, + 'startNumber' => 2, + 'stopNumber' => 3, + )), + 1 => + ezcDebugTimerStruct::__set_state(array( + 'name' => 'my query', + 'source' => NULL, + 'group' => 'html_reporter_test', + 'switchTime' => + array ( + ), + 'startTime' => 1201870820.6353, + 'stopTime' => 1201870820.6353, + 'elapsedTime' => 1.5974044799805E-5, + 'startNumber' => 4, + 'stopNumber' => 5, + )), + 2 => + ezcDebugTimerStruct::__set_state(array( + 'name' => 'my query', + 'source' => NULL, + 'group' => 'html_reporter_test', + 'switchTime' => + array ( + ), + 'startTime' => 1201870820.6353, + 'stopTime' => 1201870820.6353, + 'elapsedTime' => 1.5974044799805E-5, + 'startNumber' => 6, + 'stopNumber' => 7, + )), + 3 => + ezcDebugTimerStruct::__set_state(array( + 'name' => 'replace mysql', + 'source' => NULL, + 'group' => 'html_reporter_test', + 'switchTime' => + array ( + ), + 'startTime' => 1201870820.6354, + 'stopTime' => 1201870820.6354, + 'elapsedTime' => 1.5974044799805E-5, + 'startNumber' => 8, + 'stopNumber' => 9, + )), + 4 => + ezcDebugTimerStruct::__set_state(array( + 'name' => 'replace mysql', + 'source' => NULL, + 'group' => 'html_reporter_test', + 'switchTime' => + array ( + ), + 'startTime' => 1201870820.6354, + 'stopTime' => 1201870820.6355, + 'elapsedTime' => 1.5974044799805E-5, + 'startNumber' => 10, + 'stopNumber' => 11, + )), + 5 => + ezcDebugTimerStruct::__set_state(array( + 'name' => 'Timing module', + 'source' => NULL, + 'group' => 'content', + 'switchTime' => + array ( + ), + 'startTime' => 1201870820.6352, + 'stopTime' => 1201870820.6355, + 'elapsedTime' => 0.0003199577331543, + 'startNumber' => 1, + 'stopNumber' => 12, + )), + 6 => + ezcDebugTimerStruct::__set_state(array( + 'name' => 'Script', + 'source' => NULL, + 'group' => 'html_reporter_test', + 'switchTime' => + array ( + ), + 'startTime' => 1201870820.6351, + 'stopTime' => 1201870820.6355, + 'elapsedTime' => 0.00037717819213867, + 'startNumber' => 0, + 'stopNumber' => 13, + )), + ); + return $time; } protected function mySQLFunction(&$time) Modified: trunk/Debug/tests/formatters/html_formatter_test.php ============================================================================== --- trunk/Debug/tests/formatters/html_formatter_test.php [iso-8859-1] (original) +++ trunk/Debug/tests/formatters/html_formatter_test.php [iso-8859-1] Fri Feb 1 15:16:31 2008 @@ -23,18 +23,13 @@ $struct = new HtmlReporterDataStructures(); $out = $html->generateOutput($struct->getLogStructure(), $struct->getTimeStructure()); - - - /* - $fh = fopen("output.html", "w"); - fwrite( $fh, $out); - fclose($fh); - */ + $expected = file_get_contents( dirname( __FILE__ ) . '/output/output.html' ); + self::assertEquals( $expected, $out ); } public static function suite() { - return new PHPUnit_Framework_TestSuite(__CLASS__); + return new PHPUnit_Framework_TestSuite( __CLASS__ ); } } ?> Added: trunk/Debug/tests/formatters/output/output.html ============================================================================== --- trunk/Debug/tests/formatters/output/output.html (added) +++ trunk/Debug/tests/formatters/output/output.html [iso-8859-1] Fri Feb 1 15:16:31 2008 @@ -1,0 +1,74 @@ +<div class="ezc-debug-output"><table class='log'> +<tr class='debugheader'> + <td class='source'> + <span class='verbosity1'>1: content::sql</span> + </td> + <td class='date'>2008-02-01 12:49:51 +0000</td> +</tr> +<tr class='debugbody'> + <td colspan='2'>SELECT contentobject_id, login, email, password_hash, password_hash_type + FROM ezuser + WHERE contentobject_id='10'</td> +</tr><tr class='debugheader'> + <td class='source'> + <span class='verbosity2'>2: content::sql</span> + </td> + <td class='date'>2008-02-01 12:49:51 +0000</td> +</tr> +<tr class='debugbody'> + <td colspan='2'>SELECT DISTINCT ezdiscountrule.id + FROM ezdiscountrule, + ezuser_discountrule + WHERE ezuser_discountrule.contentobject_id = '10' AND +ezuser_discountrule.discountrule_id = ezdiscountrule.id</td> +</tr></table> +<table class='accumulator'> + <tr> + <th>Timings</th> + <th>Elapsed</th> + <th>Percent</th> + <th>Count</th> + <th>Average</th> + </tr> + <tr class='group-header'> + <th colspan='5'>html_reporter_test</th> + </tr> + <tr class='group'> + <td class='timingpoint-name'>my query</td> + <td class='timingpoint-elapsed'>0.00005</td> + <td class='timingpoint-percent'>11.09 %</td> + <td class='timingpoint-count'>3</td> + <td class='timingpoint-average'>0.00002</td> + </tr> + <tr class='group'> + <td class='timingpoint-name'>replace mysql</td> + <td class='timingpoint-elapsed'>0.00003</td> + <td class='timingpoint-percent'>6.94 %</td> + <td class='timingpoint-count'>2</td> + <td class='timingpoint-average'>0.00002</td> + </tr> + <tr class='group'> + <td class='timingpoint-name'>Script</td> + <td class='timingpoint-elapsed'>0.00038</td> + <td class='timingpoint-percent'>81.97 %</td> + <td class='timingpoint-count'>1</td> + <td class='timingpoint-average'>0.00038</td> + </tr> + <tr class='totals'> + <th class='timingpoint-total'>Total:</th> + <td class='timingpoint-elapsed'>0.00046</td> + <td class='timingpoint-percent'>100.00 %</td> + <td class='timingpoint-count'>6</td> + <td class='timingpoint-average'>0.00008</td> + </tr> + <tr class='group-header'> + <th colspan='5'>content</th> + </tr> + <tr class='group'> + <td class='timingpoint-name'>Timing module</td> + <td class='timingpoint-elapsed'>0.00032</td> + <td class='timingpoint-percent'>100.00 %</td> + <td class='timingpoint-count'>1</td> + <td class='timingpoint-average'>0.00032</td> + </tr> +</table></div> Propchange: trunk/Debug/tests/formatters/output/output.html ------------------------------------------------------------------------------ svn:eol-style = native -- svn-components mailing list svn-components@lists.ez.no http://lists.ez.no/mailman/listinfo/svn-components