-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug.class.php
97 lines (83 loc) · 2.14 KB
/
debug.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
define("ESCAPE_HTML", "<!--//>-->");
class iiDebug {
static private $traceCount = 0;
static private $times = array();
/**
* trace
* @param all $target
* @param Boolean $is_end
*/
static public function trace($target, $is_end = false) {
self::$traceCount++;
// parsing
$data = print_r($target, 1);
$data = str_replace(array(" ", "<"), array(" ", "<"), $data);
$data = preg_replace("/\[([^\]]+)\] \=\> /ismU", "<b>[\\1]</b> ", $data);
$data = nl2br($data);
// GUI
if (!$is_end) {
$position = self::$traceCount * 50;
echo "<div style='position:absolute; left:{$position}px; top:{$position}px; padding:5px; background-color:#fff; font:10px verdana; border:3px solid red; z-index:100;' ondblclick='this.parentNode.removeChild(this);'>{$data}</div>";
}
// inline
else {
echo ESCAPE_HTML."<hr />{$data}";
}
}
/**
* 시간을 체크한다
* @param String $name prefix
*/
static public function check($name) {
$microtime = microtime();
$tmp = explode(" ", $microtime);
$time = $tmp[0] + $tmp[1];
// 결과값 넣기
if (isset(self::$times[$name])) {
self::$times[$name]['end'] = $time;
}
// 시작값 넣기
else {
self::$times[$name] = array(
'start' => $time,
'end' => null
);
}
}
/**
* 체크된 시간을 출력한다
* @param String $name
* @param Boolean $is_return
* @return string message is_return 이 true 일 때만 return 값이 있음
*/
static public function printTime($name, $is_return = false) {
if (!isset(self::$times[$name])) {
$result = "didn't set check for {$name}";
}
else if (self::$times[$name]['end'] == null) {
self::check($name);
}
if (isset(self::$times[$name])) {
$result = sprintf("%f", (self::$times[$name]['end'] - self::$times[$name]['start']));
}
$msg = "[{$name}] {$result}\n";
if ($is_return) {
return $msg;
}
else {
self::trace($msg);
}
}
/**
* 모든 체크된 시간을 출력한다
*/
static public function printTimes() {
$output = "";
foreach (self::$times as $key => $val) {
$output .= self::printTime($key, 1);
}
self::trace($output);
}
}
?>