From e3df210a649bed95114e03bc43e720e25b20f0e9 Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 27 Aug 2014 11:31:33 -0700 Subject: [PATCH 01/15] Remove Composer support from XHProf Summary: See . This is currently broken and extremely insecure. We may want to restore it eventually, but understanding composer is very complex (no one who touched this realized that the package was owned by someone unrelated to the project who can apparently redirect it at will with no accountability). No one on the ticket seems to have any reason why this isn't totally wide open, and I haven't gotten in touch with anyone in `#composer-dev`. Test Plan: N/A Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Differential Revision: https://secure.phabricator.com/D10365 --- composer.json | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 composer.json diff --git a/composer.json b/composer.json deleted file mode 100644 index 2efe9628..00000000 --- a/composer.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "name": "facebook/xhprof", - "type": "library", - "description": "XHProf: A Hierarchical Profiler for PHP", - "keywords": ["profiling", "performance"], - "homepage": "http://pecl.php.net/package/xhprof", - "license": "Apache-2.0", - "require": { - "php": ">=5.2.0" - }, - "autoload": { - "files": [ - "xhprof_lib/utils/xhprof_lib.php", - "xhprof_lib/utils/xhprof_runs.php" - ] - } -} From 6065346905d469cefe4f2c621da6bb779f65b081 Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 27 Aug 2014 11:31:39 -0700 Subject: [PATCH 02/15] Update .arcconfig and acknowledge that we're the new maintainers in XHProf Summary: Modernize this stuff a bit. Test Plan: Ran `arc diff` to produce this diff. Read `CREDITS`. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Differential Revision: https://secure.phabricator.com/D10366 --- .arcconfig | 7 ++----- CREDITS | 3 ++- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/.arcconfig b/.arcconfig index 30d1e80d..783f1d23 100644 --- a/.arcconfig +++ b/.arcconfig @@ -1,6 +1,3 @@ { - "project_id" : "xhprof", - "conduit_uri" : "https://secure.phabricator.com/", - "remote_hooks_installed" : true, - "copyright_holder" : "Facebook, Inc." -} \ No newline at end of file + "phabricator.uri": "https://secure.phabricator.com/" +} diff --git a/CREDITS b/CREDITS index fd032202..1b9af6b8 100644 --- a/CREDITS +++ b/CREDITS @@ -1,5 +1,7 @@ Originally developed at Facebook, XHProf was open sourced in Mar, 2009. +XHProf is now maintained by Phacility. + Creators: Changhao Jiang Kannan Muthukkaruppan @@ -9,4 +11,3 @@ Creators: Additional Contributors: George Cabrera - UI enhancements Paul Saab - FreeBSD port - From 28d18dd1d4f87544c551ba53ff8d5dcca3d52d5e Mon Sep 17 00:00:00 2001 From: Johnson Page Date: Thu, 28 Aug 2014 10:11:57 +1000 Subject: [PATCH 03/15] Fix mismatched tag in contacts Summary: See . Reviewed by: epriestley --- package.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.xml b/package.xml index 478ee25f..59e92a75 100644 --- a/package.xml +++ b/package.xml @@ -50,7 +50,7 @@ XHProf is a function-level hierarchical profiler for PHP and has a simple HTML b macvicar scott@fb.com yes - + 2009-03-28 0.9.2 From 7adedecdba3f7e89c55bc2ad153aadc6157c5f62 Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 28 Aug 2014 10:33:38 -0700 Subject: [PATCH 04/15] XHProf: add .arclint, fix some minor issues Summary: Add a .arclint file and fix some stray tabs and whitespace issues. Test Plan: Built xhprof, ran tests (some failures, but preexisting). Reviewers: chad, btrahan Reviewed By: btrahan Subscribers: epriestley Differential Revision: https://secure.phabricator.com/D10372 --- .arclint | 30 +++++++++++++++++++++++++ .gitignore | 7 ++++++ LICENSE | 1 - README | 2 -- extension/config.m4 | 1 - extension/php_xhprof.h | 2 +- extension/tests/common.php | 1 - extension/xhprof.c | 1 - xhprof_html/css/xhprof.css | 1 - xhprof_lib/display/typeahead_common.php | 1 - xhprof_lib/display/xhprof.php | 2 +- xhprof_lib/utils/xhprof_lib.php | 1 - 12 files changed, 39 insertions(+), 11 deletions(-) create mode 100644 .arclint diff --git a/.arclint b/.arclint new file mode 100644 index 00000000..e141495b --- /dev/null +++ b/.arclint @@ -0,0 +1,30 @@ +{ + "exclude": [ + "(^xhprof_html/jquery/)", + "(^xhprof_html/docs/)", + "(^extension/Makefile.local)" + ], + "linters": { + "chmod": { + "type": "chmod" + }, + "filename": { + "type": "filename" + }, + "generated": { + "type": "generated" + }, + "merge-conflict": { + "type": "merge-conflict" + }, + "nolint": { + "type": "nolint" + }, + "text-without-length": { + "type": "text", + "severity": { + "3": "disabled" + } + } + } +} diff --git a/.gitignore b/.gitignore index e75f3af4..0b8f03db 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,10 @@ extension/* !extension/php_xhprof.h !extension/tests/ !extension/xhprof.c + +extension/tests/*.sh +extension/tests/*.exp +extension/tests/*.out +extension/tests/*.diff +extension/tests/*.log +extension/tests/*.php diff --git a/LICENSE b/LICENSE index f433b1a5..d9a10c0d 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,3 @@ - Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ diff --git a/README b/README index 309dcfe2..a8c15fa9 100644 --- a/README +++ b/README @@ -3,5 +3,3 @@ For installation and usage notes refer to: To view the latest version of the doc, go to: http://pecl.php.net/package/xhprof ---> [View Documentation] - - diff --git a/extension/config.m4 b/extension/config.m4 index 351786bd..75401474 100644 --- a/extension/config.m4 +++ b/extension/config.m4 @@ -1,4 +1,3 @@ - PHP_ARG_ENABLE(xhprof, whether to enable xhprof support, [ --enable-xhprof Enable xhprof support]) diff --git a/extension/php_xhprof.h b/extension/php_xhprof.h index 42fb23b4..13d914c6 100644 --- a/extension/php_xhprof.h +++ b/extension/php_xhprof.h @@ -42,4 +42,4 @@ PHP_FUNCTION(xhprof_disable); PHP_FUNCTION(xhprof_sample_enable); PHP_FUNCTION(xhprof_sample_disable); -#endif /* PHP_XHPROF_H */ +#endif /* PHP_XHPROF_H */ diff --git a/extension/tests/common.php b/extension/tests/common.php index 23b2f719..f808ff38 100644 --- a/extension/tests/common.php +++ b/extension/tests/common.php @@ -32,4 +32,3 @@ function print_canonical($xhprof_data) { echo "\n"; } } - diff --git a/extension/xhprof.c b/extension/xhprof.c index f97bcf1d..7ce3f49d 100644 --- a/extension/xhprof.c +++ b/extension/xhprof.c @@ -2016,4 +2016,3 @@ static inline void hp_array_del(char **name_array) { efree(name_array); } } - diff --git a/xhprof_html/css/xhprof.css b/xhprof_html/css/xhprof.css index 88933db3..c3abf862 100644 --- a/xhprof_html/css/xhprof.css +++ b/xhprof_html/css/xhprof.css @@ -79,4 +79,3 @@ ul.xhprof_actions li a:hover { background:#3B5998 none repeat scroll 0 0; color:#FFFFFF; } - diff --git a/xhprof_lib/display/typeahead_common.php b/xhprof_lib/display/typeahead_common.php index 7b1098f4..0cd304d6 100644 --- a/xhprof_lib/display/typeahead_common.php +++ b/xhprof_lib/display/typeahead_common.php @@ -77,4 +77,3 @@ foreach ($functions as $f) { echo $f."\n"; } - diff --git a/xhprof_lib/display/xhprof.php b/xhprof_lib/display/xhprof.php index 4be67bc8..a57ec175 100644 --- a/xhprof_lib/display/xhprof.php +++ b/xhprof_lib/display/xhprof.php @@ -1003,7 +1003,7 @@ function print_pc_array($url_params, $results, $base_ct, $base_info, $parent, function print_source_link($info) { if (strncmp($info['fn'], 'run_init', 8) && $info['fn'] !== 'main()') { - if (defined('XHPROF_SYMBOL_LOOKUP_URL')) { + if (defined('XHPROF_SYMBOL_LOOKUP_URL')) { $link = xhprof_render_link( 'source', XHPROF_SYMBOL_LOOKUP_URL . '?symbol='.rawurlencode($info["fn"])); diff --git a/xhprof_lib/utils/xhprof_lib.php b/xhprof_lib/utils/xhprof_lib.php index 1e398a9d..4a07e900 100644 --- a/xhprof_lib/utils/xhprof_lib.php +++ b/xhprof_lib/utils/xhprof_lib.php @@ -943,4 +943,3 @@ function xhprof_get_matching_functions($q, $xhprof_data) { return ($res); } - From a39446cf68f396413ba838276a4c6b97ad2f89ed Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 28 Aug 2014 10:34:11 -0700 Subject: [PATCH 05/15] Add a basic `arc unit` test binding to XHProf Summary: This allows "arc unit" to more-or-less run the PHP extension tests in an approximately correct way. Note that there are two test failures at HEAD on recent PHP, and they've been failing for some time. Test Plan: Used `arc unit` to run some tests. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Differential Revision: https://secure.phabricator.com/D10373 --- .arcconfig | 4 +- .gitignore | 2 + support/libxhprof/__phutil_library_init__.php | 3 ++ support/libxhprof/__phutil_library_map__.php | 18 +++++++ .../libxhprof/unit/XHProfUnitTestEngine.php | 53 +++++++++++++++++++ 5 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 support/libxhprof/__phutil_library_init__.php create mode 100644 support/libxhprof/__phutil_library_map__.php create mode 100644 support/libxhprof/unit/XHProfUnitTestEngine.php diff --git a/.arcconfig b/.arcconfig index 783f1d23..9e489cb8 100644 --- a/.arcconfig +++ b/.arcconfig @@ -1,3 +1,5 @@ { - "phabricator.uri": "https://secure.phabricator.com/" + "phabricator.uri": "https://secure.phabricator.com/", + "load": ["support/libxhprof"], + "unit.engine": "XHProfExtensionUnitTestEngine" } diff --git a/.gitignore b/.gitignore index 0b8f03db..f1631981 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,5 @@ extension/tests/*.out extension/tests/*.diff extension/tests/*.log extension/tests/*.php + +support/libxhprof/.phutil_module_cache diff --git a/support/libxhprof/__phutil_library_init__.php b/support/libxhprof/__phutil_library_init__.php new file mode 100644 index 00000000..31f0c680 --- /dev/null +++ b/support/libxhprof/__phutil_library_init__.php @@ -0,0 +1,3 @@ + 2, + 'class' => array( + 'XHProfExtensionUnitTestEngine' => 'unit/XHProfUnitTestEngine.php', + ), + 'function' => array(), + 'xmap' => array( + 'XHProfExtensionUnitTestEngine' => 'ArcanistUnitTestEngine', + ), +)); diff --git a/support/libxhprof/unit/XHProfUnitTestEngine.php b/support/libxhprof/unit/XHProfUnitTestEngine.php new file mode 100644 index 00000000..955261a2 --- /dev/null +++ b/support/libxhprof/unit/XHProfUnitTestEngine.php @@ -0,0 +1,53 @@ +getWorkingCopy()->getProjectRoot().'/extension/'; + + $start_time = microtime(true); + + id(new ExecFuture('phpize && ./configure && make -j4')) + ->setCWD($root) + ->resolvex(); + + $out = id(new ExecFuture('make -f Makefile.local test_with_exit_status')) + ->setCWD($root) + ->setEnv( + array( + 'TEST_PHP_ARGS' => '-q', + )) + ->resolvex(); + + // NOTE: REPORT_EXIT_STATUS doesn't seem to work properly in some versions + // of PHP. Just "parse" stdout to approximate the results. + + list($stdout) = $out; + + $tests = array(); + + foreach (phutil_split_lines($stdout) as $line) { + $matches = null; + + // NOTE: The test script writes the name of the test originally, then + // uses "\r" to erase it and write the result. This splits as a single + // line. + if (preg_match('/^TEST .*\r(PASS|FAIL) (.*)/', $line, $matches)) { + if ($matches[1] == 'PASS') { + $result = ArcanistUnitTestResult::RESULT_PASS; + } else { + $result = ArcanistUnitTestResult::RESULT_FAIL; + } + + $name = trim($matches[2]); + + $tests[] = id(new ArcanistUnitTestResult()) + ->setName($name) + ->setResult($result) + ->setDuration(microtime(true) - $start_time); + } + } + + return $tests; + } +} From d8ca30af371e5eeeea7bf37220a8264e61f63422 Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 28 Aug 2014 10:34:21 -0700 Subject: [PATCH 06/15] Add a failing test case for the XHProf PHP 5.5 segfault Summary: This adds a failing test case for the bug discussed in . It also adds a `bin/xhprofile` script which makes it easier to test stuff like this, by invoking the profiler on some other script. This isn't hugely useful in production but is valuable diagnostically, and helped me reduce this test case. Test Plan: - Ran `arc unit` and got a failure. - Verified that this test passes if `class_exists()` is commented out (which makes the test not segfault). Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Differential Revision: https://secure.phabricator.com/D10374 --- bin/xhprofile | 1 + extension/tests/xhprof_009.phpt | 19 +++++++++++++++++++ scripts/xhprofile.php | 19 +++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 120000 bin/xhprofile create mode 100644 extension/tests/xhprof_009.phpt create mode 100755 scripts/xhprofile.php diff --git a/bin/xhprofile b/bin/xhprofile new file mode 120000 index 00000000..56da2f66 --- /dev/null +++ b/bin/xhprofile @@ -0,0 +1 @@ +../scripts/xhprofile.php \ No newline at end of file diff --git a/extension/tests/xhprof_009.phpt b/extension/tests/xhprof_009.phpt new file mode 100644 index 00000000..9e1a55c6 --- /dev/null +++ b/extension/tests/xhprof_009.phpt @@ -0,0 +1,19 @@ +--TEST-- +XHPRrof: PHP 5.5 crash in hp_execute_internal +Author: epriestley +--FILE-- + +} + +spl_autoload_register('loader', $throw = true); + +xhprof_enable(); + +class_exists('ThisClassDoesNotExist'); +echo "OK\n"; + +--EXPECT-- +OK diff --git a/scripts/xhprofile.php b/scripts/xhprofile.php new file mode 100755 index 00000000..36891e99 --- /dev/null +++ b/scripts/xhprofile.php @@ -0,0 +1,19 @@ +#!/usr/bin/env php +'); +} + +$__xhprof_target__ = $argv[1]; + +$argv = array_slice($argv, 1); +$argc = count($argv); + +xhprof_enable(); +require_once $__xhprof_target__; +$xhprof_data = xhprof_disable(); + +var_dump($xhprof_data); From 55a47c0d8ffeea4b84133fd21103caa816676b5d Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 28 Aug 2014 10:34:42 -0700 Subject: [PATCH 07/15] Fix XHProf segfault when calling internal functions in PHP 5.5 Summary: Fixes . Since the issue with that patch was CLA, I developed this independently. This works because it just inlines the body of `execute_internal()`, which is nearly identical: ``` ZEND_API void execute_internal(zend_execute_data *execute_data_ptr, zend_fcall_info *fci, int return_value_used TSRMLS_DC) { if(fci != NULL) { ((zend_internal_function *) execute_data_ptr->function_state.function)->handler(fci->param_count, *fci->retval_ptr_ptr, fci->retval_ptr_ptr, fci->object_ptr, 1 TSRMLS_CC); } else { zval **return_value_ptr = &EX_TMP_VAR(execute_data_ptr, execute_data_ptr->opline->result.var)->var.ptr; ((zend_internal_function *) execute_data_ptr->function_state.function)->handler(execute_data_ptr->opline->extended_value, *return_value_ptr, (execute_data_ptr->function_state.function->common.fn_flags & ZEND_ACC_RETURN_REFERENCE)?return_value_ptr:NULL, execute_data_ptr->object, return_value_used TSRMLS_CC); } } ``` Test Plan: Failing test now passes. No more segfaults on PHP 5.5.8. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Differential Revision: https://secure.phabricator.com/D10375 --- extension/xhprof.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/extension/xhprof.c b/extension/xhprof.c index 7ce3f49d..537b9e46 100644 --- a/extension/xhprof.c +++ b/extension/xhprof.c @@ -1703,8 +1703,30 @@ ZEND_DLEXPORT void hp_execute_internal(zend_execute_data *execute_data, if (!_zend_execute_internal) { /* no old override to begin with. so invoke the builtin's implementation */ + +#if ZEND_EXTENSION_API_NO >= 220121212 + /* PHP 5.5. This is just inlining a copy of execute_internal(). */ + + if (fci != NULL) { + ((zend_internal_function *) execute_data->function_state.function)->handler( + fci->param_count, + *fci->retval_ptr_ptr, + fci->retval_ptr_ptr, + fci->object_ptr, + 1 TSRMLS_CC); + } else { + zval **return_value_ptr = &EX_TMP_VAR(execute_data, execute_data->opline->result.var)->var.ptr; + ((zend_internal_function *) execute_data->function_state.function)->handler( + execute_data->opline->extended_value, + *return_value_ptr, + (execute_data->function_state.function->common.fn_flags & ZEND_ACC_RETURN_REFERENCE) + ? return_value_ptr + : NULL, + execute_data->object, + ret TSRMLS_CC); + } +#elif ZEND_EXTENSION_API_NO >= 220100525 zend_op *opline = EX(opline); -#if ZEND_EXTENSION_API_NO >= 220100525 temp_variable *retvar = &EX_T(opline->result.var); ((zend_internal_function *) EX(function_state).function)->handler( opline->extended_value, @@ -1713,6 +1735,7 @@ ZEND_DLEXPORT void hp_execute_internal(zend_execute_data *execute_data, &retvar->var.ptr:NULL, EX(object), ret TSRMLS_CC); #else + zend_op *opline = EX(opline); ((zend_internal_function *) EX(function_state).function)->handler( opline->extended_value, EX_T(opline->result.u.var).var.ptr, From 91e0be91da03ec4aa2b63a991f70c1c10151cc71 Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 28 Aug 2014 10:34:52 -0700 Subject: [PATCH 08/15] Fix broken XHProf unit tests Summary: There are two broken tests. One (007) is easy to fix. It was failing because of array-to-string conversion warnings. Since I didn't want to add function calls because that would change the test output, I just silenced the warnings with "@". The other test (004) was also easy to fix but I can't really explain what's going on there. Seems like it works though? It shouldn't do anything bad, since we would have generated a meaningless "???_op" otherwise. Test Plan: Ran tests, tests passed. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Differential Revision: https://secure.phabricator.com/D10376 --- extension/tests/xhprof_007.phpt | 12 ++++++------ extension/xhprof.c | 4 +++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/extension/tests/xhprof_007.phpt b/extension/tests/xhprof_007.phpt index d1f26d60..f0fd7302 100644 --- a/extension/tests/xhprof_007.phpt +++ b/extension/tests/xhprof_007.phpt @@ -6,7 +6,7 @@ Author: mpal include_once dirname(__FILE__).'/common.php'; -$xhprof_ignored_functions = array( 'ignored_functions' => +$xhprof_ignored_functions = array( 'ignored_functions' => array('call_user_func', 'call_user_func_array', 'my_call_user_func_safe', @@ -20,8 +20,8 @@ function foo($x) { for ($idx = 0; $idx < 2; $idx++) { $sum += bar(); } - echo "hello: {$x}\n" ; - return strlen("hello: {$x}"); + echo @"hello: {$x}\n" ; + return @strlen("hello: {$x}"); } function foo_array($x1, $x2 = 'test') { @@ -30,8 +30,8 @@ function foo_array($x1, $x2 = 'test') { foreach ($x as $idx) { $sum += bar(); } - echo "hello: " . $x[0] . $x[1] . "\n"; - return strlen("hello: {$x[0]} {$x[1]}"); + echo @"hello: {$x[0]}{$x[1]}\n"; + return @strlen("hello: {$x[0]} {$x[1]}"); } function my_call_user_func_safe($function, $args = 'my_safe') { @@ -161,7 +161,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' => +$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'); diff --git a/extension/xhprof.c b/extension/xhprof.c index 537b9e46..d213f5cc 100644 --- a/extension/xhprof.c +++ b/extension/xhprof.c @@ -961,7 +961,9 @@ static char *hp_get_function_name(zend_op_array *ops TSRMLS_DC) { /* we are dealing with a special directive/function like * include, eval, etc. */ -#if ZEND_EXTENSION_API_NO >= 220100525 +#if ZEND_EXTENSION_API_NO >= 220121212 + curr_op = data->prev_execute_data->opline->extended_value; +#elif ZEND_EXTENSION_API_NO >= 220100525 curr_op = data->opline->extended_value; #else curr_op = data->opline->op2.u.constant.value.lval; From fdd10ab307aed1526ed2982a7c31224fc6fe1663 Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 26 Feb 2015 05:56:16 -0800 Subject: [PATCH 09/15] Add a failing test for crashes during auto_append_file See . --- extension/tests/xhprof_010.phpt | 16 ++++++++++++++++ extension/tests/xhprof_010_append.php | 3 +++ 2 files changed, 19 insertions(+) create mode 100644 extension/tests/xhprof_010.phpt create mode 100644 extension/tests/xhprof_010_append.php diff --git a/extension/tests/xhprof_010.phpt b/extension/tests/xhprof_010.phpt new file mode 100644 index 00000000..33b4a14e --- /dev/null +++ b/extension/tests/xhprof_010.phpt @@ -0,0 +1,16 @@ +--TEST-- +XHProf: Crash with auto_append_file +Author: epriestley +--INI-- +include_path={PWD} +auto_append_file=xhprof_010_append.php +--FILE-- + +--EXPECTF-- +MAIN +APPENDED diff --git a/extension/tests/xhprof_010_append.php b/extension/tests/xhprof_010_append.php new file mode 100644 index 00000000..7e569914 --- /dev/null +++ b/extension/tests/xhprof_010_append.php @@ -0,0 +1,3 @@ + Date: Thu, 26 Feb 2015 05:56:16 -0800 Subject: [PATCH 10/15] Add a failing test for auto_prepend_file See . --- extension/tests/xhprof_011.phpt | 15 +++++++++++++++ extension/tests/xhprof_011_prepend.php | 4 ++++ 2 files changed, 19 insertions(+) create mode 100644 extension/tests/xhprof_011.phpt create mode 100644 extension/tests/xhprof_011_prepend.php diff --git a/extension/tests/xhprof_011.phpt b/extension/tests/xhprof_011.phpt new file mode 100644 index 00000000..4021243d --- /dev/null +++ b/extension/tests/xhprof_011.phpt @@ -0,0 +1,15 @@ +--TEST-- +XHProf: Crash with auto_prepend_file +Author: epriestley +--INI-- +include_path={PWD} +auto_prepend_file=xhprof_011_prepend.php +--FILE-- + +--EXPECTF-- +PREPENDED +MAIN diff --git a/extension/tests/xhprof_011_prepend.php b/extension/tests/xhprof_011_prepend.php new file mode 100644 index 00000000..22386904 --- /dev/null +++ b/extension/tests/xhprof_011_prepend.php @@ -0,0 +1,4 @@ + Date: Thu, 26 Feb 2015 06:13:21 -0800 Subject: [PATCH 11/15] Fix segfaults with auto_prepend_file and auto_append_file See: - - --- extension/xhprof.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/extension/xhprof.c b/extension/xhprof.c index d213f5cc..eeb57bb2 100644 --- a/extension/xhprof.c +++ b/extension/xhprof.c @@ -962,7 +962,11 @@ static char *hp_get_function_name(zend_op_array *ops TSRMLS_DC) { * include, eval, etc. */ #if ZEND_EXTENSION_API_NO >= 220121212 - curr_op = data->prev_execute_data->opline->extended_value; + if (data->prev_execute_data) { + curr_op = data->prev_execute_data->opline->extended_value; + } else { + curr_op = data->opline->extended_value; + } #elif ZEND_EXTENSION_API_NO >= 220100525 curr_op = data->opline->extended_value; #else From 4dbb1aa774ab43ded0a35c8102cdfc2a4f361a42 Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 26 Feb 2015 06:20:38 -0800 Subject: [PATCH 12/15] Fix misspelling of "XHProf" as "XHPRrof" in several tests --- extension/tests/xhprof_001.phpt | 2 +- extension/tests/xhprof_002.phpt | 2 +- extension/tests/xhprof_003.phpt | 2 +- extension/tests/xhprof_004.phpt | 2 +- extension/tests/xhprof_005.phpt | 2 +- extension/tests/xhprof_006.phpt | 2 +- extension/tests/xhprof_007.phpt | 2 +- extension/tests/xhprof_008.phpt | 4 ++-- extension/tests/xhprof_009.phpt | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/extension/tests/xhprof_001.phpt b/extension/tests/xhprof_001.phpt index dc14c28c..40d76f02 100644 --- a/extension/tests/xhprof_001.phpt +++ b/extension/tests/xhprof_001.phpt @@ -1,5 +1,5 @@ --TEST-- -XHPRrof: Basic Profiling Test +XHProf: Basic Profiling Test Author: Kannan --FILE-- Date: Thu, 26 Feb 2015 06:28:59 -0800 Subject: [PATCH 13/15] Add a test case for a memory leak in xhprof_enable() See . --- extension/tests/xhprof_012.phpt | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 extension/tests/xhprof_012.phpt diff --git a/extension/tests/xhprof_012.phpt b/extension/tests/xhprof_012.phpt new file mode 100644 index 00000000..ef815e47 --- /dev/null +++ b/extension/tests/xhprof_012.phpt @@ -0,0 +1,32 @@ +--TEST-- +XHProf: Memory Leak in Ignored Functions +Author: epriestley +--FILE-- + array($large))); +xhprof_disable(); +unset($large); + +xhprof_enable(); +xhprof_disable(); + +$new = memory_get_usage(); + +$missing = ($new - $old); + +if ($missing >= (1024 * 1024 * 16)) { + echo "LEAKED A LOT OF MEMORY\n"; +} else { + echo "DID NOT LEAK A LOT OF MEMORY\n"; +} + +?> +--EXPECTF-- +DID NOT LEAK A LOT OF MEMORY From ff8b3892d0cfc53e744631ff5c6b34f13421edce Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 26 Feb 2015 06:32:07 -0800 Subject: [PATCH 14/15] Fix a memory leak in the ignored function list See: - - --- extension/xhprof.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/extension/xhprof.c b/extension/xhprof.c index eeb57bb2..66aa041e 100644 --- a/extension/xhprof.c +++ b/extension/xhprof.c @@ -596,6 +596,11 @@ static inline uint8 hp_inline_hash(char * str) { * @author mpal */ static void hp_get_ignored_functions_from_arg(zval *args) { + + if (hp_globals.ignored_function_names) { + hp_array_del(hp_globals.ignored_function_names); + } + if (args != NULL) { zval *zresult = NULL; From 0bbf2a2ac34f495e42aa852293fe0ed821659047 Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 26 Feb 2015 06:37:51 -0800 Subject: [PATCH 15/15] Use sys_get_temp_dir(), not hardcoded "/tmp" See: --- xhprof_lib/utils/xhprof_runs.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/xhprof_lib/utils/xhprof_runs.php b/xhprof_lib/utils/xhprof_runs.php index cde5ff55..2a22a5dc 100644 --- a/xhprof_lib/utils/xhprof_runs.php +++ b/xhprof_lib/utils/xhprof_runs.php @@ -95,8 +95,7 @@ public function __construct($dir = null) { $dir = ini_get("xhprof.output_dir"); if (empty($dir)) { - // some default that at least works on unix... - $dir = "/tmp"; + $dir = sys_get_temp_dir(); xhprof_error("Warning: Must specify directory location for XHProf runs. ". "Trying {$dir} as default. You can either pass the " .