mybatis-plus性能分析组件p6spy
依赖添加
<!--p6spy依赖-->
<dependency>
   <groupId>p6spy</groupId>
   <artifactId>p6spy</artifactId>
   <version>3.8.7</version>
</dependency>
数据连接修改
#驱动需要改为p6spy的驱动
driverClassName: com.p6spy.engine.spy.P6SpyDriver
#连接串修改,jdbc后面添加p6spy,其他没有变化
url: jdbc:p6spy:mysql://localhost:3306/lwpstudy?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8
p6spy配置文件添加
文件名为:spy.properties,存放路径和application.yml同级
#3.2.1以上使用
modulelist=com.baomidou.mybatisplus.extension.p6spy.MybatisPlusLogFactory,com.p6spy.engine.outage.P6OutageFactory
#3.2.1以下使用或者不配置
#modulelist=com.p6spy.engine.logging.P6LogFactory,com.p6spy.engine.outage.P6OutageFactory
# 自定义日志打印
logMessageFormat=com.baomidou.mybatisplus.extension.p6spy.P6SpyLogger
#日志输出到控制台
appender=com.baomidou.mybatisplus.extension.p6spy.StdoutLogger
# 使用日志系统记录 sql
#appender=com.p6spy.engine.spy.appender.Slf4JLogger
# 设置 p6spy driver 代理
deregisterdrivers=true
# 取消JDBC URL前缀
useprefix=true
# 配置记录 Log 例外,可去掉的结果集有error,info,batch,debug,statement,commit,rollback,result,resultset.
excludecategories=info,debug,result,commit,resultset
# 日期格式
dateformat=yyyy-MM-dd HH:mm:ss
# 实际驱动可多个
#driverlist=org.h2.Driver
# 是否开启慢SQL记录
outagedetection=true
# 慢SQL记录标准 2 秒
outagedetectioninterval=2
测试执行
//会输出查询的耗时以及查询的语句
Consume Time:2 ms 2021-07-11 21:25:17
Execute SQL:SELECT stuId,stuName,stuSex,stuAddress,stuAge,version,deleted,create_time AS createTime,update_time AS updateTime FROM student WHERE deleted=0
注意
- 该插件有性能损耗,不建议生产环境使用。