From 6243ebe8fd70b22b9f69cc83f8ccb833210a63e1 Mon Sep 17 00:00:00 2001 From: Florian Engelhardt Date: Wed, 22 Nov 2023 16:27:59 +0100 Subject: [PATCH] allow to enable all experimental features --- profiling/src/config.rs | 23 +++++++++++++++++++ profiling/src/lib.rs | 42 +++++++++++++++++++++++++++++----- profiling/src/profiling/mod.rs | 1 + 3 files changed, 60 insertions(+), 6 deletions(-) diff --git a/profiling/src/config.rs b/profiling/src/config.rs index d339c70e2fc..1086b245aea 100644 --- a/profiling/src/config.rs +++ b/profiling/src/config.rs @@ -137,6 +137,7 @@ pub(crate) unsafe fn get_value(id: ConfigId) -> &'static mut zval { #[derive(Clone, Copy)] pub(crate) enum ConfigId { ProfilingEnabled = 0, + ProfilingExperimentalFeaturesEnabled, ProfilingEndpointCollectionEnabled, ProfilingExperimentalCpuTimeEnabled, ProfilingAllocationEnabled, @@ -162,6 +163,7 @@ impl ConfigId { const fn env_var_name(&self) -> ZaiStr { let bytes: &'static [u8] = match self { ProfilingEnabled => b"DD_PROFILING_ENABLED\0", + ProfilingExperimentalFeaturesEnabled => b"DD_PROFILING_EXPERIMENTAL_FEATURES_ENABLED\0", ProfilingEndpointCollectionEnabled => b"DD_PROFILING_ENDPOINT_COLLECTION_ENABLED\0", ProfilingExperimentalCpuTimeEnabled => b"DD_PROFILING_EXPERIMENTAL_CPU_TIME_ENABLED\0", ProfilingAllocationEnabled => b"DD_PROFILING_ALLOCATION_ENABLED\0", @@ -200,6 +202,13 @@ pub(crate) unsafe fn profiling_enabled() -> bool { get_bool(ProfilingEnabled, true) } +/// # Safety +/// This function must only be called after config has been initialized in +/// rinit, and before it is uninitialized in mshutdown. +pub(crate) unsafe fn profiling_experimental_features_enabled() -> bool { + get_bool(ProfilingExperimentalFeaturesEnabled, false) +} + /// # Safety /// This function must only be called after config has been initialized in /// rinit, and before it is uninitialized in mshutdown. @@ -449,6 +458,16 @@ pub(crate) fn minit(module_number: libc::c_int) { ini_change: None, parser: None, }, + zai_config_entry { + id: transmute(ProfilingExperimentalFeaturesEnabled), + name: ProfilingExperimentalFeaturesEnabled.env_var_name(), + type_: ZAI_CONFIG_TYPE_BOOL, + default_encoded_value: ZaiStr::literal(b"0\0"), + aliases: std::ptr::null_mut(), + aliases_count: 0, + ini_change: None, + parser: None, + }, zai_config_entry { id: transmute(ProfilingEndpointCollectionEnabled), name: ProfilingEndpointCollectionEnabled.env_var_name(), @@ -628,6 +647,10 @@ mod tests { (b"DD_TRACE_AGENT_PORT\0", "datadog.trace.agent_port"), (b"DD_AGENT_HOST\0", "datadog.agent_host"), (b"DD_PROFILING_ENABLED\0", "datadog.profiling.enabled"), + ( + b"DD_PROFILING_EXPERIMENTAL_FEATURES_ENABLED\0", + "datadog.profiling.experimental_features_enabled", + ), ( b"DD_PROFILING_ENDPOINT_COLLECTION_ENABLED\0", "datadog.profiling.endpoint_collection_enabled", diff --git a/profiling/src/lib.rs b/profiling/src/lib.rs index b373144c157..2f76b4663f3 100644 --- a/profiling/src/lib.rs +++ b/profiling/src/lib.rs @@ -371,6 +371,7 @@ pub struct RequestLocals { pub env: Option>, pub interrupt_count: AtomicU32, pub profiling_enabled: bool, + pub profiling_experimental_features_enabled: bool, pub profiling_endpoint_collection_enabled: bool, pub profiling_experimental_cpu_time_enabled: bool, pub profiling_allocation_enabled: bool, @@ -387,6 +388,7 @@ pub struct RequestLocals { impl RequestLocals { pub fn disable(&mut self) { self.profiling_enabled = false; + self.profiling_experimental_features_enabled = false; self.profiling_endpoint_collection_enabled = false; self.profiling_experimental_cpu_time_enabled = false; self.profiling_allocation_enabled = false; @@ -401,6 +403,7 @@ impl Default for RequestLocals { env: None, interrupt_count: AtomicU32::new(0), profiling_enabled: false, + profiling_experimental_features_enabled: false, profiling_endpoint_collection_enabled: true, profiling_experimental_cpu_time_enabled: true, profiling_allocation_enabled: true, @@ -465,6 +468,7 @@ extern "C" fn rinit(_type: c_int, _module_number: c_int) -> ZendResult { // Safety: We are after first rinit and before mshutdown. let ( profiling_enabled, + profiling_experimental_features_enabled, profiling_endpoint_collection_enabled, profiling_experimental_cpu_time_enabled, profiling_allocation_enabled, @@ -475,13 +479,19 @@ extern "C" fn rinit(_type: c_int, _module_number: c_int) -> ZendResult { output_pprof, ) = unsafe { let profiling_enabled = config::profiling_enabled(); + let profiling_experimental_features_enabled = + config::profiling_experimental_features_enabled(); ( profiling_enabled, + profiling_enabled && profiling_experimental_features_enabled, profiling_enabled && config::profiling_endpoint_collection_enabled(), - profiling_enabled && config::profiling_experimental_cpu_time_enabled(), + profiling_experimental_features_enabled + || profiling_enabled && config::profiling_experimental_cpu_time_enabled(), profiling_enabled && config::profiling_allocation_enabled(), - profiling_enabled && config::profiling_experimental_timeline_enabled(), - profiling_enabled && config::profiling_experimental_exception_enabled(), + profiling_experimental_features_enabled + || profiling_enabled && config::profiling_experimental_timeline_enabled(), + profiling_experimental_features_enabled + || profiling_enabled && config::profiling_experimental_exception_enabled(), config::profiling_experimental_exception_sampling_distance(), config::profiling_log_level(), config::profiling_output_pprof(), @@ -496,6 +506,7 @@ extern "C" fn rinit(_type: c_int, _module_number: c_int) -> ZendResult { locals.interrupt_count.store(0, Ordering::SeqCst); locals.profiling_enabled = profiling_enabled; + locals.profiling_experimental_features_enabled = profiling_experimental_features_enabled; locals.profiling_endpoint_collection_enabled = profiling_endpoint_collection_enabled; locals.profiling_experimental_cpu_time_enabled = profiling_experimental_cpu_time_enabled; locals.profiling_allocation_enabled = profiling_allocation_enabled; @@ -766,6 +777,7 @@ unsafe extern "C" fn minfo(module_ptr: *mut zend::ModuleEntry) { REQUEST_LOCALS.with(|cell| { let locals = cell.borrow(); let yes: &[u8] = b"true\0"; + let yes_exp: &[u8] = b"true (all experimental features enabled)\0"; let no: &[u8] = b"false\0"; let no_all: &[u8] = b"false (profiling disabled)\0"; zend::php_info_print_table_start(); @@ -776,11 +788,21 @@ unsafe extern "C" fn minfo(module_ptr: *mut zend::ModuleEntry) { if locals.profiling_enabled { yes } else { no }, ); + zend::php_info_print_table_row( + 2, + b"Profiling Experimental Features Enabled\0".as_ptr(), + if locals.profiling_experimental_features_enabled { yes } else { no }, + ); + zend::php_info_print_table_row( 2, b"Experimental CPU Time Profiling Enabled\0".as_ptr(), if locals.profiling_experimental_cpu_time_enabled { - yes + if locals.profiling_experimental_features_enabled { + yes_exp + } else { + yes + } } else if locals.profiling_enabled { no } else { @@ -818,7 +840,11 @@ unsafe extern "C" fn minfo(module_ptr: *mut zend::ModuleEntry) { 2, b"Experimental Timeline Enabled\0".as_ptr(), if locals.profiling_experimental_timeline_enabled { - yes + if locals.profiling_experimental_features_enabled { + yes_exp + } else { + yes + } } else if locals.profiling_enabled { no } else { @@ -840,7 +866,11 @@ unsafe extern "C" fn minfo(module_ptr: *mut zend::ModuleEntry) { 2, b"Experimental Exception Profiling Enabled\0".as_ptr(), if locals.profiling_experimental_exception_enabled { - yes + if locals.profiling_experimental_features_enabled { + yes_exp + } else { + yes + } } else if locals.profiling_enabled { no } else { diff --git a/profiling/src/profiling/mod.rs b/profiling/src/profiling/mod.rs index 4c20b2c30f8..8cd1633197a 100644 --- a/profiling/src/profiling/mod.rs +++ b/profiling/src/profiling/mod.rs @@ -1110,6 +1110,7 @@ mod tests { env: None, interrupt_count: AtomicU32::new(0), profiling_enabled: true, + profiling_experimental_features_enabled: false, profiling_endpoint_collection_enabled: true, profiling_experimental_cpu_time_enabled: false, profiling_allocation_enabled: false,