PHPackages                             eliashaeussler/scope-profiler - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. eliashaeussler/scope-profiler

ActiveLibrary

eliashaeussler/scope-profiler
=============================

Simple profiler to measure duration, memory usage and memory peak of various scoped actions

1.0.0(today)026↑2669.2%[1 issues](https://github.com/eliashaeussler/scope-profiler/issues)GPL-3.0-or-laterPHPPHP ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0CI passing

Since Jul 28Pushed today1 watchersCompare

[ Source](https://github.com/eliashaeussler/scope-profiler)[ Packagist](https://packagist.org/packages/eliashaeussler/scope-profiler)[ RSS](/packages/eliashaeussler-scope-profiler/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (10)Versions (2)Used By (0)

Scope Profiler
==============

[](#scope-profiler)

[![Coverage](https://camo.githubusercontent.com/20100b01c4012c8a4271d52d0dc9b12bdf10fb6cb46903c9071615b207b2a5b4/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c73436f7665726167652f6769746875622f656c6961736861657573736c65722f73636f70652d70726f66696c65723f6c6f676f3d636f766572616c6c73)](https://coveralls.io/github/eliashaeussler/scope-profiler)[![CI](https://camo.githubusercontent.com/56b4d2a6ef1165421c78630a1bed9eb31d1727a2be266699423315b968b0aa7d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f656c6961736861657573736c65722f73636f70652d70726f66696c65722f63692e79616d6c3f6c6162656c3d4349266c6f676f3d676974687562)](https://github.com/eliashaeussler/scope-profiler/actions/workflows/ci.yaml)[![Supported PHP Versions](https://camo.githubusercontent.com/0237b19fee389c055cf067aaedc713ed106a9a0a648c0a5c7b676f0e0096c072/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f656c6961736861657573736c65722f73636f70652d70726f66696c65722f7068703f6c6f676f3d706870)](https://packagist.org/packages/eliashaeussler/scope-profiler)

A simple profiler to measure duration, memory usage and memory peak of various scoped actions.

🔥 Installation
--------------

[](#-installation)

[![Packagist](https://camo.githubusercontent.com/42c1d878b3a250f8594ab2407069dd0eea4577c70a7516ae2f98492714dc3d45/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f656c6961736861657573736c65722f73636f70652d70726f66696c65723f6c6162656c3d76657273696f6e266c6f676f3d7061636b6167697374)](https://packagist.org/packages/eliashaeussler/scope-profiler)[![Packagist Downloads](https://camo.githubusercontent.com/718c282fc269b6441188209c37ef11ad801f69a8466db5b4cab0e282963f85bd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f656c6961736861657573736c65722f73636f70652d70726f66696c65723f636f6c6f723d627269676874677265656e)](https://packagist.org/packages/eliashaeussler/scope-profiler)

```
composer require eliashaeussler/scope-profiler
```

⚡️ Usage
--------

[](#️-usage)

### Initalization

[](#initalization)

Initialize a new [`ScopeProfiler\ScopeProfiler`](src/ScopeProfiler.php) instance – either as singleton if you prefer to use a shared instance or as a new instance if you want to use multiple profilers:

```
use Eliashaeussler\ScopeProfiler;

// Option A: Shared instance (singleton)
$profiler = ScopeProfiler\ScopeProfiler::get();

// Option B: New instance
$profiler = new ScopeProfiler\ScopeProfiler();
```

To push a new scope, call `pushScope()` and pass the action name:

```
$scope = $profiler->pushScope('Crawling the internet');
```

### Run task

[](#run-task)

You will receive an instance of [`ScopeProfiler\Scope`](src/Scope.php) which you can use to measure the duration, memory usage and memory peak of the action. This can either be done automatically by using the `run()` method or manually by using the `start()` and `stop()` methods:

```
$task = new SomeLongRunningTask();

// Option A: Automatic start and stop
$result = $scope->run($task->execute(...));

// Option B: Manual start, execute, and stop
$scope->start();
$result = $task->execute();
$scope->stop();
```

### Measure scope

[](#measure-scope)

You can always profile a scope by measuring the current duration, memory usage and memory peak – either while the scope is still active or after it has finished:

```
$measurement = $scope->measure();
```

The received object is an instance of [`ScopeProfiler\Measurement`](src/Measurement.php) which contains the following properties:

```
$duration = $measurement->duration; // float
$memoryUsage = $measurement->memoryUsage; // int
$memoryPeak = $measurement->memoryPeak; // int
```

### Format measurement

[](#format-measurement)

To get a nicely formatted string representation of the measurement, call any of the `format*()` methods:

```
$formattedMeasurement = $measurement->format(); // Crawling the internet took 7 min and consumed 8 GiB of memory (peak at 16 GiB)
$formattedDuration = $measurement->formatDuration(); // 7 min
$formattedMemoryUsage = $measurement->formatMemoryUsage(); // 8 GiB
$formattedMemoryPeak = $measurement->formatMemoryPeak(); // 16 GiB
```

### Release scopes

[](#release-scopes)

You can use the profiler to release all scopes at once:

```
$scopes = $profiler->releaseScopes();
```

This is especially useful if you want to summarize the results of all scopes at once.

🧑‍💻 Contributing
----------------

[](#‍-contributing)

Please have a look at [`CONTRIBUTING.md`](CONTRIBUTING.md).

⭐ License
---------

[](#-license)

This project is licensed under [GNU General Public License 3.0 (or later)](LICENSE).

###  Health Score

44

—

FairBetter than 90% of packages

Maintenance100

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

0d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/16313625?v=4)[Elias Häußler](/maintainers/eliashaeussler)[@eliashaeussler](https://github.com/eliashaeussler)

---

Top Contributors

[![eliashaeussler](https://avatars.githubusercontent.com/u/16313625?v=4)](https://github.com/eliashaeussler "eliashaeussler (1 commits)")

---

Tags

composer-librarydurationmemoryphpprofiler

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/eliashaeussler-scope-profiler/health.svg)

```
[![Health](https://phpackages.com/badges/eliashaeussler-scope-profiler/health.svg)](https://phpackages.com/packages/eliashaeussler-scope-profiler)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
