Skip to content

Commit

Permalink
do not emit profiles if the feature is inactive
Browse files Browse the repository at this point in the history
  • Loading branch information
realFlowControl committed Nov 28, 2023
1 parent e623d7e commit 87d9d12
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions profiling/src/timeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 87d9d12

Please sign in to comment.