Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

php_formatter.php
Go to the documentation of this file.
1 <?php
11 class ezpRestDebugPHPFormatter implements ezcDebugOutputFormatter
12 {
16 public function __construct()
17 {
18
19 }
20
28 public function generateOutput( array $writerData, array $timerData )
29 {
30 return array(
31 'Logs' => $this->getLog( $writerData ),
32 'Timer' => $this->getTimingsAccumulator( $timerData )
33 );
34 }
35
42 public function getLog( array $writerData )
43 {
44 $result = array();
45
46 foreach( $writerData as $w )
47 {
48 $result[$w->verbosity.': '.$w->source.'::'.$w->category] = $w->message;
49 }
50
51 if ( isset( $w->stackTrace ) )
52 {
53 $result['stackTrace'] = $this->formatStackTrace( $w->stackTrace );
54 }
55
56 return $result;
57 }
58
65 public function getTimingsAccumulator( array $timerData )
66 {
67 $groups = $this->getGroups( $timerData );
68 $res = array();
69
70 if ( sizeof( $groups ) > 0 )
71 {
72 foreach ( $groups as $groupName => $group )
73 {
74 $groupStats = new stdClass();
75
76 // Calculate the total time.
77 foreach ( $group->elements as $name => $element )
78 {
79 $elapsedTime = sprintf( '%.5f', $element->elapsedTime );
80 $percent = sprintf( '%.2f', (100 * ($element->elapsedTime / $group->elapsedTime ) ) );
81 $average = sprintf( '%.5f', ( $element->elapsedTime / $element->count ) );
82 $groupInfos = new stdClass();
83 $groupInfos->name = $name;
84 $groupInfos->elapsed = $elapsedTime;
85 $groupInfos->percent = $percent.' %';
86 $groupInfos->count = $element->count;
87 $groupInfos->average = $average;
88 $groupInfos->switches = array();
89
90 foreach ( $element->switchTime as $switch )
91 {
92 $switchInfos = new stdClass();
93 $elapsedTime = sprintf( '%.5f', $switch->time - $element->startTime );
94 $percent = sprintf( '%.2f', ( 100 * ( $elapsedTime / $group->elapsedTime ) ) );
95 $switchInfos->name = $switch->name;
96 $switchInfos->elapsed = $elapsedTime;
97 $switchInfos->percent = $percent.' %';
98
99 $groupInfos->switches[] = $switchInfos;
100 }
101
102 $groupStats->elements[] = $groupInfos;
103 }
104
105 if ( $group->count > 1 )
106 {
107 $elapsedTime = sprintf( '%.5f', $group->elapsedTime );
108 $average = sprintf( '%.5f', ( $group->elapsedTime / $group->count ) );
109 $groupStats->totalElapsed = $elapsedTime;
110 $groupStats->count = $group->count;
111 $groupStats->average = $average;
112 }
113
114 $res[$groupName] = $groupStats;
115 }
116 }
117
118 return $res;
119 }
120
127 private function getGroups( array $timers )
128 {
129 $groups = array();
130 foreach ( $timers as $time )
131 {
132 if ( !isset( $groups[$time->group] ) )
133 {
134 $groups[$time->group] = new ezcDebugStructure();
135 $groups[$time->group]->elements = array();
136 $groups[$time->group]->count = 0;
137 $groups[$time->group]->elapsedTime = 0;
138 $groups[$time->group]->startTime = INF; // Infinite high number.
139 $groups[$time->group]->stopTime = 0;
140 }
141
142 // $groups[$time->group]->elements[] = $time;
143 $this->addElement( $groups[$time->group]->elements, $time );
144
145 $groups[$time->group]->count++;
146 $groups[$time->group]->elapsedTime += $time->elapsedTime;
147 $groups[$time->group]->startTime = min( $groups[$time->group]->startTime, $time->startTime );
148 $groups[$time->group]->stopTime = max( $groups[$time->group]->stopTime, $time->stopTime );
149 }
150
151 return $groups;
152 }
153
160 private function addElement( &$element, $timeStruct )
161 {
162 if ( !isset( $element[$timeStruct->name] ) )
163 {
164 $element[$timeStruct->name] = new ezcDebugStructure();
165
166 $element[$timeStruct->name]->count = 0;
167 $element[$timeStruct->name]->elapsedTime = 0;
168 $element[$timeStruct->name]->startTime = INF;
169 $element[$timeStruct->name]->stopTime = 0;
170 }
171
172 $element[$timeStruct->name]->count++;
173 $element[$timeStruct->name]->elapsedTime += $timeStruct->elapsedTime;
174 $element[$timeStruct->name]->startTime = min( $element[$timeStruct->name]->startTime, $timeStruct->startTime );
175 $element[$timeStruct->name]->stopTime = max( $element[$timeStruct->name]->stopTime, $timeStruct->stopTime );
176
177
178 $element[$timeStruct->name]->switchTime = $timeStruct->switchTime;
179 }
180
190 public function formatStackTrace( ezcDebugStacktraceIterator $stackTrace )
191 {
192 $res = array();
193 foreach ( $stackTrace as $index => $element )
194 {
195 $function = ( isset( $element['class'] ) ? "{$element['class']}::" : '' )
196 . $element['function'] . '('
197 . implode( ', ', $element['params'] )
198 . ')';
199 $location = "{$element['file']}:{$element['line']}";
200 $res[$index] = $function.' ('.$location.')';
201 }
202 return $res;
203 }
204 }
205 ?>
$group
$group
Definition: admin/articleedit.php:799
ezpRestDebugPHPFormatter
Definition: php_formatter.php:12
ezpRestDebugPHPFormatter\generateOutput
generateOutput(array $writerData, array $timerData)
Definition: php_formatter.php:28
ezpRestDebugPHPFormatter\getLog
getLog(array $writerData)
Definition: php_formatter.php:42
ezpRestDebugPHPFormatter\formatStackTrace
formatStackTrace(ezcDebugStacktraceIterator $stackTrace)
Definition: php_formatter.php:190
ezpRestDebugPHPFormatter\addElement
addElement(&$element, $timeStruct)
Definition: php_formatter.php:160
ezpRestDebugPHPFormatter\__construct
__construct()
Definition: php_formatter.php:16
ezpRestDebugPHPFormatter\getGroups
getGroups(array $timers)
Definition: php_formatter.php:127
ezpRestDebugPHPFormatter\getTimingsAccumulator
getTimingsAccumulator(array $timerData)
Definition: php_formatter.php:65
$result
$result
Definition: companysearch.php:94
$name
$name
Definition: companytypelist.php:194
$groups
if( $CategoryID !=0) $groups
Definition: ezbulkmail/admin/categoryedit.php:108
$index
$index
Definition: ezforum/user/messageedit.php:36
$res
$res
Definition: ezstats/admin/cron.php:45
$element
if(! $parent) $element
Definition: folder.php:64
$time
$time
Definition: homepage.php:327
$location
$location
Definition: user/gotolink.php:43
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.