This is monorepo and php-profiler is split into two packages.
One package php-profiler
is used to profile PHP code and does not include any external dependencies and support legacy PHP versions (7.2+).
The other package php-profiler-cli
is used to analyse profiler data created by php-profiler
package.
Because analyse process does not run on production env this library requires external dependencies and might require modern PHP version.
- Fetch from server your file with serialized profiler data.
- Clone this repository and go to directory
./packages/php-profiler-cli
and editcomposer.json
{
"name": "mmo/php-profiler-cli",
# ...
"repositories": [
{
"type": "path",
"url": "../php-profiler"
}
],
"minimum-stability": "dev"
}
- Install dependencies -
composer install
. You had to editcomposer.json
because at this moment these packages are not published. - Call command
parse-profiler-data
to convert data to SQL queries for SQLite -./php-profiler-cli parse-profiler-data /path/to/saved/profiler/data | sqlite3 profiler.db
- Open
profiler.db
insqlitebrowser
or other client e.g. PHPStorm. - Use SQL to select/filter stored data and export them to CSV/TSV for better analyse in for example LibreOffice Calc.
SELECT MIN, MAX, AVG, total duration, number of probes:
SELECT MIN(duration) as min, MAX(duration) as max, AVG(duration) as avg, SUM(duration) as total_duration, count(1) as number_of_probes
FROM profiler
WHERE depth = 0;
Filter rows which has a field userID
with value 123
in metadata:
SELECT * FROM profiler WHERE json_extract(metadata, '$.userID') = 123;
Convert duration to INT
SELECT *, CAST(ROUND(duration, 0) as INT) duration_ms_int FROM profiler;
⚠️ Warning To use english function names you need mark a checkbox Use English function names.From "Tools" menu, select "Options". In showed dialog from left menu expand item "LibreOffice Calc" and then select "Formula" item. On the right check the checkbox "Use English function names"
95% PERCENTILE - =PERCENTILE(A1:A10;0.95)
MEDIAN - =MEDIAN(A1:A10)
This repo contains a fantastic external script to generate flame graph.
./php-profiler-cli create-flame-graph /path/to/saved/profiler/data /output/direcotry/for/svg/files
The "sql-matrix" command generates an SQL query that, for each samples with depth=1, represents each sample as a column. The share of a given sample in the full execution time is also calculated.
./php-profiler-cli sql-matrix /path/to/saved/profiler/data