Download the PHP package cheprasov/php-simple-profiler without Composer
On this page you can find all versions of the php package cheprasov/php-simple-profiler. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cheprasov/php-simple-profiler
More information about cheprasov/php-simple-profiler
Files in cheprasov/php-simple-profiler
Package php-simple-profiler
Short Description Simple profiler for PHP
License MIT
Homepage https://github.com/cheprasov/php-simple-profiler
Informations about the package php-simple-profiler
SimpleProfiler v3.0.0 for PHP >= 7.0
The SimpleProfiler is a tool for automatic analysis of code. Or, you can just using simple tools like Stopwatch and Counter.
Features:
- Easy to connect with a project if you want of analysis of your code.
- It has 'Stopwatch' and 'Counter' tools.
- Support profiling for anonymous function.
- Support collecting arguments, result and exceptions of functions.
- Written on PHP, you do not need install any extensions.
- Easy to enable/disable it only for some classes based on your logic.
- The profiler works with tree structure of function calls.
1. How to add the profiler to you project for automatic analysis of code
Note. You can use profiler tools like 'Stopwatch' and 'Counter' without this step.
You need to open your 'autoload' function, and use the profiler's function for loading class.
Example:
2. How to get result
The Profiler has 2 methods that return collected data:
-
\SimpleProfiler\Profiler::getRawData() : array|null
\SimpleProfiler\Profiler::getLog() : string
You can use function \SimpleProfiler\Profiler::getLog()
for getting already formatted log data as string.
Example of output:
Lets see what we have in the output
SimpleProfiler\Tests\TestClass::get_random_int 42:27
-function name
andline:column
in codedata: {"arguments":[100,300],"result":271}
- data of the function: arguments and resultcost: 0.0 %, count: 1, avg: 0.000013 sec, total: 0.000013 sec
-
cost: 0.0 %
- How much time it took out of the parent function total time.
-
count: 1
- Count of call the function. Note, functions with data are calculated without grouping.
-
avg: 0.000013 sec
- Average time for 1 call of the function.
-
total: 0.000013 sec
- Total time for all calls of the function.
3. Usage of Profiler tool
- Add profiler to a file.
Arguments:
string
$classPath - path to file of a classstring|null
regExpFilter - RegExp for adding profiler by function name. Use/^\{closure\}$/
for profiling only anonymous functions.
- Get result:
or
- Configure profile.
By default, the Profiler uses \SimpleProfiler\Unit\FunctionUnit::class
for collecting statistic.
You can set another unit
\SimpleProfiler\Unit\FunctionUnit::class
- the unit collects base stats without arguments and result.\SimpleProfiler\Unit\DetailedFunctionUnit::class
- the unit collects detailed stats with arguments and result.
Another function setProfilerUnitVarName
, it changes var's name that will injected in code.
4. Usage Counter tool
-
Counter::clear() : void
- clear all counters -
Counter::increment(string $name, int $count = 1): int
- increment the counter, it returns new value -
Counter::decrement(string $name, int $count = 1): int
- decrement the counter, it returns new value -
Counter::get(string $name): int
- get the counter's value Counter::getAll(): array
- get values of all counters
5. Usage Stopwatch tool
-
Stopwatch::clear() : void
- clear all timers -
Stopwatch::start(string $name): void
- start timer, or continue it after stop. -
Stopwatch::stop(string $name): float
- stop timer, and get duration in sec. -
Stopwatch::get(string $name): int
- get the timer's duration Stopwatch::getAll(): array
- get durations of all timers
Example with phpMyAdmin-4.6.0
-
I changed the file
phpMyAdmin-4.6.0/libraries/Psr4Autoloader.php
-
I added echo of the Profiler's log in file
phpMyAdmin-4.6.0/server_sql.php
- I opened phpMyAdmin in a browser and got this, and we can see that function
PMA\libraries\Language::activate
took 70.9% of working time.
Full log:
Composer
Download composer:
wget -nc http://getcomposer.org/composer.phar
and add dependency to your project:
php composer.phar cheprasov/php-simple-profiler
Something doesn't work
Feel free to fork project, fix bugs and finally request for pull