irap/profiling
Composer 安装命令:
composer require irap/profiling
包简介
Profiling library for PHP 5.6+
关键字:
README 文档
README
This is a package for PHP which makes it easier to find which functions/areas take the most time.
Installation
Install through composer with:
composer require irap/profiling
Usage
Below is an example script that demonstrates using this tool:
<?php # Include the autoloader for packages. require_once(__DIR__ . '/vendor/autoload.php'); function Bar() { \iRAP\Profiling\FunctionAnalyzer::start(); sleep(3); \iRAP\Profiling\FunctionAnalyzer::stop(); } function Foo() { \iRAP\Profiling\FunctionAnalyzer::start(); sleep(1); Bar(); \iRAP\Profiling\FunctionAnalyzer::stop(); } Foo(); print \iRAP\Profiling\FunctionAnalyzer::getResults();
This should output something similar to:
Foo: 1.0001013278961 seconds
Bar: 3.0002498626709 seconds
Notice that even though Bar is called from within Foo, so Foo takes a total of 4 seconds to execute, the result for Foo is just 1 second because the tool is showing how much time was taken up doing logic in Foo rather than within Bar because Bar is already being profiled separately. If you wanted the total time taken within Foo including Bar, then one just needs to take the analyzer calls out of the Bar method:
<?php # Include the autoloader for packages. require_once(__DIR__ . '/vendor/autoload.php'); function Bar() { sleep(3); } function Foo() { \iRAP\Profiling\FunctionAnalyzer::start(); sleep(1); Bar(); \iRAP\Profiling\FunctionAnalyzer::stop(); } Foo(); print \iRAP\Profiling\FunctionAnalyzer::getResults();
Output:
Foo: 4.0003681182861 seconds
Profiling Small Sections - Custom Names
If you have a very long function, and want to profile separate parts of it, then you can just provide a custom name to the start and stop methods like so:
require_once(__DIR__ . '/vendor/autoload.php'); function Bar() { sleep(3); } function Foo() { sleep(1); } function main() { \iRAP\Profiling\FunctionAnalyzer::start('part1'); Foo(); \iRAP\Profiling\FunctionAnalyzer::stop('part1'); // Profiling part 2 \iRAP\Profiling\FunctionAnalyzer::start('part2'); Bar(); Foo(); \iRAP\Profiling\FunctionAnalyzer::stop('part2'); } main(); print \iRAP\Profiling\FunctionAnalyzer::getResults();
... which outputs:
part1: 1.0000782012939 seconds
part2: 4.0001401901245 seconds
irap/profiling 适用场景与选型建议
irap/profiling 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 06 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「profiling」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 irap/profiling 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 irap/profiling 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 irap/profiling 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Quick profiling of your code for Laravel
Excimetry PHP package. Bridge between ext-eximer and open telemetry
An SDK for sending profiling data to Perfbase
MongoQP is a frontend for MongoDB's query profiler collection.
PHPUnit loggers to profile tests.
Database Profiler for Laravel Web and Console Applications.
统计信息
- 总下载量: 3k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-06-13