-
Notifications
You must be signed in to change notification settings - Fork 164
fix(prof) follow PHP globals model #3175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #3175 +/- ##
============================================
+ Coverage 76.38% 79.28% +2.89%
Complexity 2948 2948
============================================
Files 145 118 -27
Lines 16076 11633 -4443
Branches 1107 0 -1107
============================================
- Hits 12280 9223 -3057
+ Misses 3221 2410 -811
+ Partials 575 0 -575
Flags with carried forward coverage won't be shown. Click here to find out more. see 27 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
Benchmarks [ profiler ]Benchmark execution time: 2025-04-30 15:30:46 Comparing candidate commit 2bdc1c9 in PR branch Found 0 performance improvements and 2 performance regressions! Performance is the same for 29 metrics, 5 unstable metrics. scenario:walk_stack/50
scenario:walk_stack/99
|
71e58f0
to
386c78f
Compare
386c78f
to
43c1d6f
Compare
4b03225
to
779fa59
Compare
f0bb47f
to
d09de99
Compare
2761ecd
to
f5f42c9
Compare
f5f42c9
to
003c3cf
Compare
6a09629
to
5315484
Compare
845c6ea
to
6379bcb
Compare
6379bcb
to
37a3256
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would still give a panic at the place we want, while not having string duplication. Linters (or maybe the compiler?) don't like panic having a constant as a format string, likes string literals.
diff --git a/profiling/src/allocation/mod.rs b/profiling/src/allocation/mod.rs
index 58437ebb9..e00158324 100644
--- a/profiling/src/allocation/mod.rs
+++ b/profiling/src/allocation/mod.rs
@@ -78,36 +78,41 @@ struct ZendMMState {
shutdown: unsafe fn(bool, bool),
}
-unsafe fn alloc_prof_panic_alloc(_len: size_t) -> *mut c_void {
+#[track_caller]
+fn init_panic() -> ! {
panic!("Allocation profiler was not initialised properly. Please fill an issue stating the PHP version and the backtrace from this panic.");
}
+unsafe fn alloc_prof_panic_alloc(_len: size_t) -> *mut c_void {
+ init_panic();
+}
+
unsafe fn alloc_prof_panic_realloc(_prev_ptr: *mut c_void, _len: size_t) -> *mut c_void {
- panic!("Allocation profiler was not initialised properly. Please fill an issue stating the PHP version and the backtrace from this panic.");
+ init_panic();
}
unsafe fn alloc_prof_panic_free(_ptr: *mut c_void) {
- panic!("Allocation profiler was not initialised properly. Please fill an issue stating the PHP version and the backtrace from this panic.");
+ init_panic();
}
#[cfg(php_zend_mm_set_custom_handlers_ex)]
unsafe fn alloc_prof_panic_gc() -> size_t {
- panic!("Allocation profiler was not initialised properly. Please fill an issue stating the PHP version and the backtrace from this panic.");
+ init_panic();
}
#[cfg(php_zend_mm_set_custom_handlers_ex)]
unsafe fn alloc_prof_panic_shutdown(_full: bool, _silent: bool) {
- panic!("Allocation profiler was not initialised properly. Please fill an issue stating the PHP version and the backtrace from this panic.");
+ init_panic();
}
#[cfg(not(php_zend_mm_set_custom_handlers_ex))]
fn prepare_zend_heap_panic(_heap: *mut zend::_zend_mm_heap) -> c_int {
- panic!("Allocation profiler was not initialised properly. Please fill an issue stating the PHP version and the backtrace from this panic.");
+ init_panic();
}
#[cfg(not(php_zend_mm_set_custom_handlers_ex))]
fn restore_zend_heap_panic(_heap: *mut zend::_zend_mm_heap, _custom_heap: c_int) {
- panic!("Allocation profiler was not initialised properly. Please fill an issue stating the PHP version and the backtrace from this panic.");
+ init_panic();
}
impl ZendMMState {
I've committed your suggestion |
Description
Since supporting ZTS versions of PHP, we started storing our profiler state in TLS (thread local storage). The assumption was that in PHP ZTS this would store the state per thread and helped us support ZTS PHP, while in NTS it would still store state in a TLS variable, but as there is only one thread, what gives!
Now it turns out there is at least one extension out there which does the following:
\extension\namespace\do_somthing()
functionEven though what that extension is doing is a race condition and violates thread safety, we should still not crash. Basically what the allocation profiler did was to make a race condition that might crash super seldom into a 100% guaranteed crash 😜
PROF-11471
Reviewer checklist