oxdebuginfo.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class oxDebugInfo
00008 {
00009 
00017     public function formatTemplateData($aViewData = array())
00018     {
00019         $sLog = '';
00020         reset($aViewData);
00021         while (list($sViewName, $oViewData) = each($aViewData)) {
00022             // show debbuging information
00023             $sLog .= "TemplateData[$sViewName] : <br />\n";
00024             $sLog .= print_r($oViewData, 1);
00025         }
00026 
00027         return $sLog;
00028     }
00029 
00035     public function formatMemoryUsage()
00036     {
00037         $sLog = '';
00038         if (function_exists('memory_get_usage')) {
00039             $iKb = ( int ) (memory_get_usage() / 1024);
00040             $iMb = round($iKb / 1024, 3);
00041             $sLog .= 'Memory usage: ' . $iMb . ' MB';
00042 
00043             if (function_exists('memory_get_peak_usage')) {
00044                 $iPeakKb = ( int ) (memory_get_peak_usage() / 1024);
00045                 $iPeakMb = round($iPeakKb / 1024, 3);
00046                 $sLog .= ' (peak: ' . $iPeakMb . ' MB)';
00047             }
00048             $sLog .= '<br />';
00049 
00050             if (version_compare(PHP_VERSION, '5.2.0', '>=')) {
00051                 $iKb = ( int ) (memory_get_usage(true) / 1024);
00052                 $iMb = round($iKb / 1024, 3);
00053                 $sLog .= 'System memory usage: ' . $iMb . ' MB';
00054 
00055                 if (function_exists('memory_get_peak_usage')) {
00056                     $iPeakKb = ( int ) (memory_get_peak_usage(true) / 1024);
00057                     $iPeakMb = round($iPeakKb / 1024, 3);
00058                     $sLog .= ' (peak: ' . $iPeakMb . ' MB)';
00059                 }
00060                 $sLog .= '<br />';
00061             }
00062         }
00063 
00064         return $sLog;
00065     }
00066 
00074     public function formatExecutionTime($dTotalTime)
00075     {
00076         $sLog = 'Execution time:' . round($dTotalTime, 4) . '<br />';
00077         global $aProfileTimes;
00078         global $aExecutionCounts;
00079         global $aProfileBacktraces;
00080         if (is_array($aProfileTimes)) {
00081             $sLog .= "----------------------------------------------------------<br>" . PHP_EOL;
00082             arsort($aProfileTimes);
00083             $sLog .= "<table cellspacing='10px' style='border: 1px solid #000'>";
00084             $iNr = 1;
00085             foreach ($aProfileTimes as $sKey => $sVal) {
00086                 $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>";
00087                 if ($dTotalTime) {
00088                     $sLog .= "<td style='border-bottom: 1px dotted #000;min-width:100px;'>" . round($sVal * 100 / $dTotalTime, 2) . "%</td>";
00089                 }
00090                 if ($aExecutionCounts[$sKey]) {
00091                     $sLog .= " <td style='border-bottom: 1px dotted #000;min-width:50px;padding-right:30px;' align='right'>" . $aExecutionCounts[$sKey] . "</td>"
00092                              . "<td style='border-bottom: 1px dotted #000;min-width:15px; '>*</td>"
00093                              . "<td style='border-bottom: 1px dotted #000;min-width:100px;'>" . round($sVal / $aExecutionCounts[$sKey], 5) . "s</td>" . PHP_EOL;
00094                 } else {
00095                     $sLog .= " <td colspan=3 style='border-bottom: 1px dotted #000;min-width:100px;'> not stopped correctly! </td>" . PHP_EOL;
00096                 }
00097 
00098                 if (isset($aProfileBacktraces[$sKey])) {
00099                     $sLog .= "<td style='border-bottom: 1px dotted #000;min-width:15px; '>";
00100                     foreach ($aProfileBacktraces[$sKey] as $sBtId => $aBt) {
00101                         $iCnt = (int) $aProfileBacktraceCounts[$sBtId];
00102                         $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>";
00103                         $sLog .= "<div id='profdbg_trace_$iNr' style='display:none'>";
00104                         foreach ($aBt as $iLevel => $aInfo) {
00105                             $sLog .= "<i><strong>$iLevel: {$aInfo['function']}</strong></i> at {$aInfo['file']}:{$aInfo['line']}<br>";
00106                         }
00107                         $sLog .= "</div>";
00108                         $iNr++;
00109                     }
00110                     $sLog .= "</td>";
00111                 }
00112                 $sLog .= '</tr>';
00113             }
00114             $sLog .= "</table>";
00115         }
00116 
00117         return $sLog;
00118     }
00119 
00120 
00126     public function formatGeneralInfo()
00127     {
00128         $sLog = "cl=" . oxRegistry::getConfig()->getActiveView()->getClassName();
00129         if (($sFnc = oxRegistry::getConfig()->getActiveView()->getFncName())) {
00130             $sLog .= " fnc=$sFnc";
00131         }
00132 
00133         return $sLog;
00134     }
00135 
00141     public function formatDbInfo()
00142     {
00143         $sLog = "----------------------------------------------------------<br>" . PHP_EOL;
00144         $sLog .= "-- oxdebugdb --<br>" . PHP_EOL;
00145         $oDbgDb = oxNew('oxdebugdb');
00146         $aWarnings = $oDbgDb->getWarnings();
00147         $iNr = 1;
00148         foreach ($aWarnings as $w) {
00149             $sLog .= "{$w['check']}: {$w['time']} - <span style='color:#900000;margin:5px'>" . htmlentities($w['sql'], ENT_QUOTES, 'UTF-8') . "</span>";
00150             $sLog .= "<div id='dbgdb_trace_$iNr' style='display:none'>" . nl2br($w['trace']) . "</div>";
00151             $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>";
00152             ++$iNr;
00153         }
00154 
00155         return $sLog;
00156     }
00157 
00163     public function formatAdoDbPerf()
00164     {
00165         $oPerfMonitor = @NewPerfMonitor(oxDb::getDb());
00166         if ($oPerfMonitor) {
00167             ob_start();
00168             $oPerfMonitor->UI(5);
00169 
00170             return ob_get_clean();
00171         }
00172 
00173         return '';
00174     }
00175 
00181     public function formatTimeStamp()
00182     {
00183         $sLog = '';
00184         $sClassName = oxRegistry::getConfig()->getActiveView()->getClassName();
00185         $sLog .= "<div id='" . $sClassName . "_executed'>Executed: " . date('Y-m-d H:i:s') . "</div>";
00186         $sLog .= "<div id='" . $sClassName . "_timestamp'>Timestamp: " . microtime(true) . "</div>";
00187 
00188         return $sLog;
00189     }
00190 
00191 }