OXID eShop CE  4.10.0
 All Classes Namespaces Files Functions Variables Pages
oxdebuginfo.php
Go to the documentation of this file.
1 <?php
2 
8 {
9 
17  public function formatTemplateData($aViewData = array())
18  {
19  $sLog = '';
20  reset($aViewData);
21  while (list($sViewName, $oViewData) = each($aViewData)) {
22  // show debbuging information
23  $sLog .= "TemplateData[$sViewName] : <br />\n";
24  $sLog .= print_r($oViewData, 1);
25  }
26 
27  return $sLog;
28  }
29 
35  public function formatMemoryUsage()
36  {
37  $sLog = '';
38  if (function_exists('memory_get_usage')) {
39  $iKb = ( int ) (memory_get_usage() / 1024);
40  $iMb = round($iKb / 1024, 3);
41  $sLog .= 'Memory usage: ' . $iMb . ' MB';
42 
43  if (function_exists('memory_get_peak_usage')) {
44  $iPeakKb = ( int ) (memory_get_peak_usage() / 1024);
45  $iPeakMb = round($iPeakKb / 1024, 3);
46  $sLog .= ' (peak: ' . $iPeakMb . ' MB)';
47  }
48  $sLog .= '<br />';
49 
50  if (version_compare(PHP_VERSION, '5.2.0', '>=')) {
51  $iKb = ( int ) (memory_get_usage(true) / 1024);
52  $iMb = round($iKb / 1024, 3);
53  $sLog .= 'System memory usage: ' . $iMb . ' MB';
54 
55  if (function_exists('memory_get_peak_usage')) {
56  $iPeakKb = ( int ) (memory_get_peak_usage(true) / 1024);
57  $iPeakMb = round($iPeakKb / 1024, 3);
58  $sLog .= ' (peak: ' . $iPeakMb . ' MB)';
59  }
60  $sLog .= '<br />';
61  }
62  }
63 
64  return $sLog;
65  }
66 
74  public function formatExecutionTime($dTotalTime)
75  {
76  $sLog = 'Execution time:' . round($dTotalTime, 4) . '<br />';
77  global $aProfileTimes;
78  global $aExecutionCounts;
79  global $aProfileBacktraces;
80  if (is_array($aProfileTimes)) {
81  $sLog .= "----------------------------------------------------------<br>" . PHP_EOL;
82  arsort($aProfileTimes);
83  $sLog .= "<table cellspacing='10px' style='border: 1px solid #000'>";
84  $iNr = 1;
85  foreach ($aProfileTimes as $sKey => $sVal) {
86  $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>";
87  if ($dTotalTime) {
88  $sLog .= "<td style='border-bottom: 1px dotted #000;min-width:100px;'>" . round($sVal * 100 / $dTotalTime, 2) . "%</td>";
89  }
90  if ($aExecutionCounts[$sKey]) {
91  $sLog .= " <td style='border-bottom: 1px dotted #000;min-width:50px;padding-right:30px;' align='right'>" . $aExecutionCounts[$sKey] . "</td>"
92  . "<td style='border-bottom: 1px dotted #000;min-width:15px; '>*</td>"
93  . "<td style='border-bottom: 1px dotted #000;min-width:100px;'>" . round($sVal / $aExecutionCounts[$sKey], 5) . "s</td>" . PHP_EOL;
94  } else {
95  $sLog .= " <td colspan=3 style='border-bottom: 1px dotted #000;min-width:100px;'> not stopped correctly! </td>" . PHP_EOL;
96  }
97 
98  if (isset($aProfileBacktraces[$sKey])) {
99  $sLog .= "<td style='border-bottom: 1px dotted #000;min-width:15px; '>";
100  foreach ($aProfileBacktraces[$sKey] as $sBtId => $aBt) {
101  $iCnt = (int) $aProfileBacktraceCounts[$sBtId];
102  $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>";
103  $sLog .= "<div id='profdbg_trace_$iNr' style='display:none'>";
104  foreach ($aBt as $iLevel => $aInfo) {
105  $sLog .= "<i><strong>$iLevel: {$aInfo['function']}</strong></i> at {$aInfo['file']}:{$aInfo['line']}<br>";
106  }
107  $sLog .= "</div>";
108  $iNr++;
109  }
110  $sLog .= "</td>";
111  }
112  $sLog .= '</tr>';
113  }
114  $sLog .= "</table>";
115  }
116 
117  return $sLog;
118  }
119 
120 
126  public function formatGeneralInfo()
127  {
128  $sLog = "cl=" . oxRegistry::getConfig()->getActiveView()->getClassName();
129  if (($sFnc = oxRegistry::getConfig()->getActiveView()->getFncName())) {
130  $sLog .= " fnc=$sFnc";
131  }
132 
133  return $sLog;
134  }
135 
143  public function formatDbInfo()
144  {
145  $sLog = "----------------------------------------------------------<br>" . PHP_EOL;
146  $sLog .= "-- oxdebugdb --<br>" . PHP_EOL;
147  $oDbgDb = oxNew('oxdebugdb');
148  $aWarnings = $oDbgDb->getWarnings();
149  $iNr = 1;
150  foreach ($aWarnings as $w) {
151  $sLog .= "{$w['check']}: {$w['time']} - <span style='color:#900000;margin:5px'>" . htmlentities($w['sql'], ENT_QUOTES, 'UTF-8') . "</span>";
152  $sLog .= "<div id='dbgdb_trace_$iNr' style='display:none'>" . nl2br($w['trace']) . "</div>";
153  $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>";
154  ++$iNr;
155  }
156 
157  return $sLog;
158  }
159 
167  public function formatAdoDbPerf()
168  {
169  $oPerfMonitor = @NewPerfMonitor(oxDb::getDb());
170  if ($oPerfMonitor) {
171  ob_start();
172  $oPerfMonitor->UI(5);
173 
174  return ob_get_clean();
175  }
176 
177  return '';
178  }
179 
185  public function formatTimeStamp()
186  {
187  $sLog = '';
188  $sClassName = oxRegistry::getConfig()->getActiveView()->getClassName();
189  $sLog .= "<div id='" . $sClassName . "_executed'>Executed: " . date('Y-m-d H:i:s') . "</div>";
190  $sLog .= "<div id='" . $sClassName . "_timestamp'>Timestamp: " . microtime(true) . "</div>";
191 
192  return $sLog;
193  }
194 
195 }