利用P6SPY +SQL Profiler記錄、統(tǒng)計(jì)web app對(duì)數(shù)據(jù)庫(kù)的操作。
弄hibernate時(shí),想顯示sql語(yǔ)句,可以設(shè)置show_sql為true來(lái)達(dá)到這個(gè)目的,但是參數(shù)值全是像PreparedStatement一樣,用?來(lái)代替的。
用p6spy可以達(dá)到顯示的那些參數(shù)原值的目的,但可讀性差。可以利用SQL Profiler來(lái)處理這個(gè)事情。
p6spy: http://www.p6spy.com
SQL Profile: http://www.jahia.net/jahia/page597.html
p6spy安裝:
* 將p6spy.jar放到WEB-INF/lib目錄下,將spy.properties放到WEB-INF/classes目錄下。
* 修改你 原有 JDBC Driver為:com.p6spy.engine.spy.P6SpyDriver
* 修改 spy.properties 中的 realdriver 值為 原有 的JDBC Driver,比如我的是:com.mysql.jdbc.Driver
* 完成,運(yùn)行web server。
我的日志記錄產(chǎn)生在 %TOMCAT_HOME%\bin下,此log位置可以能過(guò)修改 logfile = x:\x_dir\spy.log 來(lái)控制
打開看看,看里面的日志是不是看起來(lái)比較不爽?下面我們安裝SQL Profiler來(lái)讓自已的視線爽一點(diǎn)。
SQL Profiler安裝:(須p6spy成功安裝)
* 將SQL Profiler自帶的spy.properties覆蓋原來(lái)的classes目錄下文件
* 修改現(xiàn)在spy.properties中realdriver 值為 原有 的JDBC Driver
看后看看readme注意這幾句 ^__^ :
1. Start the GUI
2. Start the webapp, in starts doing some JDBC requests we will ignore
3. Press the "reset" button on the GUI
4. Make a request to the webapp
5. Press the "pause" button after the request has finished executing
6. Press the "report" button to save profiling results as a CSV file
* 我們先用java -jar sqlprofiler.jar 運(yùn)行 sql profiler
* 然后啟動(dòng)web server :-)
一切盡在眼前了吧?
當(dāng)然,p6spy 和 sql profiler 能做的不止這些,sql profiler還能根據(jù)你的query來(lái)幫你生成建立合適的index功能等等。
只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。 | ||
![]() |
||
網(wǎng)站導(dǎo)航:
博客園
IT新聞
Chat2DB
C++博客
博問(wèn)
管理
|
||
相關(guān)文章:
|
||