Skip to content

Commit

Permalink
-- add a sanity test for timer (kannan)
Browse files Browse the repository at this point in the history
-- fix for compile error on debian linux (russ)


git-svn-id: https://svn.php.net/repository/pecl/xhprof/trunk@277908 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information
kannan committed Mar 28, 2009
1 parent ef3a0ad commit 3944f38
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 6 deletions.
82 changes: 82 additions & 0 deletions extension/tests/xhprof_005.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,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 gives 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
-------------
7 changes: 5 additions & 2 deletions extension/xhprof.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
#include "config.h"
#endif

#ifdef linux
/* To enable CPU_ZERO and CPU_SET, etc. */
# define _GNU_SOURCE
#endif

#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
Expand All @@ -40,8 +45,6 @@
# error "This version of FreeBSD does not support cpusets"
# endif /* __FreeBSD_version */
#else
/* To enable CPU_ZERO and CPU_SET, etc. */
# define __USE_GNU
/* For sched_getaffinity, sched_setaffinity */
# include <sched.h>
# define SET_AFFINITY(pid, size, mask) sched_setaffinity(0, size, mask)
Expand Down
24 changes: 20 additions & 4 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,19 @@ XHProf is a function-level hierarchical profiler for PHP and has a simple HTML b
<email>haiping@php.net</email>
<active>yes</active>
</developer>
<date>2009-03-21</date>
<date>2009-03-28</date>
<version>
<release>0.9.1</release>
<api>0.9.1</api>
<release>0.9.2</release>
<api>0.9.2</api>
</version>
<stability>
<release>beta</release>
<api>beta</api>
</stability>
<license uri="http://www.apache.org/licenses/LICENSE-2.0.html">Apache 2.0</license>
<notes>
-- doc improvements/fixes
-- add a sanity test for timer (kannan)
-- fix for compile error on debian linux (russ)
</notes>
<contents>
<dir name="/">
Expand All @@ -66,6 +67,7 @@ XHProf is a function-level hierarchical profiler for PHP and has a simple HTML b
<file role="test" name="xhprof_003.phpt" />
<file role="test" name="xhprof_004_inc.php" />
<file role="test" name="xhprof_004.phpt" />
<file role="test" name="xhprof_005.phpt" />
</dir>
</dir>
<dir name="xhprof_html">
Expand Down Expand Up @@ -121,6 +123,20 @@ XHProf is a function-level hierarchical profiler for PHP and has a simple HTML b
<providesextension>xhprof</providesextension>
<extsrcrelease/>
<changelog>
<release>
<version>
<release>0.9.1</release>
<api>0.9.1</api>
</version>
<date>2009-03-21</date>
<stability>
<release>beta</release>
<api>beta</api>
</stability>
<notes>
-- doc improvements/fixes
</notes>
</release>
<release>
<version>
<release>0.9.0</release>
Expand Down

0 comments on commit 3944f38

Please sign in to comment.