Skip to content

Commit 703fec2

Browse files
disable heap live if allocation is disabled
1 parent 78d6d60 commit 703fec2

3 files changed

Lines changed: 73 additions & 1 deletion

File tree

profiling/src/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,13 @@ impl SystemSettings {
143143
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");
144144
}
145145
system_settings.profiling_allocation_enabled = false;
146+
system_settings.profiling_experimental_heap_live_enabled = false;
146147
}
147148
#[cfg(php_zend_mm_set_custom_handlers_ex)]
148149
if allocation::allocation_ge84::first_rinit_should_disable_due_to_jit() {
149150
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");
150151
system_settings.profiling_allocation_enabled = false;
152+
system_settings.profiling_experimental_heap_live_enabled = false;
151153
}
152154

153155
SystemSettings::log_state(

profiling/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,8 @@ extern "C" fn rinit(_type: c_int, _module_number: c_int) -> ZendResult {
616616
}
617617
locals.tags = tags;
618618
locals.profiling_experimental_heap_live_enabled =
619-
config::profiling_experimental_heap_live_enabled_current();
619+
system_settings.as_ref().profiling_experimental_heap_live_enabled
620+
&& config::profiling_experimental_heap_live_enabled_current();
620621
}
621622
locals.system_settings = system_settings;
622623
});
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
--TEST--
2+
[profiling] heap live profiling with active JIT
3+
--DESCRIPTION--
4+
Verify that heap live profiling is disabled if allocation profiling is disabled due to the JIT bug workaround,
5+
and works normally otherwise.
6+
--SKIPIF--
7+
<?php
8+
if (!extension_loaded('datadog-profiling'))
9+
echo "skip: test requires Datadog Continuous Profiler\n";
10+
if (PHP_VERSION_ID < 80000)
11+
echo "skip: JIT requires PHP >= 8.0\n";
12+
13+
$affected = (PHP_VERSION_ID >= 80000 && PHP_VERSION_ID < 80121)
14+
|| (PHP_VERSION_ID >= 80200 && PHP_VERSION_ID < 80208)
15+
|| (PHP_VERSION_ID >= 80400 && PHP_VERSION_ID < 80407);
16+
17+
if (!$affected) {
18+
echo "skip: JIT workaround is inactive on this PHP version\n";
19+
}
20+
?>
21+
--ENV--
22+
DD_PROFILING_ENABLED=yes
23+
DD_PROFILING_ALLOCATION_ENABLED=yes
24+
DD_PROFILING_EXPERIMENTAL_HEAP_LIVE_ENABLED=yes
25+
DD_PROFILING_EXPERIMENTAL_CPU_TIME_ENABLED=no
26+
--INI--
27+
assert.exception=1
28+
zend_extension=opcache
29+
opcache.enable_cli=1
30+
opcache.jit=tracing
31+
opcache.jit_buffer_size=4M
32+
--FILE--
33+
<?php
34+
35+
ob_start();
36+
$extension = new ReflectionExtension('datadog-profiling');
37+
$extension->info();
38+
$output = ob_get_clean();
39+
40+
$lines = preg_split("/\R/", $output);
41+
$values = [];
42+
foreach ($lines as $line) {
43+
$pair = explode("=>", $line);
44+
if (count($pair) != 2) {
45+
continue;
46+
}
47+
$values[trim($pair[0])] = trim($pair[1]);
48+
}
49+
50+
$allocation_enabled = $values["Allocation Profiling Enabled"];
51+
$heap_live_enabled = $values["Experimental Heap Live Profiling Enabled"];
52+
53+
var_dump($allocation_enabled);
54+
var_dump($heap_live_enabled);
55+
56+
// If allocation profiling is not fully active, then heap live profiling MUST NOT be active
57+
if ($allocation_enabled !== "true") {
58+
assert($heap_live_enabled === "false (requires allocation profiling)");
59+
} else {
60+
assert($heap_live_enabled === "true");
61+
}
62+
63+
echo "Done.";
64+
65+
?>
66+
--EXPECTF--
67+
string(%d) "%s"
68+
string(%d) "%s"
69+
Done.

0 commit comments

Comments
 (0)