Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
realFlowControl committed Dec 5, 2024
1 parent 6e13b73 commit 4bd7be9
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 61 deletions.
28 changes: 2 additions & 26 deletions profiling/src/allocation/allocation_ge84.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion profiling/src/allocation/allocation_le83.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() };
}

Expand Down
22 changes: 3 additions & 19 deletions profiling/src/allocation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
4 changes: 2 additions & 2 deletions profiling/src/bindings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,13 @@ pub struct ModuleEntry {
/// thread for module globals. The function pointers in [`ModuleEntry::globals_ctor`] and
/// [`ModuleEntry::globals_dtor`] will only be called if this is a non-zero.
pub globals_size: size_t,
#[cfg(php_zts)]
/// Pointer to a `ts_rsrc_id` (which is a [`i32`]). For C-Extension this is created using the
/// `ZEND_DECLARE_MODULE_GLOBALS(module_name)` macro.
/// See <https://heap.space/xref/PHP-8.3/Zend/zend_API.h?r=a89d22cc#249>
#[cfg(php_zts)]
pub globals_id_ptr: *mut ts_rsrc_id,
#[cfg(not(php_zts))]
/// Pointer to the module globals struct in NTS mode
#[cfg(not(php_zts))]
pub globals_ptr: *mut c_void,
/// Constructor for module globals.
/// Be aware this will only be called in case [`ModuleEntry::globals_size`] is non-zero and for
Expand Down
18 changes: 5 additions & 13 deletions profiling/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -184,31 +183,30 @@ 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,
#[cfg(php_zts)]
globals_id_ptr: unsafe { &mut GLOBALS_ID_PTR },
#[cfg(not(php_zts))]
globals_ptr: ptr::null_mut(),
..Default::default()
});

// SAFETY: well, it's at least as safe as what every single C extension does.
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();

println!("GINIT");

#[cfg(feature = "allocation_profiling")]
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();
Expand Down Expand Up @@ -349,9 +347,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.
Expand Down Expand Up @@ -857,9 +852,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
Expand All @@ -884,7 +876,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
Expand Down

0 comments on commit 4bd7be9

Please sign in to comment.