File tree 2 files changed +43
-0
lines changed
2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -176,6 +176,16 @@ pub fn allocation_profiling_rinit() {
176
176
}
177
177
178
178
pub fn allocation_profiling_rshutdown ( ) {
179
+ let allocation_profiling = REQUEST_LOCALS . with ( |cell| {
180
+ cell. try_borrow ( )
181
+ . map ( |locals| locals. profiling_allocation_enabled )
182
+ . unwrap_or ( false )
183
+ } ) ;
184
+
185
+ if !allocation_profiling {
186
+ return ;
187
+ }
188
+
179
189
// If `is_zend_mm()` is true, the custom handlers have been reset to `None`
180
190
// already. This is unexpected, therefore we will not touch the ZendMM handlers
181
191
// anymore as resetting to prev handlers might result in segfaults and other
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ [profiling] Allocation profiling should not crash when run with `USE_ZEND_ALLOC=0`
3
+ --DESCRIPTION--
4
+ When running PHP with `USE_ZEND_ALLOC=0` and disabled allocation profiling
5
+ (either explicit disabled or due to the JIT bug), PHP will install the system
6
+ allocator in https://heap.space/xref/PHP-8.2/Zend/zend_alloc.c?r=4553258d#2895-2918
7
+ and set the `AG(heap)->use_custom_heap` to `ZEND_MM_CUSTOM_HEAP_STD` (which is 1),
8
+ so future calls to `is_zend_mm()` will return false which might lead to a situation
9
+ where we assume we are hooked into, while we are not.
10
+ --SKIPIF--
11
+ <?php
12
+ if (!extension_loaded ('datadog-profiling ' ))
13
+ echo "skip: test requires datadog-profiling " , PHP_EOL ;
14
+ ?>
15
+ --ENV--
16
+ USE_ZEND_ALLOC=0
17
+ --INI--
18
+ datadog.profiling.enabled=yes
19
+ datadog.profiling.log_level=debug
20
+ datadog.profiling.allocation_enabled=yes
21
+ datadog.profiling.experimental_cpu_time_enabled=no
22
+ zend_extension=opcache
23
+ opcache.enable_cli=1
24
+ opcache.jit=tracing
25
+ opcache.jit_buffer_size=4M
26
+ --FILE--
27
+ <?php
28
+ echo "Done. " , PHP_EOL ;
29
+ ?>
30
+ --EXPECTREGEX--
31
+ .*Done.
32
+ .*Stopping profiler.
33
+ .*
You can’t perform that action at this time.
0 commit comments