p6spy 에 대한 소개

6226 단어 P6spy
최근 회사 프로젝트 에 서 는 실 행 된 sql 로 그 를 파일 아래 에 두 는 데 사용 해 야 합 니 다.회사 의 한 신 급 인물 이 해결 되 어 방금 연구 하 는 데 시간 이 좀 걸 렸 다.
그 가 사용 하 는 것 은 p6spy 인 데, 사실 일 도 별로 하지 않 았 다.주요 작업 p6spy 다 했 어 요.
p6 spy 제 이 해 는 p6 spy 가 응용 한 데이터 원본 을 납 치 했 습 니 다. 응용 조작 데이터 베 이 스 는 사실 p6 spy 의 데이터 원본 을 호출 하고 p6 spy 가 실행 해 야 할 sql 또는 hql 같은 문 구 를 납치 한 후에 그 는 스스로 realDatasource 를 호출 한 다음 에 데이터 베 이 스 를 조작 합 니 다. sql 을 납치 한 후에 할 수 있 는 일이 많 습 니 다.
p6 spy 는 파일 에 로 그 를 출력 하거나 콘 솔 에 전달 하거나 Log4j 에 전달 할 수 있 으 며 SQL Profiler 나 IronTrackSQL 도형 화 모니터링 SQL 문 구 를 배치 하여 어떤 문장의 실행 이 시간 이 걸 리 는 지 모니터링 하고 하나씩 최적화 할 수 있 습 니 다.SQL Profiler 나 IronTrackSQL 과 의 결합 에 대해 매개 변수 파일 을 사용 할 수 있 는 링크 입 니 다. 
p6spy sourceforge 에서 다운로드:http://sourceforge.net/projects/p6spy/?source=dlp
p6spy 설정: 첫 번 째: p6spy. jar 를 응용 프로그램의 classpath 에 넣 고 두 번 째: 연결 탱크 나 연결 설정 을 수정 한 jdbc 의 구동 이 p6spy 에 제공 하 는 구동, com. p6spy. engine. spy. P6Spy 드라이버
    Hibernate    ,        hibernate.cfg.xml  ,           connection.driver_class   oracle.jdbc.driver.OracleDriver  com.p6spy.engine.spy.P6SpyDriver                    . web   ,        ,      jdbc-driver     。

Hibernate.cfg.xml:
<session-factory>
    <!--      p6spy       -->
    <property name="connection.driver_class">com.p6spy.engine.spy.P6SpyDriver</property>       
    <property name="connection.url">jdbc:oracle:thin:@localhost:1521:orcl</property>
    <property name="connection.username">scott</property>
    <property name="connection.password">tiger</property>
    <property name="connection.pool_size">1</property>
    <property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
    <property name="current_session_context_class">thread</property>
    <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
    <property name="show_sql">true</property>
    <property name="hbm2ddl.auto">false</property>
    <property name="hibernate.jdbc.batch_size">0</property>
</session-factory>

세 번 째:
수정 하 다.
spy.properties
classpath 아래 에 놓 기:
(파일 내용 이 너무 많아 서 중요 한 것 만 첨부 합 니 다)
#################################################################
# MODULES                                                       #
#                                                               #
# Modules provide the P6Spy functionality.  If a module, such   #
# as module_log is commented out, that functionality will not   #
# be available.  If it is not commented out (if it is active),  #
# the functionality will be active.                             #
#                                                               #
# Values set in Modules cannot be reloaded using the            #
# reloadproperties variable.  Once they are loaded, they remain #
# in memory until the application is restarted.                 #
#                                                               #
#################################################################
#  :module.log       ,     ,P6SPY       ,    :
module.log=com.p6spy.engine.logging.P6LogFactory
#module.outage=com.p6spy.engine.outage.P6OutageFactory

#################################################################
# REALDRIVER(s)                                                 #
#                                                               #
# In your application server configuration file you replace the #
# "real driver" name with com.p6spy.engine.P6SpyDriver. This is #
# where you put the name of your real driver P6Spy can find and #
# register your real driver to do the database work.            #
#                                                               #
# If your application uses several drivers specify them in      #
# realdriver2, realdriver3.  See the documentation for more     #
# details.                                                      #
#                                                               #
# Values set in REALDRIVER(s) cannot be reloaded using the      #
# reloadproperties variable.  Once they are loaded, they remain #
# in memory until the application is restarted.                 #
#                                                               #
#################################################################

#  :       ,   ,    
# oracle driver
# realdriver=oracle.jdbc.driver.OracleDriver

# mysql Connector/J driver
# realdriver=com.mysql.jdbc.Driver

# informix driver
# realdriver=com.informix.jdbc.IfxDriver

# ibm db2 driver
# realdriver=COM.ibm.db2.jdbc.net.DB2Driver

# the mysql open source driver
realdriver=org.gjt.mm.mysql.Driver

#specifies another driver to use
realdriver2=
#specifies a third driver to use
realdriver3=

#  :appender  ,      
#specifies the appender to use for logging
#appender=com.p6spy.engine.logging.appender.Log4jLogger
#   
#appender=com.p6spy.engine.logging.appender.StdoutLogger
appender=com.p6spy.engine.logging.appender.FileLogger

# name of logfile to use, note Windows users should make sure to use forward slashes in their pathname (e:/test/spy.log) (used for file logger only)
#            
logfile     = spy.log

# append to  the p6spy log file.  if this is set to false the
# log file is truncated every time.  (file logger only)
append=true

#The following are for log4j logging only
log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender
log4j.appender.STDOUT.layout=org.apache.log4j.PatternLayout
log4j.appender.STDOUT.layout.ConversionPattern=p6spy - %m%n

log4j.logger.p6spy=INFO,STDOUT

요약: 설정 이 쉬 워 요. 사용 이 쉬 워 요. 기능 이 강해 요!

좋은 웹페이지 즐겨찾기