-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofiler.php
More file actions
69 lines (62 loc) · 1.91 KB
/
profiler.php
File metadata and controls
69 lines (62 loc) · 1.91 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
<?php
// apd_set_pprof_trace();
$profiler_stats = array(
'time_start' => microtime(TRUE),
'query_num' => 0,
'query_time' => 0.0,
'statements' => array()
);
function profiler_log_sql($db, $statement, $query_time, $result)
{
global $profiler_stats;
$profiler_stats['query_num'] += 1;
$profiler_stats['query_time'] += $query_time;
$profiler_stats['statements'][] = $statement;
}
function profiler_render_begin()
{
global $profiler_stats;
$profiler_stats['render_time'] = microtime(TRUE);
}
function profiler_instrument_begin($inst_id)
{
global $profiler_stats;
if (array_key_exists($inst_id, $profiler_stats)) {
$profiler_stats[$inst_id]['last'] = microtime(TRUE);
} else {
$profiler_stats[$inst_id] = array(
'time' => 0.0,
'last' => microtime(TRUE)
);
}
}
function profiler_instrument_end($inst_id)
{
global $profiler_stats;
if (array_key_exists($inst_id, $profiler_stats)) {
$last = $profiler_stats[$inst_id]['last'];
$duration = microtime(TRUE) - $last;
$profiler_stats[$inst_id]['time'] += $duration;
}
}
function profiler_instrument_read($inst_id)
{
global $profiler_stats;
if (array_key_exists($inst_id, $profiler_stats))
return round($profiler_stats[$inst_id]['time'], 4);
return '';
}
function profiler_dump()
{
global $profiler_stats;
$time_start = $profiler_stats['time_start'];
$query_num = $profiler_stats['query_num'];
$query_time = round($profiler_stats['query_time'], 4);
$time_cost = round(microtime(TRUE) - $time_start, 4);
$render_time = round(microtime(TRUE) - $profiler_stats['render_time'], 4);
$instruments = profiler_instrument_read('countRegistrants').' '.profiler_instrument_read('fetchRealName');
echo "{$time_cost} - render ${render_time} - instru ${instruments} - {$query_num} queries - {$query_time} @ " . INSTANCE_NAME;
if (SQL_DEBUG) {
echo "<pre>" . implode("\n", $profiler_stats['statements']) . "</pre>";
}
}