Skip to content

Commit 79269a2

Browse files
clearify some things regarding ZTS
1 parent 099c6c1 commit 79269a2

3 files changed

Lines changed: 19 additions & 6 deletions

File tree

profiling/src/exception.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ use std::sync::atomic::Ordering;
99

1010
use rand_distr::{Distribution, Poisson};
1111

12-
/// The engine's previous throw exception hook
12+
/// The engine's previous throw exception hook.
13+
/// We need to occupy the `zend_throw_exception_hook` in MINIT which is before threads get started
14+
/// (in ZTS), so we do not need a thread local for this function pointer.
1315
static mut PREV_ZEND_THROW_EXCEPTION_HOOK: Option<zend::VmZendThrowExceptionHook> = None;
1416

1517
/// Take a sample every 100 exceptions
18+
/// Will be initialized on first RINIT and is controlled by a INI_SYSTEM, so we do not need a
19+
/// thread local for the profiling interval.
1620
pub static EXCEPTION_PROFILING_INTERVAL: AtomicU32 = AtomicU32::new(100);
1721

1822
/// This will store the number of exceptions thrown during a profiling period. It will overflow
@@ -102,9 +106,18 @@ pub fn exception_profiling_minit() {
102106
}
103107

104108
/// This initializes the `EXCEPTION_PROFILING_INTERVAL` atomic on first RINIT with the value from
105-
/// the INI / ENV variable. We need to initialize here even when exception profiling is turned off,
106-
/// as it might get enabled via a per directory setting
109+
/// the INI / ENV variable.
107110
pub fn exception_profiling_first_rinit() {
111+
let exception_profiling = REQUEST_LOCALS.with(|cell| {
112+
cell.try_borrow()
113+
.map(|locals| locals.system_settings().profiling_exception_enabled)
114+
.unwrap_or(false)
115+
});
116+
117+
if !exception_profiling {
118+
return;
119+
}
120+
108121
let sampling_distance = REQUEST_LOCALS.with(|cell| {
109122
match cell.try_borrow() {
110123
Ok(locals) => locals.system_settings().profiling_exception_sampling_distance,
@@ -117,7 +130,7 @@ pub fn exception_profiling_first_rinit() {
117130

118131
EXCEPTION_PROFILING_INTERVAL.store(sampling_distance, Ordering::SeqCst);
119132

120-
info!("Exception profiling sampling distance initialized to {sampling_distance}");
133+
info!("Exception profiling initialized with sampling distance: {sampling_distance}");
121134
}
122135

123136
pub fn exception_profiling_mshutdown() {

profiling/tests/phpt/exceptions_01.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ echo 'Done.';
4040

4141
?>
4242
--EXPECTREGEX--
43-
.* Exception profiling sampling distance initialized to 20
43+
.* Exception profiling initialized with sampling distance: 20
4444
.* Sent stack sample of 2 frames, 1 labels with Exception RuntimeException to profiler.
4545
.*Done..*
4646
.*

profiling/tests/phpt/exceptions_zts_01.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ echo 'Done.';
5050

5151
?>
5252
--EXPECTREGEX--
53-
.* Exception profiling sampling distance initialized to 20
53+
.* Exception profiling initialized with sampling distance: 20
5454
.* Sent stack sample of 1 frames, 1 labels with Exception RuntimeException to profiler.
5555
.*Worker [0-9] exited
5656
.*Done..*

0 commit comments

Comments
 (0)