Skip to content

Commit 446a8d9

Browse files
Merge branch 'master' into florian/heap-live-profiling
2 parents 703fec2 + c05c43c commit 446a8d9

8 files changed

Lines changed: 262 additions & 44 deletions

File tree

Cargo.lock

Lines changed: 55 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/signals.c

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,24 @@ const ddog_CharSlice PHP_OPCACHE_ENABLE = DDOG_CHARSLICE_C("php.opcache.enable")
183183
// Fetches certain opcache tags and adds them with the pattern of php.opcache.*.
184184
static void dd_crasht_add_opcache_inis(ddog_Vec_Tag *tags) {
185185
#if PHP_VERSION_ID >= 80000
186-
// We'll push php.opcache.enabled:0 whenever we detect we're disabled.
187-
188186
bool loaded = zend_get_extension("Zend OPcache");
189187
if (UNEXPECTED(!loaded)) {
190188
goto opcache_disabled;
191189
}
192190

191+
// The CLI SAPI has an additional configuration for being enabled. This is
192+
// INI_SYSTEM so we can check it here.
193+
bool is_cli_sapi = strcmp("cli", sapi_module.name) == 0;
194+
if (is_cli_sapi) {
195+
ddog_CharSlice tag = DDOG_CHARSLICE_C("php.opcache.enable_cli");
196+
zend_string *value = dd_crasht_find_ini_by_tag(tag);
197+
if (EXPECTED(value)) {
198+
bool is_enabled = zend_ini_parse_bool(value);
199+
ddog_CharSlice val = is_enabled ? ONE : ZERO;
200+
dd_crasht_push_tag(tags, tag, val);
201+
}
202+
}
203+
193204
// opcache.jit_buffer_size is INI_SYSTEM, so we can check it now. If it's
194205
// zero, then JIT won't operate.
195206
{
@@ -209,25 +220,6 @@ static void dd_crasht_add_opcache_inis(ddog_Vec_Tag *tags) {
209220
? dd_zend_string_to_CharSlice(value)
210221
: ZERO;
211222
dd_crasht_push_tag(tags, tag, val);
212-
if (UNEXPECTED(!is_positive)) {
213-
goto opcache_disabled;
214-
}
215-
}
216-
}
217-
218-
// The CLI SAPI has an additional configuration for being enabled. This is
219-
// INI_SYSTEM so we can check it here.
220-
bool is_cli_sapi = strcmp("cli", sapi_module.name) == 0;
221-
if (is_cli_sapi) {
222-
ddog_CharSlice tag = DDOG_CHARSLICE_C("php.opcache.enable_cli");
223-
zend_string *value = dd_crasht_find_ini_by_tag(tag);
224-
if (EXPECTED(value)) {
225-
bool is_enabled = zend_ini_parse_bool(value);
226-
ddog_CharSlice val = is_enabled ? ONE : ZERO;
227-
dd_crasht_push_tag(tags, tag, val);
228-
if (UNEXPECTED(!is_enabled)) {
229-
goto opcache_disabled;
230-
}
231223
}
232224
}
233225

profiling/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ cpu-time = { version = "1.0" }
2323
chrono = { version = "0.4" }
2424
crossbeam-channel = { version = "0.5", default-features = false, features = ["std"] }
2525
dashmap = { version = "6.1" }
26+
dynasmrt = "2.0"
2627
http = { version = "1.4" }
2728
libdd-alloc = { path = "../libdatadog/libdd-alloc" }
2829
libdd-profiling = { path = "../libdatadog/libdd-profiling" }

profiling/build.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ fn main() {
3636
let post_startup_cb = cfg_post_startup_cb(vernum);
3737
let preload = cfg_preload(vernum);
3838
let fibers = cfg_fibers(vernum);
39+
let frameless = cfg_frameless(vernum);
3940
let run_time_cache = cfg_run_time_cache(vernum);
4041
let trigger_time_sample = cfg_trigger_time_sample();
4142
let zend_error_observer = cfg_zend_error_observer(vernum);
@@ -47,6 +48,7 @@ fn main() {
4748
preload,
4849
run_time_cache,
4950
fibers,
51+
frameless,
5052
trigger_time_sample,
5153
zend_error_observer,
5254
);
@@ -104,6 +106,7 @@ fn build_zend_php_ffis(
104106
preload: bool,
105107
run_time_cache: bool,
106108
fibers: bool,
109+
frameless: bool,
107110
trigger_time_sample: bool,
108111
zend_error_observer: bool,
109112
) {
@@ -144,6 +147,7 @@ fn build_zend_php_ffis(
144147
let post_startup_cb = if post_startup_cb { "1" } else { "0" };
145148
let preload = if preload { "1" } else { "0" };
146149
let fibers = if fibers { "1" } else { "0" };
150+
let frameless = if frameless { "1" } else { "0" };
147151
let run_time_cache = if run_time_cache { "1" } else { "0" };
148152
let trigger_time_sample = if trigger_time_sample { "1" } else { "0" };
149153
let zend_error_observer = if zend_error_observer { "1" } else { "0" };
@@ -160,6 +164,7 @@ fn build_zend_php_ffis(
160164
.define("CFG_POST_STARTUP_CB", post_startup_cb)
161165
.define("CFG_PRELOAD", preload)
162166
.define("CFG_FIBERS", fibers)
167+
.define("CFG_FRAMELESS", frameless)
163168
.define("CFG_RUN_TIME_CACHE", run_time_cache)
164169
.define("CFG_STACK_WALKING_TESTS", stack_walking_tests)
165170
.define("CFG_TRIGGER_TIME_SAMPLE", trigger_time_sample)
@@ -374,6 +379,16 @@ fn cfg_fibers(vernum: u64) -> bool {
374379
}
375380
}
376381

382+
fn cfg_frameless(vernum: u64) -> bool {
383+
println!("cargo::rustc-check-cfg=cfg(php_frameless)");
384+
if vernum >= 80400 {
385+
println!("cargo:rustc-cfg=php_frameless");
386+
true
387+
} else {
388+
false
389+
}
390+
}
391+
377392
fn cfg_php_feature_flags(vernum: u64) {
378393
println!("cargo::rustc-check-cfg=cfg(php_gc_status, php_zend_compile_string_has_position, php_gc_status_extended, php_frameless, php_opcache_restart_hook, php_zend_mm_set_custom_handlers_ex)");
379394

@@ -387,7 +402,6 @@ fn cfg_php_feature_flags(vernum: u64) {
387402
println!("cargo:rustc-cfg=php_gc_status_extended");
388403
}
389404
if vernum >= 80400 {
390-
println!("cargo:rustc-cfg=php_frameless");
391405
println!("cargo:rustc-cfg=php_opcache_restart_hook");
392406
println!("cargo:rustc-cfg=php_zend_mm_set_custom_handlers_ex");
393407
}

profiling/src/php_ffi.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ bool ddog_php_prof_is_post_startup(void) {
121121
static post_startup_cb_result (*orig_post_startup_cb)(void) = NULL;
122122

123123
static post_startup_cb_result ddog_php_prof_post_startup_cb(void) {
124+
#if CFG_FRAMELESS
125+
ddog_php_prof_post_startup(); // before preload+JIT (which may hardcode the flf handlers)
126+
#endif
127+
124128
if (orig_post_startup_cb) {
125129
post_startup_cb_result (*cb)(void) = orig_post_startup_cb;
126130

@@ -557,9 +561,6 @@ void ddog_php_test_free_fake_zend_function(zend_function *func) {
557561
free(func);
558562
}
559563

560-
// Stub for zend_flf_functions (PHP 8.4+ frameless calls) to allow tests to link
561-
// without the real PHP runtime. The test doesn't exercise frameless code paths.
562-
__attribute__((weak)) zend_function **zend_flf_functions;
563564
#endif // CFG_STACK_WALKING_TESTS || CFG_TEST
564565

565566
void *opcache_handle = NULL;

profiling/src/php_ffi.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ void ddog_php_prof_zend_mm_set_custom_handlers(zend_mm_heap *heap,
163163

164164
zend_execute_data* ddog_php_prof_get_current_execute_data();
165165

166+
#if CFG_FRAMELESS
167+
void ddog_php_prof_post_startup();
168+
#endif
169+
166170
#if CFG_FIBERS
167171
zend_fiber* ddog_php_prof_get_active_fiber();
168172
zend_fiber* ddog_php_prof_get_active_fiber_test();

0 commit comments

Comments
 (0)