forked from phacility/xhprof
/
xhprof_005.phpt
82 lines (67 loc) · 1.64 KB
/
xhprof_005.phpt
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
--TEST--
XHPRrof: Timer Tests
Author: Kannan
--FILE--
<?php
//
// Some coarse grained sanity tests for the time just
// to make sure profiler's timer implementation isn't
// way off.
// The test allows for a 25% margin of error.
//
include_once dirname(__FILE__).'/common.php';
// sleep 10000 microsecs (10 millisecs)
function sleep_10000_micro() {
usleep(10000);
}
// sleep 20000 microsecs (20 millisecs)
function sleep_20000_micro() {
usleep(20000);
}
// sleep 50000 microsecs (50 millisecs)
function sleep_50000_micro() {
usleep(50000);
}
function invoke_all() {
sleep_10000_micro();
sleep_20000_micro();
sleep_50000_micro();
}
xhprof_enable();
invoke_all();
$output = xhprof_disable();
// verify output
function verify($expected, $actual, $description) {
echo "Verifying ${description}...\n";
// 25% tolerance
$range_low = ($expected * 0.75);
$range_high = ($expected * 1.25);
if (($actual < $range_low) ||
($actual > $range_high)) {
echo "Failed ${description}. Expected: ${expected} microsecs. ".
"Actual: ${actual} microsecs.\n";
} else {
echo "OK: ${description}\n";
}
echo "-------------\n";
}
verify(10000,
$output["sleep_10000_micro==>usleep"]["wt"],
"sleep_10000_micro");
verify(20000,
$output["sleep_20000_micro==>usleep"]["wt"],
"sleep_20000_micro");
verify(50000,
$output["sleep_50000_micro==>usleep"]["wt"],
"sleep_50000_micro");
?>
--EXPECT--
Verifying sleep_10000_micro...
OK: sleep_10000_micro
-------------
Verifying sleep_20000_micro...
OK: sleep_20000_micro
-------------
Verifying sleep_50000_micro...
OK: sleep_50000_micro
-------------