link0 / profiler
PHP 的性能分析库,使用 XHProf 或 uprofiler,并提供了多个持久化层
v1.0.1
2015-03-10 23:11 UTC
Requires
- php: >=5.3.3
- league/flysystem: ^1.0
- predis/predis: v1.0.0
- rhumsaa/uuid: ^2.7.3
- zendframework/zend-db: ~2.3
Requires (Dev)
- mockery/mockery: 0.9.2
- phpunit/phpunit: ~4.2
This package is not auto-updated.
Last update: 2024-09-24 02:52:36 UTC
README
Link0/Profiler 作为 XHProf 性能分析的层,并持久化配置文件以供后续分析。
代码相对较新,如果您遇到任何错误,请报告,即使单元测试应该覆盖 100% 的代码。
欢迎所有想法,也欢迎贡献者。
要求
安装
要将 Link0/Profiler 添加为您的项目的本地、项目级别的依赖项,只需使用 Composer 依赖项 link0/profiler
。
composer require "link0/profiler" "~1.0"
还有可用的 Symfony2 扩展包,请参阅 Link0/ProfilerBundle。要安装它,请使用以下 composer 包
composer require "link0/profiler-bundle" "~1.0"
在您的机器上安装 XHProf
pecl install -f xhprof
或者
apt-get install php5-xhprof
或者
# If you have the josegonzalez/homebrew-php formulae tapped, install them with brew.
# Change your version accordingly
brew install php55-xhprof
使用 XHGui 进行快速设置
要开始使用此性能分析包和 XHGui,请将 XHGui 配置为监听您的 MongoDB 实例。
对于您想要进行性能分析的所有项目,并将结果聚合到集中式服务器,请设置以下配置
$connectionAddress = 'mongodb://mongodb.example.com:27017'; $mongoClient = new \Link0\Profiler\PersistenceHandler\MongoDbHandler\MongoClient($connectionAddress); $persistenceHandler = new \Link0\Profiler\PersistenceHandler\MongoDbHandler($mongoClient); $profiler = new \Link0\Profiler\Profiler($persistenceHandler); $profiler->start();
更详细的信息
该库完全是关于 Profiler,您想要实例化它并让它施展魔法
$profiler = new \Link0\Profiler\Profiler(); $profiler->start(); print_r($profiler->stop());
如果您想使用基于浏览器的工具(如 XHProf Helper)开始性能分析,您可以使用此方法
$profiler = new \Link0\Profiler\Profiler(); $profiler->startOn(@$_COOKIE['_profiler']); // or $profiler->startOn(@$_COOKIE['XHProf_Profile']);
如果您想存储结果,可以将一个 PersistenceHandler 对象传递给 Profiler
$persistenceHandler = new \Link0\Profiler\PersistenceHandler\MemoryHandler(); $profiler = new \Link0\Profiler\Profiler($persistenceHandler);
这样,结果存储在内存中,可能不太方便,但可以方便地玩耍。
还有一个实现,使用 Flysystem 库在文件系统中存储配置文件。
$filesystemAdapter = new \League\Flysystem\Adapter\Local('/tmp/profiler'); $filesystem = new \League\Flysystem\Filesystem($filesystemAdapter); $persistenceHandler = new \Link0\Profiler\PersistenceHandler\FilesystemHandler($filesystem); $profiler = new \Link0\Profiler\Profiler($persistenceHandler);