展开
拓展 关闭
订阅号推广码
GitHub
视频
公告栏 关闭

性能分析插件

  • pom.xml
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>p6spy</groupId>
<artifactId>p6spy</artifactId>
</dependency>
  • spy.properties
modulelist=com.baomidou.mybatisplus.extension.p6spy.MybatisPlusLogFactory,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
  • 配置类
@Configuration
public class MybatisPlusConfig {
// 该插件 3.1.2 后版本废弃,推荐使用
// @Bean
// public PerformanceInterceptor performanceInterceptor(){
// //启用性能分析插件
// return new PerformanceInterceptor();
// }
}
  • 测试
@SpringBootTest
public class PerformanceTest {
@Autowired
private StudentMapper studentMapper;
@Test
public void test(){
studentMapper.selectList(new QueryWrapper<>());
}
}
  • 控制台
Consume Time2 ms 2022-07-21 08:56:49
Execute SQLDROP TABLE IF EXISTS student
Consume Time6 ms 2022-07-21 08:56:49
Execute SQLCREATE TABLE student ( id BIGINT (20) NOT NULL COMMENT '主键ID', name VARCHAR(30) NULL DEFAULT NULL COMMENT '姓名', age INT (11) NULL DEFAULT NULL COMMENT '年龄', PRIMARY KEY (id) )
Consume Time1 ms 2022-07-21 08:56:49
Execute SQLDELETE FROM student
Consume Time1 ms 2022-07-21 08:56:49
Execute SQLINSERT INTO student (id, name, age) VALUES (1, 'Jone', 18),(2, 'Jack', 20),(3, 'Tom', 28), (4, 'Sandy', 21),(5, 'Billie', 24)
_ _ |_ _ _|_. ___ _ | _
| | |\/|_)(_| | |_\ |_)||_|_\
/ |
3.5.2
2022-07-21 08:56:50.000 INFO 12328 --- [ main] c.b.samples.performance.PerformanceTest : Started PerformanceTest in 1.543 seconds (JVM running for 2.706)
Consume Time2 ms 2022-07-21 08:56:50
Execute SQLSELECT id,name,age FROM student
posted @   DogLeftover  阅读(29)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
· 提示词工程——AI应用必不可少的技术
点击右上角即可分享
微信分享提示