justbetter / magento2-xhprof-profiler

justbetter/magento2-xhprof-profiler

Xhprof profiler integration for Magento

magento2-module Compatibility: Not yet tested Code Quality: Pending Tests: N/A Security: Pending MIT

Are you the maintainer of justbetter?

Packagento pulls justbetter's Composer packages from the public registry so buyers can find them here.

Claim the namespace to take ownership, publish new releases directly, and start charging for premium versions.

Claim this namespace →

Viewing version 0.1.0. Latest version is 0.2.0. Switch to latest

Xhprof Profiler for Magento 2

Overview

This module integrates Xhprof profiling capabilities into your Magento 2 application. It provides an easy way to profile and analyze your application's performance by tracking and storing profiling data.

Requirements

  • Magento 2.4.7 or higher
  • Xhprof PHP extension
  • Compatible with Buggregator

Installation

  1. Install via composer:

    composer require justbetter/magento2-xhprof-profiler
    
  2. Enable the module:

    bin/magento module:enable JustBetter_XhprofProfiler
    
  3. Run setup upgrade and di compile:

    bin/magento setup:upgrade
    bin/magento setup:di:compile
    

Configuration

Configure the module by adding the following configuration to your app/etc/env.php file:

return [
    // ... other configurations ...
    'xhprofprofiler' => [
        'app_name' => 'Magento 247',
        'endpoint' => 'http://exciting_chatelet.orb.local/profiler/store'
    ],
];
  • app_name: The name of your application.
  • endpoint: The endpoint where the profiling data will be stored.

Usage

The profiling is automatically enabled for all requests. The module uses the AppInterfacePlugin to start and terminate the profiler around each request.

Key Classes and Methods

  • XhprofProfiler

    • Constants:
      • HEADER: The header key used to enable Xhprof profiling.
      • IGNORED_FUNCTIONS_KEY: The key for ignored functions in the profiler.
    • Methods:
      • __construct(): Initializes the profiler with the given driver, deployment configuration, and optional tags.
      • handle(): Starts the profiler.
      • terminate(): Ends the profiler and stores the profiling data.
  • AppInterfacePlugin

    • Methods:
      • aroundLaunch(): Wraps around the application launch to start and stop the profiler.

Buggregator Compatibility

This module is compatible with Buggregator, a debug and profiler tool for PHP applications. Buggregator can collect and visualize profiling data generated by this module, providing a comprehensive debugging and performance analysis experience.

To integrate with Buggregator:

  1. Ensure Buggregator is installed and configured in your environment.
  2. Configure the endpoint in app/etc/env.php to point to Buggregator's profiling data endpoint.

Example configuration:

return [
    // ... other configurations ...
    'xhprofprofiler' => [
        'app_name' => 'Magento 247',
        'endpoint' => 'http://your_buggregator_instance/profiler/store'
    ],
];

Example

Here is an example of how the profiler is used in the plugin:

namespace JustBetter\XhprofProfiler\Plugin;

use JustBetter\XhprofProfiler\Model\Profiler\XhprofProfiler;
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\AppInterface as Application;

class AppInterfacePlugin
{
    public function __construct(
        protected XhprofProfiler $profiler
    )
    {
    }

    public function aroundLaunch(
        Application $subject,
        callable $proceed,
    ) : ResponseInterface {
        $this->profiler->handle();
        $response = $proceed();
        $this->profiler->terminate();
        return $response;
    }
}

Exception Handling

The terminate method of the XhprofProfiler class can throw the following exceptions:

  • FileSystemException: If there is an issue with the file system.
  • RuntimeException: If there is a runtime issue.

Ensure you have proper exception handling in place when integrating this module.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

  1. Fork the repository.
  2. Create your feature branch (git checkout -b feature/fooBar).
  3. Commit your changes (git commit -am 'Add some fooBar').
  4. Push to the branch (git push origin feature/fooBar).
  5. Create a new Pull Request.

Contact

If you have any questions or need further assistance, please contact [[email protected]].


By following this README, you should be able to integrate and use the Xhprof Profiler in your Magento 2 application effectively. Happy profiling!

No changelog yet

The vendor hasn't published a changelog. Tagged releases appear in the Versions tab.

Versions
Version Stability QA Status Compatibility Released
0.2.0 stable Fail Magento 2.4.7-2.4.9 Details 2024-11-13 08:44:54
0.1.0 stable Not tested Not yet tested Details 2024-10-23 11:49:14

Requires 5

Package Constraint
magento/framework *
magento/module-config ^101.2
perftools/php-profiler ^1.1
php >=8.2
spiral-packages/profiler ^1.2

Requires-dev 2

Package Constraint
bitexpert/phpstan-magento ^0.30.1
phpstan/phpstan ^1.10

No QA results yet

QA pipelines haven't run for this version. Compatibility and quality results appear here once the vendor publishes a tagged release that gets ingested.

License
MIT
Authors

More from justbetter

View vendor
Make it pay

Turn an existing module into recurring revenue.

If you already maintain a Magento 2 module on GitHub or GitLab, listing it on Packagento takes about five minutes. We mirror your tags, handle distribution signing, and route paid licenses through Stripe Connect, so you can keep shipping the way you already do.