netpromotion / profiler
带有 Tracy 适配器的性能分析器
v1.4.0-rc2
2016-11-14 10:45 UTC
Requires
- php: >=5.4
- petrknap/php-profiler: ^1.1
- petrknap/php-singleton: ^1.0
Requires (Dev)
- laravel/lumen-framework: ^5.0
- latte/latte: ^2.3
- netpromotion/tracy-psr-logger: ^1.1
- netpromotion/tracy-wrapper: ^1.0
- nette/application: ^2.3
- nette/bootstrap: ^2.3
- nette/di: *
- phpunit/phpunit: ^4.8
- psr/log: *
- tracy/tracy: *
Conflicts
- nette/di: <2.2 || >=3
- psr/log: <1.0 || >= 2
- tracy/tracy: <2.2 || >=3
This package is not auto-updated.
Last update: 2024-09-14 19:25:45 UTC
README
此仓库包含一个轻量级、非常快速且易于使用的性能分析器(Profiler),并为 Tracy 提供适配器。
用法
如果您想分析一段代码,只需在 Profiler::start
和 Profiler::finish
调用之间包装它。
<?php // index.php if (/* Is debug mode enabled? */) { Profiler::enable(); } Profiler::start(); require(__DIR__ . "/required_file.php"); Profiler::finish();
<?php // required_file.php // If you wish to use default labels, call functions without parameters Profiler::start(/* sprintf("%s#%s", __FILE__, __LINE__) */); /* your code goes here */ Profiler::finish(/* sprintf("%s#%s", __FILE__, __LINE__) */); // If you wish to use static labels, place label as first parameter Profiler::start("static label"); /* your code goes here */ Profiler::finish("static label"); // If you wish to use dynamic labels, call functions like sprintf Profiler::start(/* sprintf( */ "line %s", __LINE__ /* ) */); /* your code goes here */ Profiler::finish(/* sprintf( */ "line %s", __LINE__ /* ) */); // If you wish to create more detailed profiles, start new profile inside another one Profiler::start("Profile 1"); /* your code goes here */ Profiler::start("Profile 1.1"); Profiler::start("Profile 1.1.1"); /* your code goes here */ Profiler::finish("Profile 1.1.1"); /* your code goes here */ Profiler::start("Profile 1.1.2"); /* your code goes here */ Profiler::finish("Profile 1.1.2"); /* your code goes here */ Profiler::finish("Profile 1.1"); Profiler::finish("Profile 1");
如果您想了解更多关于 Profiler 的信息,请访问 Profiler 的 README.md。
安装方法
在您的项目目录中运行 composer require netpromotion/profiler
。
Nette
将扩展 Netpromotion\Profiler\Extension\ProfilerNetteExtension
添加到您的配置中,不需要调用 Profiler::enable
。
extensions: profiler: Netpromotion\Profiler\Extension\ProfilerNetteExtension
如果您想在容器准备就绪之前进行性能分析,请手动调用 Profiler::enable
。
配置
profiler: profile: createService: false # or true bar: primaryValue: effective # or absolute show: memoryUsageChart: true # or false shortProfiles: true # or false timeLines: true # or false
有一个实时演示可用 - 运行 make demo
并 点击此处。
Lumen、纯 PHP 以及其他一切
通过 Bar::addPanel
方法手动将面板 Netpromotion\Profiler\Adapter\TracyBarAdapter
添加到您的条目中,或使用 netpromotion/tracy-wrapper。
tracy_wrap(function() { /* your code goes here */ }, [new TracyBarAdapter([ "primaryValue" => "effective", // or "absolute" "show" => [ "memoryUsageChart" => true, // or false "shortProfiles" => true, // or false "timeLines" => true // or false ] ])]);
有一个实时演示可用 - 运行 make demo
并 点击此处。