展开
拓展 关闭
订阅号推广码
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 Time:2 ms 2022-07-21 08:56:49
 Execute SQL:DROP TABLE IF EXISTS student

 Consume Time:6 ms 2022-07-21 08:56:49
 Execute SQL:CREATE 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 Time:1 ms 2022-07-21 08:56:49
 Execute SQL:DELETE FROM student

 Consume Time:1 ms 2022-07-21 08:56:49
 Execute SQL:INSERT 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 Time:2 ms 2022-07-21 08:56:50
 Execute SQL:SELECT id,name,age FROM student
posted @ 2022-07-21 09:01  DogLeftover  阅读(28)  评论(0编辑  收藏  举报