网站dns服务,域名建网站,wordpress文章摘要调用,828企业服务平台目录 1. 说明
2. PHP脚本性能监测方案
2.1 安装xdebug
2.2 配置xdebug.ini
2.3 命令行与VS Code中使用
- 命令行
- VS Code
2.4 QCacheGrind 浏览
3. Python脚本性能监测方案
3.1 命令行
4. 工具
5.参考 1. 说明 获取我们的脚本程序运行时的指标#xff0c;对分析…目录 1. 说明
2. PHP脚本性能监测方案
2.1 安装xdebug
2.2 配置xdebug.ini
2.3 命令行与VS Code中使用
- 命令行
- VS Code
2.4 QCacheGrind 浏览
3. Python脚本性能监测方案
3.1 命令行
4. 工具
5.参考 1. 说明 获取我们的脚本程序运行时的指标对分析与解决性能瓶颈问题是非常重要的一环以下介绍在PHP与Python下的实践方案安装性能监测插件 产生监测日志 用QCacheGrind工具分析
2. PHP脚本性能监测方案
2.1 安装xdebug
# wsl2下的ubuntu20 LTS为例apt install php7.4-xdebug2.2 配置xdebug.ini
tips: 路径可通过查php -i|grep xdebug.ini获取
zend_extensionxdebug.so# 指定日志输出路径
xdebug.output_dir /xdebug_logs
xdebug.profiler_append 0xdebug.mode profile
xdebug.start_with_request trigger
xdebug.log_level 7
2.3 命令行与VS Code中使用
- 命令行
php -dxdebug.modeprofile myscript
- VS Code
切记vscode运行时连接WSL选择对应的ubuntu目录不然你的运行环境将不一致
普通的launch.json
{name: Debug current script in console,type: php,request: launch,program: ${file},cwd: ${fileDirname},runtimeArgs: [-d xdebug.modeprofile],externalConsole: false,port: 9003
}
以TP6为例的launch.json
{name: Run PHP Profile,type: php,request: launch,cwd: ${workspaceRoot},program: ${workspaceRoot}/think,args: [myaction,0],runtimeArgs: [-d xdebug.modeprofile],externalConsole: false,port: 9003
}
截图:
2.4 QCacheGrind 浏览 生成的日志保存在 \\wsl.localhost\Ubuntu-20.04\xdebug_logs 3. Python脚本性能监测方案
python内部已经提供了cProfile性能监测模块我们用它就好只需要把它出来的文件转换一下
3.1 命令行
# 产生日志到./tmp/profile_output.prof
python -m cProfile -o ./tmp/profile_output.prof ./class_test2.py# 转换格式
python -m pyprof2calltree -i profile_output.prof -o callgrind.cprof 4. 工具
工具说明QCacheGrind windows工具能可视化查看callgrind格式的性能数据 下载https://sourceforge.net/projects/qcachegrindwin/ PHPXDebug官网: Xdebug - Debugger and Profiler Tool for PHPPythoncProfile内置标准模块, 性能分析模块 例子: python -m cProfile -o ./tmp/profile_output.prof ./class_test2.pypyprof2calltree把cprofile产生的性能日志转换为QCacheGrind格式, 例子: python -m pyprof2calltree -i profile_output.prof -o callgrind.cprof
5.参考
- Xdebug: Documentation » Profiling
- The Python Profilers — Python 3.13.0 documentation
- https://gist.github.com/Susensio/efd9422e14556dff4122434c3603aff3