smilian / perfreporter
Measures the performance of PHP code for Symfony projects. Process measurements, lead times, file location...
Requires
- php: >=7.4
- nesbot/carbon: ^2.57
This package is auto-updated.
Last update: 2024-11-21 20:59:11 UTC
README
Perf-Reporter is a package dedicated to Symfony 5 and more, allowing to measure the performance of the runtime through its execution time and the memory allocated to it.
To install it, run the following command:
composer require smilian/perfreporter
Publish files
After installing the package, run the following command to publish the files:
php vendor/smilian/perfreporter/publish
By publishing those files, a new controller called "DisplayPerfReportsController.php" has been created in src/Controller folder and defines a new Route with URL: "/perf-reporter". Some commands have been added to bin/console with the "app" namespace. Check them with:
bin/console --short
Unpublish files
If you want to remove the files corresponding to the package, you can also debug them with the command:php vendor/smilian/perfreporter/unpublish
Public methods list
// Set timezone (default: "Europe/London") PerformancesLogger::setTimezone(string $zone); // Set locale (default: "en") PerformancesLogger::setLocale(string $locale); // Launch chronometer PerformancesLogger::setStart(); // Set Alarm step value in seconds (default: 3) PerformancesLogger::setAlarmStep(int $val); // Set Maximum report files to create/conserve (default: 4) PerformancesLogger::setMax(int $val); // Set report title (default: "Performances and Measurement") PerformancesLogger::setTitle(string $data); // Set app/site owner/customer logo where $data is a absolute path/to/your/image PerformancesLogger::setAppOwnerLogo(string $data); // As breadcrumbs, dispatch this method anywhere you want to get performances PerformancesLogger::setStep(string $data); // Optional, Set some information if needed, that will fill an array like self::$header[$key] = $value; PerformancesLogger::setHeader(string $key, mixed $value); // Render the Report file PerformancesLogger::getResult(); // Delete reports/ folder PerformancesLogger::deleteReports(); // Get the list of all reports (if mode === 'html' return perf-reports template, but if mode === '' as default, will return reports list) PerformancesLogger::getReportList(string $mode = ''); // Get report html content PerformancesLogger::getReport(string $path);
Usage
In the file where the process works:
// ... use Smile\Perfreporter\Performers\PerformancesLogger; // ... $perfs = PerformancesLogger::setTitle(YOUR_CUSTOM_TITLE) ->setTimezone('Europe/Paris') ->setLocale('fr') ->setAppOwnerLogo(PATH_TO_IMAGE) ->setStart(); // Process to check $perfs::setStep(DETAIL_YOU_NEED_TO_FILL); // End of the process $perfs::getResult();
Because Smile\Perfreporter\Performers\PerformancesLogger is a static class, you can put some setStep() in any file where the process works and finish to use setRender() in the file where the process ends.
Where process starts
// ... use Smile\Perfreporter\Performers\PerformancesLogger; // ... $perfs = PerformancesLogger::setTitle(YOUR_CUSTOM_TITLE) ->setTimezone('Europe/Paris') ->setLocale('fr') ->setAppOwnerLogo(PATH_TO_IMAGE) ->setStart(); // ...
Some file where process works
// ... use Smile\Perfreporter\Performers\PerformancesLogger; // ... $perfs::setStep(DETAIL_YOU_NEED_TO_FILL); // ...
Where process ends
// ... use Smile\Perfreporter\Performers\PerformancesLogger; // ... $perfs::getResult(); // ...