-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathdebug.php
More file actions
88 lines (61 loc) · 2.67 KB
/
debug.php
File metadata and controls
88 lines (61 loc) · 2.67 KB
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
<?php # maxsim.tech — MIT License — Copyright (c) 2005-2020 Javier González González <gonzo@virtualpol.com>
function ___($echo='', $echo2=false, $scroll_down=false) {
global $maxsim;
if (!isset($maxsim['debug']['crono']))
$maxsim['debug']['crono'] = $_SERVER['REQUEST_TIME_FLOAT'];
$microtime = $maxsim['debug']['crono'];
echo '<br />'."\n";
echo ++$maxsim['debug']['count'].'. <span title="'.date('Y-m-d H:i:s').'">'.implode(' ', profiler($microtime)).'</span> ';
if (is_array($echo2)) {
echo $echo;
echo '<xmp style="background:#EEE;padding:4px;">'.print_r($echo2, true).'</xmp>';
} else if (is_string($echo)) {
echo $echo;
} else if (is_array($echo) OR is_object($echo)) {
echo '<xmp style="background:#EEE;padding:4px;">'.print_r($echo, true).'</xmp>';
} else {
var_dump($echo);
}
if ($scroll_down) {
if ($maxsim['debug']['count']==1) {
if (function_exists('apache_setenv')) {
@apache_setenv('no-gzip', 1);
}
ob_end_flush();
echo '<script>function __sd() { window.scrollTo(0,document.body.scrollHeight); }</script>';
}
echo '<script>__sd();</script>';
flush();
ob_flush();
}
$maxsim['debug']['crono'] = microtime(true);
}
function profiler($microtime=false) {
global $maxsim, $__sql, $__rpc;
if (!$microtime)
$microtime = $_SERVER['REQUEST_TIME_FLOAT'];
$output[] = number_format((microtime(true)-$microtime)*1000,2).' ms';
if (is_numeric($__sql['count']))
$output[] = number_format($__sql['count']).' sql';
if (is_numeric($__rpc['count']))
$output[] = number_format($__rpc['count']).' rpc';
$output[] = number_format(memory_get_usage(false)/1024).' kb';
return $output;
}
function maxsim_timing() {
global $maxsim;
$maxsim['debug']['timing']['template'] = microtime(true);
$microtime_last = $_SERVER['REQUEST_TIME_FLOAT'];
foreach ((array) $maxsim['debug']['timing'] AS $key => $value) {
if ($value > 1000000000) {
$server_timing[] = ++$id.';dur='.round(($value-$microtime_last)*1000, 2).';desc="'.$key.'"';
$microtime_last = $value;
} else {
$server_timing[] = $key.';dur='.$value.';desc="'.$key.'"';
}
}
$server_timing[] = '99;desc="memory '.number_format(memory_get_usage(false)/1024).' kb"';
$server_timing[] = 'Total;dur='.round((microtime(true)-$_SERVER['REQUEST_TIME_FLOAT'])*1000, 2);
header('server-timing: '.implode(', ', (array)$server_timing));
}
header_register_callback('maxsim_timing');