Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
wdebug.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
5  * @package FDL
6 */
7 /**
8  * Set of usefull debug functions
9  *
10  * @author Anakeen 2008
11  * @version $Id: wdebug.php,v 1.2 2008/12/11 15:16:21 eric Exp $
12  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
13  * @package FDL
14  * @subpackage CORE
15  */
16 /**
17  */
18 
20 global $TSQLDELAY;
21 $SQLDEBUG = true;
22 
23 function dtic($text = "")
24 {
25  static $ptic = 0;
26  static $ptic0 = 0;
27 
28  $deb = gettimeofday();
29  $tuc1 = $deb["sec"] + $deb["usec"] / 1000000;
30  if ($ptic == 0) {
31  $ptic = $tuc1;
32  $ptic0 = $tuc1;
33  }
34 
35  $msg = sprintf("%s : %.03f - %.03f ", $text, ($tuc1 - $ptic) , ($tuc1 - $ptic0));
36  $ptic = $tuc1;
37  return $msg;
38 }
39 
40 function dtrace($text)
41 {
42  global $trace;
43  global $TSQLDELAY;
44  $tsql = count($TSQLDELAY);
45  $trace[] = dtic($text) . "#$tsql";
46 }
47 
48 function stacktrace($level = 3, $uplevel = 1)
49 {
50  if (!function_exists('xdebug_get_function_stack')) return '';
51  $stack = xdebug_get_function_stack();
52  $t = array();
53  foreach ($stack as $k => $v) {
54  $t[] = sprintf("[%s:%d]%s", basename($v["file"]) , $v["line"], $v["function"]);
55  }
56  $l = (-1 - $level);
57  $t = array_slice($t, $l, -$uplevel);
58  return implode("/<br>", $t);
59 }
60 function dmtrace($text = "", $level = 3)
61 {
62  dtrace(stacktrace($level, 2) . ':' . $text);
63 }
64 
65 function printdtrace()
66 {
67 
68  global $trace;
69  foreach ($trace as $k => $v) {
70  //[test.php:26]AddFile/<br>[Class.Dir.php:276]updateFldRelations:updateFldRelations : 0.075 - 0.075 #17
71  if (preg_match("/(.*):([^-]+)-([^#]+)#(.*)$/", $v, $reg)) {
72  printf("%30.30s : %.03f | %02.03f | %d\n", substr($reg[1], -30) , $reg[2], $reg[3], $reg[4]);
73  }
74  }
75 }
76 ?>
← centre documentaire © anakeen - published under CC License - Dynacase