Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/prof_asan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ jobs:
set -eux
switch-php nts-asan
cd profiling
phpize
./configure --with-php-config="$(command -v php-config)"
export CARGO_TARGET_DIR=/tmp/build-cargo
export CC=clang-17
export CFLAGS='-fsanitize=address -fno-omit-frame-pointer'
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/prof_correctness.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ jobs:
sudo apt-get update
sudo apt install -y clang-17
cd profiling
phpize
./configure --with-php-config="$(command -v php-config)"
version_number=$(awk -F' = ' '$1 == "channel" { gsub(/"/, "", $2); print $2 }' rust-toolchain.toml)
curl https://sh.rustup.rs -sSf | sh -s -- --profile minimal -y --default-toolchain "$version_number"
cargo rustc --features="trigger_time_sample" --profile profiler-release --crate-type=cdylib
Expand Down
2 changes: 2 additions & 0 deletions .gitlab/build-profiler.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ else
fi

cd profiling
phpize
./configure --with-php-config="$(command -v php-config)"
CARGO_TARGET_DIR="${CARGO_TARGET_DIR:-target}"
echo "${CARGO_TARGET_DIR}"
if [ "$thread_safety" = "zts" ]; then
Expand Down
8 changes: 8 additions & 0 deletions .gitlab/generate-profiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,17 @@

- '# NTS'
- command -v switch-php && switch-php "${PHP_MAJOR_MINOR}"
- phpize
- ./configure --with-php-config="$(command -v php-config)"
- cargo build --profile profiler-release --all-features
- (cd ../; TEST_PHP_JUNIT="${CI_PROJECT_DIR}/artifacts/profiler-tests/nts-results.xml" php profiling/tests/run-tests.php -d "extension=/mnt/ramdisk/cargo/profiler-release/libdatadog_php_profiling.so" --show-diff -g "FAIL,XFAIL,BORK,WARN,LEAK,XLEAK,SKIP" "profiling/tests/phpt")

- touch build.rs #make sure `build.rs` gets executed after `switch-php` call

- '# ZTS'
- command -v switch-php && switch-php "${PHP_MAJOR_MINOR}-zts"
- phpize
- ./configure --with-php-config="$(command -v php-config)"
- cargo build --profile profiler-release --all-features
- (cd ../; TEST_PHP_JUNIT="${CI_PROJECT_DIR}/artifacts/profiler-tests/zts-results.xml" php profiling/tests/run-tests.php -d "extension=/mnt/ramdisk/cargo/profiler-release/libdatadog_php_profiling.so" --show-diff -g "FAIL,XFAIL,BORK,WARN,LEAK,XLEAK,SKIP" "profiling/tests/phpt")
after_script:
Expand Down Expand Up @@ -85,6 +89,8 @@
script:
- switch-php nts # not compatible with debug
- cd profiling
- phpize
- ./configure --with-php-config="$(command -v php-config)"
- sed -i -e "s/crate-type.*$/crate-type = [\"rlib\"]/g" Cargo.toml
- cargo clippy --all-targets --all-features -- -D warnings -Aunknown-lints

Expand All @@ -101,4 +107,6 @@
script:
- switch-php nts # not compatible with debug
- cd profiling
- phpize
- ./configure --with-php-config="$(command -v php-config)"
- cargo test --all-features
3 changes: 3 additions & 0 deletions benchmark/runall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ if [ "$SCENARIO" = "profiler" ]; then
# Run Profiling Benchmarks
cd ../profiling/

phpize
./configure --with-php-config="$(command -v php-config)"

cargo build --release --features trigger_time_sample

sirun benches/timeline.json > "$ARTIFACTS_DIR/sirun_timeline.ndjson"
Expand Down
18 changes: 18 additions & 0 deletions profiling/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/Makefile
/Makefile.objects
/Makefile.fragments
/aclocal.m4
/autom4te.cache/
/build/
/config.cache
/config.h
/config.h.in
/config.log
/config.nice
/config.status
/configure
/configure.ac
/libtool
/ltmain.sh
/modules/
/target/
59 changes: 59 additions & 0 deletions profiling/Makefile.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
DD_PROFILING_NAME = datadog-profiling
DD_PROFILING_MODULE = modules/$(DD_PROFILING_NAME).$(SHLIB_DL_SUFFIX_NAME)
DD_PROFILING_MODULE_LA = modules/$(DD_PROFILING_NAME).la

DD_PROFILING_CARGO_TARGET_DIR = $(top_builddir)/target

DD_PROFILING_UNAME_S := $(shell uname -s)
ifeq ($(DD_PROFILING_UNAME_S),Darwin)
DD_PROFILING_RUST_EXT = dylib
else
DD_PROFILING_RUST_EXT = so
endif

DD_PROFILING_RUST_LIB = $(DD_PROFILING_CARGO_TARGET_DIR)/$(DD_PROFILING_CARGO_PROFILE)/libdatadog_php_profiling.$(DD_PROFILING_RUST_EXT)
DD_PROFILING_CARGO_FEATURES_CLEAN = $(shell echo "$(DD_PROFILING_CARGO_FEATURES)" | tr ',' ' ')

.PHONY: cargo-test clean distclean clean-profiling distclean-profiling

PHP_MODULES += $(DD_PROFILING_MODULE_LA)
all: $(DD_PROFILING_MODULE_LA)

$(DD_PROFILING_RUST_LIB): $(top_builddir)/Makefile $(top_builddir)/config.h
@echo "Building Rust profiler ($(DD_PROFILING_CARGO_PROFILE))"
@CARGO_TARGET_DIR="$(DD_PROFILING_CARGO_TARGET_DIR)" \
PHP_INCLUDES="$(INCLUDES)" \
PHP_INCLUDE_DIR="$(phpincludedir)" \
PHP_PREFIX="$(prefix)" \
PHP_VERSION_ID="$(DATADOG_PHP_VERSION_ID)" \
$(DD_PROFILING_CARGO) build --manifest-path "$(top_srcdir)/Cargo.toml" $(DD_PROFILING_CARGO_ARGS) $(if $(DD_PROFILING_CARGO_FEATURES_CLEAN),--features "$(DD_PROFILING_CARGO_FEATURES_CLEAN)",)

$(DD_PROFILING_MODULE): $(DD_PROFILING_RUST_LIB)
@mkdir -p modules
@cp -f "$(DD_PROFILING_RUST_LIB)" "$@"

$(DD_PROFILING_MODULE_LA): $(DD_PROFILING_MODULE)
@printf "dlname='%s'\n" "$(DD_PROFILING_NAME).$(SHLIB_DL_SUFFIX_NAME)" > "$@"

cargo-test:
@CARGO_TARGET_DIR="$(DD_PROFILING_CARGO_TARGET_DIR)" \
PHP_INCLUDES="$(INCLUDES)" \
PHP_INCLUDE_DIR="$(phpincludedir)" \
PHP_PREFIX="$(prefix)" \
PHP_VERSION_ID="$(DATADOG_PHP_VERSION_ID)" \
$(DD_PROFILING_CARGO) test --manifest-path "$(top_srcdir)/Cargo.toml" $(if $(DD_PROFILING_CARGO_FEATURES_CLEAN),--features "$(DD_PROFILING_CARGO_FEATURES_CLEAN)",)

clean: clean-profiling

clean-profiling:
@rm -f "$(DD_PROFILING_MODULE)"
@# Only cleans the profiler crate; dependencies remain cached.
@$(DD_PROFILING_CARGO) clean -p datadog-php-profiling

distclean: distclean-profiling

distclean-profiling:
@rm -rf "$(DD_PROFILING_CARGO_TARGET_DIR)"
@rm -rf build autom4te.cache modules
@rm -f configure configure.ac config.h config.h.in config.nice run-tests.php
@rm -f *~ *.orig
64 changes: 64 additions & 0 deletions profiling/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,70 @@ allows us to gloss over minor differences in const-correctness in the engine
definitions across versions, as well as provide more idiomatic types in some
cases where they are ABI compatible.

### Phpize build (recommended for installs)

From the `profiling/` directory, use the normal extension build flow:

```sh
# Choose the PHP version to build against
export PATH="/opt/php/8.4/bin:$PATH"

phpize
./configure
make
make install
```

This builds `modules/datadog-profiling.so` and installs it into the PHP
extension directory reported by `php-config --extension-dir`.

To build with the Cargo debug profile:

```sh
./configure --enable-datadog-profiling-debug
```

To enable specific Cargo features:

```sh
./configure --with-datadog-profiling-cargo-features="stack_walking_tests,trigger_time_sample"
```

To run the PHPT tests with the built extension:

```sh
make test
```

To suppress the failure report prompt:

```sh
NO_INTERACTION=1 make test
```

To show diffs on failure, or to run tests in parallel, pass flags via `TESTS`:

```sh
make test TESTS="--show-diff -j8 tests/phpt"
```

To run tests in parallel on newer PHP versions (PHP 8.0+ supports `-j`):

```sh
make test TESTS="-j8 tests/phpt"
```

Note: direct `cargo build` expects you to have run `phpize` and
`./configure` so `build.rs` can read PHP settings from the generated
`Makefile`.

If you want to run cargo commands and want to reuse artifacts from the phpize
flow, run it with the same target directory:

```sh
CARGO_TARGET_DIR=target cargo build --release
```

## Testing

The command `cargo test` will run the tests on the profiler. To also run the
Expand Down
Loading
Loading