'color_name_using_css_names') * * @var array(int=>string) */ private $verbosityColors = array(); /** * Constructs a new HTML reporter. */ public function __construct() { } /** * Sets the output $color of debug messages of the verbosity $verbosity. * * $color must be specified in a CSS color value. * * @param int $verbosity * @param string $color * * @deprecated This method does not have any effect anymore. Use CSS instead. */ public function setVerbosityColor( $verbosity, $color ) { $this->verbosityColors[$verbosity] = $color; } /** * Returns a string containing the HTML formatted output. * * Returns the data submitted in $timerData and $writerData as an HTML * formatted string to be displayed in a web browser. * * @param array $writerData * @param array(ezcDebugStructure) $timerData * @return string */ public function generateOutput( array $writerData, array $timerData ) { $str = '
'; $str .= $this->getLog( $writerData ); $str .= $this->getTimingsAccumulator( $timerData ); $str .= "
\n"; return $str; } /** * Returns a string containing the HTML formatted output based on $writerData. * * @param array $writerData * @return string */ public function getLog( array $writerData ) { $str = "\n"; foreach ( $writerData as $w ) { $color = isset( $this->verbosityColors[$w->verbosity]) ? $this->verbosityColors[$w->verbosity] : ""; $date = date( 'Y-m-d H:i:s O', $w->datetime ); $str .= << ENDT; if ( isset( $w->stackTrace ) ) { $str .= ""; $str .= ""; $str .= ""; } } $str .= "
{$w->verbosity}: {$w->source}::{$w->category} {$date}
{$w->message}
"; $str .= $this->formatStackTrace( $w->stackTrace ); $str .= "
\n"; return $str; } /** * Returns an HTML formatted representation of the given $stackTrace. * * Iterates through the given $stackTrace and returns an HTML formatted * string representation. * * @param ezcDebugStacktraceIterator $stackTrace * @return string */ public function formatStackTrace( ezcDebugStacktraceIterator $stackTrace ) { $res = << # Function Location EOT; foreach ( $stackTrace as $index => $element ) { $function = ( isset( $element['class'] ) ? "{$element['class']}::" : '' ) . $element['function'] . '(' . implode( ', ', $element['params'] ) . ')'; $location = "{$element['file']}:{$element['line']}"; $res .= << $index $function $location EOT; } $res .= "\n"; return $res; } /** * Returns a string containing the HTML formatted output based on $timerData. * * @param array(ezcDebugStructure) $timerData * @return string */ public function getTimingsAccumulator( array $timerData ) { $groups = $this->getGroups( $timerData ); if ( sizeof( $groups ) > 0 ) { $str = << Timings Elapsed Percent Count Average ENDT; foreach ( $groups as $groupName => $group ) { $str .= << {$groupName} ENDT; // Calculate the total time. foreach ( $group->elements as $name => $element ) { $elapsedTime = sprintf( '%.5f', $element->elapsedTime ); $percent = sprintf( '%.2f', (100 * ($element->elapsedTime / $group->elapsedTime ) ) ); $average = sprintf( '%.5f', ( $element->elapsedTime / $element->count ) ); $str .= << {$name} {$elapsedTime} {$percent} % {$element->count} {$average} ENDT; foreach ( $element->switchTime as $switch ) { $elapsedTime = sprintf( '%.5f', $switch->time - $element->startTime ); $percent = sprintf( '%.2f', ( 100 * ( $elapsedTime / $group->elapsedTime ) ) ); $str .= << {$switch->name} {$elapsedTime} {$percent} % - - ENDT; } } if ( $group->count > 1 ) { $elapsedTime = sprintf( '%.5f', $group->elapsedTime ); $average = sprintf( '%.5f', ( $group->elapsedTime / $group->count ) ); $str .= << Total: {$elapsedTime} 100.00 % {$group->count} {$average} ENDT; } } $str .= ""; return $str; } return ""; } /** * Returns the timer groups of the given $timers. * * @param array(ezcDebugStructure) $timers * @return array(ezcDebugStructure) */ private function getGroups( array $timers ) { $groups = array(); foreach ( $timers as $time ) { if ( !isset( $groups[$time->group] ) ) { $groups[$time->group] = new ezcDebugStructure(); $groups[$time->group]->elements = array(); $groups[$time->group]->count = 0; $groups[$time->group]->elapsedTime = 0; $groups[$time->group]->startTime = INF; // Infinite high number. $groups[$time->group]->stopTime = 0; } // $groups[$time->group]->elements[] = $time; $this->addElement( $groups[$time->group]->elements, $time ); $groups[$time->group]->count++; $groups[$time->group]->elapsedTime += $time->elapsedTime; $groups[$time->group]->startTime = min( $groups[$time->group]->startTime, $time->startTime ); $groups[$time->group]->stopTime = max( $groups[$time->group]->stopTime, $time->stopTime ); } return $groups; } /** * Prepares $element to contain $timeStruct information. * * @param array $element * @param ezcDebugTimerStruct $timeStruct */ private function addElement( &$element, $timeStruct ) { if ( !isset( $element[$timeStruct->name] ) ) { $element[$timeStruct->name] = new ezcDebugStructure(); $element[$timeStruct->name]->count = 0; $element[$timeStruct->name]->elapsedTime = 0; $element[$timeStruct->name]->startTime = INF; $element[$timeStruct->name]->stopTime = 0; } $element[$timeStruct->name]->count++; $element[$timeStruct->name]->elapsedTime += $timeStruct->elapsedTime; $element[$timeStruct->name]->startTime = min( $element[$timeStruct->name]->startTime, $timeStruct->startTime ); $element[$timeStruct->name]->stopTime = max( $element[$timeStruct->name]->stopTime, $timeStruct->stopTime ); $element[$timeStruct->name]->switchTime = $timeStruct->switchTime; } } ?>