Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
NoiseByNorthwest committed Sep 22, 2024
1 parent b9dd4c2 commit 3a5f39b
Show file tree
Hide file tree
Showing 16 changed files with 387 additions and 222 deletions.
269 changes: 161 additions & 108 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,113 +14,166 @@ on:
- master

jobs:
build:
name: build / php-${{ matrix.php }}-${{ matrix.ts }}-${{ matrix.name }}-${{ matrix.compiler }}

runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
php: [ '5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3' ]

name:
- linux
- debian
- mac

include:
# Linux
- { name: linux, ts: 'nts', compiler: 'gcc', os: ubuntu-20.04 }
# Debian (docker)
- { name: debian, ts: 'nts', compiler: 'gcc', os: ubuntu-20.04 }
# macOS
- { name: mac, ts: 'nts', compiler: 'clang', os: macos-12 }

steps:
- uses: actions/checkout@v3

# configure spx artifact name in next format:
# {php}-{ts}-{os.name}-{compiler}
# spx-php-8.1-nts-linux-gcc
- name: Set artifact name
id: setup-artifact
run: |
echo "spx_file_name=spx-php-${{ matrix.php }}-${{ matrix.ts }}-${{ matrix.name }}-${{ matrix.compiler }}" >> $GITHUB_OUTPUT
- name: Build extension for Ubuntu and macOS
if: matrix.name != 'debian'
uses: ./.github/workflows/build-linux-mac-ext

- name: Build extension for Debian using docker
if: matrix.name == 'debian' && matrix.php != '5.4' && matrix.php != '5.5'
uses: ./.github/workflows/build-debian-ext

- name: Upload build artifacts after Failure
if: failure()
uses: actions/upload-artifact@v3
with:
name: debug-${{ steps.setup-artifact.outputs.spx_file_name }}
path: |
${{ github.workspace }}/*.log
${{ github.workspace }}/tests/*.log
retention-days: 7

- name: Create ZIP archive with build artifact
run: |
zip -rvj ${{ steps.setup-artifact.outputs.spx_file_name }}.zip \
./modules/spx.so LICENSE $ZIP_EXCLUDE
zip -rv ${{ steps.setup-artifact.outputs.spx_file_name }}.zip \
./assets $ZIP_EXCLUDE
env:
ZIP_EXCLUDE: -x ".*" -x "__MACOSX" -x "*.DS_Store"

- name: Check Release notes
run: |
echo "-- Parsing Release Notes from CHANGELOG"
./.github/release-notes.sh ./CHANGELOG.md
- name: Upload build artifact
uses: actions/upload-artifact@v3
with:
name: ${{ steps.setup-artifact.outputs.spx_file_name }}.zip
path: ${{ steps.setup-artifact.outputs.spx_file_name }}.zip

release:
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')

needs: [ build ]
name: Create Release
runs-on: ubuntu-20.04

# build:
# name: build / php-${{ matrix.php }}-${{ matrix.ts }}-${{ matrix.name }}-${{ matrix.compiler }}

# runs-on: ${{ matrix.os }}
# strategy:
# fail-fast: false
# matrix:
# php: [ '5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3' ]

# name:
# - linux
# - debian
# - mac

# include:
# # Linux
# - { name: linux, ts: 'nts', compiler: 'gcc', os: ubuntu-20.04 }
# # Debian (docker)
# - { name: debian, ts: 'nts', compiler: 'gcc', os: ubuntu-20.04 }
# # macOS
# - { name: mac, ts: 'nts', compiler: 'clang', os: macos-12 }

# steps:
# - uses: actions/checkout@v3

# # configure spx artifact name in next format:
# # {php}-{ts}-{os.name}-{compiler}
# # spx-php-8.1-nts-linux-gcc
# - name: Set artifact name
# id: setup-artifact
# run: |
# echo "spx_file_name=spx-php-${{ matrix.php }}-${{ matrix.ts }}-${{ matrix.name }}-${{ matrix.compiler }}" >> $GITHUB_OUTPUT

# - name: Build extension for Ubuntu and macOS
# if: matrix.name != 'debian'
# uses: ./.github/workflows/build-linux-mac-ext

# - name: Build extension for Debian using docker
# if: matrix.name == 'debian' && matrix.php != '5.4' && matrix.php != '5.5'
# uses: ./.github/workflows/build-debian-ext

# - name: Upload build artifacts after Failure
# if: failure()
# uses: actions/upload-artifact@v3
# with:
# name: debug-${{ steps.setup-artifact.outputs.spx_file_name }}
# path: |
# ${{ github.workspace }}/*.log
# ${{ github.workspace }}/tests/*.log
# retention-days: 7

# - name: Create ZIP archive with build artifact
# run: |
# zip -rvj ${{ steps.setup-artifact.outputs.spx_file_name }}.zip \
# ./modules/spx.so LICENSE $ZIP_EXCLUDE
# zip -rv ${{ steps.setup-artifact.outputs.spx_file_name }}.zip \
# ./assets $ZIP_EXCLUDE
# env:
# ZIP_EXCLUDE: -x ".*" -x "__MACOSX" -x "*.DS_Store"

# - name: Check Release notes
# run: |
# echo "-- Parsing Release Notes from CHANGELOG"
# ./.github/release-notes.sh ./CHANGELOG.md

# - name: Upload build artifact
# uses: actions/upload-artifact@v3
# with:
# name: ${{ steps.setup-artifact.outputs.spx_file_name }}.zip
# path: ${{ steps.setup-artifact.outputs.spx_file_name }}.zip

# build-win-old:
# # FIXME this hacky pipeline will be cleaned later
# runs-on: windows-latest
# steps:
# - name: Install zlib
# run: |
# vcpkg.exe install zlib
# - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
# - uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1.13.0
# - name: Setup PHP SDK with Developer Pack
# uses: zephir-lang/setup-php-sdk@fd5f1bce00956a7e8ac30faaa1ff0692d6dacdfb # v1.0
# with:
# php_version: '8.3'
# ts: 'nts'
# msvc: 'vs16'
# arch: 'x64'
# install_dir: 'C:\tools'
# cache_dir: 'C:\Temp'
# - name: Clone PHP-src
# run: |
# git clone https://github.com/php/php-src.git C:\php-src
# - name: Copy SPX to PHP-src ext directory
# run: |
# xcopy /e /k /h /i . C:\php-src\ext\php-spx
# - name: Configure and build 1
# run: |
# cd C:\php-src
# ./buildconf.bat
# - name: Configure and build 2
# run: |
# cd C:\php-src
# ./configure --help
# ./configure --disable-all --enable-cli --enable-spx
# - name: Configure and build 3
# run: |
# cd C:\php-src
# nmake

build-win:
runs-on: windows-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
fetch-depth: 1

- name: Get the release version
id: get-version
run: |
echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
- name: Download SPX build artifacts
id: download
uses: actions/[email protected]
with:
path: ./build-artifacts

- name: Prepare Release notes
run: |
echo "-- Creating Release Notes"
./.github/release-notes.sh ./CHANGELOG.md > ./release-notes.md
- name: Create Release
uses: ncipollo/release-action@v1
- name: Build the extension
uses: php/php-windows-builder/extension@5106db21e6a35781bff937be3c9e1e56d7b17789
with:
token: ${{ secrets.GITHUB_TOKEN }}
name: ${{ steps.get-version.outputs.version }}
tag: ${{ steps.get-version.outputs.version }}
bodyFile: "./release-notes.md"
allowUpdates: true
artifacts: "./build-artifacts/*/*.zip"
artifactContentType: application/octet-stream
#extension-url: https://github.com/xdebug/xdebug
#extension-ref: '3.3.1'
php-version: '8.3'
ts: nts
run-tests: false
arch: x64
args: --enable-spx
libs: zlib

# release:
# if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')

# needs: [ build ]
# name: Create Release
# runs-on: ubuntu-20.04

# steps:
# - name: Checkout Code
# uses: actions/checkout@v3
# with:
# fetch-depth: 1

# - name: Get the release version
# id: get-version
# run: |
# echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT

# - name: Download SPX build artifacts
# id: download
# uses: actions/[email protected]
# with:
# path: ./build-artifacts

# - name: Prepare Release notes
# run: |
# echo "-- Creating Release Notes"
# ./.github/release-notes.sh ./CHANGELOG.md > ./release-notes.md

# - name: Create Release
# uses: ncipollo/release-action@v1
# with:
# token: ${{ secrets.GITHUB_TOKEN }}
# name: ${{ steps.get-version.outputs.version }}
# tag: ${{ steps.get-version.outputs.version }}
# bodyFile: "./release-notes.md"
# allowUpdates: true
# artifacts: "./build-artifacts/*/*.zip"
# artifactContentType: application/octet-stream
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Build Status][:badge-ci:]][:link-ci:]
![Supported PHP versions: 5.4 .. 8.x][:badge-php-versions:]
![Supported platforms: GNU/Linux, macOS & FreeBSD][:badge-supported-platforms:]
![Supported platforms: Linux, macOS, FreeBSD & Windows][:badge-supported-platforms:]
![Supported architectures: x86-64 or ARM64][:badge-supported-arch:]
[![License][:badge-license:]][:link-license:]

Expand Down Expand Up @@ -34,12 +34,8 @@ It differentiates itself from other similar extensions as being:

## Requirements

Platforms support is currently quite limited. Feel free to open an issue if your platform is not supported.
Current requirements are:

* x86-64 or ARM64
* **GNU/Linux**, **macOS** or **FreeBSD**
* zlib dev package (e.g. zlib1g-dev on Debian based distros)
* **Linux**, **macOS**, **FreeBSD** or **Windows**
* PHP 5.4 to 8.3

## Installation
Expand All @@ -66,6 +62,12 @@ sudo make install
Then add `extension=spx.so` to your *php.ini*, or in a dedicated *spx.ini* file created within the include directory.
You may also want to override [default SPX configuration](#configuration) to be able to profile a web request, with [this one](#private-environment) for example for a local development environment.

### Windows

Windows is supported, with these extra limitations:
- live update of flat profile in CLI (`SPX_FP_LIVE=1`) is not supported.

Also, consider Windows support as still being in beta.

### ZTS PHP (multi-thread)

Expand All @@ -78,7 +80,7 @@ Also, consider ZTS PHP support as still being in beta.

### Linux, PHP-FPM & I/O stats

On GNU/Linux, SPX uses procfs (i.e. by reading files under `/proc` directory) to get some stats for the current process or thread. This is what is done under the hood when you select at least one of these metrics: `mor`, `io`, `ior` or `iow`.
On Linux, SPX uses procfs (i.e. by reading files under `/proc` directory) to get some stats for the current process or thread. This is what is done under the hood when you select at least one of these metrics: `mor`, `io`, `ior` or `iow`.

But, on most PHP-FPM setups, you will have a permission issue preventing SPX to open a file under `/proc/self` directory.
This is due to the fact that PHP-FPM master process runs as root when child processes run as another unprivileged user.
Expand Down Expand Up @@ -315,7 +317,7 @@ Here is the list of available metrics to collect. By default only _Wall time_ an

_\*: Allocated and freed byte counts will not be collected if you use a custom allocator or if you force the libc one through the `USE_ZEND_ALLOC` environment variable set to `0`._

_\*\*: RSS & I/O metrics are not supported on macOS and FreeBSD. On GNU/Linux you should [read this if you use PHP-FPM](#linux-php-fpm--io-stats)._
_\*\*: RSS & I/O metrics are not supported on macOS and FreeBSD. On Linux you should [read this if you use PHP-FPM](#linux-php-fpm--io-stats)._

### Command line script

Expand Down Expand Up @@ -504,7 +506,7 @@ See the [LICENSE][:link-license:] file for more information.
[:link-ci:]: https://github.com/NoiseByNorthwest/php-spx/actions/workflows/main.yml

[:badge-php-versions:]: https://img.shields.io/badge/php-5.4--8.3-blue.svg
[:badge-supported-platforms:]: https://img.shields.io/badge/platform-GNU/Linux%20|%20macOS%20|%20FreeBSD%20-yellow
[:badge-supported-platforms:]: https://img.shields.io/badge/platform-Linux%20|%20macOS%20|%20FreeBSD%20-yellow
[:badge-supported-arch:]: https://img.shields.io/badge/architecture-x86--64%20|%20ARM64%20-silver

[:badge-license:]: https://img.shields.io/github/license/NoiseByNorthwest/php-spx
Expand Down
40 changes: 40 additions & 0 deletions config.w32
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
ARG_ENABLE("spx", "Enable SPX extension", "no");

ARG_ENABLE("spx-dev", "Compile SPX with debugging symbols", "no");

if (PHP_SPX == "yes") {
AC_DEFINE("HAVE_SPX", 1, "spx");

ADD_FLAG("CFLAGS", "/Ox /Wall /WX /W2 /wd4820 /wd4774 /wd4711 /wd4710 /wd4464");

if (PHP_SPX_DEV == "yes") {
ADD_FLAG("CFLAGS", "/Zi");
}

if (
! CHECK_LIB("zlib_a.lib;zlib.lib", "zlib", PHP_ZLIB) ||
! CHECK_HEADER_ADD_INCLUDE("zlib.h", "CFLAGS", "..\\zlib;" + php_usual_include_suspects)
) {
ERROR("zlib not found");
}

EXTENSION("spx", "src/php_spx.c \
src/spx_profiler.c \
src/spx_profiler_tracer.c \
src/spx_profiler_sampler.c \
src/spx_reporter_full.c \
src/spx_reporter_fp.c \
src/spx_reporter_trace.c \
src/spx_metric.c \
src/spx_resource_stats.c \
src/spx_hmap.c \
src/spx_str_builder.c \
src/spx_output_stream.c \
src/spx_php.c \
src/spx_stdio.c \
src/spx_config.c \
src/spx_utils.c \
src/spx_fmt.c", true);

ADD_MAKEFILE_FRAGMENT();
}
Loading

0 comments on commit 3a5f39b

Please sign in to comment.