tobento / app-profiler
应用性能分析器。
Requires
- php: >=8.0
- symfony/var-dumper: ^6.0
- tobento/app: ^1.0.7
- tobento/app-http: ^1.1.0
- tobento/app-migration: ^1.0.3
- tobento/app-view: ^1.0.2
- tobento/service-collection: ^1.0.7
- tobento/service-filesystem: ^1.0.5
Requires (Dev)
- phpunit/phpunit: ^9.5
- tobento/app-console: ^1.0
- tobento/app-database: ^1.0.2
- tobento/app-event: ^1.0.2
- tobento/app-logging: ^1.0
- tobento/app-queue: ^1.0.1
- tobento/app-testing: ^1.0
- tobento/app-translation: ^1.0
- tobento/app-user: ^1.0
- vimeo/psalm: ^4.0
README
性能分析器是一个开发工具,如果配置文件中启用了,它会提供有关HTTP请求或控制台命令执行详细信息的工具。
目录
入门
运行此命令以添加运行中的应用性能分析器项目的最新版本。
composer require tobento/app-profiler
需求
- PHP 8.0或更高版本
文档
应用
如果您正在使用骨架,请查看应用骨架。
您还可以查看应用以了解更多关于应用程序的一般信息。
性能分析器启动
性能分析器启动执行以下操作
- 安装和加载性能分析器配置文件
- 根据配置实现接口
- 根据配置添加收集器
- 启动性能分析器后期启动
- 在响应触发时,从收集器收集数据,并可能注入性能分析器工具栏
use Tobento\App\AppFactory; // Create the app $app = (new AppFactory())->createApp(); // Add directories: $app->dirs() ->dir(realpath(__DIR__.'/../'), 'root') ->dir(realpath(__DIR__.'/../app/'), 'app') ->dir($app->dir('app').'config', 'config', group: 'config') ->dir($app->dir('root').'public', 'public') ->dir($app->dir('root').'vendor', 'vendor'); // Adding boots: $app->boot(\Tobento\App\Profiler\Boot\Profiler::class); // ... // Run the app: $app->run();
性能分析器配置
性能分析器的配置位于默认应用骨架配置位置的app/config/profiler.php
文件中,您可以在其中为应用程序配置性能分析器。
性能分析
性能分析器将仅在HTML响应中注入来自当前性能分析的工具栏。任何AJAX请求都将更新工具栏中的性能分析选择,您可以在它们之间切换。
对于JSON响应等其他类型的内容,请使用性能分析页面。只需浏览到/profiler/profiles
URL即可查看所有性能分析。
可用的收集器
默认情况下,所有收集器都在性能分析器配置中定义。即使它们被设置,只有在它们收集数据的服务的安装了的情况下,它们才会收集数据。但您可以选择取消注释不需要的收集器。
启动收集器
此收集器将按调用顺序显示当前启动的启动以及所有注册的启动。
在app/config/profiler.php
文件中
'collectors' => [ \Tobento\App\Profiler\Collector\Boots::class, ],
事件收集器
如果您启动了应用事件 - 事件启动,此收集器将显示当前分发的事件和监听器。
在app/config/profiler.php
文件中
'collectors' => [ \Tobento\App\Profiler\Collector\Events::class, ],
任务收集器
如果您启动了应用队列 - 队列启动,此收集器将显示当前推送的任务。
在app/config/profiler.php
文件中
'collectors' => [ \Tobento\App\Profiler\Collector\Jobs::class, ],
日志收集器
如果您启动了应用日志 - 日志启动,此收集器将显示每个指定记录器当前记录的消息。
在app/config/profiler.php
文件中
'collectors' => [ \Tobento\App\Profiler\Collector\Logs::class, // or \Tobento\App\Profiler\Collector\Logs::class => [ // specify the logger names not to collect messages from: 'exceptLoggers' => ['null'], ], ],
中间件收集器
如果您启动了应用Http - 中间件启动,此收集器将显示当前分发的中间件以及可用的别名。
在app/config/profiler.php
文件中
'collectors' => [ \Tobento\App\Profiler\Collector\Middleware::class, ],
请求和响应收集器
如果您启动了应用Http - Http启动,此收集器将显示当前请求和响应数据。
在app/config/profiler.php
文件中
'collectors' => [ \Tobento\App\Profiler\Collector\RequestResponse::class, ],
路由收集器
如果您启动了应用Http - 路由启动,此收集器将显示所有注册的路由。
在app/config/profiler.php
文件中
'collectors' => [ \Tobento\App\Profiler\Collector\Routes::class, ],
会话收集器
如果您已启动了App Http - Session Boot,此收集器将显示所有会话数据。
在app/config/profiler.php
文件中
'collectors' => [ \Tobento\App\Profiler\Collector\Session::class, // or: \Tobento\App\Profiler\Collector\Session::class => [ // specify the data you wont't to hide: 'hiddens' => [ '_session_flash_once', '_session_flash.old', ], ], ],
存储查询收集器
如果您已启动了App Database - Database Boot,此收集器将显示从任何配置的存储数据库执行的所有查询。
在app/config/profiler.php
文件中
'collectors' => [ \Tobento\App\Profiler\Collector\StorageQueries::class, ],
翻译收集器
如果您已启动了App Translation - Translation Boot,此收集器将显示所有未翻译的内容。
在app/config/profiler.php
文件中
'collectors' => [ \Tobento\App\Profiler\Collector\Translation::class, ],
视图收集器
如果您已启动了App View - View Boot,此收集器将显示当前渲染的视图和资源。
在app/config/profiler.php
文件中
'collectors' => [ \Tobento\App\Profiler\Collector\View::class, // or you may configure only the data to collect: \Tobento\App\Profiler\Collector\View::class => [ 'collectViews' => true, 'collectAssets' => false, ], ],
创建收集器
您可以通过实现Tobento\App\Profiler\Collector\CollectorInterface
或Tobento\App\Profiler\Collector\LateCollectorInterface
来创建自己的数据收集器。
通过实现CollectorInterface
,收集器类将在分析器启动后创建,而实现LateCollectorInterface
的类将在延迟分析器启动后创建。
我建议投资于其实现可用的收集器。