From 93a3d632fcc92263a0678659bd43a4ac647d641e Mon Sep 17 00:00:00 2001 From: Florian Engelhardt Date: Thu, 5 Dec 2024 11:19:54 +0100 Subject: [PATCH] cleanup --- profiling/src/allocation/allocation_ge84.rs | 28 ++------------------- profiling/src/allocation/allocation_le83.rs | 2 +- profiling/src/allocation/mod.rs | 22 +++------------- profiling/src/lib.rs | 13 +--------- 4 files changed, 7 insertions(+), 58 deletions(-) diff --git a/profiling/src/allocation/allocation_ge84.rs b/profiling/src/allocation/allocation_ge84.rs index 1d19bc6181..6be8ba5fcc 100644 --- a/profiling/src/allocation/allocation_ge84.rs +++ b/profiling/src/allocation/allocation_ge84.rs @@ -95,36 +95,12 @@ macro_rules! tls_zend_mm_state { }; } -#[allow(dead_code)] -pub fn alloc_prof_minit() { - #[cfg(not(php_zts))] - alloc_prof_custom_heap_init(); -} - -#[allow(dead_code)] -pub fn alloc_prof_mshutdown() { - #[cfg(not(php_zts))] - alloc_prof_custom_heap_reset(); -} - -#[allow(dead_code)] -pub fn alloc_prof_ginit() { - #[cfg(php_zts)] - alloc_prof_custom_heap_init(); -} - -#[allow(dead_code)] -pub fn alloc_prof_gshutdown() { - #[cfg(php_zts)] - alloc_prof_custom_heap_reset(); -} - /// This initializes the thread locale variable `ZEND_MM_STATE` with respect to the currently /// installed `zend_mm_heap` in ZendMM. It guarantees compliance with the safety guarantees /// described in the `ZendMMState` structure, specifically for `ZendMMState::alloc`, /// `ZendMMState::realloc`, `ZendMMState::free`, `ZendMMState::gc` and `ZendMMState::shutdown`. /// This function may panic if called out of order! -fn alloc_prof_custom_heap_init() { +pub fn alloc_prof_ginit() { ZEND_MM_STATE.with(|cell| { let zend_mm_state = cell.get(); @@ -192,7 +168,7 @@ fn alloc_prof_custom_heap_init() { /// guarantees compliance with the safety guarantees described in the `ZendMMState` structure, /// specifically for `ZendMMState::alloc`, `ZendMMState::realloc`, `ZendMMState::free`, /// `ZendMMState::gc` and `ZendMMState::shutdown`. -fn alloc_prof_custom_heap_reset() { +pub fn alloc_prof_gshutdown() { ZEND_MM_STATE.with(|cell| { let zend_mm_state = cell.get(); unsafe { diff --git a/profiling/src/allocation/allocation_le83.rs b/profiling/src/allocation/allocation_le83.rs index 7b27485d3a..7f8b12617d 100644 --- a/profiling/src/allocation/allocation_le83.rs +++ b/profiling/src/allocation/allocation_le83.rs @@ -87,7 +87,7 @@ lazy_static! { static ref JIT_ENABLED: bool = unsafe { zend::ddog_php_jit_enabled() }; } -pub fn alloc_prof_minit() { +pub fn alloc_prof_ginit() { unsafe { zend::ddog_php_opcache_init_handle() }; } diff --git a/profiling/src/allocation/mod.rs b/profiling/src/allocation/mod.rs index 9980db0adf..f20e2e31be 100644 --- a/profiling/src/allocation/mod.rs +++ b/profiling/src/allocation/mod.rs @@ -77,36 +77,20 @@ thread_local! { RefCell::new(AllocationProfilingStats::new()); } -pub fn alloc_prof_minit() { - #[cfg(not(php_zend_mm_set_custom_handlers_ex))] - allocation_le83::alloc_prof_minit(); - #[cfg(php_zend_mm_set_custom_handlers_ex)] - allocation_ge84::alloc_prof_minit(); -} - -#[allow(dead_code)] -pub fn alloc_prof_mshutdown() { - #[cfg(php_zend_mm_set_custom_handlers_ex)] - allocation_ge84::alloc_prof_mshutdown(); -} - -#[allow(dead_code)] -#[cfg(php_zts)] pub fn alloc_prof_ginit() { + #[cfg(not(php_zend_mm_set_custom_handlers_ex))] + allocation_le83::alloc_prof_ginit(); #[cfg(php_zend_mm_set_custom_handlers_ex)] allocation_ge84::alloc_prof_ginit(); } -#[allow(dead_code)] -#[cfg(php_zts)] pub fn alloc_prof_gshutdown() { #[cfg(php_zend_mm_set_custom_handlers_ex)] allocation_ge84::alloc_prof_gshutdown(); } -#[allow(dead_code)] +#[cfg(not(php_zend_mm_set_custom_handlers_ex))] pub fn alloc_prof_startup() { - #[cfg(not(php_zend_mm_set_custom_handlers_ex))] allocation_le83::alloc_prof_startup(); } diff --git a/profiling/src/lib.rs b/profiling/src/lib.rs index e15efb26b1..f3f876a96c 100644 --- a/profiling/src/lib.rs +++ b/profiling/src/lib.rs @@ -31,7 +31,6 @@ use core::ptr; use ddcommon::{cstr, tag, tag::Tag}; use lazy_static::lazy_static; use libc::c_char; -#[cfg(php_zts)] use libc::c_void; use log::{debug, error, info, trace, warn}; use once_cell::sync::{Lazy, OnceCell}; @@ -184,9 +183,7 @@ pub extern "C" fn get_module() -> &'static mut zend::ModuleEntry { version: PROFILER_VERSION.as_ptr(), post_deactivate_func: Some(prshutdown), deps: DEPS.as_ptr(), - #[cfg(php_zts)] globals_ctor: Some(ginit), - #[cfg(php_zts)] globals_dtor: Some(gshutdown), #[cfg(php_zts)] globals_size: 1, @@ -199,7 +196,6 @@ pub extern "C" fn get_module() -> &'static mut zend::ModuleEntry { unsafe { &mut *ptr::addr_of_mut!(MODULE) } } -#[cfg(php_zts)] unsafe extern "C" fn ginit(_globals_ptr: *mut c_void) { #[cfg(all(feature = "timeline", php_zts))] timeline::timeline_ginit(); @@ -208,7 +204,6 @@ unsafe extern "C" fn ginit(_globals_ptr: *mut c_void) { allocation::alloc_prof_ginit(); } -#[cfg(php_zts)] unsafe extern "C" fn gshutdown(_globals_ptr: *mut c_void) { #[cfg(all(feature = "timeline", php_zts))] timeline::timeline_gshutdown(); @@ -349,9 +344,6 @@ extern "C" fn minit(_type: c_int, module_number: c_int) -> ZendResult { #[cfg(feature = "exception_profiling")] exception::exception_profiling_minit(); - #[cfg(feature = "allocation_profiling")] - allocation::alloc_prof_minit(); - // There are a few things which need to do something on the first rinit of // each minit/mshutdown cycle. In Apache, when doing `apachectl graceful`, // there can be more than one of these cycles per process. @@ -857,9 +849,6 @@ extern "C" fn mshutdown(_type: c_int, _module_number: c_int) -> ZendResult { #[cfg(feature = "exception_profiling")] exception::exception_profiling_mshutdown(); - #[cfg(feature = "allocation_profiling")] - allocation::alloc_prof_mshutdown(); - Profiler::stop(Duration::from_secs(1)); ZendResult::Success @@ -884,7 +873,7 @@ extern "C" fn startup(extension: *mut ZendExtension) -> ZendResult { timeline::timeline_startup(); } - #[cfg(feature = "allocation_profiling")] + #[cfg(all(feature = "allocation_profiling", not(php_zend_mm_set_custom_handlers_ex)))] allocation::alloc_prof_startup(); ZendResult::Success