@@ -9,10 +9,14 @@ use std::sync::atomic::Ordering;
99
1010use 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.
1315static 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.
1620pub 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.
107110pub 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
123136pub fn exception_profiling_mshutdown ( ) {
0 commit comments