Go to the documentation of this file.00001 <?php
00002
00007 class oxDebugInfo
00008 {
00016 public function formatTemplateData($aViewData = array())
00017 {
00018 $sLog = '';
00019 reset( $aViewData );
00020 while ( list( $sViewName, $oViewData ) = each( $aViewData ) ) {
00021
00022 $sLog .= "TemplateData[$sViewName] : <br />\n";
00023 $sLog .= print_r( $oViewData, 1);
00024 }
00025 return $sLog;
00026 }
00027
00033 public function formatMemoryUsage()
00034 {
00035 $sLog = '';
00036 if ( function_exists( 'memory_get_usage' ) ) {
00037 $iKb = ( int ) ( memory_get_usage() / 1024 );
00038 $iMb = round($iKb / 1024, 3);
00039 $sLog .= 'Memory usage: '.$iMb.' MB';
00040
00041 if ( function_exists( 'memory_get_peak_usage' ) ) {
00042 $iPeakKb = ( int ) ( memory_get_peak_usage() / 1024 );
00043 $iPeakMb = round($iPeakKb / 1024, 3);
00044 $sLog .= ' (peak: '.$iPeakMb.' MB)';
00045 }
00046 $sLog .= '<br />';
00047
00048 if ( version_compare( PHP_VERSION, '5.2.0', '>=' ) ) {
00049 $iKb = ( int ) ( memory_get_usage( true ) / 1024 );
00050 $iMb = round($iKb / 1024, 3);
00051 $sLog .= 'System memory usage: '.$iMb.' MB';
00052
00053 if ( function_exists( 'memory_get_peak_usage' ) ) {
00054 $iPeakKb = ( int ) ( memory_get_peak_usage( true ) / 1024 );
00055 $iPeakMb = round($iPeakKb / 1024, 3);
00056 $sLog .= ' (peak: '.$iPeakMb.' MB)';
00057 }
00058 $sLog .= '<br />';
00059 }
00060 }
00061 return $sLog;
00062 }
00063
00071 public function formatExecutionTime($dTotalTime)
00072 {
00073 $sLog = 'Execution time:'.round($dTotalTime, 4).'<br />';
00074 global $aProfileTimes;
00075 global $aExecutionCounts;
00076 global $aProfileBacktraces;
00077 if (is_array($aProfileTimes)) {
00078 $sLog .= "----------------------------------------------------------<br>".PHP_EOL;
00079 arsort($aProfileTimes);
00080 $sLog .= "<table cellspacing='10px' style='border: 1px solid #000'>";
00081 $iNr = 1;
00082 foreach ($aProfileTimes as $sKey => $sVal) {
00083 $sLog .= "<tr><td style='border-bottom: 1px dotted #000;min-width:300px;'>Profile $sKey: </td><td style='border-bottom: 1px dotted #000;min-width:100px;'>" . round($sVal, 5) ."s</td>" ;
00084 if ($dTotalTime) {
00085 $sLog .= "<td style='border-bottom: 1px dotted #000;min-width:100px;'>".round($sVal*100/$dTotalTime, 2)."%</td>";
00086 }
00087 if ($aExecutionCounts[$sKey]) {
00088 $sLog .= " <td style='border-bottom: 1px dotted #000;min-width:50px;padding-right:30px;' align='right'>" . $aExecutionCounts[$sKey] . "</td>"
00089 ."<td style='border-bottom: 1px dotted #000;min-width:15px; '>*</td>"
00090 ."<td style='border-bottom: 1px dotted #000;min-width:100px;'>" . round($sVal / $aExecutionCounts[$sKey], 5) . "s</td>" . PHP_EOL;
00091 } else {
00092 $sLog .= " <td colspan=3 style='border-bottom: 1px dotted #000;min-width:100px;'> not stopped correctly! </td>" . PHP_EOL;
00093 }
00094
00095 if (isset($aProfileBacktraces[$sKey])) {
00096 $sLog .= "<td style='border-bottom: 1px dotted #000;min-width:15px; '>";
00097 foreach ($aProfileBacktraces[$sKey] as $sBtId => $aBt) {
00098 $iCnt = (int)$aProfileBacktraceCounts[$sBtId];
00099 $sLog .= "<a style='color:#00AA00;margin:5px;cursor:pointer' onclick='var el=document.getElementById(\"profdbg_trace_$iNr\"); if (el.style.display==\"block\")el.style.display=\"none\"; else el.style.display = \"block\";'>Count($iCnt) - TRACE (show/hide)</a><br><br>";
00100 $sLog .= "<div id='profdbg_trace_$iNr' style='display:none'>";
00101 foreach ($aBt as $iLevel => $aInfo) {
00102 $sLog .= "<i><strong>$iLevel: {$aInfo['function']}</strong></i> at {$aInfo['file']}:{$aInfo['line']}<br>";
00103 }
00104 $sLog .= "</div>";
00105 $iNr++;
00106 }
00107 $sLog .= "</td>";
00108 }
00109 $sLog .= '</tr>';
00110 }
00111 $sLog .= "</table>";
00112 }
00113 return $sLog;
00114 }
00115
00116
00122 public function formatGeneralInfo()
00123 {
00124 $sLog = "cl=".oxRegistry::getConfig()->getActiveView()->getClassName();
00125 if ( ($sFnc = oxRegistry::getConfig()->getActiveView()->getFncName() ) ) {
00126 $sLog .= " fnc=$sFnc";
00127 }
00128 return $sLog;
00129 }
00130
00136 public function formatDbInfo()
00137 {
00138 $sLog = "----------------------------------------------------------<br>".PHP_EOL;
00139 $sLog .= "-- oxdebugdb --<br>".PHP_EOL;
00140 $oDbgDb = oxNew('oxdebugdb');
00141 $aWarnings = $oDbgDb->getWarnings();
00142 $iNr = 1;
00143 foreach ($aWarnings as $w) {
00144 $sLog .= "{$w['check']}: {$w['time']} - <span style='color:#900000;margin:5px'>".htmlentities($w['sql'], ENT_QUOTES, 'UTF-8')."</span>";
00145 $sLog .= "<div id='dbgdb_trace_$iNr' style='display:none'>".nl2br($w['trace'])."</div>";
00146 $sLog .= "<a style='color:#00AA00;margin:5px;cursor:pointer' onclick='var el=document.getElementById(\"dbgdb_trace_$iNr\"); if (el.style.display==\"block\")el.style.display=\"none\"; else el.style.display = \"block\";'>TRACE (show/hide)</a><br><br>";
00147 ++$iNr;
00148 }
00149 return $sLog;
00150 }
00151
00157 public function formatAdoDbPerf()
00158 {
00159 $oPerfMonitor = @NewPerfMonitor( oxDb::getDb() );
00160 if ( $oPerfMonitor ) {
00161 ob_start();
00162 $oPerfMonitor->UI( 5 );
00163 return ob_get_clean();
00164 }
00165 return '';
00166 }
00167
00173 public function formatTimeStamp()
00174 {
00175 $sLog = '';
00176 $sClassName = oxRegistry::getConfig()->getActiveView()->getClassName();
00177 $sLog .= "<div id='". $sClassName ."_executed'>Executed: ". date( 'Y-m-d H:i:s' ) ."</div>";
00178 $sLog .= "<div id='". $sClassName ."_timestamp'>Timestamp: ". microtime(true) ."</div>";
00179 return $sLog;
00180 }
00181
00182 }