Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Profiler Bundle Laravel Package

clamidity/profiler-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the bundle via Composer:

    composer require clamidity/profiler-bundle
    

    Enable it in config/bundles.php:

    return [
        // ...
        Clamidity\ProfilerBundle\ClamidityProfilerBundle::class => ['all' => true],
    ];
    
  2. First Use Case Enable XHProf in config/packages/clamidity_profiler.yaml:

    clamidity_profiler:
        enabled: true
        xhprof:
            enabled: true
    

    Clear cache:

    php bin/console cache:clear
    

    Access /_profiler to see XHProf data alongside Symfony’s built-in profiler.


Implementation Patterns

Workflows

  1. Debugging Slow Endpoints

    • Use the profiler’s wall time and memory usage metrics to identify bottlenecks.
    • Example: Compare /api/users before/after a database optimization.
  2. Integration with Symfony Profiler

    • Merge XHProf data with Symfony’s profiler tabs (e.g., Request, Doctrine).
    • Use the ProfilerListener to attach XHProf data to Symfony’s DataCollector.
  3. Conditional Profiling

    • Disable in production via config:
      clamidity_profiler:
          enabled: '%kernel.debug%'  # Only active in dev
      
  4. Custom Data Collection

    • Extend the bundle by overriding Clamidity\ProfilerBundle\DataCollector\XhprofDataCollector.
    • Example: Add custom annotations to function calls:
      $profiler->addCustomData('user_action', 'login');
      

Integration Tips

  • Database Queries: Pair with stof/doctrine-extensions to profile QueryBuilder calls.
  • APIs: Use the HttpKernel event listener to profile only specific routes:
    clamidity_profiler:
        xhprof:
            enabled_routes: ['^/api/']
    

Gotchas and Tips

Pitfalls

  1. Performance Overhead

    • XHProf adds ~10-20% overhead in dev. Disable in staging/prod:
      enabled: false
      
    • Use xhprof_disable() in critical paths (e.g., CLI commands).
  2. Memory Leaks

    • XHProf stores call stacks in memory. For long-running processes (e.g., queues), manually clear data:
      $profiler->clear();
      
  3. Symfony 5+ Compatibility

Debugging

  • Missing Data: Verify extension=xhprof.so is loaded in php.ini.
  • Config Overrides: Check for typos in clamidity_profiler.yaml (YAML is strict).
  • Logs: Enable debug mode to see XHProf errors in var/log/dev.log.

Extension Points

  1. Custom Storage Override the storage adapter to save XHProf data to a database:

    // src/Profiler/XhprofStorage.php
    class CustomXhprofStorage extends \Clamidity\ProfilerBundle\Storage\XhprofStorage
    {
        public function save($data) {
            // Save to DB instead of file
        }
    }
    

    Register in services.yaml:

    Clamidity\ProfilerBundle\Storage\XhprofStorage: '@App\Profiler\CustomXhprofStorage'
    
  2. UI Customization Extend the Twig templates in templates/bundles/clamidityprofiler/ to modify the profiler UI.

  3. Asynchronous Profiling Use the ProfilerEvent to profile background jobs (e.g., Symfony Messenger):

    // src/EventListener/ProfilerListener.php
    public function onMessage(WorkerMessageEvent $event) {
        if ($event->getMessage() instanceof YourMessage) {
            $profiler->start('message_processing');
            // Process message
            $profiler->stop('message_processing');
        }
    }
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver