saeedvir/laravel-profile-provider
Composer 安装命令:
composer require saeedvir/laravel-profile-provider
包简介
Laravel package to profile and analyze service provider performance with timing, memory usage and diagnostic analysis
README 文档
README
A powerful Laravel package to profile and analyze service provider performance with detailed timing, memory usage, and diagnostic analysis. Identify bottlenecks in your Laravel application's boot process and optimize service provider performance.
Features
- 📊 Detailed Timing Analysis - Separate timing for registration and boot phases
- 💾 Memory Usage Tracking - Monitor memory consumption per provider
- 🚦 Diagnostic Analysis - Detect common performance issues (filesystem operations, HTTP calls, database queries, etc.)
- 📈 Comparison Mode - Compare current run with previous runs to track performance changes
- 🔄 Parallel Boot Estimation - Estimate potential speedup with parallel provider loading
- 📤 Multiple Export Formats - Export results in JSON, CSV, or formatted tables
- 🎨 Color-Coded Output - Visual highlighting of slow providers and performance issues
- 🔍 Dependency Analysis - Analyze provider dependencies and their impact
- ⚡ Performance Recommendations - Get actionable suggestions to optimize your application
- 🎯 Deferred Provider Detection - Identify which providers are deferred and which should be
Requirements
- PHP 8.1 or higher
- Laravel 10.x, 11.x, or 12.x
Installation
Install the package via Composer:
composer require saeedvir/laravel-profile-provider --dev
The package will automatically register its service provider.
Configuration
Optionally, publish the configuration file:
php artisan vendor:publish --provider="Saeedvir\LaravelProfileProvider\LaravelProfileProviderServiceProvider"
This will create a config/profile-provider.php file with the following options:
return [ // Default threshold in seconds for marking providers as slow 'threshold' => 0.01, // Default number of top slowest providers to display 'top' => 20, // Default field to sort providers by (total, register, boot, memory) 'sort' => 'total', // How many hours to keep previous run data for comparison 'cache_ttl_hours' => 24, // Maximum length for provider names in output tables 'max_provider_name_length' => 50, ];
Usage
Basic Usage
Run the profiler with default settings:
php artisan profile:providers
This will display a table showing all service providers with their registration time, boot time, total time, and diagnostic information.
Common Use Cases
1. Find the Slowest Providers
Show only the top 10 slowest providers:
php artisan profile:providers --top=10
2. Track Memory Usage
Include memory consumption analysis:
php artisan profile:providers --memory
3. Compare Performance Over Time
Compare current run with the previous run to track performance changes:
php artisan profile:providers --compare
4. Export Results
Export results to a JSON file for further analysis:
php artisan profile:providers --format=json --export=storage/profiling/results.json
Export to CSV:
php artisan profile:providers --format=csv --export=storage/profiling/results.csv
5. Focus on Specific Threshold
Only show providers slower than 50ms:
php artisan profile:providers --threshold=0.05
6. Sort by Different Metrics
Sort by registration time:
php artisan profile:providers --sort=register
Sort by boot time:
php artisan profile:providers --sort=boot
Sort by memory usage:
php artisan profile:providers --sort=memory --memory
7. Estimate Parallel Boot Performance
See potential speedup with parallel provider loading:
php artisan profile:providers --parallel
8. Dry Run (Simulation)
Simulate profiling without actual execution (useful for testing):
php artisan profile:providers --dry-run
9. Profile Cached Providers
Profile only providers from the bootstrap cache:
php artisan profile:providers --use-cache
Or profile exclusively cached providers:
php artisan profile:providers --only-cached
10. Skip Diagnostics
For faster profiling without diagnostic analysis:
php artisan profile:providers --no-diagnostics
Advanced Usage Examples
Complete Performance Analysis
php artisan profile:providers \
--top=15 \
--threshold=0.01 \
--memory \
--compare \
--parallel \
--export=storage/profiling/analysis-$(date +%Y%m%d).json
Quick Check for Slow Providers
php artisan profile:providers --top=5 --threshold=0.1 --no-diagnostics
Detailed Analysis with All Features
php artisan profile:providers \
--memory \
--compare \
--parallel \
--sort=total \
--format=table
Available Options
| Option | Description | Default |
|---|---|---|
--top=N |
Show top N slowest providers | 20 |
--threshold=N |
Mark providers slower than N seconds | 0.01 |
--sort=FIELD |
Sort by: total, register, boot, memory | total |
--format=FORMAT |
Output format: table, json, csv | table |
--export=PATH |
Save results to file | - |
--compare |
Compare with previous run | false |
--memory |
Include memory usage tracking | false |
--no-diagnostics |
Skip diagnostic analysis | false |
--use-cache |
Read providers from bootstrap cache | false |
--dry-run |
Simulate profiling without execution | false |
--only-cached |
Profile only cached providers | false |
--parallel |
Estimate parallel boot timing | false |
Understanding the Output
Table Output
The default table output includes:
- Provider: The fully qualified class name of the service provider
- Register(s): Time taken during the registration phase
- Boot(s): Time taken during the boot phase
- Total(s): Combined registration and boot time
- Type: Shows "DEFERRED" if the provider is deferred
- Status: Shows "SLOW" if the provider exceeds the threshold
- Memory: Memory consumption (when
--memoryis used) - Diagnostics: Detected performance patterns (filesystem, http, database, etc.)
- Errors: Any errors encountered during profiling
Summary Statistics
The summary section provides:
- Total number of providers
- Successful vs failed providers
- Number of deferred providers
- Count of slow providers
- Total boot time
- Average and median times
- Memory statistics (when enabled)
- Percentile distribution (P50, P75, P90, P95, P99, P100)
Diagnostic Patterns
The profiler detects the following patterns:
- filesystem: File operations (File::allFiles, glob, Storage)
- http: HTTP requests (Http, GuzzleHttp, curl)
- config: Configuration access
- container: Container bindings and resolutions
- database: Database queries (DB, Eloquent, Schema)
- cache: Cache operations
- event: Event listeners and dispatchers
- queue: Queue operations
- broadcast: Broadcasting operations
- mail: Mail operations
- notification: Notification operations
- session: Session operations
- validation: Validation operations
- view: View operations
- route: Route operations
- auth: Authentication operations
- log: Logging operations
- redis: Redis operations
- artisan: Artisan command operations
- count_in_loop: Performance anti-pattern
- potential_n1_query: Potential N+1 query issues
Recommendations
The profiler provides actionable recommendations such as:
- ⚡ Consider optimizing/deferring slow providers
- 🔁 Found count() in loops - consider caching counts
- ⏱️ Consider making more providers deferred if possible
- 🎯 Focus optimization on top slow providers (Pareto principle)
Practical Examples
Example 1: Identifying Slow Providers in Production
# Profile with memory tracking and export results
php artisan profile:providers \
--memory \
--threshold=0.05 \
--export=storage/logs/provider-profile.json
Example 2: Continuous Performance Monitoring
# Compare with previous run to track regressions
php artisan profile:providers \
--compare \
--top=20 \
--memory
Example 3: Optimizing Application Boot Time
# Get detailed analysis with parallel estimation
php artisan profile:providers \
--parallel \
--memory \
--sort=total \
--top=10
Example 4: Debugging Specific Performance Issues
# Focus on providers with database operations php artisan profile:providers \ --memory \ --format=json | jq '.providers | to_entries[] | select(.value.diagnostics | contains(["database"]))'
Best Practices
- Run in Development: This package is intended for development and should be installed with
--dev - Regular Profiling: Profile your application regularly to catch performance regressions early
- Compare Runs: Use
--compareto track performance changes over time - Focus on Top Offenders: Use
--top=10to focus on the most impactful providers - Export Results: Export results for historical tracking and analysis
- Consider Deferring: Look for providers that can be deferred to speed up boot time
- Memory Tracking: Use
--memorywhen investigating memory issues - Parallel Estimation: Use
--parallelto understand potential speedup opportunities
Performance Tips
Based on the profiler's output, consider these optimization strategies:
- Defer Providers: Make providers deferred when their services aren't needed on every request
- Lazy Loading: Avoid loading resources during registration/boot that can be loaded on-demand
- Cache Configuration: Cache configuration values instead of reading files repeatedly
- Optimize Database Queries: Move database queries out of the boot process
- Avoid HTTP Calls: Never make HTTP requests during provider registration/boot
- Minimize File Operations: Reduce filesystem operations during boot
- Use Singleton Bindings: Use singleton bindings for services that should be instantiated once
Troubleshooting
No Providers Found
If you see "No providers found", ensure:
- Your application has registered providers in
config/app.phporbootstrap/providers.php - You're running the command from your Laravel application root
- The cache is cleared:
php artisan config:clear
High Memory Usage
If profiling causes high memory usage:
- Use
--no-diagnosticsto skip diagnostic analysis - Use
--top=Nto limit the number of providers analyzed - Profile in batches using
--only-cachedand without cache
Inaccurate Timings
For more accurate timings:
- Run the profiler multiple times and compare results
- Avoid running other processes during profiling
- Use
--compareto track trends rather than absolute values
Testing
Run the test suite:
composer test
Run tests with coverage:
composer test-coverage
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Security
If you discover any security-related issues, please email saeed.es91@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
Support
If you find this package helpful, please consider:
- ⭐ Starring the repository
- 🐛 Reporting bugs
- 💡 Suggesting new features
- 📖 Improving documentation
- 🔀 Contributing code
Related Packages
- Laravel Debugbar - Debug bar for Laravel
- Laravel Telescope - Debug assistant for Laravel
- Clockwork - Development tools for PHP
saeedvir/laravel-profile-provider 适用场景与选型建议
saeedvir/laravel-profile-provider 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 2, 最近一次更新时间为 2025 年 12 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「performance」 「service provider」 「optimization」 「laravel」 「profile」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 saeedvir/laravel-profile-provider 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 saeedvir/laravel-profile-provider 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 saeedvir/laravel-profile-provider 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
g4 application profiler package
CSS/Javascript Minificator, Compressor and Concatenator for TYPO3 - highly configurable frontend asset optimization for CSS/JS merging, minification and compression with optional body parsing, async/defer loading, inline output, data-ignore exclusions, SRI integrity validation/calculation, external
WordPress mu-plugin to remove jQuery Migrate from the list of jQuery dependencies and to allow jQuery to enqueue before </body> instead of in the <head>.
Time provider, providing consistent current date, time, datetime and timezone across the request.
An Zend Expressive module for loading ZF2 or ZF3 modules.
Create link to static resources with cache-breaking segment based on md5 of the file
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 22
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-28