Download the PHP package duckstery/process-analyzer without Composer
On this page you can find all versions of the php package duckstery/process-analyzer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download duckstery/process-analyzer
More information about duckstery/process-analyzer
Files in duckstery/process-analyzer
Package process-analyzer
Short Description Dependency free process analyzer for PHP
License MIT
Homepage https://github.com/duckstery/process-analyzer
Informations about the package process-analyzer
Dependency free process analyzer for PHP
Table of Contents
- Feature
-
Installation
- PHP 8+
- Laravel
-
Configuration
- How to config
- Options
- Printer's hooks
-
Usage
- Basic
- Use default Profile name and extra metrics
- Use default Record name
- Use multiple Profile
- Testing
- Issue
- License
Feature
- Provide 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:
After that, you will get a report like this
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
For PHP 8+
Run script to install
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
Package's ServiceProvider will be auto required by Laravel. If you don't use auto-discovery, you need to manually add ServiceProvider
to the providers array in
Then, you can publish config file for better customization
Configuration
How to config
Before use, you should config package to match your needs.
To config, create a class and extend like this
Then, you can override 's properties or functions and change their value
Beware that config with function override will ignore the property's value. If you config logic is big, you should use function override instead.
After creating config class, init with your class's instance
Options
: This option will enable and disable . With this option, you can include this package in production. If you need it to measure your process in production, you can switch it on. But remember to switch it off after
- Type:
- Default: true
: Define default Profile name
- Type:
- Default: "Default"
: Define getter method name. This method will return Record's default name
- Type: | |
- Default:
: Define extra metrics for Profile. These metrics can be retrieved at the start or end of execution. After that, can calculate difference or format them
- Type:
- Default:
: Profile class. You can customize by create a new class that extend
- Type:
- Default:
: Record class
- Type:
- Default:
: Printer class
- Type:
- Default:
: Print report in table
- Type:
- Default: true
- Example:
: Print each Record in report in a line. Ignored if : true
- Type:
- Default:
- Example:
: Show Record's UID in report
- Type:
- Default: true
: Define path to directory that holds report file. Report file will be created each day. If is false, report won't be printed to any file
- Type:
- Default: "logs"
: Print result to console. If is false, report won't be printed to console
- Type:
- Default: true
: Define Profile's name prefix
- Type:
- Default: ""
: Define Profile's name suffix
- Type:
- Default: ""
: Define Record's name prefix
- Type:
- Default: ""
: Define Record's suffix
- Type:
- Default: ""
: Define unit of time
- Type:
- Default: "ms"
: Define a callback to modify main time metrics. Ignored if this option is defined
- Type: | |
- Default: null
: Define unit of memory
- Type:
- Default: "KB"
: Define a callback to modify main memory metrics. Ignored if this option is defined
- Type: | |
- Default:
: Define top left corner character
- Type:
- Default: "╭"
: Define top right corner character
- Type:
- Default: "╮"
: Define bottom left corner character
- Type:
- Default: "╰"
: Define bottom right corner character
- Type:
- Default: "╯"
: Define top fork character
- Type:
- Default: "┬"
: Define right fork character
- Type:
- Default: "┤"
: Define bottom fork character
- Type:
- Default: "┴"
: Define left fork character
- Type:
- Default: "├"
: Define cross character
- Type:
- Default: "┼"
Printer's hooks
There are some printer's hooks that allow you to interact with report data. To use these hooks, create a class and extend
Then, override methods like this
These are some hooks that you can use:
: Execute before process Profile
- Param: : Profile can be modified at this hook
: Execute on each Record and before process Record
- Param: : Record can be modified at this hook
: Execute on each Record and after process Record
- Param:
-
Example: Without Profile's extras
- Example: With Profile's extras (peak)
: Execute on each Record and after convert Record to string
- Param:
: Execute after complete the report
- Param: : This is the final report
- Note: Modify this won't change your file or console result. If you want to send your report elsewhere, you should disable and and define your logic in this hook instead.
Usage
These are some examples to instruct you to use this package. You will be provided with a static class.
will only measure execution time and memory of your execution. It'll exclude self execution time and memory out of final result.
The basic approach is placing your logic inside and . When everything is done, call so Analyzer can generate the report for you.
The Laravel integration has a specific middleware that will execute at the end of request. So you don't need to while using that integration. But in most case, you have to flush
at the end of your program (or at least at the end of the process that you desired to measure).
For any unmentioned situation, you can issue me for more detail.
Basic
Analyzer
only measure execution time and memory of your execution
Report
SomeController --------------------
╭───────────────┬──────────┬─────────────┬────────╮
│ Uid │ Name │ Time │ Memory │
├───────────────┼──────────┼─────────────┼────────┤
│ 654af62889e08 │ handle │ 5036.472 ms │ 5 KB │
│ 654af62889e09 │ processA │ 6.472 ms │ 0 KB │
│ 654af62889e10 │ processB │ 6.472 ms │ 5 KB │
│ 654af62889e11 │ processC │ 5000.472 ms │ 0 KB │
╰───────────────┴──────────┴─────────────┴────────╯
------------------------------
Use default Profile name and extra metrics
Config
Capture metrics by using default Profile
Report
Default --------------------
╭───────────────┬────────────────────────┬─────────────┬────────┬────────────┬────────────┬───────────╮
│ Uid │ Name │ Time │ Memory │ Start peak │ Stop peak │ Diff peak │
├───────────────┼────────────────────────┼─────────────┼────────┼────────────┼────────────┼───────────┤
│ 654af62889e08 │ SomeController::handle │ 2006.472 ms │ 0 KB │ 16502872 B │ 16502872 B │ 0 B │
╰───────────────┴────────────────────────┴─────────────┴────────┴────────────┴────────────┴───────────╯
----------------------------
Use default Record name
Capture metrics by using default Record name
Report
Default --------------------
╭───────────────┬──────────────────┬─────────────┬────────┬────────────┬────────────┬───────────╮
│ Uid │ Name │ Time │ Memory │ Start peak │ Stop peak │ Diff peak │
├───────────────┼──────────────────┼─────────────┼────────┼────────────┼────────────┼───────────┤
│ 654af62889e08 │ Function: handle │ 2006.472 ms │ 0 KB │ 16502872 B │ 16502872 B │ 0 B │
╰───────────────┴──────────────────┴─────────────┴────────┴────────────┴────────────┴───────────╯
----------------------------
Use multiple Profile
Capture metrics with multiple Profile
Report
Profile 1 --------------------
╭───────────────┬──────────────────┬─────────────┬────────╮
│ Uid │ Name │ Time │ Memory │
├───────────────┼──────────────────┼─────────────┼────────┤
│ 654af62889e08 │ Function: handle │ 2006.472 ms │ 0 KB │
╰───────────────┴──────────────────┴─────────────┴────────╯
------------------------------
Profile 2 --------------------
╭───────────────┬────────────────┬─────────────┬────────╮
│ Uid │ Name │ Time │ Memory │
├───────────────┼────────────────┼─────────────┼────────┤
│ 654af62889e09 │ Function: todo │ 2006.472 ms │ 0 KB │
╰───────────────┴────────────────┴─────────────┴────────╯
------------------------------
Testing
For testing
composer run-script test
For coverage
composer run-script test-coverage
Issue
If you discover any security-related issues, bugs or ideas, please feel free to create an issue.
License
The MIT License (MIT). Please see License File for more information.