25 private $iStartMicrotime;
29 private static $tTime;
30 private static $tTimeById;
32 public function __construct($sMicrotime){
34 $this->iStartMicrotime=self::microtime($sMicrotime);
36 $iEndTime=self::microtime();
37 self::$tTime[]=array(
'End',$iEndTime);
39 $iDiff=($iEndTime-$this->iStartMicrotime);
41 $this->add(
'Time',sprintf(
'%0.3f',$iDiff).
's');
43 $this->addComplexTimes(
'times',self::$tTime);
45 $this->addComplex(
'$_GET',print_r($_GET,1));
48 $this->addComplex(
'$_POST',print_r($_POST,1));
52 $this->addComplex(
'$_SESSION',print_r($_SESSION,1));
56 $this->addComplex(
'$_SERVER',print_r($_SERVER,1));
61 $this->add(
'Module',$oRequest->getModule());
62 $this->add(
'Action',$oRequest->getAction());
65 if($oFileLog->exist()){
67 $sContentLog=$oFileLog->getContent();
68 $this->addFileLog(
'File log',$sContentLog);
73 $this->addComplexIni(
'Connexions',array($sVarIniConfig=>$tClassSgbd));
75 $tConfigSection=array(
90 foreach($tConfigSection as $sSection){
94 $this->addComplexIni(
'Config',$tConfig);
97 $this->addComplexSpy(
'Spy variables',self::$tSpy);
109 public static function addSpy($uLabel,$uVar){
110 self::$tSpy[][$uLabel]=$uVar;
118 $iTime=self::microtime();
119 self::$tTime[]=array($uLabel,$iTime);
127 $iTime=self::microtime();
128 self::$tTimeById[$uLabel][
'start']=$iTime;
136 $iTime=self::microtime();
137 self::$tTimeById[$uLabel][
'end']=$iTime;
143 public function display(){
145 var activePopup=\'\';
146 function openPopupDebug(id){
150 a.style.display="block";
154 function closePopup(){
156 var b=getById(activePopup);
158 b.style.display="none";
162 function showHideDebugBar(){
163 var a=getById(\'debugBar\');
165 if(a.style.display==\'none\'){
166 a.style.display=\'block\';
167 var b=getById(\'debugBtn\');
169 b.style.width=\'100%\';
172 a.style.display=\'none\';
173 var b=getById(\'debugBtn\');
175 b.style.width=\'80px\';
181 echo
'<div id="debugBtn" ';
182 echo
'style="position:fixed;border:2px solid #444;background:#ddd;bottom:0px;left:0px;width:100%">';
183 echo
'<div style="float:left"><input type="button" value="Masquer" onclick="showHideDebugBar()"/></div>';
184 echo
'<div id="debugBar" style="width:100%">';
190 private function addComplex($key,$value){
191 $this->addHtml(
'<input type="button" value="'.$key.
'" onclick="openPopupDebug(\'popupDebug'.$key.
'\')
" />');
194 $this->addPopupPrintr($key,$value);
196 private function addComplexTimes($key,$value){
197 $this->addHtml('<input type="button
" value="'.$key.'" onclick="openPopupDebug(\
'popupDebug'.$key.
'\')
" />');
200 $value=$this->parseTime($value);
202 $this->addPopup($key,$value);
204 private function addComplexIni($key,$value){
205 $this->addHtml('<input type="button
" value="'.$key.'" onclick="openPopupDebug(\
'popupDebug'.$key.
'\')
" />');
208 $value=$this->parseIni($value);
210 $this->addPopup($key,$value);
212 private function addComplexSpy($key,$value){
213 $this->addHtml('<input type="button
" value="'.$key.'" onclick="openPopupDebug(\
'popupDebug'.$key.
'\')
" />');
216 $sValue=$this->parseSpy($value);
218 $this->addPopup($key,$sValue);
221 private function addFileLog($key,$value){
222 $this->addHtml('<input type="button
" value="'.$key.'" onclick="openPopupDebug(\
'popupDebug'.$key.
'\')
" />');
225 $value=$this->parseLog($value);
227 $this->addPopup($key,$value);
230 private function add($key,$value){
231 $this->addHtml('<strong>'.$key.'</strong>:<span style="padding:2px 4px;background:#fff
">'.$value.'</span>');
235 private function addPopupPrintr($key,$value){
237 '<div id="popupDebug
'.$key.'"
238 style="display:none;position:absolute;left:0px;bottom:0px;border:2px solid gray;background:white
">
239 <p style="text-align:right;background:#ccc;margin:0px;
"><a href="#
" onclick="closePopup()
">Fermer</a></p>
240 <div style="height:350px;width:400px;overflow:
auto;padding:10px;
">
241 <pre>'.customHtmlentities(print_r($value,1)).'</pre>
246 private function addPopup($key,$value,$width=800){
248 '<div id="popupDebug
'.$key.'"
249 style="display:none;position:absolute;left:0px;bottom:0px;border:2px solid gray;background:white
">
250 <p style="text-align:right;background:#ccc;margin:0px;
"><a href="#
" onclick="closePopup()
">Fermer</a></p>
251 <div style="height:350px;width:
'.$width.'px;overflow:
auto;padding:10px;
">
257 private function addAcl(){
258 $this->addHtml('<input type="button
" value="Permissions
" onclick="openPopupDebug(\
'popupDebugACL\')" />');
261 $sHtml=
'<div style="position:absolute">';
262 $sHtml.=
'<table style="background:white;border-collapse:collapse">
264 <th style="border:1px solid gray;">Action</th>
265 <th style="border:1px solid gray;">Component</th>
268 if($tab and is_array($tab)):
269 foreach($tab as $tVal):
271 <td style="border:1px solid gray;';
273 $sHtml.=
'color:green;';
277 $sHtml.=
'">'.$tVal[0].
'</td>
278 <td style="border:1px solid gray;';
280 $sHtml.=
'color:green;';
284 $sHtml.=
'">'.$tVal[1].
'</td>
291 $this->addPopup(
'ACL', $sHtml,300);
294 private function addSep(){
295 $this->addHtml(
' ');
298 private function addHtml($sHtml){
299 $this->sHtml.=$sHtml;
302 private function parseLog($value){
305 $tLine=explode(
"\n",$value);
308 $iMax=count($tLine)-1;
309 for($i=$iMax;$i>0;$i--){
312 $tCase=explode(
';',$sLine,4);
314 if(isset($tCase[0])){
318 if(isset($tCase[1])){
322 if(isset($tCase[2])){
326 if(isset($tCase[3])){
334 $sHtml.=
'<p style="border-bottom:1px dotted gray">';
336 $sHtml.=
'<span >'.$sDate.
'</span> ';
337 $sHtml.=
'<span style="font-weight:bold">'.$sTime.
'</span>';
341 $sHtml.=
'<span style="color:';
342 if($sType==
'info'){ $sHtml.=
'gray';}
343 elseif($sType==
'log'){ $sHtml.=
'darkblue';}
344 $sHtml.=
'">'.$sType.
'</span>';
352 if(preg_match(
'/module a appeler/',$sLog)){
353 $sHtml.=
'<p> </p>';
360 private function parseSpy($tValue){
362 foreach($tValue as $tDetail){
363 foreach($tDetail as $ref => $value){
364 $sHtml.=
'<h2 style="border-bottom:1px solid black">'.$ref.
'</h2>';
365 $sHtml.=
'<p><pre>'.customHtmlentities(print_r($value,1)).
'</pre></p>';
372 private function parseIni($tValue){
374 foreach($tValue as $sSection => $tDetail){
375 $sHtml.=
'<h2 style="border-bottom:1px solid black">'.$sSection.
'</h2>';
376 foreach($tDetail as $sKey => $sValue){
377 $sHtml.=
'<p style="margin:0px;margin-left:10px;">';
378 $sHtml.=
'<strong>'.$sKey.
'</strong> = <span style="color:darkgreen"> '.$sValue.
'</span>';
385 private function parseTime($tValue){
387 $iPreviousTime=$this->iStartMicrotime;
388 $sPreviousStep=
'Start';
389 foreach($tValue as $tDetail){
390 list($sLabel,$iTime)=$tDetail;
391 $iDelta=($iTime-$iPreviousTime);
392 $sHtml.=
'<p><strong>'.$sPreviousStep.
' >> '.$sLabel.
'</strong> : '.sprintf(
'%0.3f',$iDelta).
's</p>';
394 $iPreviousTime=$iTime;
395 $sPreviousStep=$sLabel;
398 $sHtml.=
'<p style="border-top:1px solid gray">';
399 $sHtml.=
'<strong>Total</strong> '.sprintf(
'%0.3f',($iTime-$this->iStartMicrotime)).
's';
402 if(self::$tTimeById){
404 $sHtml.=
'<p> </p>';
406 foreach(self::$tTimeById as $sLabel => $tValue){
408 if(isset($tValue[
'end']) and isset($tValue[
'start'])){
409 $iDelta=($tValue[
'end']-$tValue[
'start']);
411 $sHtml.=
'<p><strong>'.$sLabel.
' </strong> : '.sprintf(
'%0.3f',$iDelta).
's</p>';
413 $sHtml.=
'<p><strong>'.$sLabel.
' </strong> : <span style="color:red">';
414 $sHtml.=
' Erreur il manque startChrono ou stopChrono</span></p>';
424 public static function microtime($sMicrotime=null){
425 if($sMicrotime==null){ $sMicrotime=microtime(); }
426 $tMicrotime = explode(
" ", $sMicrotime);
427 return ((
float)$tMicrotime[0] + (
float)$tMicrotime[1]);
static getConfigVar($sCatAndVar, $uDefaut=null)
static addChrono($uLabel)
static stopChrono($uLabel)
static startChrono($uLabel)
static addSpy($uLabel, $uVar)