diff --git a/.github/workflows/prof_asan.yml b/.github/workflows/prof_asan.yml index 8b7ce23b3e..3d85001f6e 100644 --- a/.github/workflows/prof_asan.yml +++ b/.github/workflows/prof_asan.yml @@ -59,17 +59,11 @@ jobs: /tmp/build-cargo/ key: ${{ runner.os }}-cargo-asan-${{ hashFiles('**/Cargo.lock') }} - - name: Fix kernel mmap rnd bits - # Asan in llvm 14 provided in ubuntu 22.04 is incompatible with - # high-entropy ASLR in much newer kernels that GitHub runners are - # using leading to random crashes: https://reviews.llvm.org/D148280 - # https://github.com/actions/runner-images/issues/9491#issuecomment-1989718917 - run: sysctl vm.mmap_rnd_bits=28 - - name: Run phpt tests run: | set -eux switch-php nts-asan cd profiling/tests cp -v $(php-config --prefix)/lib/php/build/run-tests.php . + export DD_PROFILING_OUTPUT_PPROF=/tmp/pprof php run-tests.php --show-diff --asan -d extension=datadog-profiling.so phpt diff --git a/Cargo.lock b/Cargo.lock index 699cb4d2df..e36762670e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1926,6 +1926,7 @@ dependencies = [ "datadog-trace-protobuf", "ddcommon 0.0.1", "http 0.2.11", + "hyper 0.14.28", "serde", "tracing", ] diff --git a/profiling/src/lib.rs b/profiling/src/lib.rs index d3232c2898..a7b4aa3257 100644 --- a/profiling/src/lib.rs +++ b/profiling/src/lib.rs @@ -93,18 +93,27 @@ lazy_static! { /// The Server API the profiler is running under. static ref SAPI: Sapi = { - // Safety: sapi_module is initialized before minit and there should be - // no concurrent threads. - let sapi_module = unsafe { zend::sapi_module }; - if sapi_module.name.is_null() { - panic!("the sapi_module's name is a null pointer"); - } + #[cfg(not(test))] + { + // Safety: sapi_module is initialized before minit and there should be + // no concurrent threads. + let sapi_module = unsafe { zend::sapi_module }; + if sapi_module.name.is_null() { + panic!("the sapi_module's name is a null pointer"); + } - // Safety: value has been checked for NULL; I haven't checked that the - // engine ensures its length is less than `isize::MAX`, but it is a - // risk I'm willing to take. - let sapi_name = unsafe { CStr::from_ptr(sapi_module.name) }; - Sapi::from_name(sapi_name.to_string_lossy().as_ref()) + // Safety: value has been checked for NULL; I haven't checked that the + // engine ensures its length is less than `isize::MAX`, but it is a + // risk I'm willing to take. + let sapi_name = unsafe { CStr::from_ptr(sapi_module.name) }; + Sapi::from_name(sapi_name.to_string_lossy().as_ref()) + } + // When running `cargo test` we do not link against PHP, so `zend::sapi_name` is not + // available and we just return `Sapi::Unkown` + #[cfg(test)] + { + Sapi::Unknown + } }; // Safety: PROFILER_NAME is a byte slice that satisfies the safety requirements. diff --git a/profiling/src/profiling/mod.rs b/profiling/src/profiling/mod.rs index 9b59d4fd9c..75f3e4e7ca 100644 --- a/profiling/src/profiling/mod.rs +++ b/profiling/src/profiling/mod.rs @@ -7,6 +7,7 @@ mod uploader; pub use interrupts::*; pub use sample_type_filter::*; pub use stack_walking::*; +use thread_utils::get_current_thread_name; use uploader::*; #[cfg(all(php_has_fibers, not(test)))] @@ -1145,12 +1146,17 @@ impl Profiler { /// * `n_extra_labels` - Reserve room for extra labels, such as when the /// caller adds gc or exception labels. fn common_labels(n_extra_labels: usize) -> Vec