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