您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
3-3 debug工具检测性能
发布时间:2023-05-15 22:59:18编辑:雪饮阅读()
-
如何使用debug工具进行检测性能呢?
首先假如说我们有这样一个控制器:
<?php
namespace app\controllers;
use app\models\WpUsers;
use yii\web\Controller;
class Hello2Controller extends Controller{
public function actionIndex(){
\YII::beginProfile("profile1");
echo "hello kasumi";
sleep(1);
\YII::endProfile("profile1");
print_r(WpUsers::find()->where([">","id",1])->asArray()->all());
return $this->renderPartial('index');
}
}
我们可以在上篇中我们所进入的这个debug工具中看到一些请求列表,那么在Tag这栏点击蓝色的带有Tag的数据id(有点像是md5的一串字符串),即可进入对应Tag数据id的请求里面,然后在新的页面中切换到Database选项卡上面即可看到本次请求时候的数据库查询性能信息,包含执行相关mysql语句。不晓得如果用的不是mysql数据库时候会是怎样呢。
那么性能查询里面除了数据库性能信息外,还包含普通程序片段运行的性能信息。
我们切换到Profilling选项卡,那么这里我们为了更能看的明显点我们的控制器稍微也改下
<?php namespace app\controllers; use app\models\WpUsers; use yii\web\Controller; class Hello2Controller extends Controller{ public function actionIndex(){ \YII::beginProfile("profile1"); echo "hello kasumi"; sleep(1); \YII::endProfile("profile1"); \YII::beginProfile("profile2"); echo "hello kasumi2"; sleep(1); \YII::endProfile("profile2"); print_r(WpUsers::find()->where([">","id",1])->asArray()->all()); return $this->renderPartial('index'); } },并重新请求该控制器并在产生了新的请求后进入新的请求中的这个Profiling选项卡中
可以看到这里分别记录了我们上面控制器中所定义的profile1和profile2这两个代码片段的消耗时间。另外就是说如果要重新请求当前请求接口的Profilling信息,可以直接点击这里的性能信息上面的Lastest即可。也就不用重新回到请求列表然后选择最新请求点击进来看了(万一好多人一起请求,那么请求的接口不是同一个接口,最新的请求接口就未必是你之前看到的请求接口了。。。)
关键字词:debug,性能
上一篇:3-1 关于debug工具
下一篇:4-2 GII工具应用场景