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 93a3d63
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 58 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
13 changes: 1 addition & 12 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,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,
Expand All @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 93a3d63

Please sign in to comment.