PageRenderTime 22ms CodeModel.GetById 20ms app.highlight 0ms RepoModel.GetById 1ms app.codeStats 0ms

/extension/tests/xhprof_008.phpt

http://github.com/preinheimer/xhprof
Unknown | 75 lines | 63 code | 12 blank | 0 comment | 0 complexity | 36370336430b77fb238d65b392ebe736 MD5 | raw file
 1--TEST--
 2XHPRrof: Sampling Mode Test
 3Author: kannan
 4--FILE--
 5<?php
 6
 7include_once dirname(__FILE__).'/common.php';
 8
 9function foo() {
10   // sleep 0.8 seconds
11   usleep(800000);
12}
13
14function bar() {
15   foo();
16}
17
18function goo() {
19    bar();
20}
21
22// call goo() once
23xhprof_sample_enable();
24goo();
25$output1 = xhprof_sample_disable();
26
27
28// call goo() twice
29xhprof_sample_enable();
30goo();
31goo();
32$output2 = xhprof_sample_disable();
33
34// how many usleep samples did we get in single call to goo()?
35$count1 = 0;
36foreach  ($output1 as $sample) {
37  if ($sample == "main()==>goo==>bar==>foo==>usleep") {
38    $count1++;
39  }
40}
41
42// how many usleep samples did we get in two calls to goo()?
43$count2 = 0;
44foreach  ($output2 as $sample) {
45  if ($sample == "main()==>goo==>bar==>foo==>usleep") {
46    $count2++;
47  }
48}
49
50//
51// our default sampling frequency is 0.1 seconds. So
52// we would expect about 8 samples (given that foo()
53// sleeps for 0.8 seconds). However, we might in future 
54// allow the sampling frequency to be modified. So rather
55// than depend on the absolute number of samples, we'll
56// check to see if $count2 is roughly double of $count1.
57//
58
59if (($count1 == 0)
60    || (($count2 / $count1) > 2.5)
61    || (($count2 / $count1) < 1.5)) {
62  echo "Test failed\n";
63  echo "Count of usleep samples in one call to goo(): $count1\n";
64  echo "Count of usleep samples in two calls to goo(): $count2\n";
65  echo "Samples in one call to goo(): \n";
66  var_dump($output1);
67  echo "Samples in two calls to goo(): \n";
68  var_dump($output2);
69} else {
70  echo "Test passed\n";
71}
72
73?>
74--EXPECT--
75Test passed