Grails + Mybatis执行SQL所花时间监控
我们想监控SQL执行的效率,打出执行时间。一般Spring项目都是用AOP拦截,然后计算方法开始结束时间,再减一下,就得到执行花的时间了。那Grails里更简单,不用自己写代码,其实用的是Spring的PerformanceMonitorInterceptor。
修改grails-app\conf\spring\resources.groovy
debug 'java.sql.Connection', 'java.sql.Statement', 'java.sql.PreparedStatement' //'org.mybatis', //'org.apache.ibatis', //'org.codehaus.groovy.grails.plugins.ibatis' trace 'grailsee.performanceMonitor'
OK,然后执行SQL时就自动拦截计算执行时间了,看一下控制台上,有如下信息:
grailsee.performanceMonitor StopWatch 'org.apache.ibatis.session.SqlSession.selectOne': running time (millis) = 8482
执行此SQL花了8秒,搞定!
可以参考http://www.objectpartners.com/2010/10/19/grails-plumbing-spring-aop-interceptors/