Skip to content
Merged
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
18 changes: 18 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Normalise line endings on checkout
* text=auto eol=lf

# Files and directories that must not ship in the Composer dist tarball.
# Keeps `composer require initphp/performance-meter` lean for end users.
/.github export-ignore
/docs export-ignore
/tests export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.php-cs-fixer.dist.php export-ignore
/.php-cs-fixer.cache export-ignore
/.phpunit.cache export-ignore
/.phpunit.result.cache export-ignore
/CHANGELOG.md export-ignore
/phpstan.neon.dist export-ignore
/phpunit.xml.dist export-ignore
136 changes: 136 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
name: CI

on:
push:
branches: [main]
pull_request:
branches: [main]

permissions:
contents: read

concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
tests:
name: Tests / PHP ${{ matrix.php }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
php: ['8.1', '8.2', '8.3', '8.4']
dependencies: [highest]
include:
- os: ubuntu-latest
php: '8.1'
dependencies: lowest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: pcov
tools: composer:v2
ini-values: error_reporting=E_ALL, display_errors=On, zend.assertions=1

- name: Validate composer.json
run: composer validate --strict

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT"

- name: Cache composer dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ matrix.php }}-${{ matrix.dependencies }}-${{ hashFiles('composer.json') }}
restore-keys: |
${{ runner.os }}-composer-${{ matrix.php }}-${{ matrix.dependencies }}-
${{ runner.os }}-composer-${{ matrix.php }}-

- name: Install dependencies (${{ matrix.dependencies }})
run: |
if [ "${{ matrix.dependencies }}" = "lowest" ]; then
composer update --prefer-lowest --prefer-stable --no-interaction --no-progress --prefer-dist
else
composer install --no-interaction --no-progress --prefer-dist
fi

- name: Run PHPUnit
run: vendor/bin/phpunit --testdox

static-analysis:
name: Static Analysis (PHPStan)
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
coverage: none
tools: composer:v2

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT"

- name: Cache composer dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-static-${{ hashFiles('composer.json') }}
restore-keys: |
${{ runner.os }}-composer-static-

- name: Install dependencies
run: composer install --no-interaction --no-progress --prefer-dist

- name: Run PHPStan
run: vendor/bin/phpstan analyse --memory-limit=512M --no-progress

coding-standards:
name: Coding Standards (PHP-CS-Fixer)
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
coverage: none
tools: composer:v2

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT"

- name: Cache composer dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-cs-${{ hashFiles('composer.json') }}
restore-keys: |
${{ runner.os }}-composer-cs-

- name: Install dependencies
run: composer install --no-interaction --no-progress --prefer-dist

- name: Run PHP-CS-Fixer
env:
PHP_CS_FIXER_IGNORE_ENV: 1
run: vendor/bin/php-cs-fixer fix --dry-run --diff --show-progress=none
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@
/.vscode/
/.vs/
/vendor/
/composer.lock
/composer.lock
/build/
/.phpunit.cache/
/.phpunit.result.cache
/.php-cs-fixer.cache
/.phpstan/
36 changes: 36 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

$finder = PhpCsFixer\Finder::create()
->in([__DIR__ . '/src', __DIR__ . '/tests'])
->name('*.php');

return (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules([
'@PSR12' => true,
'@PHP81Migration' => true,
'declare_strict_types' => true,
'array_syntax' => ['syntax' => 'short'],
'no_unused_imports' => true,
'ordered_imports' => [
'sort_algorithm' => 'alpha',
'imports_order' => ['class', 'function', 'const'],
],
'single_quote' => true,
'trailing_comma_in_multiline' => true,
'native_function_invocation' => [
'include' => ['@compiler_optimized'],
'scope' => 'namespaced',
'strict' => true,
],
'binary_operator_spaces' => ['default' => 'single_space'],
'concat_space' => ['spacing' => 'one'],
'no_superfluous_phpdoc_tags' => ['allow_mixed' => true],
'phpdoc_align' => ['align' => 'left'],
'phpdoc_separation' => true,
'phpdoc_trim' => true,
])
->setFinder($finder)
->setCacheFile(__DIR__ . '/.php-cs-fixer.cache');
46 changes: 46 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Changelog

All notable changes to this project are documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [2.0.0]

### Added

- `PerformanceMeter::reset()` β€” clear every recorded checkpoint.
- `PerformanceMeter::has(string $name): bool` β€” check whether a checkpoint exists.
- `PerformanceMeter::peakMemoryUsage(int $decimal = 2, bool $realUsage = false): string` β€” report the process-wide peak memory.
- `PerformanceMeter::getPointers(): array` β€” snapshot copy of the registry.
- `memoryUsage()` gained an optional `bool $realUsage = false` parameter to switch between the emalloc-tracked and the system-allocated reading.
- `setPointer()` now captures both memory readings (`memory_get_usage(false)` and `memory_get_usage(true)`) so historical pointers can be queried either way.
- Dedicated exception type `InitPHP\PerformanceMeter\Exception\PointerNotFoundException` (extends `\InvalidArgumentException`).
- Comprehensive English documentation in `docs/`: `getting-started.md`, `api-reference.md`, `cookbook.md`.
- CI workflow (`.github/workflows/ci.yml`) covering PHP 8.1 β†’ 8.4, PHPStan at `level: max`, and PHP-CS-Fixer enforcement.
- PHPUnit 10 test suite with 100% line, method, and class coverage.

### Changed

- **BREAKING:** Minimum PHP version raised from `>=7.4` to `^8.1`.
- **BREAKING:** Referencing a checkpoint that does not exist now throws `PointerNotFoundException` instead of silently falling back to "now". Affects both the `$startPoint` and a non-`null` `$endPoint` arguments of `elapsedTime()` and `memoryUsage()`.
- **BREAKING:** `memoryUsage()` no longer mis-reports freed memory β‰₯ 1 MB in KB. Negative deltas are now formatted in the correct unit with a leading `-`.
- **BREAKING:** Negative `$decimal` arguments now throw `\InvalidArgumentException`.
- **BREAKING:** The class is now `final`; `$pointers` is now `private`.
- All PHPDoc rewritten in English (org-wide convention).
- `composer.json` switched from `files` autoload to PSR-4; added `require-dev`, scripts (`test`, `phpstan`, `cs-check`, `cs-fix`, `qa`), keywords and support metadata.

### Fixed

- `memoryUsage()` returned a KB-formatted figure for deltas with `|delta| β‰₯ 1 MB` whenever the delta was negative (memory freed). The unit selection now uses `abs($delta)` and produces, e.g., `-3.00MB` instead of `-3072KB`.
- PHPDoc `@see PerformansMeter::setPointer()` typo on `mark()` corrected to a valid reference.
- `microtime()` parsing replaced with `microtime(true)`, removing an unnecessary string round-trip.

## [1.0]

Initial public release.

[Unreleased]: https://github.com/InitPHP/PerformanceMeter/compare/v2.0.0...HEAD
[2.0.0]: https://github.com/InitPHP/PerformanceMeter/releases/tag/v2.0.0
[1.0]: https://github.com/InitPHP/PerformanceMeter/releases/tag/v1.0
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 InitPHP
Copyright (c) 2022-2026 InitPHP

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Loading
Loading