Skip to content

Commit

Permalink
update tests and fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
longxinH committed Aug 3, 2018
1 parent 2182822 commit 7b14433
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 89 deletions.
4 changes: 0 additions & 4 deletions extension/tests/xhprof_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,12 @@ echo "\n";
--EXPECT--
Part 1: Default Flags
foo==>bar : ct= 2; wt=*;
foo==>strlen : ct= 1; wt=*;
main() : ct= 1; wt=*;
main()==>foo : ct= 1; wt=*;
main()==>xhprof_disable : ct= 1; wt=*;

Part 2: CPU
foo==>bar : cpu=*; ct= 2; wt=*;
foo==>strlen : cpu=*; ct= 1; wt=*;
main() : cpu=*; ct= 1; wt=*;
main()==>foo : cpu=*; ct= 1; wt=*;
main()==>xhprof_disable : cpu=*; ct= 1; wt=*;
Expand All @@ -86,14 +84,12 @@ main()==>foo : ct= 1; wt=*;

Part 4: Memory
foo==>bar : ct= 2; mu=*; pmu=*; wt=*;
foo==>strlen : ct= 1; mu=*; pmu=*; wt=*;
main() : ct= 1; mu=*; pmu=*; wt=*;
main()==>foo : ct= 1; mu=*; pmu=*; wt=*;
main()==>xhprof_disable : ct= 1; mu=*; pmu=*; wt=*;

Part 5: Memory & CPU
foo==>bar : cpu=*; ct= 2; mu=*; pmu=*; wt=*;
foo==>strlen : cpu=*; ct= 1; mu=*; pmu=*; wt=*;
main() : cpu=*; ct= 1; mu=*; pmu=*; wt=*;
main()==>foo : cpu=*; ct= 1; mu=*; pmu=*; wt=*;
main()==>xhprof_disable : cpu=*; ct= 1; mu=*; pmu=*; wt=*;
Expand Down
15 changes: 5 additions & 10 deletions extension/tests/xhprof_004.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,11 @@ I am in foo()...
I am in bar()...
Test for 'include_once' & 'require_once' operation
main() : ct= 1; wt=*;
main()==>bar : ct= 1; wt=*;
main()==>dirname : ct= 6; wt=*;
main()==>explode : ct= 2; wt=*;
main()==>foo : ct= 1; wt=*;
main()==>implode : ct= 2; wt=*;
main()==>load::tests/xhprof_004_inc.php : ct= 1; wt=*;
main()==>load::tests/xhprof_004_require.php: ct= 1; wt=*;
main()==>run_init::tests/xhprof_004_inc.php: ct= 1; wt=*;
main()==>run_init::tests/xhprof_004_require.php: ct= 1; wt=*;
main()==>xhprof_disable : ct= 1; wt=*;
run_init::tests/xhprof_004_inc.php==>explode: ct= 1; wt=*;
run_init::tests/xhprof_004_inc.php==>foo: ct= 1; wt=*;
run_init::tests/xhprof_004_inc.php==>implode: ct= 1; wt=*;
run_init::tests/xhprof_004_require.php==>bar: ct= 1; wt=*;
run_init::tests/xhprof_004_require.php==>explode: ct= 1; wt=*;
run_init::tests/xhprof_004_require.php==>implode: ct= 1; wt=*;
run_init::tests/xhprof_004_require.php==>strlen: ct= 1; wt=*;
main()==>xhprof_disable : ct= 1; wt=*;
43 changes: 16 additions & 27 deletions extension/tests/xhprof_007.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function my_call_user_func_array_safe($function, $args = array()) {
}


class test_call_user_func {
class test_call_user_class {
function test_call_user_func($test_func = 'foo',
$arg1 = 'user_func test') {
call_user_func($test_func, $arg1);
Expand Down Expand Up @@ -96,7 +96,8 @@ echo "\n";
// 2a: Sanity test ignoring call_user_func
echo "Part 2a: Ignore call_user_func\n";
xhprof_enable(0, $xhprof_ignored_functions);
$indirect_foo = new test_call_user_func('foo');
$indirect_foo = new test_call_user_class();
$indirect_foo->test_call_user_func('foo');
$output = xhprof_disable();
echo "Part 2a output:\n";
print_canonical($output);
Expand All @@ -105,7 +106,8 @@ echo "\n";
// 2b: Confirm that profiling without parameters still works
echo "Part 2b: Standard profile without parameters\n";
xhprof_enable();
$indirect_foo = new test_call_user_func('foo');
$indirect_foo = new test_call_user_class();
$indirect_foo->test_call_user_func('foo');
$output = xhprof_disable();
echo "Part 2b output:\n";
print_canonical($output);
Expand All @@ -114,7 +116,8 @@ echo "\n";
// 2c: Confirm that empty array of ignored functions works
echo "Part 2c: Standard profile with empty array of ignored functions\n";
xhprof_enable(0, array());
$indirect_foo = new test_call_user_func('foo');
$indirect_foo = new test_call_user_class();
$indirect_foo->test_call_user_func('foo');
$output = xhprof_disable();
echo "Part 2c output:\n";
print_canonical($output);
Expand Down Expand Up @@ -161,8 +164,7 @@ echo "\n";

// 5c: Sanity test to only ignore my_call_user_func_array_safe
echo "Part 5c: Only ignore call_user_func_array\n";
$xhprof_ignored_functions = array('ignored_functions' =>
'my_call_user_func_array_safe');
$xhprof_ignored_functions = array('ignored_functions' => 'my_call_user_func_array_safe');
xhprof_enable(XHPROF_FLAGS_MEMORY, $xhprof_ignored_functions);
test_my_call_user_func_array_safe('foo_array');
$output = xhprof_disable();
Expand All @@ -177,9 +179,7 @@ hello: this is a test
hello: Arraytest
Part 1 output:
foo==>bar : ct= 2; wt=*;
foo==>strlen : ct= 1; wt=*;
foo_array==>bar : ct= 2; wt=*;
foo_array==>strlen : ct= 1; wt=*;
main() : ct= 1; wt=*;
main()==>foo : ct= 1; wt=*;
main()==>foo_array : ct= 1; wt=*;
Expand All @@ -189,39 +189,33 @@ Part 2a: Ignore call_user_func
hello: user_func test
Part 2a output:
foo==>bar : ct= 2; wt=*;
foo==>strlen : ct= 1; wt=*;
main() : ct= 1; wt=*;
main()==>test_call_user_func::test_call_user_func: ct= 1; wt=*;
main()==>test_call_user_class::test_call_user_func: ct= 1; wt=*;
main()==>xhprof_disable : ct= 1; wt=*;
test_call_user_func::test_call_user_func==>foo: ct= 1; wt=*;
test_call_user_class::test_call_user_func==>foo: ct= 1; wt=*;

Part 2b: Standard profile without parameters
hello: user_func test
Part 2b output:
call_user_func==>foo : ct= 1; wt=*;
foo==>bar : ct= 2; wt=*;
foo==>strlen : ct= 1; wt=*;
main() : ct= 1; wt=*;
main()==>test_call_user_func::test_call_user_func: ct= 1; wt=*;
main()==>test_call_user_class::test_call_user_func: ct= 1; wt=*;
main()==>xhprof_disable : ct= 1; wt=*;
test_call_user_func::test_call_user_func==>call_user_func: ct= 1; wt=*;
test_call_user_class::test_call_user_func==>foo: ct= 1; wt=*;

Part 2c: Standard profile with empty array of ignored functions
hello: user_func test
Part 2c output:
call_user_func==>foo : ct= 1; wt=*;
foo==>bar : ct= 2; wt=*;
foo==>strlen : ct= 1; wt=*;
main() : ct= 1; wt=*;
main()==>test_call_user_func::test_call_user_func: ct= 1; wt=*;
main()==>test_call_user_class::test_call_user_func: ct= 1; wt=*;
main()==>xhprof_disable : ct= 1; wt=*;
test_call_user_func::test_call_user_func==>call_user_func: ct= 1; wt=*;
test_call_user_class::test_call_user_func==>foo: ct= 1; wt=*;

Part 3: Ignore call_user_func_array
hello: calling foo_array
Part 3 output:
foo_array==>bar : cpu=*; ct= 2; wt=*;
foo_array==>strlen : cpu=*; ct= 1; wt=*;
main() : cpu=*; ct= 1; wt=*;
main()==>test_call_user_func_array : cpu=*; ct= 1; wt=*;
main()==>xhprof_disable : cpu=*; ct= 1; wt=*;
Expand All @@ -231,7 +225,6 @@ Part 4: Ignore my_call_user_func_safe
hello: Array
Part 4 output:
foo==>bar : ct= 2; wt=*;
foo==>strlen : ct= 1; wt=*;
main() : ct= 1; wt=*;
main()==>test_my_call_user_func_safe : ct= 1; wt=*;
main()==>xhprof_disable : ct= 1; wt=*;
Expand All @@ -251,24 +244,20 @@ test_my_call_user_func_array_safe==>is_callable: ct= 1; mu=*; pmu=*; wt=*;
Part 5b: Profile call_user_func_array and my_call_user_func_array_safe
hello: my_user_func_array_safetest
Part 5b output:
call_user_func_array==>foo_array : ct= 1; mu=*; pmu=*; wt=*;
foo_array==>bar : ct= 2; mu=*; pmu=*; wt=*;
foo_array==>strlen : ct= 1; mu=*; pmu=*; wt=*;
main() : ct= 1; mu=*; pmu=*; wt=*;
main()==>test_my_call_user_func_array_safe: ct= 1; mu=*; pmu=*; wt=*;
main()==>xhprof_disable : ct= 1; mu=*; pmu=*; wt=*;
my_call_user_func_array_safe==>call_user_func_array: ct= 1; mu=*; pmu=*; wt=*;
my_call_user_func_array_safe==>foo_array: ct= 1; mu=*; pmu=*; wt=*;
my_call_user_func_array_safe==>is_callable: ct= 1; mu=*; pmu=*; wt=*;
test_my_call_user_func_array_safe==>my_call_user_func_array_safe: ct= 1; mu=*; pmu=*; wt=*;

Part 5c: Only ignore call_user_func_array
hello: my_user_func_array_safetest
Part 5c output:
call_user_func_array==>foo_array : ct= 1; mu=*; pmu=*; wt=*;
foo_array==>bar : ct= 2; mu=*; pmu=*; wt=*;
foo_array==>strlen : ct= 1; mu=*; pmu=*; wt=*;
main() : ct= 1; mu=*; pmu=*; wt=*;
main()==>test_my_call_user_func_array_safe: ct= 1; mu=*; pmu=*; wt=*;
main()==>xhprof_disable : ct= 1; mu=*; pmu=*; wt=*;
test_my_call_user_func_array_safe==>call_user_func_array: ct= 1; mu=*; pmu=*; wt=*;
test_my_call_user_func_array_safe==>foo_array: ct= 1; mu=*; pmu=*; wt=*;
test_my_call_user_func_array_safe==>is_callable: ct= 1; mu=*; pmu=*; wt=*;
32 changes: 0 additions & 32 deletions extension/tests/xhprof_012.phpt

This file was deleted.

29 changes: 13 additions & 16 deletions extension/xhprof.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,6 @@ void hp_ignored_functions_clear(hp_ignored_functions *functions)

memset(functions->filter, 0, XHPROF_IGNORED_FUNCTION_FILTER_SIZE);
efree(functions);

functions = NULL;
}

hp_ignored_functions *hp_ignored_functions_init(char **names)
Expand Down Expand Up @@ -1375,26 +1373,22 @@ static char **hp_strings_in_zval(zval *values)
ht = Z_ARRVAL_P(values);
count = zend_hash_num_elements(ht);

if((result = (char**) malloc(sizeof(char*) * (count + 1))) == NULL) {
if((result = (char**) emalloc(sizeof(char*) * (count + 1))) == NULL) {
return result;
}

ZEND_HASH_FOREACH_KEY_VAL(ht, num_key, key, val)
{
if (!key)
{
if (Z_TYPE_P(val) == IS_STRING && strcmp(Z_STRVAL_P(val), ROOT_SYMBOL)
!= 0)
{
ZEND_HASH_FOREACH_KEY_VAL(ht, num_key, key, val) {
if (!key) {
if (Z_TYPE_P(val) == IS_STRING && strcmp(Z_STRVAL_P(val), ROOT_SYMBOL) != 0) {
/* do not ignore "main" */
result[ix] = strdup(Z_STRVAL_P(val));
result[ix] = estrdup(Z_STRVAL_P(val));
ix++;
}
}
}ZEND_HASH_FOREACH_END();
} ZEND_HASH_FOREACH_END();

} else if (Z_TYPE_P(values) == IS_STRING) {
if((result = (char**) malloc(sizeof(char*) * 2)) == NULL) {
if ((result = (char**) emalloc(sizeof(char*) * 2)) == NULL) {
return result;
}
result[0] = estrdup(Z_STRVAL_P(values));
Expand All @@ -1417,11 +1411,10 @@ static inline void hp_array_del(char **name_array)
if (name_array != NULL) {
int i = 0;
for(; name_array[i] != NULL && i < XHPROF_MAX_IGNORED_FUNCTIONS; i++) {
free(name_array[i]);
efree(name_array[i]);
}


free(name_array);
efree(name_array);
}
}

Expand Down Expand Up @@ -1644,6 +1637,10 @@ void hp_init_trace_callbacks()
{
hp_trace_callback callback;

if (XHPROF_G(trace_callbacks)) {
return;
}

XHPROF_G(trace_callbacks) = NULL;
ALLOC_HASHTABLE(XHPROF_G(trace_callbacks));

Expand Down

0 comments on commit 7b14433

Please sign in to comment.