From 87d9d120d44c9964985bb7f56f791136593cb326 Mon Sep 17 00:00:00 2001 From: Florian Engelhardt Date: Tue, 28 Nov 2023 11:08:03 +0100 Subject: [PATCH] do not emit profiles if the feature is inactive --- profiling/src/timeline.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/profiling/src/timeline.rs b/profiling/src/timeline.rs index 27e39cc71da..e085751ece8 100644 --- a/profiling/src/timeline.rs +++ b/profiling/src/timeline.rs @@ -37,6 +37,17 @@ fn try_sleeping_fn( execute_data: *mut zend_execute_data, return_value: *mut zval, ) -> anyhow::Result<()> { + let timeline_enabled = REQUEST_LOCALS.with(|cell| { + cell.try_borrow() + .map(|locals| locals.profiling_experimental_timeline_enabled) + .unwrap_or(false) + }); + + if !timeline_enabled { + unsafe { func(execute_data, return_value) }; + return Ok(()); + } + let start = Instant::now(); // SAFETY: simple forwarding to original func with original args. @@ -186,6 +197,10 @@ pub fn timeline_rinit() { return; }; + if !locals.profiling_experimental_timeline_enabled { + return; + } + IDLE_SINCE.with(|cell| { // try to borrow and bail out if not successful let Ok(idle_since) = cell.try_borrow() else { @@ -230,6 +245,10 @@ pub(crate) fn timeline_mshutdown() { return; }; + if !locals.profiling_experimental_timeline_enabled { + return; + } + IDLE_SINCE.with(|cell| { // try to borrow and bail out if not successful let Ok(idle_since) = cell.try_borrow() else {