Changeset View
Changeset View
Standalone View
Standalone View
extension/tests/xhprof_007.phpt
| --TEST-- | --TEST-- | ||||
| XHPRrof: Test excluding call_user_func and similar functions | XHPRrof: Test excluding call_user_func and similar functions | ||||
| Author: mpal | Author: mpal | ||||
| --FILE-- | --FILE-- | ||||
| <?php | <?php | ||||
| include_once dirname(__FILE__).'/common.php'; | include_once dirname(__FILE__).'/common.php'; | ||||
| $xhprof_ignored_functions = array( 'ignored_functions' => | $xhprof_ignored_functions = array( 'ignored_functions' => | ||||
| array('call_user_func', | array('call_user_func', | ||||
| 'call_user_func_array', | 'call_user_func_array', | ||||
| 'my_call_user_func_safe', | 'my_call_user_func_safe', | ||||
| 'my_call_user_func_array_safe')); | 'my_call_user_func_array_safe')); | ||||
| function bar() { | function bar() { | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| function foo($x) { | function foo($x) { | ||||
| $sum = 0; | $sum = 0; | ||||
| for ($idx = 0; $idx < 2; $idx++) { | for ($idx = 0; $idx < 2; $idx++) { | ||||
| $sum += bar(); | $sum += bar(); | ||||
| } | } | ||||
| echo "hello: {$x}\n" ; | echo @"hello: {$x}\n" ; | ||||
| return strlen("hello: {$x}"); | return @strlen("hello: {$x}"); | ||||
| } | } | ||||
| function foo_array($x1, $x2 = 'test') { | function foo_array($x1, $x2 = 'test') { | ||||
| $sum = 0; | $sum = 0; | ||||
| $x = array($x1, $x2); | $x = array($x1, $x2); | ||||
| foreach ($x as $idx) { | foreach ($x as $idx) { | ||||
| $sum += bar(); | $sum += bar(); | ||||
| } | } | ||||
| echo "hello: " . $x[0] . $x[1] . "\n"; | echo @"hello: {$x[0]}{$x[1]}\n"; | ||||
| return strlen("hello: {$x[0]} {$x[1]}"); | return @strlen("hello: {$x[0]} {$x[1]}"); | ||||
| } | } | ||||
| function my_call_user_func_safe($function, $args = 'my_safe') { | function my_call_user_func_safe($function, $args = 'my_safe') { | ||||
| if (!is_callable($function, true)) { | if (!is_callable($function, true)) { | ||||
| throw new Exception('my_call_user_func_safe() invoked without ' . | throw new Exception('my_call_user_func_safe() invoked without ' . | ||||
| 'a valid callable.'); | 'a valid callable.'); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 113 Lines • ▼ Show 20 Lines | |||||
| test_my_call_user_func_array_safe('foo_array'); | test_my_call_user_func_array_safe('foo_array'); | ||||
| $output = xhprof_disable(); | $output = xhprof_disable(); | ||||
| echo "Part 5b output:\n"; | echo "Part 5b output:\n"; | ||||
| print_canonical($output); | print_canonical($output); | ||||
| echo "\n"; | echo "\n"; | ||||
| // 5c: Sanity test to only ignore my_call_user_func_array_safe | // 5c: Sanity test to only ignore my_call_user_func_array_safe | ||||
| echo "Part 5c: Only ignore call_user_func_array\n"; | echo "Part 5c: Only ignore call_user_func_array\n"; | ||||
| $xhprof_ignored_functions = array('ignored_functions' => | $xhprof_ignored_functions = array('ignored_functions' => | ||||
| 'my_call_user_func_array_safe'); | 'my_call_user_func_array_safe'); | ||||
| xhprof_enable(XHPROF_FLAGS_MEMORY, $xhprof_ignored_functions); | xhprof_enable(XHPROF_FLAGS_MEMORY, $xhprof_ignored_functions); | ||||
| test_my_call_user_func_array_safe('foo_array'); | test_my_call_user_func_array_safe('foo_array'); | ||||
| $output = xhprof_disable(); | $output = xhprof_disable(); | ||||
| echo "Part 5c output:\n"; | echo "Part 5c output:\n"; | ||||
| print_canonical($output); | print_canonical($output); | ||||
| echo "\n"; | echo "\n"; | ||||
| ▲ Show 20 Lines • Show All 102 Lines • Show Last 20 Lines | |||||