PHPackages                             duckstery/process-analyzer - 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. duckstery/process-analyzer

ActiveLibrary

duckstery/process-analyzer
==========================

Dependency free process analyzer for PHP

1.0.2(2y ago)0421MITPHPPHP &gt;=8.0

Since Nov 3Pushed 2y ago1 watchersCompare

[ Source](https://github.com/duckstery/process-analyzer)[ Packagist](https://packagist.org/packages/duckstery/process-analyzer)[ Docs](https://github.com/duckstery/process-analyzer)[ RSS](/packages/duckstery-process-analyzer/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (3)Versions (8)Used By (1)

Dependency free process analyzer for PHP
========================================

[](#dependency-free-process-analyzer-for-php)

 Table of Contents1. [Feature](#)
2. [Installation](#installation)
    - [PHP 8+](#for-php-8)
    - [Laravel](#for-laravel)
3. [Configuration](#configuration)
    - [How to config](#how-to-config)
    - [Options](#options)
    - [Printer's hooks](#printers-hooks)
4. [Usage](#usage)
    - [Basic](#basic)
    - [Use default Profile name and extra metrics](#use-default-profile-name-and-extra-metrics)
    - [Use default Record name](#use-default-record-name)
    - [Use multiple Profile](#use-multiple-profile)
5. [Testing](#testing)
6. [Issue](#issue)
7. [License](#license)

Feature
-------

[](#feature)

- Provide `Analyzer` that can measure the amount of time and memory of blocks of code
- Report measured amount through file or console
- Support multiple Profile for multiple metrics

For example, you can do this:

```
// Start of code
$uid = Analyzer::start("Do a simple math");

// Calculating
$output = 1 + 1;
// Print output to screen
echo $output;

// End of code
Analyzer::stop($uid);
// Flush to get report
Analyzer::flush();
```

After that, you will get a report like this

```
Default --------------------
╭───────────────┬──────────────────┬─────────────┬────────┬────────────┬────────────┬───────────╮
│ Uid           │ Name             │ Time        │ Memory │ Start peak │ Stop peak  │ Diff peak │
├───────────────┼──────────────────┼─────────────┼────────┼────────────┼────────────┼───────────┤
│ 654af62889e08 │ Do a simple math │ 2006.472 ms │ 2.5 KB │ 16502872 B │ 16502872 B │       0 B │
╰───────────────┴──────────────────┴─────────────┴────────┴────────────┴────────────┴───────────╯
----------------------------
```

The report can be printed to file or console. Moreover, you can decide to grab the report result and print it to wherever you want

Installation
------------

[](#installation)

### For PHP 8+

[](#for-php-8)

Run script to install

```
composer require --dev duckstery/process-analyzer
```

### For Laravel

[](#for-laravel)

Warning

This integration only work properly while handling request individually (1 request at a time) because it'll flush everything out at the end of the request.

Run script to install

```
composer require --dev duckstery/laravel-process-analyzer
```

Package's ServiceProvider will be auto required by Laravel. If you don't use auto-discovery, you need to manually add ServiceProvider

```
Duckstery\Laravel\Analyzer\ProcessAnalyzerServiceProvider::class
```

to the providers array in `config/app.php`

```
/*
    |--------------------------------------------------------------------------
    | Autoloaded Service Providers
    |--------------------------------------------------------------------------
    |
    | The service providers listed here will be automatically loaded on the
    | request to your application. Feel free to add your own services to
    | this array to grant expanded functionality to your applications.
    |
    */

    'providers' => ServiceProvider::defaultProviders()->merge([
        /*
         * Package Service Providers...
         */
        Duckstery\Laravel\Analyzer\ProcessAnalyzerServiceProvider::class, // ** //
        /*
         * Application Service Providers...
         */
        App\Providers\AppServiceProvider::class,
        App\Providers\AuthServiceProvider::class,
        // App\Providers\BroadcastServiceProvider::class,
        App\Providers\EventServiceProvider::class,
        App\Providers\RouteServiceProvider::class,
    ])->toArray(),
```

Then, you can publish config file for better customization

```
php artisan vendor:publish --provider="Duckstery\Laravel\Analyzer\ProcessAnalyzerServiceProvider"
```

Configuration
-------------

[](#configuration)

### How to config

[](#how-to-config)

Before use, you should config package to match your needs.

To config, create a class and extend `AnalyzerConfig` like this

```
