Skip to content

Commit 216b970

Browse files
fallback to "old" hooking for allocation profiling
1 parent 4ba40d2 commit 216b970

3 files changed

Lines changed: 40 additions & 4 deletions

File tree

profiling/build.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,10 @@ fn cfg_php_feature_flags(vernum: u64) {
410410
if vernum >= 80400 {
411411
println!("cargo:rustc-cfg=php_frameless");
412412
println!("cargo:rustc-cfg=php_opcache_restart_hook");
413-
println!("cargo:rustc-cfg=php_zend_mm_set_custom_handlers_ex");
413+
// Commenting the following line temporary disables the new hooking mechanism for
414+
// allocation profiling until we solved the intefereing with
415+
// `memory_get_usage()`/`memory_get_peak_usage()`
416+
// println!("cargo:rustc-cfg=php_zend_mm_set_custom_handlers_ex");
414417
}
415418
}
416419

profiling/src/allocation/allocation_le83.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,13 @@ macro_rules! tls_zend_mm_state_set {
114114
}
115115

116116
const NEEDS_RUN_TIME_CHECK_FOR_ENABLED_JIT: bool =
117-
zend::PHP_VERSION_ID >= 80000 && zend::PHP_VERSION_ID < 80300;
117+
zend::PHP_VERSION_ID >= 80000 && zend::PHP_VERSION_ID < 80300 || zend::PHP_VERSION_ID >= 80400;
118118

119119
fn alloc_prof_needs_disabled_for_jit(version: u32) -> bool {
120120
// see https://github.com/php/php-src/pull/11380
121-
(80000..80121).contains(&version) || (80200..80208).contains(&version)
121+
(80000..80121).contains(&version)
122+
|| (80200..80208).contains(&version)
123+
|| (80400..80406).contains(&version)
122124
}
123125

124126
lazy_static! {
@@ -134,7 +136,11 @@ pub fn first_rinit_should_disable_due_to_jit() -> bool {
134136
&& alloc_prof_needs_disabled_for_jit(crate::RUNTIME_PHP_VERSION_ID.load(Relaxed))
135137
&& *JIT_ENABLED
136138
{
137-
error!("Memory allocation profiling will be disabled as long as JIT is active. To enable allocation profiling disable JIT or upgrade PHP to at least version 8.1.21 or 8.2.8. See https://github.com/DataDog/dd-trace-php/pull/2088");
139+
if zend::PHP_VERSION_ID >= 80400 {
140+
error!("Memory allocation profiling will be disabled as long as JIT is active. To enable allocation profiling disable JIT or upgrade PHP to at least version 8.4.7. See https://github.com/DataDog/dd-trace-php/pull/3199");
141+
} else {
142+
error!("Memory allocation profiling will be disabled as long as JIT is active. To enable allocation profiling disable JIT or upgrade PHP to at least version 8.1.21 or 8.2.8. See https://github.com/DataDog/dd-trace-php/pull/2088");
143+
}
138144
true
139145
} else {
140146
false
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
[profiling] test allocation profiling not interfering with `memory_get_peak_usage()`
3+
--DESCRIPTION--
4+
https://github.com/DataDog/dd-trace-php/issues/3360
5+
--SKIPIF--
6+
<?php
7+
if (getenv('USE_ZEND_ALLOC') === '0')
8+
die("skip requires ZendMM");
9+
if (!extension_loaded('datadog-profiling'))
10+
echo "skip: test requires Datadog Continuous Profiler\n";
11+
?>
12+
--ENV--
13+
DD_PROFILING_ENABLED=yes
14+
DD_PROFILING_EXPERIMENTAL_CPU_TIME_ENABLED=no
15+
DD_PROFILING_ALLOCATION_ENABLED=yes
16+
DD_PROFILING_LOG_LEVEL=off
17+
--FILE--
18+
<?php
19+
$x = str_repeat("a", 1024*1024);
20+
var_dump(memory_get_peak_usage(false) > 0);
21+
var_dump(memory_get_peak_usage(true) > 0);
22+
echo 'Done.';
23+
?>
24+
--EXPECT--
25+
bool(true)
26+
bool(true)
27+
Done.

0 commit comments

Comments
 (0)