Skip to content

feat(profiling) allocation profiling for PHP ZTS #2506

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

Merged
merged 12 commits into from
Mar 20, 2024
Merged
5 changes: 3 additions & 2 deletions profiling/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

The profiler is implemented in Rust. To see the currently required Rust
version, refer to the [rust-toolchain](rust-toolchain) file. The profiler
requires PHP 7.1+, and does not support debug nor ZTS builds. There are bits of
ZTS support in the build system and profiler, but it's not complete.
requires PHP 7.1+, and does not support debug builds. There are bits of ZTS
support in the build system and profiler, but it's not complete, consider the
current state of ZTS support beta.

## Time Profiling

Expand Down
439 changes: 239 additions & 200 deletions profiling/src/allocation.rs

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions profiling/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ extern "C" fn minit(_type: c_int, module_number: c_int) -> ZendResult {
unsafe { zend::zend_register_extension(&extension, handle) };

#[cfg(feature = "allocation_profiling")]
allocation::allocation_profiling_minit();
allocation::alloc_prof_minit();

#[cfg(feature = "timeline")]
timeline::timeline_minit();
Expand Down Expand Up @@ -369,8 +369,8 @@ thread_local! {
/// The tags for this thread/request. These get sent to other threads,
/// which is why they are Arc. However, they are wrapped in a RefCell
/// because the values _can_ change from request to request depending on
/// the on the values sent in the SAPI for env, service, version, etc.
/// They get reset at the end of the request.
/// the values sent in the SAPI for env, service, version, etc. They get
/// reset at the end of the request.
static TAGS: RefCell<Arc<Vec<Tag>>> = RefCell::new(Arc::new(Vec::new()));
}

Expand Down Expand Up @@ -541,7 +541,7 @@ extern "C" fn rinit(_type: c_int, _module_number: c_int) -> ZendResult {
}

#[cfg(feature = "allocation_profiling")]
allocation::allocation_profiling_rinit();
allocation::alloc_prof_rinit();

// SAFETY: called after config is initialized.
#[cfg(feature = "timeline")]
Expand Down Expand Up @@ -599,7 +599,7 @@ extern "C" fn rshutdown(_type: c_int, _module_number: c_int) -> ZendResult {
});

#[cfg(feature = "allocation_profiling")]
allocation::allocation_profiling_rshutdown();
allocation::alloc_prof_rshutdown();

ZendResult::Success
}
Expand Down Expand Up @@ -843,7 +843,7 @@ extern "C" fn startup(extension: *mut ZendExtension) -> ZendResult {
}

#[cfg(feature = "allocation_profiling")]
allocation::allocation_profiling_startup();
allocation::alloc_prof_startup();

ZendResult::Success
}
Expand Down
4 changes: 2 additions & 2 deletions profiling/src/pcntl.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::allocation::allocation_profiling_rshutdown;
use crate::allocation::alloc_prof_rshutdown;
use crate::bindings::{
datadog_php_install_handler, datadog_php_zif_handler, zend_execute_data, zend_long, zval,
InternalFunctionHandler,
Expand Down Expand Up @@ -94,7 +94,7 @@ fn stop_and_forget_profiling(maybe_profiler: &mut Option<Profiler>) {
swap(&mut *maybe_profiler, &mut old_profiler);
forget(old_profiler);

allocation_profiling_rshutdown();
alloc_prof_rshutdown();

// Reset some global state to prevent further profiling and to not handle
// any pending interrupts.
Expand Down
5 changes: 0 additions & 5 deletions profiling/tests/phpt/jit_01.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ if (!extension_loaded('datadog-profiling'))
$arch = php_uname('m');
if (PHP_VERSION_ID < 80100 && in_array($arch, ['aarch64', 'arm64']))
echo "skip: JIT not available on aarch64 on PHP 8.0", PHP_EOL;

// TODO: remove once ZTS support for allocation profiling is done
if (PHP_ZTS) {
echo "skip: not support on ZTS builds at the moment";
}
?>
--INI--
datadog.profiling.enabled=yes
Expand Down
6 changes: 0 additions & 6 deletions profiling/tests/phpt/jit_02.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ if (!extension_loaded('datadog-profiling'))
$arch = php_uname('m');
if (PHP_VERSION_ID < 80100 && in_array($arch, ['aarch64', 'arm64']))
echo "skip: JIT not available on aarch64 on PHP 8.0", PHP_EOL;

// TODO: remove once ZTS support for allocation profiling is done
if (PHP_ZTS) {
echo "skip: not support on ZTS builds at the moment";
}

?>
--INI--
datadog.profiling.enabled=yes
Expand Down
5 changes: 0 additions & 5 deletions profiling/tests/phpt/phpinfo_02.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ if (!extension_loaded('datadog-profiling'))
$arch = php_uname('m');
if (PHP_VERSION_ID < 80100 && in_array($arch, ['aarch64', 'arm64']))
echo "skip: JIT not available on aarch64 on PHP 8.0", PHP_EOL;

// TODO: remove once ZTS support for allocation profiling is done
if (PHP_ZTS) {
echo "skip: not support on ZTS builds at the moment";
}
?>
--ENV--
DD_PROFILING_ENABLED=yes
Expand Down
Loading