Cheetah
ChProfiler.php
Go to the documentation of this file.
1 <?php
2 
8 define ('CH_PROFILER_DISPLAY', 1);
9 
10 require_once(CH_DIRECTORY_PATH_MODULES . 'cheetah/profiler/install/config.php');
11 
12 $GLOBALS['ch_profiler_module'] = array (
13  'title' => $aConfig['title'],
14  'vendor' => $aConfig['vendor'],
15  'path' => $aConfig['home_dir'],
16  'uri' => $aConfig['home_uri'],
17  'class_prefix' => $aConfig['class_prefix'],
18  'db_prefix' => $aConfig['db_prefix'],
19 );
20 
21 ch_import('Template', $GLOBALS['ch_profiler_module']);
22 ch_import('Config', $GLOBALS['ch_profiler_module']);
23 
25 {
27 
28  var $aConf = array ();
29 
30  var $_iTimeStart = 0;
31 
32  var $_aQueries = array();
33  var $_sQueryIndex = 0;
34 
35  var $_aModules = array();
36  var $_aModulesNames = array();
37  var $_aModulesLevel = 0;
38 
39  var $_sLogDateFormat = "Y-m-d H:i:s";
41  var $_sLogFilename = 64;
42 
46  function __construct($iTimeStart)
47  {
48  $this->oConfig = new ChProfilerConfig ($GLOBALS['ch_profiler_module']);
49  $this->oTemplate = new ChProfilerTemplate ($this->oConfig);
50 
51  $aCss = array (
52  'modules/cheetah/profiler/templates/base/css/|profiler.css',
53  'modules/cheetah/profiler/plugins/jush/|jush.css',
54  );
55  $aJs = array (
56  'profiler.js',
57  'plugins/jquery/|jquery.tablesorter.js',
58  'modules/cheetah/profiler/plugins/jush/|jush.js',
59  );
60 
61  foreach ($aCss as $sCssPath) {
62  $this->oTemplate->addCss ($sCssPath);
63  $this->oTemplate->addCssAdmin ($sCssPath);
64  }
65  foreach ($aJs as $sJsPath) {
66  $this->oTemplate->addJs($sJsPath);
67  $this->oTemplate->addJsAdmin($sJsPath);
68  }
69 
70  if (getParam ('ch_profiler_long_sql_queries_log'))
71  $this->aConf['long_query'] = getParam ('ch_profiler_long_sql_queries_time');
72  if (getParam ('ch_profiler_long_module_query_log'))
73  $this->aConf['long_module'] = getParam ('ch_profiler_long_module_query_time');
74  if (getParam ('ch_profiler_long_page_log'))
75  $this->aConf['long_page'] = getParam ('ch_profiler_long_page_time');
76 
77  $this->_iTimeStart = $iTimeStart;
78  }
79 
83  function output ()
84  {
85  $iPageTIme = $this->_getCurrentDelay ();
86  if (isset($this->aConf['long_page']) && $iPageTIme > $this->aConf['long_page'])
87  $this->logPageOpen ($iPageTIme);
88 
89  switch (getParam('ch_profiler_show_debug_panel')) {
90  case 'all':
91  break;
92  case 'admins':
93  if (!$GLOBALS['logged']['admin'])
94  return;
95  break;
96  case 'none':
97  default:
98  return;
99  }
100  echo $this->_plankMain ();
101  echo $this->_plankMenus ();
102  echo $this->_plankTemplates ();
103  echo $this->_plankInjections ();
104  echo $this->_plankPagesBlocks ();
105  echo $this->_plankSql ();
106  echo $this->_plankModules ();
107  }
108 
109  function _logBegin ($s)
110  {
111  $sDate = date ($this->_sLogDateFormat);
112  return "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n" . $sDate . " " . $s . "\n" .
113  "User ID: " . getLoggedId() . "\n" .
114  "User role: " . (isAdmin() ? 'admin' : (isMember() ? 'member' : 'guest')) . "\n";
115  }
116 
117  function _logEnd ()
118  {
119  return "\n";
120  }
121 
122  function _appendToLog ($s)
123  {
124  $f = fopen ( CH_DIRECTORY_PATH_MODULES . $GLOBALS['ch_profiler_module']['path'] . 'log/profiler.log', 'a');
125  if (!$f)
126  return;
127  fwrite($f, $s);
128  fclose($f);
129  }
130 
131  function logSqlQuery ($iTime, $aSqlQuery, &$res)
132  {
133  $s = $this->_logBegin ('LONG SQL QUERY: ' . $aSqlQuery['time']);
134  $s .= "Rows: " . $aSqlQuery['rows'] . "\n";
135  $s .= "Affected: " . $aSqlQuery['affected'] . "\n";
136  $s .= "Query: " . $aSqlQuery['sql'] . "\n";
137  if (getParam('ch_profiler_long_sql_queries_debug'))
138  $s .= "Backtrace: \n" . $this->_debugBackTrace (3);
139  $s .= $this->_logEnd();
140  $this->_appendToLog ($s);
141  }
142 
143  function logModuleQuery ($iTime, $aModuleQuery)
144  {
145  $s = $this->_logBegin ('LONG MODULE QUERY: ' . $aModuleQuery['time']);
146  $s .= "Module name: " . $aModuleQuery['name'] . "\n";
147  $s .= "Query type: " . $aModuleQuery['type'] . "\n";
148  $s .= "Class/file: " . $aModuleQuery['class/file'] . "\n";
149  $s .= "Method: " . $aModuleQuery['method'] . "\n";
150  if (getParam('ch_profiler_long_module_query_debug'))
151  $s .= "Backtrace: \n" . $this->_debugBackTrace (3);
152  $s .= $this->_logEnd();
153  $this->_appendToLog ($s);
154  }
155 
156  function logPageOpen ($iTime)
157  {
158  $s = $this->_logBegin ('LONG PAGE OPEN: ' . $this->_formatTime($iTime, 5));
159  $s .= "Request method: " . $_SERVER['REQUEST_METHOD'] . "\n";
160  $s .= "Query string: " . $_SERVER['QUERY_STRING'] . "\n";
161  $s .= "Request URI: " . $_SERVER['REQUEST_URI'] . "\n";
162  $s .= "Script name: " . $_SERVER['SCRIPT_NAME'] . "\n";
163  $s .= "PHP self: " . $_SERVER['PHP_SELF'] . "\n";
164  if (getParam('ch_profiler_long_page_debug'))
165  $s .= "All server vars: \n" . print_r ($_SERVER, true);
166  $s .= $this->_logEnd();
167  $this->_appendToLog ($s);
168  }
169 
170  function beginModule($sType, $sHash, &$aModule, $sClassFile, $sMethod = '' )
171  {
173  $this->_aModulesNames[$aModule['title']] = isset($this->_aModulesNames[$aModule['title']]) ? $this->_aModulesNames[$aModule['title']] + 1 : 1;
174  $this->_aModules[$sHash] = array (
175  'name' => str_repeat('&#160;&#160;', $this->_aModulesLevel-1) . $aModule['title'],
176  'type' => $sType,
177  'class/file' => $sClassFile,
178  'method' => $sMethod,
179  'begin' => microtime (),
180  'time' => -1,
181  );
182  }
183 
184  function endModule($sType, $sHash)
185  {
187  $iTime = $this->_calcTime ($this->_aModules[$sHash]['begin']);
188  unset ($this->_aModules[$sHash]['begin']);
189  $this->_aModules[$sHash]['time'] = $this->_formatTime($iTime, 5);
190  $this->_aModules[$sHash]['raw_time'] = $iTime;
191  if (isset($this->aConf['long_module']) && $iTime > $this->aConf['long_module'])
192  $this->logModuleQuery ($iTime, $this->_aModules[$sHash]);
193  }
194 
195  function beginInjection ($sId)
196  {
197  $this->_sInjectionIndex = $sId;
198  $this->_aInjections[$sId]['begin'] = microtime ();
199  }
200 
201  function endInjection ($sId, $sName, $sKey, $isReplace)
202  {
203  if (!isset($this->_aInjections[$sId]))
204  return;
205  $iTime = $this->_calcTime ($this->_aInjections[$sId]['begin']);
206  unset ($this->_aInjections[$sId]['begin']);
207  $this->_aInjections[$sId]['name'] = $sName;
208  $this->_aInjections[$sId]['key'] = $sKey;
209  $this->_aInjections[$sId]['replace'] = $isReplace ? 'yes' : 'no';
210  $this->_aInjections[$sId]['time'] = $this->_formatTime($iTime, 5);
211  $this->_aInjections[$sId]['raw_time'] = $iTime;
212  }
213 
214  function beginPageBlock ($sName, $iBlockId)
215  {
216  $this->_sPageBlockIndex = $iBlockId;
217  $this->_aPagesBlocks[$this->_sPageBlockIndex]['name'] = $sName;
218  $this->_aPagesBlocks[$this->_sPageBlockIndex]['begin'] = microtime ();
219  }
220 
221  function endPageBlock ($iBlockId, $isEmpty, $isCached)
222  {
223  if (!$this->_sPageBlockIndex)
224  return;
225  $iTime = $this->_calcTime ($this->_aPagesBlocks[$this->_sPageBlockIndex]['begin']);
226  unset ($this->_aPagesBlocks[$this->_sPageBlockIndex]['begin']);
227  $this->_aPagesBlocks[$this->_sPageBlockIndex]['cached'] = $isCached ? 'yes' : 'no';
228  $this->_aPagesBlocks[$this->_sPageBlockIndex]['empty'] = $isEmpty ? 'yes' : 'no';
229  $this->_aPagesBlocks[$this->_sPageBlockIndex]['time'] = $this->_formatTime($iTime, 5);
230  $this->_aPagesBlocks[$this->_sPageBlockIndex]['raw_time'] = $iTime;
231  }
232 
233  function beginPage ($sName)
234  {
235  $this->_sPageIndex = md5 ($sName.time().rand());
236  $this->_aPages[$this->_sPageIndex]['name'] = $sName;
237  $this->_aPages[$this->_sPageIndex]['begin'] = microtime ();
238  }
239 
240  function endPage (&$sContent)
241  {
242  if (!$this->_sPageIndex)
243  return;
244  $iTime = $this->_calcTime ($this->_aPages[$this->_sPageIndex]['begin']);
245  unset ($this->_aPages[$this->_sPageIndex]['begin']);
246  $this->_aPages[$this->_sPageIndex]['time'] = $this->_formatTime($iTime, 5);
247  $this->_aPages[$this->_sPageIndex]['raw_time'] = $iTime;
248  }
249 
250  function beginTemplate ($sName, $sRand)
251  {
252  $this->_aTemplateIndexes[$sName.$sRand] = 1;
253  $this->_aTemplates[$sName.$sRand]['name'] = $sName;
254  $this->_aTemplates[$sName.$sRand]['begin'] = microtime ();
255  }
256 
257  function endTemplate ($sName, $sRand, &$sContent, $isCached)
258  {
259  if (!isset($this->_aTemplateIndexes[$sName.$sRand]))
260  return;
261  $iTime = $this->_calcTime ($this->_aTemplates[$sName.$sRand]['begin']);
262  unset ($this->_aTemplates[$sName.$sRand]['begin']);
263  $this->_aTemplates[$sName.$sRand]['cached'] = $isCached ? 'yes' : 'no';
264  $this->_aTemplates[$sName.$sRand]['time'] = $this->_formatTime($iTime, 5);
265  $this->_aTemplates[$sName.$sRand]['raw_time'] = $iTime;
266  }
267 
268  function beginQuery ($sSql)
269  {
270  $this->_sQueryIndex = md5 ($sSql.time().rand());
271  $this->_aQueries[$this->_sQueryIndex]['sql'] = $sSql;
272  $this->_aQueries[$this->_sQueryIndex]['begin'] = microtime ();
273  }
274 
275  function endQuery (&$res)
276  {
277  if (!$this->_sQueryIndex)
278  return;
279  $iTime = $this->_calcTime ($this->_aQueries[$this->_sQueryIndex]['begin']);
280  unset ($this->_aQueries[$this->_sQueryIndex]['begin']);
281  $this->_aQueries[$this->_sQueryIndex]['time'] = $this->_formatTime($iTime, 5);
282  $this->_aQueries[$this->_sQueryIndex]['raw_time'] = $iTime;
283  $this->_aQueries[$this->_sQueryIndex]['rows'] = $res ? $GLOBALS['MySQL']->getNumRows($res) : '';
284  $this->_aQueries[$this->_sQueryIndex]['affected'] = $res ? $GLOBALS['MySQL']->getAffectedRows($res) : '';
285  if (isset($this->aConf['long_query']) && $iTime > $this->aConf['long_query'])
286  $this->logSqlQuery ($iTime, $this->_aQueries[$this->_sQueryIndex], $res);
287  }
288 
289  function beginMenu ($sName)
290  {
291  $this->_aMenus[$sName]['name'] = $sName;
292  $this->_aMenus[$sName]['begin'] = microtime ();
293  }
294 
295  function endMenu ($sName)
296  {
297  if (!isset($this->_aMenus[$sName]))
298  return;
299  $iTime = $this->_calcTime ($this->_aMenus[$sName]['begin']);
300  unset ($this->_aMenus[$sName]['begin']);
301  $this->_aMenus[$sName]['time'] = $this->_formatTime($iTime, 5);
302  $this->_aMenus[$sName]['raw_time'] = $iTime;
303  }
304 
305  function _getCurrentDelay ()
306  {
307  $i1 = explode(' ', microtime ());
308  $i2 = explode(' ', $this->_iTimeStart);
309  return ($i1[0]+$i1[1]) - ($i2[0]+$i2[1]);
310  }
311 
312  function _plankMain ()
313  {
314  $sTime = $this->_formatTime($this->_getCurrentDelay ());
315  if (function_exists('memory_get_usage'))
316  $sMemory = $this->_formatBytes(memory_get_usage(true)) . ' of ' . ini_get('memory_limit') . ' allowed';
317 
318  return $this->oTemplate->plank(
319  $this->oTemplate->nameValue('Time:', $sTime) .
320  (function_exists('memory_get_usage') ? $this->oTemplate->nameValue('Memory:', $sMemory) : '') .
321  $this->oTemplate->nameValue('PHP:', phpversion()) .
322  $this->oTemplate->nameValue('SAPI:', php_sapi_name()) .
323  $this->oTemplate->nameValue('OS:', php_uname('s r m'))
324  );
325  }
326 
327  function _plankTemplates ()
328  {
329  if (empty($GLOBALS['ch_profiler']->_aPages) && empty($GLOBALS['ch_profiler']->_aTemplates))
330  return;
331 
332  $sPages = '';
333  if (!empty($GLOBALS['ch_profiler']->_aPages)) {
334  $iTimePages = 0;
335  foreach ($GLOBALS['ch_profiler']->_aPages as $k => $r) {
336  $iTimePages += $r['raw_time'];
337  unset ($GLOBALS['ch_profiler']->_aPages[$k]['raw_time']);
338  }
339  $sPages = count($GLOBALS['ch_profiler']->_aPages); // . ' (' . $this->_formatTime($iTimePages, 3) . ')';
340  }
341 
342  $sTemplatesCached = '';
343  $sTemplatesNotCached = '';
344  if ($GLOBALS['ch_profiler']->_aTemplates) {
345  $iTimeTemplatesCached = 0;
346  $iTimeTemplatesNotCached = 0;
347  $sTemplatesCached = 0;
348  $sTemplatesNotCached = 0;
349  foreach ($GLOBALS['ch_profiler']->_aTemplates as $k => $r) {
350  if ('yes' == $r['cached']) {
351  $iTimeTemplatesCached += $r['raw_time'];
352  ++$sTemplatesCached;
353  } else {
354  $iTimeTemplatesNotCached += $r['raw_time'];
355  ++$sTemplatesNotCached;
356  }
357  unset ($GLOBALS['ch_profiler']->_aTemplates[$k]['raw_time']);
358  }
359  if ($sTemplatesCached)
360  $sTemplatesCached .= ' (' . $this->_formatTime($iTimeTemplatesCached, 3) . ')';
361  if ($sTemplatesNotCached)
362  $sTemplatesNotCached .= ' (' . $this->_formatTime($iTimeTemplatesNotCached, 3) . ')';
363  }
364 
365  return $this->oTemplate->plank(
366  ($sPages ? $this->oTemplate->nameValue('Pages:', $sPages) : '') .
367  ($sTemplatesCached ? $this->oTemplate->nameValue('Templates Cached:', $sTemplatesCached) : '') .
368  ($sTemplatesNotCached ? $this->oTemplate->nameValue('Templates Not Cached:', $sTemplatesNotCached) : ''),
369  $this->oTemplate->table($GLOBALS['ch_profiler']->_aTemplates)
370  );
371  }
372 
373  function _plankInjections ()
374  {
375  if (!$GLOBALS['ch_profiler']->_aInjections)
376  return;
377 
378  $iTimeInjections = 0;
379  foreach ($GLOBALS['ch_profiler']->_aInjections as $k => $r) {
380  $iTimeInjections += $r['raw_time'];
381  unset ($GLOBALS['ch_profiler']->_aInjections[$k]['raw_time']);
382  }
383 
384  $sInjections = count($GLOBALS['ch_profiler']->_aInjections) . ' injection (' . $this->_formatTime($iTimeInjections, 3) . ')';
385 
386  return $this->oTemplate->plank(
387  $this->oTemplate->nameValue('Injections:', $sInjections),
388  $this->oTemplate->table($GLOBALS['ch_profiler']->_aInjections)
389  );
390  }
391 
392  function _plankPagesBlocks ()
393  {
394  if (empty($GLOBALS['ch_profiler']->_aPagesBlocks))
395  return;
396 
397  $iTimeBlocks = 0;
398  $iTimeBlocksCached = 0;
399  $iTimeBlocksNotCached = 0;
400  $iTimeBlocksEmpty = 0;
401  $iTimeBlocksNotEmpty = 0;
402 
403  $iCountBlocksCached = 0;
404  $iCountBlocksNotCached = 0;
405  $iCountBlocksEmpty = 0;
406  $iCountBlocksNotEmpty = 0;
407 
408  foreach ($GLOBALS['ch_profiler']->_aPagesBlocks as $k => $r) {
409  $iTimeBlocks += $r['raw_time'];
410  if ($r['cached'] == 'yes') {
411  $iTimeBlocksCached += $r['raw_time'];
412  ++$iCountBlocksCached;
413  } else {
414  $iTimeBlocksNotCached += $r['raw_time'];
415  ++$iCountBlocksNotCached;
416  }
417  if ($r['empty'] == 'yes') {
418  $iTimeBlocksEmpty += $r['raw_time'];
419  ++$iCountBlocksEmpty;
420  } else {
421  $iTimeBlocksNotEmpty += $r['raw_time'];
422  ++$iCountBlocksNotEmpty;
423  }
424  unset ($GLOBALS['ch_profiler']->_aPagesBlocks[$k]['raw_time']);
425  }
426 
427  $sBlocks = count($GLOBALS['ch_profiler']->_aPagesBlocks) . ' (' . $this->_formatTime($iTimeBlocks, 3) . ')';
428  if ($iCountBlocksCached)
429  $sBlocksCached = $iCountBlocksCached . ' (' . $this->_formatTime($iTimeBlocksCached, 3) . ')';
430  if ($iCountBlocksNotCached)
431  $sBlocksNotCached = $iCountBlocksNotCached . ' (' . $this->_formatTime($iTimeBlocksNotCached, 3) . ')';
432  if ($iCountBlocksEmpty)
433  $sBlocksEmpty = $iCountBlocksEmpty . ' (' . $this->_formatTime($iTimeBlocksEmpty, 3) . ')';
434  if ($iCountBlocksNotEmpty)
435  $sBlocksNotEmpty = $iCountBlocksNotEmpty . ' (' . $this->_formatTime($iTimeBlocksNotEmpty, 3) . ')';
436 
437  return $this->oTemplate->plank(
438  $this->oTemplate->nameValue('Pages Blocks:', $sBlocks) .
439  ($iCountBlocksCached ? $this->oTemplate->nameValue('Cached:', $sBlocksCached) : '') .
440  ($iCountBlocksNotCached ? $this->oTemplate->nameValue('Not Cached:', $sBlocksNotCached) : '') .
441  ($iCountBlocksEmpty ? $this->oTemplate->nameValue('Empty:', $sBlocksEmpty) : '') .
442  ($iCountBlocksNotEmpty ? $this->oTemplate->nameValue('Not Empty:', $sBlocksNotEmpty) : ''),
443  $this->oTemplate->table($GLOBALS['ch_profiler']->_aPagesBlocks)
444  );
445  }
446 
447  function _plankMenus ()
448  {
449  if (empty($GLOBALS['ch_profiler']->_aMenus))
450  return;
451 
452  $iTimeMenus = 0;
453  foreach ($GLOBALS['ch_profiler']->_aMenus as $k => $r) {
454  $iTimeMenus += $r['raw_time'];
455  unset ($GLOBALS['ch_profiler']->_aMenus[$k]['raw_time']);
456  }
457 
458  $sMenus = count($GLOBALS['ch_profiler']->_aMenus) . ' menus (' . $this->_formatTime($iTimeMenus, 3) . ')';
459 
460  return $this->oTemplate->plank(
461  $this->oTemplate->nameValue('Menus:', $sMenus),
462  $this->oTemplate->table($GLOBALS['ch_profiler']->_aMenus)
463  );
464  }
465 
466  function _plankSql ()
467  {
468  if (empty($GLOBALS['ch_profiler']->_aQueries))
469  return;
470 
471  $iTimeQueries = 0;
472  foreach ($GLOBALS['ch_profiler']->_aQueries as $k => $r) {
473  $iTimeQueries += $r['raw_time'];
474  unset ($GLOBALS['ch_profiler']->_aQueries[$k]['raw_time']);
475  }
476 
477  $sQueries = count($GLOBALS['ch_profiler']->_aQueries) . ' queries (' . $this->_formatTime($iTimeQueries, 3) . ')';
478 
479  return $this->oTemplate->plank(
480  $this->oTemplate->nameValue('SQL:', $sQueries),
481  $this->oTemplate->table($GLOBALS['ch_profiler']->_aQueries, 'sql')
482  );
483  }
484 
485  function _plankModules ()
486  {
487  if (empty($GLOBALS['ch_profiler']->_aModules))
488  return;
489 
490  $iTimeModules = 0;
491  foreach ($GLOBALS['ch_profiler']->_aModules as $k => $r) {
492  $iTimeModules += $r['raw_time'];
493  unset ($GLOBALS['ch_profiler']->_aModules[$k]['raw_time']);
494  }
495 
496  $sModules = count($GLOBALS['ch_profiler']->_aModulesNames) . ' modules loaded';
497  $sModulesQueries = count($GLOBALS['ch_profiler']->_aModules) . ' modules queries (' . $this->_formatTime($iTimeModules, 3) . ')';
498 
499  return $this->oTemplate->plank(
500  $this->oTemplate->nameValue('Modules:', $sModules) .
501  $this->oTemplate->nameValue('Modules Queries:', $sModulesQueries),
502  $this->oTemplate->table($GLOBALS['ch_profiler']->_aModules)
503  );
504  }
505 
506  function _formatTime ($i, $iPrecision = 3)
507  {
508  return round($i, $iPrecision) . ' sec';
509  }
510 
511  function _formatBytes ($i)
512  {
513  if ($i > 1024*1024)
514  return round($i/1024/1024, 1) . 'M';
515  elseif ($i > 1024)
516  return round($i/1024, 1) . 'K';
517  else
518  return $i . 'B';
519  }
520 
522  {
523  if (isset($GLOBALS['ch_profiler_disable']) || isset($_GET['ch_profiler_disable']))
524  return true;
525  if (
526  preg_match('/gzip_loader\.php/', $_SERVER['PHP_SELF']) ||
527  preg_match('/get_rss_feed\.php/', $_SERVER['PHP_SELF']) ||
528  preg_match('/fields\.parse\.php/', $_SERVER['PHP_SELF']) ||
529  preg_match('/flash/', $_SERVER['PHP_SELF']) ||
530  preg_match('/forum/', $_SERVER['PHP_SELF'])
531  )
532  return true;
533  return false;
534  }
535 
536  function _calcTime ($begin)
537  {
538  if (!$begin)
539  return 0;
540  $i1 = explode(' ', microtime ());
541  $i2 = explode(' ', $begin);
542  return ($i1[0]+$i1[1]) - ($i2[0]+$i2[1]);
543  }
544 
545  function _debugPrintArray ($mixed)
546  {
547  $sArgs .= 'Array(';
548  foreach ($mixed as $mixed2)
549  $sArgs .= (is_object($mixed2) ? $this->_debugPrintObject($mixed2) : $this->_debugPrintAny($mixed2)) . ',';
550  $sArgs = substr($sArgs, 0, -1);
551  $sArgs .= ')';
552  return $sArgs;
553  }
554 
555  function _debugPrintObject ($mixed)
556  {
557  return get_class($mixed) . ' instance';
558  }
559 
560  function _debugPrintAny ($mixed)
561  {
562  if (is_string)
563  return "'" . (strlen($mixed) > $this->_sLogMaxArgLength ? substr($mixed, 0, $this->_sLogMaxArgLength) . '...' : $mixed) . "'";
564  else
565  return $mixed;
566  }
567 
568  function _debugBackTrace ($iShifts = 0)
569  {
570  $a = debug_backtrace();
571  while (--$iShifts > -1)
572  array_shift($a);
573 
574  $s = '';
575  foreach ($a as $r) {
576 
577  $sArgs = '';
578  foreach ($r['args'] as $mixed) {
579  switch (true) {
580  case is_array($mixed):
581  $sArgs .= $this->_debugPrintArray($mixed);
582  break;
583  case is_object($mixed):
584  $sArgs .= $this->_debugPrintObject($mixed);
585  break;
586  default:
587  $sArgs .= $this->_debugPrintAny($mixed);
588  }
589  $sArgs .= ',';
590  }
591  $sArgs = substr($sArgs, 0, -1);
592 
593  $s .= "--------------------------------------\n";
594  $s .= "{$r['line']} {$r['file']}\n";
595  $s .= "{$r['class']}{$r['type']}{$r['function']} ({$sArgs});\n";
596  }
597  return $s;
598  }
599 }
600 
601 if (defined('CH_PROFILER') && CH_PROFILER) {
602  $GLOBALS['ch_profiler'] = new ChProfiler($GLOBALS['ch_profiler_start']);
603  if (!$GLOBALS['ch_profiler']->_isProfilerDisabled())
604  register_shutdown_function (array ($GLOBALS['ch_profiler'], 'output'));
605 }
ChProfiler\$oTemplate
$oTemplate
Definition: ChProfiler.php:26
ChProfiler\_appendToLog
_appendToLog($s)
Definition: ChProfiler.php:122
ChProfiler\_calcTime
_calcTime($begin)
Definition: ChProfiler.php:536
ChProfiler\endInjection
endInjection($sId, $sName, $sKey, $isReplace)
Definition: ChProfiler.php:201
$f
global $f
Definition: callback.php:13
ChProfiler\_plankMain
_plankMain()
Definition: ChProfiler.php:312
ChProfiler\beginPageBlock
beginPageBlock($sName, $iBlockId)
Definition: ChProfiler.php:214
ChProfiler\$_sLogDateFormat
$_sLogDateFormat
Definition: ChProfiler.php:39
$aModule
$aModule
Definition: classifieds.php:21
ChProfiler\beginMenu
beginMenu($sName)
Definition: ChProfiler.php:289
ChProfiler\_getCurrentDelay
_getCurrentDelay()
Definition: ChProfiler.php:305
ch_import
ch_import($sClassName, $aModule=array())
Definition: utils.inc.php:1218
ChProfiler\beginInjection
beginInjection($sId)
Definition: ChProfiler.php:195
ChProfiler\_formatTime
_formatTime($i, $iPrecision=3)
Definition: ChProfiler.php:506
php
ChProfiler\beginTemplate
beginTemplate($sName, $sRand)
Definition: ChProfiler.php:250
ChProfiler\_debugPrintObject
_debugPrintObject($mixed)
Definition: ChProfiler.php:555
ChProfiler\_isProfilerDisabled
_isProfilerDisabled()
Definition: ChProfiler.php:521
ChProfiler\logPageOpen
logPageOpen($iTime)
Definition: ChProfiler.php:156
ChProfiler\endModule
endModule($sType, $sHash)
Definition: ChProfiler.php:184
ChProfiler\_debugPrintAny
_debugPrintAny($mixed)
Definition: ChProfiler.php:560
ChProfiler\logSqlQuery
logSqlQuery($iTime, $aSqlQuery, &$res)
Definition: ChProfiler.php:131
$aSqlQuery
$aSqlQuery
Definition: post_mod_crss.php:50
isAdmin
isAdmin()
Definition: index.php:649
ChProfiler\output
output()
Definition: ChProfiler.php:83
$sType
$sType
Definition: actions.inc.php:11
$_GET
$_GET['debug']
Definition: index.php:67
getParam
getParam($sParamName, $bUseCache=true)
Definition: db.inc.php:130
ChProfiler\__construct
__construct($iTimeStart)
Definition: ChProfiler.php:46
ChProfiler\logModuleQuery
logModuleQuery($iTime, $aModuleQuery)
Definition: ChProfiler.php:143
ChProfiler\_formatBytes
_formatBytes($i)
Definition: ChProfiler.php:511
getLoggedId
getLoggedId()
Definition: profiles.inc.php:32
$sTime
$sTime
Definition: actions.inc.php:14
ChProfiler\_plankTemplates
_plankTemplates()
Definition: ChProfiler.php:327
ChProfiler\endPage
endPage(&$sContent)
Definition: ChProfiler.php:240
ChProfiler\beginPage
beginPage($sName)
Definition: ChProfiler.php:233
ChProfiler\endPageBlock
endPageBlock($iBlockId, $isEmpty, $isCached)
Definition: ChProfiler.php:221
ChProfiler\endTemplate
endTemplate($sName, $sRand, &$sContent, $isCached)
Definition: ChProfiler.php:257
ChProfiler\_debugBackTrace
_debugBackTrace($iShifts=0)
Definition: ChProfiler.php:568
ChProfiler\$_aModulesLevel
$_aModulesLevel
Definition: ChProfiler.php:37
ChProfiler\$_aModules
$_aModules
Definition: ChProfiler.php:35
ChProfiler\_plankSql
_plankSql()
Definition: ChProfiler.php:466
$sContent
$sContent
Definition: bottom_menu_compose.php:169
ChProfiler\$_sQueryIndex
$_sQueryIndex
Definition: ChProfiler.php:33
ChProfiler\$oConfig
$oConfig
Definition: ChProfiler.php:26
ChProfiler\_logEnd
_logEnd()
Definition: ChProfiler.php:117
ChProfiler\endQuery
endQuery(&$res)
Definition: ChProfiler.php:275
$GLOBALS
$GLOBALS['ch_profiler_module']
Definition: ChProfiler.php:12
$aConfig
$aConfig
Definition: config.php:8
ChProfiler\$_aQueries
$_aQueries
Definition: ChProfiler.php:32
ChProfiler\_plankMenus
_plankMenus()
Definition: ChProfiler.php:447
$s
$s
Definition: embed.php:13
ChProfiler\_plankModules
_plankModules()
Definition: ChProfiler.php:485
ChProfiler\$aConf
$aConf
Definition: ChProfiler.php:28
ChProfiler\$_sLogMaxArgLength
$_sLogMaxArgLength
Definition: ChProfiler.php:40
$sId
$sId
Definition: actions.inc.php:8
ChProfiler\beginModule
beginModule($sType, $sHash, &$aModule, $sClassFile, $sMethod='')
Definition: ChProfiler.php:170
ChProfiler\$_iTimeStart
$_iTimeStart
Definition: ChProfiler.php:30
ChProfiler\_plankInjections
_plankInjections()
Definition: ChProfiler.php:373
ChProfiler\_plankPagesBlocks
_plankPagesBlocks()
Definition: ChProfiler.php:392
ChProfiler\$_aModulesNames
$_aModulesNames
Definition: ChProfiler.php:36
empty
Attr AllowedRel this is empty
Definition: Attr.AllowedRel.txt:7
ChProfiler\_debugPrintArray
_debugPrintArray($mixed)
Definition: ChProfiler.php:545
ChProfilerTemplate
Definition: ChProfilerTemplate.php:11
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10
$sName
$sName
Definition: ChWsbAdminTools.php:853
ChProfiler\$_sLogFilename
$_sLogFilename
Definition: ChProfiler.php:41
ChProfiler
Definition: ChProfiler.php:25
ChProfiler\endMenu
endMenu($sName)
Definition: ChProfiler.php:295
ChProfilerConfig
Definition: ChProfilerConfig.php:11
ChProfiler\beginQuery
beginQuery($sSql)
Definition: ChProfiler.php:268
isMember
isMember($iId=0)
Definition: profiles.inc.php:44
ChProfiler\_logBegin
_logBegin($s)
Definition: ChProfiler.php:109