Created
August 25, 2014 07:23
-
-
Save jballanc/1a713c2024e2ab35b796 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- /Users/jballanc/Downloads/ConcurrentStatisticsImpl.java 2014-08-25 04:04:59.000000000 +0300 | |
+++ ConcurrentStatisticsImpl.java 2014-08-24 19:58:59.000000000 +0300 | |
@@ -1,3 +1,26 @@ | |
+/* | |
+ * Hibernate, Relational Persistence for Idiomatic Java | |
+ * | |
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as | |
+ * indicated by the @author tags or express copyright attribution | |
+ * statements applied by the authors. All third-party contributions are | |
+ * distributed under license by Red Hat Inc. | |
+ * | |
+ * This copyrighted material is made available to anyone wishing to use, modify, | |
+ * copy, or redistribute it subject to the terms and conditions of the GNU | |
+ * Lesser General Public License, as published by the Free Software Foundation. | |
+ * | |
+ * This program is distributed in the hope that it will be useful, | |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | |
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License | |
+ * for more details. | |
+ * | |
+ * You should have received a copy of the GNU Lesser General Public License | |
+ * along with this distribution; if not, write to: | |
+ * Free Software Foundation, Inc. | |
+ * 51 Franklin Street, Fifth Floor | |
+ * Boston, MA 02110-1301 USA | |
+ */ | |
package org.hibernate.stat; | |
import java.util.concurrent.ConcurrentHashMap; | |
@@ -6,19 +29,25 @@ | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
+ | |
import org.hibernate.cache.Region; | |
-import org.hibernate.engine.SessionFactoryImplementor; | |
+import org.hibernate.engine.spi.SessionFactoryImplementor; | |
import org.hibernate.util.ArrayHelper; | |
/** | |
+ * Implementation of {@link Statistics}, as well as {@link StatisticsImplementor}, based on the | |
+ * {@link java.util.concurrent} package introduced in Java 5. | |
+ * | |
* @author Alex Snaps | |
- * @see org.hibernate.stat.Statistics | |
*/ | |
public class ConcurrentStatisticsImpl implements Statistics, StatisticsImplementor { | |
- //TODO: we should provide some way to get keys of collection of statistics to make it easier to retrieve from a GUI perspective | |
+ private static final Logger log = LoggerFactory.getLogger( ConcurrentStatisticsImpl.class ); | |
+ private static final Logger PERF_LOG = LoggerFactory.getLogger( Statistics.class ); | |
- private static final Logger log = LoggerFactory.getLogger(ConcurrentStatisticsImpl.class); | |
+ static { | |
+ log.info("OMERO-specific ConcurrentStatisticsImpl"); | |
+ } | |
private SessionFactoryImplementor sessionFactory; | |
@@ -54,7 +83,7 @@ | |
private AtomicLong queryCacheMissCount = new AtomicLong(); | |
private AtomicLong queryCachePutCount = new AtomicLong(); | |
- private AtomicLong commitedTransactionCount = new AtomicLong(); | |
+ private AtomicLong committedTransactionCount = new AtomicLong(); | |
private AtomicLong transactionCount = new AtomicLong(); | |
private AtomicLong optimisticFailureCount = new AtomicLong(); | |
@@ -74,7 +103,7 @@ | |
/** | |
* entity statistics per query string (HQL or SQL) | |
*/ | |
- private final ConcurrentMap queryStatistics = new ConcurrentHashMap(); | |
+ private final ConcurrentMap queryStatistics = null; | |
public ConcurrentStatisticsImpl() { | |
clear(); | |
@@ -89,46 +118,46 @@ | |
* reset all statistics | |
*/ | |
public void clear() { | |
- secondLevelCacheHitCount.set(0); | |
- secondLevelCacheMissCount.set(0); | |
- secondLevelCachePutCount.set(0); | |
- | |
- sessionCloseCount.set(0); | |
- sessionOpenCount.set(0); | |
- flushCount.set(0); | |
- connectCount.set(0); | |
- | |
- prepareStatementCount.set(0); | |
- closeStatementCount.set(0); | |
- | |
- entityDeleteCount.set(0); | |
- entityInsertCount.set(0); | |
- entityUpdateCount.set(0); | |
- entityLoadCount.set(0); | |
- entityFetchCount.set(0); | |
- | |
- collectionRemoveCount.set(0); | |
- collectionUpdateCount.set(0); | |
- collectionRecreateCount.set(0); | |
- collectionLoadCount.set(0); | |
- collectionFetchCount.set(0); | |
- | |
- queryExecutionCount.set(0); | |
- queryCacheHitCount.set(0); | |
- queryExecutionMaxTime.set(0); | |
+ secondLevelCacheHitCount.set( 0 ); | |
+ secondLevelCacheMissCount.set( 0 ); | |
+ secondLevelCachePutCount.set( 0 ); | |
+ | |
+ sessionCloseCount.set( 0 ); | |
+ sessionOpenCount.set( 0 ); | |
+ flushCount.set( 0 ); | |
+ connectCount.set( 0 ); | |
+ | |
+ prepareStatementCount.set( 0 ); | |
+ closeStatementCount.set( 0 ); | |
+ | |
+ entityDeleteCount.set( 0 ); | |
+ entityInsertCount.set( 0 ); | |
+ entityUpdateCount.set( 0 ); | |
+ entityLoadCount.set( 0 ); | |
+ entityFetchCount.set( 0 ); | |
+ | |
+ collectionRemoveCount.set( 0 ); | |
+ collectionUpdateCount.set( 0 ); | |
+ collectionRecreateCount.set( 0 ); | |
+ collectionLoadCount.set( 0 ); | |
+ collectionFetchCount.set( 0 ); | |
+ | |
+ queryExecutionCount.set( 0 ); | |
+ queryCacheHitCount.set( 0 ); | |
+ queryExecutionMaxTime.set( 0 ); | |
queryExecutionMaxTimeQueryString = null; | |
- queryCacheMissCount.set(0); | |
- queryCachePutCount.set(0); | |
+ queryCacheMissCount.set( 0 ); | |
+ queryCachePutCount.set( 0 ); | |
- transactionCount.set(0); | |
- commitedTransactionCount.set(0); | |
+ transactionCount.set( 0 ); | |
+ committedTransactionCount.set( 0 ); | |
- optimisticFailureCount.set(0); | |
+ optimisticFailureCount.set( 0 ); | |
secondLevelCacheStatistics.clear(); | |
entityStatistics.clear(); | |
collectionStatistics.clear(); | |
- queryStatistics.clear(); | |
+ // queryStatistics.clear(); | |
startTime = System.currentTimeMillis(); | |
} | |
@@ -151,26 +180,29 @@ | |
public void loadEntity(String entityName) { | |
entityLoadCount.getAndIncrement(); | |
- ((ConcurrentEntityStatisticsImpl) getEntityStatistics(entityName)).incrementLoadCount(); | |
+ ( (ConcurrentEntityStatisticsImpl) getEntityStatistics( entityName ) ).incrementLoadCount(); | |
} | |
public void fetchEntity(String entityName) { | |
entityFetchCount.getAndIncrement(); | |
- ((ConcurrentEntityStatisticsImpl) getEntityStatistics(entityName)).incrementFetchCount(); | |
+ ( (ConcurrentEntityStatisticsImpl) getEntityStatistics( entityName ) ).incrementFetchCount(); | |
} | |
/** | |
* find entity statistics per name | |
* | |
* @param entityName entity name | |
+ * | |
* @return EntityStatistics object | |
*/ | |
public EntityStatistics getEntityStatistics(String entityName) { | |
- ConcurrentEntityStatisticsImpl es = (ConcurrentEntityStatisticsImpl) entityStatistics.get(entityName); | |
- if (es == null) { | |
- es = new ConcurrentEntityStatisticsImpl(entityName); | |
+ ConcurrentEntityStatisticsImpl es = (ConcurrentEntityStatisticsImpl) entityStatistics.get( entityName ); | |
+ if ( es == null ) { | |
+ es = new ConcurrentEntityStatisticsImpl( entityName ); | |
ConcurrentEntityStatisticsImpl previous; | |
- if ((previous = (ConcurrentEntityStatisticsImpl) entityStatistics.putIfAbsent(entityName, es)) != null) { | |
+ if ( ( previous = (ConcurrentEntityStatisticsImpl) entityStatistics.putIfAbsent( | |
+ entityName, es | |
+ ) ) != null ) { | |
es = previous; | |
} | |
} | |
@@ -179,19 +211,19 @@ | |
public void updateEntity(String entityName) { | |
entityUpdateCount.getAndIncrement(); | |
- ConcurrentEntityStatisticsImpl es = (ConcurrentEntityStatisticsImpl) getEntityStatistics(entityName); | |
+ ConcurrentEntityStatisticsImpl es = (ConcurrentEntityStatisticsImpl) getEntityStatistics( entityName ); | |
es.incrementUpdateCount(); | |
} | |
public void insertEntity(String entityName) { | |
entityInsertCount.getAndIncrement(); | |
- ConcurrentEntityStatisticsImpl es = (ConcurrentEntityStatisticsImpl) getEntityStatistics(entityName); | |
+ ConcurrentEntityStatisticsImpl es = (ConcurrentEntityStatisticsImpl) getEntityStatistics( entityName ); | |
es.incrementInsertCount(); | |
} | |
public void deleteEntity(String entityName) { | |
entityDeleteCount.getAndIncrement(); | |
- ConcurrentEntityStatisticsImpl es = (ConcurrentEntityStatisticsImpl) getEntityStatistics(entityName); | |
+ ConcurrentEntityStatisticsImpl es = (ConcurrentEntityStatisticsImpl) getEntityStatistics( entityName ); | |
es.incrementDeleteCount(); | |
} | |
@@ -199,14 +231,17 @@ | |
* Get collection statistics per role | |
* | |
* @param role collection role | |
+ * | |
* @return CollectionStatistics | |
*/ | |
public CollectionStatistics getCollectionStatistics(String role) { | |
- ConcurrentCollectionStatisticsImpl cs = (ConcurrentCollectionStatisticsImpl) collectionStatistics.get(role); | |
- if (cs == null) { | |
- cs = new ConcurrentCollectionStatisticsImpl(role); | |
+ ConcurrentCollectionStatisticsImpl cs = (ConcurrentCollectionStatisticsImpl) collectionStatistics.get( role ); | |
+ if ( cs == null ) { | |
+ cs = new ConcurrentCollectionStatisticsImpl( role ); | |
ConcurrentCollectionStatisticsImpl previous; | |
- if ((previous = (ConcurrentCollectionStatisticsImpl) collectionStatistics.putIfAbsent(role, cs)) != null) { | |
+ if ( ( previous = (ConcurrentCollectionStatisticsImpl) collectionStatistics.putIfAbsent( | |
+ role, cs | |
+ ) ) != null ) { | |
cs = previous; | |
} | |
} | |
@@ -215,49 +250,52 @@ | |
public void loadCollection(String role) { | |
collectionLoadCount.getAndIncrement(); | |
- ((ConcurrentCollectionStatisticsImpl) getCollectionStatistics(role)).incrementLoadCount(); | |
+ ( (ConcurrentCollectionStatisticsImpl) getCollectionStatistics( role ) ).incrementLoadCount(); | |
} | |
public void fetchCollection(String role) { | |
collectionFetchCount.getAndIncrement(); | |
- ((ConcurrentCollectionStatisticsImpl) getCollectionStatistics(role)).incrementFetchCount(); | |
+ ( (ConcurrentCollectionStatisticsImpl) getCollectionStatistics( role ) ).incrementFetchCount(); | |
} | |
public void updateCollection(String role) { | |
collectionUpdateCount.getAndIncrement(); | |
- ((ConcurrentCollectionStatisticsImpl) getCollectionStatistics(role)).incrementUpdateCount(); | |
+ ( (ConcurrentCollectionStatisticsImpl) getCollectionStatistics( role ) ).incrementUpdateCount(); | |
} | |
public void recreateCollection(String role) { | |
collectionRecreateCount.getAndIncrement(); | |
- ((ConcurrentCollectionStatisticsImpl) getCollectionStatistics(role)).incrementRecreateCount(); | |
+ ( (ConcurrentCollectionStatisticsImpl) getCollectionStatistics( role ) ).incrementRecreateCount(); | |
} | |
public void removeCollection(String role) { | |
collectionRemoveCount.getAndIncrement(); | |
- ((ConcurrentCollectionStatisticsImpl) getCollectionStatistics(role)).incrementRemoveCount(); | |
+ ( (ConcurrentCollectionStatisticsImpl) getCollectionStatistics( role ) ).incrementRemoveCount(); | |
} | |
/** | |
* Second level cache statistics per region | |
* | |
* @param regionName region name | |
+ * | |
* @return SecondLevelCacheStatistics | |
*/ | |
public SecondLevelCacheStatistics getSecondLevelCacheStatistics(String regionName) { | |
ConcurrentSecondLevelCacheStatisticsImpl slcs | |
- = (ConcurrentSecondLevelCacheStatisticsImpl) secondLevelCacheStatistics.get(regionName); | |
- if (slcs == null) { | |
- if (sessionFactory == null) { | |
+ = (ConcurrentSecondLevelCacheStatisticsImpl) secondLevelCacheStatistics.get( regionName ); | |
+ if ( slcs == null ) { | |
+ if ( sessionFactory == null ) { | |
return null; | |
} | |
- Region region = sessionFactory.getSecondLevelCacheRegion(regionName); | |
- if (region == null) { | |
+ Region region = sessionFactory.getSecondLevelCacheRegion( regionName ); | |
+ if ( region == null ) { | |
return null; | |
} | |
- slcs = new ConcurrentSecondLevelCacheStatisticsImpl(region); | |
+ slcs = new ConcurrentSecondLevelCacheStatisticsImpl( region ); | |
ConcurrentSecondLevelCacheStatisticsImpl previous; | |
- if ((previous = (ConcurrentSecondLevelCacheStatisticsImpl) secondLevelCacheStatistics.putIfAbsent(regionName, slcs)) != null) { | |
+ if ( ( previous = (ConcurrentSecondLevelCacheStatisticsImpl) secondLevelCacheStatistics.putIfAbsent( | |
+ regionName, slcs | |
+ ) ) != null ) { | |
slcs = previous; | |
} | |
} | |
@@ -266,60 +304,70 @@ | |
public void secondLevelCachePut(String regionName) { | |
secondLevelCachePutCount.getAndIncrement(); | |
- ((ConcurrentSecondLevelCacheStatisticsImpl) getSecondLevelCacheStatistics(regionName)).incrementPutCount(); | |
+ ( (ConcurrentSecondLevelCacheStatisticsImpl) getSecondLevelCacheStatistics( regionName ) ).incrementPutCount(); | |
} | |
public void secondLevelCacheHit(String regionName) { | |
secondLevelCacheHitCount.getAndIncrement(); | |
- ((ConcurrentSecondLevelCacheStatisticsImpl) getSecondLevelCacheStatistics(regionName)).incrementHitCount(); | |
+ ( (ConcurrentSecondLevelCacheStatisticsImpl) getSecondLevelCacheStatistics( regionName ) ).incrementHitCount(); | |
} | |
public void secondLevelCacheMiss(String regionName) { | |
secondLevelCacheMissCount.getAndIncrement(); | |
- ((ConcurrentSecondLevelCacheStatisticsImpl) getSecondLevelCacheStatistics(regionName)).incrementMissCount(); | |
+ ( (ConcurrentSecondLevelCacheStatisticsImpl) getSecondLevelCacheStatistics( regionName ) ).incrementMissCount(); | |
} | |
public void queryExecuted(String hql, int rows, long time) { | |
+ PERF_LOG.info( "HQL: {}, time: {}ms, rows: {}", new Object[] {hql, Long.valueOf( time ), Long.valueOf(rows)} ); | |
queryExecutionCount.getAndIncrement(); | |
boolean isLongestQuery = false; | |
- for (long old = queryExecutionMaxTime.get(); (time > old) && (isLongestQuery = !queryExecutionMaxTime.compareAndSet(old, time)); old = queryExecutionMaxTime.get()) | |
- ; | |
- if (isLongestQuery) { | |
+ for ( long old = queryExecutionMaxTime.get(); | |
+ ( time > old ) && ( isLongestQuery = !queryExecutionMaxTime.compareAndSet( old, time ) ); | |
+ old = queryExecutionMaxTime.get() ) { | |
+ // nothing to do here given the odd loop structure... | |
+ } | |
+ if ( isLongestQuery ) { | |
queryExecutionMaxTimeQueryString = hql; | |
} | |
- if (hql != null) { | |
- ConcurrentQueryStatisticsImpl qs = (ConcurrentQueryStatisticsImpl) getQueryStatistics(hql); | |
- qs.executed(rows, time); | |
+ if ( hql != null ) { | |
+ ConcurrentQueryStatisticsImpl qs = (ConcurrentQueryStatisticsImpl) getQueryStatistics( hql ); | |
+ qs.executed( rows, time ); | |
} | |
} | |
public void queryCacheHit(String hql, String regionName) { | |
queryCacheHitCount.getAndIncrement(); | |
- if (hql != null) { | |
- ConcurrentQueryStatisticsImpl qs = (ConcurrentQueryStatisticsImpl) getQueryStatistics(hql); | |
+ if ( hql != null ) { | |
+ ConcurrentQueryStatisticsImpl qs = (ConcurrentQueryStatisticsImpl) getQueryStatistics( hql ); | |
qs.incrementCacheHitCount(); | |
} | |
- ConcurrentSecondLevelCacheStatisticsImpl slcs = (ConcurrentSecondLevelCacheStatisticsImpl) getSecondLevelCacheStatistics(regionName); | |
+ ConcurrentSecondLevelCacheStatisticsImpl slcs = (ConcurrentSecondLevelCacheStatisticsImpl) getSecondLevelCacheStatistics( | |
+ regionName | |
+ ); | |
slcs.incrementHitCount(); | |
} | |
public void queryCacheMiss(String hql, String regionName) { | |
queryCacheMissCount.getAndIncrement(); | |
- if (hql != null) { | |
- ConcurrentQueryStatisticsImpl qs = (ConcurrentQueryStatisticsImpl) getQueryStatistics(hql); | |
+ if ( hql != null ) { | |
+ ConcurrentQueryStatisticsImpl qs = (ConcurrentQueryStatisticsImpl) getQueryStatistics( hql ); | |
qs.incrementCacheMissCount(); | |
} | |
- ConcurrentSecondLevelCacheStatisticsImpl slcs = (ConcurrentSecondLevelCacheStatisticsImpl) getSecondLevelCacheStatistics(regionName); | |
+ ConcurrentSecondLevelCacheStatisticsImpl slcs = (ConcurrentSecondLevelCacheStatisticsImpl) getSecondLevelCacheStatistics( | |
+ regionName | |
+ ); | |
slcs.incrementMissCount(); | |
} | |
public void queryCachePut(String hql, String regionName) { | |
queryCachePutCount.getAndIncrement(); | |
- if (hql != null) { | |
- ConcurrentQueryStatisticsImpl qs = (ConcurrentQueryStatisticsImpl) getQueryStatistics(hql); | |
+ if ( hql != null ) { | |
+ ConcurrentQueryStatisticsImpl qs = (ConcurrentQueryStatisticsImpl) getQueryStatistics( hql ); | |
qs.incrementCachePutCount(); | |
} | |
- ConcurrentSecondLevelCacheStatisticsImpl slcs = (ConcurrentSecondLevelCacheStatisticsImpl) getSecondLevelCacheStatistics(regionName); | |
+ ConcurrentSecondLevelCacheStatisticsImpl slcs = (ConcurrentSecondLevelCacheStatisticsImpl) getSecondLevelCacheStatistics( | |
+ regionName | |
+ ); | |
slcs.incrementPutCount(); | |
} | |
@@ -327,18 +375,24 @@ | |
* Query statistics from query string (HQL or SQL) | |
* | |
* @param queryString query string | |
+ * | |
* @return QueryStatistics | |
*/ | |
public QueryStatistics getQueryStatistics(String queryString) { | |
- ConcurrentQueryStatisticsImpl qs = (ConcurrentQueryStatisticsImpl) queryStatistics.get(queryString); | |
- if (qs == null) { | |
- qs = new ConcurrentQueryStatisticsImpl(queryString); | |
+ return new ConcurrentQueryStatisticsImpl( queryString ); | |
+ /* | |
+ ConcurrentQueryStatisticsImpl qs = (ConcurrentQueryStatisticsImpl) queryStatistics.get( queryString ); | |
+ if ( qs == null ) { | |
+ qs = new ConcurrentQueryStatisticsImpl( queryString ); | |
ConcurrentQueryStatisticsImpl previous; | |
- if ((previous = (ConcurrentQueryStatisticsImpl) queryStatistics.putIfAbsent(queryString, qs)) != null) { | |
+ if ( ( previous = (ConcurrentQueryStatisticsImpl) queryStatistics.putIfAbsent( | |
+ queryString, qs | |
+ ) ) != null ) { | |
qs = previous; | |
} | |
} | |
return qs; | |
+ */ | |
} | |
/** | |
@@ -488,35 +542,35 @@ | |
* log in info level the main statistics | |
*/ | |
public void logSummary() { | |
- log.info("Logging statistics...."); | |
- log.info("start time: " + startTime); | |
- log.info("sessions opened: " + sessionOpenCount); | |
- log.info("sessions closed: " + sessionCloseCount); | |
- log.info("transactions: " + transactionCount); | |
- log.info("successful transactions: " + commitedTransactionCount); | |
- log.info("optimistic lock failures: " + optimisticFailureCount); | |
- log.info("flushes: " + flushCount); | |
- log.info("connections obtained: " + connectCount); | |
- log.info("statements prepared: " + prepareStatementCount); | |
- log.info("statements closed: " + closeStatementCount); | |
- log.info("second level cache puts: " + secondLevelCachePutCount); | |
- log.info("second level cache hits: " + secondLevelCacheHitCount); | |
- log.info("second level cache misses: " + secondLevelCacheMissCount); | |
- log.info("entities loaded: " + entityLoadCount); | |
- log.info("entities updated: " + entityUpdateCount); | |
- log.info("entities inserted: " + entityInsertCount); | |
- log.info("entities deleted: " + entityDeleteCount); | |
- log.info("entities fetched (minimize this): " + entityFetchCount); | |
- log.info("collections loaded: " + collectionLoadCount); | |
- log.info("collections updated: " + collectionUpdateCount); | |
- log.info("collections removed: " + collectionRemoveCount); | |
- log.info("collections recreated: " + collectionRecreateCount); | |
- log.info("collections fetched (minimize this): " + collectionFetchCount); | |
- log.info("queries executed to database: " + queryExecutionCount); | |
- log.info("query cache puts: " + queryCachePutCount); | |
- log.info("query cache hits: " + queryCacheHitCount); | |
- log.info("query cache misses: " + queryCacheMissCount); | |
- log.info("max query time: " + queryExecutionMaxTime + "ms"); | |
+ log.info( "Logging statistics...." ); | |
+ log.info( "start time: " + startTime ); | |
+ log.info( "sessions opened: " + sessionOpenCount ); | |
+ log.info( "sessions closed: " + sessionCloseCount ); | |
+ log.info( "transactions: " + transactionCount ); | |
+ log.info( "successful transactions: " + committedTransactionCount ); | |
+ log.info( "optimistic lock failures: " + optimisticFailureCount ); | |
+ log.info( "flushes: " + flushCount ); | |
+ log.info( "connections obtained: " + connectCount ); | |
+ log.info( "statements prepared: " + prepareStatementCount ); | |
+ log.info( "statements closed: " + closeStatementCount ); | |
+ log.info( "second level cache puts: " + secondLevelCachePutCount ); | |
+ log.info( "second level cache hits: " + secondLevelCacheHitCount ); | |
+ log.info( "second level cache misses: " + secondLevelCacheMissCount ); | |
+ log.info( "entities loaded: " + entityLoadCount ); | |
+ log.info( "entities updated: " + entityUpdateCount ); | |
+ log.info( "entities inserted: " + entityInsertCount ); | |
+ log.info( "entities deleted: " + entityDeleteCount ); | |
+ log.info( "entities fetched (minimize this): " + entityFetchCount ); | |
+ log.info( "collections loaded: " + collectionLoadCount ); | |
+ log.info( "collections updated: " + collectionUpdateCount ); | |
+ log.info( "collections removed: " + collectionRemoveCount ); | |
+ log.info( "collections recreated: " + collectionRecreateCount ); | |
+ log.info( "collections fetched (minimize this): " + collectionFetchCount ); | |
+ log.info( "queries executed to database: " + queryExecutionCount ); | |
+ log.info( "query cache puts: " + queryCachePutCount ); | |
+ log.info( "query cache hits: " + queryCacheHitCount ); | |
+ log.info( "query cache misses: " + queryCacheMissCount ); | |
+ log.info( "max query time: " + queryExecutionMaxTime + "ms" ); | |
} | |
/** | |
@@ -545,17 +599,18 @@ | |
* Get all executed query strings | |
*/ | |
public String[] getQueries() { | |
- return ArrayHelper.toStringArray(queryStatistics.keySet()); | |
+ return new String[]{}; // ArrayHelper.toStringArray( queryStatistics.keySet() ); | |
} | |
/** | |
* Get the names of all entities | |
*/ | |
public String[] getEntityNames() { | |
- if (sessionFactory == null) { | |
- return ArrayHelper.toStringArray(entityStatistics.keySet()); | |
- } else { | |
- return ArrayHelper.toStringArray(sessionFactory.getAllClassMetadata().keySet()); | |
+ if ( sessionFactory == null ) { | |
+ return ArrayHelper.toStringArray( entityStatistics.keySet() ); | |
+ } | |
+ else { | |
+ return ArrayHelper.toStringArray( sessionFactory.getAllClassMetadata().keySet() ); | |
} | |
} | |
@@ -563,10 +618,11 @@ | |
* Get the names of all collection roles | |
*/ | |
public String[] getCollectionRoleNames() { | |
- if (sessionFactory == null) { | |
- return ArrayHelper.toStringArray(collectionStatistics.keySet()); | |
- } else { | |
- return ArrayHelper.toStringArray(sessionFactory.getAllCollectionMetadata().keySet()); | |
+ if ( sessionFactory == null ) { | |
+ return ArrayHelper.toStringArray( collectionStatistics.keySet() ); | |
+ } | |
+ else { | |
+ return ArrayHelper.toStringArray( sessionFactory.getAllCollectionMetadata().keySet() ); | |
} | |
} | |
@@ -574,20 +630,23 @@ | |
* Get all second-level cache region names | |
*/ | |
public String[] getSecondLevelCacheRegionNames() { | |
- if (sessionFactory == null) { | |
- return ArrayHelper.toStringArray(secondLevelCacheStatistics.keySet()); | |
- } else { | |
- return ArrayHelper.toStringArray(sessionFactory.getAllSecondLevelCacheRegions().keySet()); | |
+ if ( sessionFactory == null ) { | |
+ return ArrayHelper.toStringArray( secondLevelCacheStatistics.keySet() ); | |
+ } | |
+ else { | |
+ return ArrayHelper.toStringArray( sessionFactory.getAllSecondLevelCacheRegions().keySet() ); | |
} | |
} | |
public void endTransaction(boolean success) { | |
transactionCount.getAndIncrement(); | |
- if (success) commitedTransactionCount.getAndIncrement(); | |
+ if ( success ) { | |
+ committedTransactionCount.getAndIncrement(); | |
+ } | |
} | |
public long getSuccessfulTransactionCount() { | |
- return commitedTransactionCount.get(); | |
+ return committedTransactionCount.get(); | |
} | |
public long getTransactionCount() { | |
@@ -612,7 +671,7 @@ | |
public void optimisticFailure(String entityName) { | |
optimisticFailureCount.getAndIncrement(); | |
- ((ConcurrentEntityStatisticsImpl) getEntityStatistics(entityName)).incrementOptimisticFailureCount(); | |
+ ( (ConcurrentEntityStatisticsImpl) getEntityStatistics( entityName ) ).incrementOptimisticFailureCount(); | |
} | |
public long getOptimisticFailureCount() { | |
@@ -621,36 +680,36 @@ | |
public String toString() { | |
return new StringBuilder() | |
- .append("Statistics[") | |
- .append("start time=").append(startTime) | |
- .append(",sessions opened=").append(sessionOpenCount) | |
- .append(",sessions closed=").append(sessionCloseCount) | |
- .append(",transactions=").append(transactionCount) | |
- .append(",successful transactions=").append(commitedTransactionCount) | |
- .append(",optimistic lock failures=").append(optimisticFailureCount) | |
- .append(",flushes=").append(flushCount) | |
- .append(",connections obtained=").append(connectCount) | |
- .append(",statements prepared=").append(prepareStatementCount) | |
- .append(",statements closed=").append(closeStatementCount) | |
- .append(",second level cache puts=").append(secondLevelCachePutCount) | |
- .append(",second level cache hits=").append(secondLevelCacheHitCount) | |
- .append(",second level cache misses=").append(secondLevelCacheMissCount) | |
- .append(",entities loaded=").append(entityLoadCount) | |
- .append(",entities updated=").append(entityUpdateCount) | |
- .append(",entities inserted=").append(entityInsertCount) | |
- .append(",entities deleted=").append(entityDeleteCount) | |
- .append(",entities fetched=").append(entityFetchCount) | |
- .append(",collections loaded=").append(collectionLoadCount) | |
- .append(",collections updated=").append(collectionUpdateCount) | |
- .append(",collections removed=").append(collectionRemoveCount) | |
- .append(",collections recreated=").append(collectionRecreateCount) | |
- .append(",collections fetched=").append(collectionFetchCount) | |
- .append(",queries executed to database=").append(queryExecutionCount) | |
- .append(",query cache puts=").append(queryCachePutCount) | |
- .append(",query cache hits=").append(queryCacheHitCount) | |
- .append(",query cache misses=").append(queryCacheMissCount) | |
- .append(",max query time=").append(queryExecutionMaxTime) | |
- .append(']') | |
+ .append( "Statistics[" ) | |
+ .append( "start time=" ).append( startTime ) | |
+ .append( ",sessions opened=" ).append( sessionOpenCount ) | |
+ .append( ",sessions closed=" ).append( sessionCloseCount ) | |
+ .append( ",transactions=" ).append( transactionCount ) | |
+ .append( ",successful transactions=" ).append( committedTransactionCount ) | |
+ .append( ",optimistic lock failures=" ).append( optimisticFailureCount ) | |
+ .append( ",flushes=" ).append( flushCount ) | |
+ .append( ",connections obtained=" ).append( connectCount ) | |
+ .append( ",statements prepared=" ).append( prepareStatementCount ) | |
+ .append( ",statements closed=" ).append( closeStatementCount ) | |
+ .append( ",second level cache puts=" ).append( secondLevelCachePutCount ) | |
+ .append( ",second level cache hits=" ).append( secondLevelCacheHitCount ) | |
+ .append( ",second level cache misses=" ).append( secondLevelCacheMissCount ) | |
+ .append( ",entities loaded=" ).append( entityLoadCount ) | |
+ .append( ",entities updated=" ).append( entityUpdateCount ) | |
+ .append( ",entities inserted=" ).append( entityInsertCount ) | |
+ .append( ",entities deleted=" ).append( entityDeleteCount ) | |
+ .append( ",entities fetched=" ).append( entityFetchCount ) | |
+ .append( ",collections loaded=" ).append( collectionLoadCount ) | |
+ .append( ",collections updated=" ).append( collectionUpdateCount ) | |
+ .append( ",collections removed=" ).append( collectionRemoveCount ) | |
+ .append( ",collections recreated=" ).append( collectionRecreateCount ) | |
+ .append( ",collections fetched=" ).append( collectionFetchCount ) | |
+ .append( ",queries executed to database=" ).append( queryExecutionCount ) | |
+ .append( ",query cache puts=" ).append( queryCachePutCount ) | |
+ .append( ",query cache hits=" ).append( queryCacheHitCount ) | |
+ .append( ",query cache misses=" ).append( queryCacheMissCount ) | |
+ .append( ",max query time=" ).append( queryExecutionMaxTime ) | |
+ .append( ']' ) | |
.toString(); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- /Users/jballanc/Glencoe/Source/openmicroscopy/components/blitz/src/org/hibernate/stat/ConcurrentStatisticsImpl.java 2014-08-24 19:58:59.000000000 +0300 | |
+++ ./ConcurrentStatisticsImpl.java 2014-07-29 18:06:53.000000000 +0300 | |
@@ -21,33 +21,35 @@ | |
* 51 Franklin Street, Fifth Floor | |
* Boston, MA 02110-1301 USA | |
*/ | |
-package org.hibernate.stat; | |
+package org.hibernate.stat.internal; | |
import java.util.concurrent.ConcurrentHashMap; | |
import java.util.concurrent.ConcurrentMap; | |
import java.util.concurrent.atomic.AtomicLong; | |
-import org.slf4j.Logger; | |
-import org.slf4j.LoggerFactory; | |
- | |
-import org.hibernate.cache.Region; | |
+import org.hibernate.cache.spi.Region; | |
import org.hibernate.engine.spi.SessionFactoryImplementor; | |
-import org.hibernate.util.ArrayHelper; | |
+import org.hibernate.internal.CoreMessageLogger; | |
+import org.hibernate.internal.util.collections.ArrayHelper; | |
+import org.hibernate.service.Service; | |
+import org.hibernate.stat.CollectionStatistics; | |
+import org.hibernate.stat.EntityStatistics; | |
+import org.hibernate.stat.NaturalIdCacheStatistics; | |
+import org.hibernate.stat.QueryStatistics; | |
+import org.hibernate.stat.SecondLevelCacheStatistics; | |
+import org.hibernate.stat.spi.StatisticsImplementor; | |
+ | |
+import org.jboss.logging.Logger; | |
/** | |
- * Implementation of {@link Statistics}, as well as {@link StatisticsImplementor}, based on the | |
- * {@link java.util.concurrent} package introduced in Java 5. | |
+ * Implementation of {@link org.hibernate.stat.Statistics} based on the {@link java.util.concurrent} package. | |
* | |
* @author Alex Snaps | |
*/ | |
-public class ConcurrentStatisticsImpl implements Statistics, StatisticsImplementor { | |
+@SuppressWarnings({ "unchecked" }) | |
+public class ConcurrentStatisticsImpl implements StatisticsImplementor, Service { | |
- private static final Logger log = LoggerFactory.getLogger( ConcurrentStatisticsImpl.class ); | |
- private static final Logger PERF_LOG = LoggerFactory.getLogger( Statistics.class ); | |
- | |
- static { | |
- log.info("OMERO-specific ConcurrentStatisticsImpl"); | |
- } | |
+ private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, ConcurrentStatisticsImpl.class.getName()); | |
private SessionFactoryImplementor sessionFactory; | |
@@ -75,7 +77,14 @@ | |
private AtomicLong secondLevelCacheHitCount = new AtomicLong(); | |
private AtomicLong secondLevelCacheMissCount = new AtomicLong(); | |
private AtomicLong secondLevelCachePutCount = new AtomicLong(); | |
- | |
+ | |
+ private AtomicLong naturalIdCacheHitCount = new AtomicLong(); | |
+ private AtomicLong naturalIdCacheMissCount = new AtomicLong(); | |
+ private AtomicLong naturalIdCachePutCount = new AtomicLong(); | |
+ private AtomicLong naturalIdQueryExecutionCount = new AtomicLong(); | |
+ private AtomicLong naturalIdQueryExecutionMaxTime = new AtomicLong(); | |
+ private volatile String naturalIdQueryExecutionMaxTimeRegion; | |
+ | |
private AtomicLong queryExecutionCount = new AtomicLong(); | |
private AtomicLong queryExecutionMaxTime = new AtomicLong(); | |
private volatile String queryExecutionMaxTimeQueryString; | |
@@ -83,12 +92,20 @@ | |
private AtomicLong queryCacheMissCount = new AtomicLong(); | |
private AtomicLong queryCachePutCount = new AtomicLong(); | |
+ private AtomicLong updateTimestampsCacheHitCount = new AtomicLong(); | |
+ private AtomicLong updateTimestampsCacheMissCount = new AtomicLong(); | |
+ private AtomicLong updateTimestampsCachePutCount = new AtomicLong(); | |
+ | |
private AtomicLong committedTransactionCount = new AtomicLong(); | |
private AtomicLong transactionCount = new AtomicLong(); | |
private AtomicLong optimisticFailureCount = new AtomicLong(); | |
/** | |
+ * natural id cache statistics per region | |
+ */ | |
+ private final ConcurrentMap naturalIdCacheStatistics = new ConcurrentHashMap(); | |
+ /** | |
* second level cache statistics per region | |
*/ | |
private final ConcurrentMap secondLevelCacheStatistics = new ConcurrentHashMap(); | |
@@ -103,8 +120,9 @@ | |
/** | |
* entity statistics per query string (HQL or SQL) | |
*/ | |
- private final ConcurrentMap queryStatistics = null; | |
+ private final ConcurrentMap queryStatistics = new ConcurrentHashMap(); | |
+ @SuppressWarnings({ "UnusedDeclaration" }) | |
public ConcurrentStatisticsImpl() { | |
clear(); | |
} | |
@@ -121,6 +139,13 @@ | |
secondLevelCacheHitCount.set( 0 ); | |
secondLevelCacheMissCount.set( 0 ); | |
secondLevelCachePutCount.set( 0 ); | |
+ | |
+ naturalIdCacheHitCount.set( 0 ); | |
+ naturalIdCacheMissCount.set( 0 ); | |
+ naturalIdCachePutCount.set( 0 ); | |
+ naturalIdQueryExecutionCount.set( 0 ); | |
+ naturalIdQueryExecutionMaxTime.set( 0 ); | |
+ naturalIdQueryExecutionMaxTimeRegion = null; | |
sessionCloseCount.set( 0 ); | |
sessionOpenCount.set( 0 ); | |
@@ -149,6 +174,10 @@ | |
queryCacheMissCount.set( 0 ); | |
queryCachePutCount.set( 0 ); | |
+ updateTimestampsCacheMissCount.set( 0 ); | |
+ updateTimestampsCacheHitCount.set( 0 ); | |
+ updateTimestampsCachePutCount.set( 0 ); | |
+ | |
transactionCount.set( 0 ); | |
committedTransactionCount.set( 0 ); | |
@@ -157,7 +186,8 @@ | |
secondLevelCacheStatistics.clear(); | |
entityStatistics.clear(); | |
collectionStatistics.clear(); | |
- // queryStatistics.clear(); | |
+ queryStatistics.clear(); | |
+ naturalIdCacheStatistics.clear(); | |
startTime = System.currentTimeMillis(); | |
} | |
@@ -272,6 +302,31 @@ | |
collectionRemoveCount.getAndIncrement(); | |
( (ConcurrentCollectionStatisticsImpl) getCollectionStatistics( role ) ).incrementRemoveCount(); | |
} | |
+ | |
+ | |
+ @Override | |
+ public NaturalIdCacheStatistics getNaturalIdCacheStatistics(String regionName) { | |
+ ConcurrentNaturalIdCacheStatisticsImpl nics = | |
+ (ConcurrentNaturalIdCacheStatisticsImpl) naturalIdCacheStatistics.get( regionName ); | |
+ | |
+ if ( nics == null ) { | |
+ if ( sessionFactory == null ) { | |
+ return null; | |
+ } | |
+ Region region = sessionFactory.getNaturalIdCacheRegion( regionName ); | |
+ if ( region == null ) { | |
+ return null; | |
+ } | |
+ nics = new ConcurrentNaturalIdCacheStatisticsImpl( region ); | |
+ ConcurrentNaturalIdCacheStatisticsImpl previous; | |
+ if ( ( previous = (ConcurrentNaturalIdCacheStatisticsImpl) naturalIdCacheStatistics.putIfAbsent( | |
+ regionName, nics | |
+ ) ) != null ) { | |
+ nics = previous; | |
+ } | |
+ } | |
+ return nics; | |
+ } | |
/** | |
* Second level cache statistics per region | |
@@ -316,13 +371,49 @@ | |
secondLevelCacheMissCount.getAndIncrement(); | |
( (ConcurrentSecondLevelCacheStatisticsImpl) getSecondLevelCacheStatistics( regionName ) ).incrementMissCount(); | |
} | |
+ | |
+ @Override | |
+ public void naturalIdCachePut(String regionName) { | |
+ naturalIdCachePutCount.getAndIncrement(); | |
+ ( (ConcurrentNaturalIdCacheStatisticsImpl) getNaturalIdCacheStatistics( regionName ) ).incrementPutCount(); | |
+ } | |
+ | |
+ @Override | |
+ public void naturalIdCacheHit(String regionName) { | |
+ naturalIdCacheHitCount.getAndIncrement(); | |
+ ( (ConcurrentNaturalIdCacheStatisticsImpl) getNaturalIdCacheStatistics( regionName ) ).incrementHitCount(); | |
+ } | |
+ | |
+ @Override | |
+ public void naturalIdCacheMiss(String regionName) { | |
+ naturalIdCacheMissCount.getAndIncrement(); | |
+ ( (ConcurrentNaturalIdCacheStatisticsImpl) getNaturalIdCacheStatistics( regionName ) ).incrementMissCount(); | |
+ } | |
+ | |
+ @Override | |
+ public void naturalIdQueryExecuted(String regionName, long time) { | |
+ naturalIdQueryExecutionCount.getAndIncrement(); | |
+ boolean isLongestQuery = false; | |
+ for ( long old = naturalIdQueryExecutionMaxTime.get(); | |
+ ( isLongestQuery = time > old ) && ( !naturalIdQueryExecutionMaxTime.compareAndSet( old, time ) ); | |
+ old = naturalIdQueryExecutionMaxTime.get() ) { | |
+ // nothing to do here given the odd loop structure... | |
+ } | |
+ if ( isLongestQuery && regionName != null ) { | |
+ naturalIdQueryExecutionMaxTimeRegion = regionName; | |
+ } | |
+ if ( regionName != null ) { | |
+ ( (ConcurrentNaturalIdCacheStatisticsImpl) getNaturalIdCacheStatistics( regionName ) ).queryExecuted( time ); | |
+ } | |
+ } | |
+ @Override | |
public void queryExecuted(String hql, int rows, long time) { | |
- PERF_LOG.info( "HQL: {}, time: {}ms, rows: {}", new Object[] {hql, Long.valueOf( time ), Long.valueOf(rows)} ); | |
+ LOG.hql(hql, time, (long) rows ); | |
queryExecutionCount.getAndIncrement(); | |
boolean isLongestQuery = false; | |
for ( long old = queryExecutionMaxTime.get(); | |
- ( time > old ) && ( isLongestQuery = !queryExecutionMaxTime.compareAndSet( old, time ) ); | |
+ ( isLongestQuery = time > old ) && ( !queryExecutionMaxTime.compareAndSet( old, time ) ); | |
old = queryExecutionMaxTime.get() ) { | |
// nothing to do here given the odd loop structure... | |
} | |
@@ -334,7 +425,7 @@ | |
qs.executed( rows, time ); | |
} | |
} | |
- | |
+ @Override | |
public void queryCacheHit(String hql, String regionName) { | |
queryCacheHitCount.getAndIncrement(); | |
if ( hql != null ) { | |
@@ -346,7 +437,7 @@ | |
); | |
slcs.incrementHitCount(); | |
} | |
- | |
+ @Override | |
public void queryCacheMiss(String hql, String regionName) { | |
queryCacheMissCount.getAndIncrement(); | |
if ( hql != null ) { | |
@@ -358,7 +449,7 @@ | |
); | |
slcs.incrementMissCount(); | |
} | |
- | |
+ @Override | |
public void queryCachePut(String hql, String regionName) { | |
queryCachePutCount.getAndIncrement(); | |
if ( hql != null ) { | |
@@ -371,6 +462,21 @@ | |
slcs.incrementPutCount(); | |
} | |
+ @Override | |
+ public void updateTimestampsCacheHit() { | |
+ updateTimestampsCacheHitCount.getAndIncrement(); | |
+ } | |
+ | |
+ @Override | |
+ public void updateTimestampsCacheMiss() { | |
+ updateTimestampsCacheMissCount.getAndIncrement(); | |
+ } | |
+ | |
+ @Override | |
+ public void updateTimestampsCachePut() { | |
+ updateTimestampsCachePutCount.getAndIncrement(); | |
+ } | |
+ | |
/** | |
* Query statistics from query string (HQL or SQL) | |
* | |
@@ -378,9 +484,8 @@ | |
* | |
* @return QueryStatistics | |
*/ | |
+ @Override | |
public QueryStatistics getQueryStatistics(String queryString) { | |
- return new ConcurrentQueryStatisticsImpl( queryString ); | |
- /* | |
ConcurrentQueryStatisticsImpl qs = (ConcurrentQueryStatisticsImpl) queryStatistics.get( queryString ); | |
if ( qs == null ) { | |
qs = new ConcurrentQueryStatisticsImpl( queryString ); | |
@@ -392,12 +497,12 @@ | |
} | |
} | |
return qs; | |
- */ | |
} | |
/** | |
* @return entity deletion count | |
*/ | |
+ @Override | |
public long getEntityDeleteCount() { | |
return entityDeleteCount.get(); | |
} | |
@@ -405,6 +510,7 @@ | |
/** | |
* @return entity insertion count | |
*/ | |
+ @Override | |
public long getEntityInsertCount() { | |
return entityInsertCount.get(); | |
} | |
@@ -412,6 +518,7 @@ | |
/** | |
* @return entity load (from DB) | |
*/ | |
+ @Override | |
public long getEntityLoadCount() { | |
return entityLoadCount.get(); | |
} | |
@@ -419,6 +526,7 @@ | |
/** | |
* @return entity fetch (from DB) | |
*/ | |
+ @Override | |
public long getEntityFetchCount() { | |
return entityFetchCount.get(); | |
} | |
@@ -426,29 +534,43 @@ | |
/** | |
* @return entity update | |
*/ | |
+ @Override | |
public long getEntityUpdateCount() { | |
return entityUpdateCount.get(); | |
} | |
- | |
+ @Override | |
public long getQueryExecutionCount() { | |
return queryExecutionCount.get(); | |
} | |
- | |
+ @Override | |
public long getQueryCacheHitCount() { | |
return queryCacheHitCount.get(); | |
} | |
- | |
+ @Override | |
public long getQueryCacheMissCount() { | |
return queryCacheMissCount.get(); | |
} | |
- | |
+ @Override | |
public long getQueryCachePutCount() { | |
return queryCachePutCount.get(); | |
} | |
+ @Override | |
+ public long getUpdateTimestampsCacheHitCount() { | |
+ return updateTimestampsCacheHitCount.get(); | |
+ } | |
+ @Override | |
+ public long getUpdateTimestampsCacheMissCount() { | |
+ return updateTimestampsCacheMissCount.get(); | |
+ } | |
+ @Override | |
+ public long getUpdateTimestampsCachePutCount() { | |
+ return updateTimestampsCachePutCount.get(); | |
+ } | |
/** | |
* @return flush | |
*/ | |
+ @Override | |
public long getFlushCount() { | |
return flushCount.get(); | |
} | |
@@ -456,6 +578,7 @@ | |
/** | |
* @return session connect | |
*/ | |
+ @Override | |
public long getConnectCount() { | |
return connectCount.get(); | |
} | |
@@ -463,6 +586,7 @@ | |
/** | |
* @return second level cache hit | |
*/ | |
+ @Override | |
public long getSecondLevelCacheHitCount() { | |
return secondLevelCacheHitCount.get(); | |
} | |
@@ -470,6 +594,7 @@ | |
/** | |
* @return second level cache miss | |
*/ | |
+ @Override | |
public long getSecondLevelCacheMissCount() { | |
return secondLevelCacheMissCount.get(); | |
} | |
@@ -477,13 +602,45 @@ | |
/** | |
* @return second level cache put | |
*/ | |
+ @Override | |
public long getSecondLevelCachePutCount() { | |
return secondLevelCachePutCount.get(); | |
} | |
+ @Override | |
+ public long getNaturalIdQueryExecutionCount() { | |
+ return naturalIdQueryExecutionCount.get(); | |
+ } | |
+ | |
+ @Override | |
+ public long getNaturalIdQueryExecutionMaxTime() { | |
+ return naturalIdQueryExecutionMaxTime.get(); | |
+ } | |
+ | |
+ @Override | |
+ public String getNaturalIdQueryExecutionMaxTimeRegion() { | |
+ return naturalIdQueryExecutionMaxTimeRegion; | |
+ } | |
+ | |
+ @Override | |
+ public long getNaturalIdCacheHitCount() { | |
+ return naturalIdCacheHitCount.get(); | |
+ } | |
+ | |
+ @Override | |
+ public long getNaturalIdCacheMissCount() { | |
+ return naturalIdCacheMissCount.get(); | |
+ } | |
+ | |
+ @Override | |
+ public long getNaturalIdCachePutCount() { | |
+ return naturalIdCachePutCount.get(); | |
+ } | |
+ | |
/** | |
* @return session closing | |
*/ | |
+ @Override | |
public long getSessionCloseCount() { | |
return sessionCloseCount.get(); | |
} | |
@@ -491,6 +648,7 @@ | |
/** | |
* @return session opening | |
*/ | |
+ @Override | |
public long getSessionOpenCount() { | |
return sessionOpenCount.get(); | |
} | |
@@ -498,6 +656,7 @@ | |
/** | |
* @return collection loading (from DB) | |
*/ | |
+ @Override | |
public long getCollectionLoadCount() { | |
return collectionLoadCount.get(); | |
} | |
@@ -505,6 +664,7 @@ | |
/** | |
* @return collection fetching (from DB) | |
*/ | |
+ @Override | |
public long getCollectionFetchCount() { | |
return collectionFetchCount.get(); | |
} | |
@@ -512,6 +672,7 @@ | |
/** | |
* @return collection update | |
*/ | |
+ @Override | |
public long getCollectionUpdateCount() { | |
return collectionUpdateCount.get(); | |
} | |
@@ -520,6 +681,7 @@ | |
* @return collection removal | |
* FIXME: even if isInverse="true"? | |
*/ | |
+ @Override | |
public long getCollectionRemoveCount() { | |
return collectionRemoveCount.get(); | |
} | |
@@ -527,6 +689,7 @@ | |
/** | |
* @return collection recreation | |
*/ | |
+ @Override | |
public long getCollectionRecreateCount() { | |
return collectionRecreateCount.get(); | |
} | |
@@ -534,6 +697,7 @@ | |
/** | |
* @return start time in ms (JVM standards {@link System#currentTimeMillis()}) | |
*/ | |
+ @Override | |
public long getStartTime() { | |
return startTime; | |
} | |
@@ -541,41 +705,51 @@ | |
/** | |
* log in info level the main statistics | |
*/ | |
+ @Override | |
public void logSummary() { | |
- log.info( "Logging statistics...." ); | |
- log.info( "start time: " + startTime ); | |
- log.info( "sessions opened: " + sessionOpenCount ); | |
- log.info( "sessions closed: " + sessionCloseCount ); | |
- log.info( "transactions: " + transactionCount ); | |
- log.info( "successful transactions: " + committedTransactionCount ); | |
- log.info( "optimistic lock failures: " + optimisticFailureCount ); | |
- log.info( "flushes: " + flushCount ); | |
- log.info( "connections obtained: " + connectCount ); | |
- log.info( "statements prepared: " + prepareStatementCount ); | |
- log.info( "statements closed: " + closeStatementCount ); | |
- log.info( "second level cache puts: " + secondLevelCachePutCount ); | |
- log.info( "second level cache hits: " + secondLevelCacheHitCount ); | |
- log.info( "second level cache misses: " + secondLevelCacheMissCount ); | |
- log.info( "entities loaded: " + entityLoadCount ); | |
- log.info( "entities updated: " + entityUpdateCount ); | |
- log.info( "entities inserted: " + entityInsertCount ); | |
- log.info( "entities deleted: " + entityDeleteCount ); | |
- log.info( "entities fetched (minimize this): " + entityFetchCount ); | |
- log.info( "collections loaded: " + collectionLoadCount ); | |
- log.info( "collections updated: " + collectionUpdateCount ); | |
- log.info( "collections removed: " + collectionRemoveCount ); | |
- log.info( "collections recreated: " + collectionRecreateCount ); | |
- log.info( "collections fetched (minimize this): " + collectionFetchCount ); | |
- log.info( "queries executed to database: " + queryExecutionCount ); | |
- log.info( "query cache puts: " + queryCachePutCount ); | |
- log.info( "query cache hits: " + queryCacheHitCount ); | |
- log.info( "query cache misses: " + queryCacheMissCount ); | |
- log.info( "max query time: " + queryExecutionMaxTime + "ms" ); | |
+ LOG.loggingStatistics(); | |
+ LOG.startTime( startTime ); | |
+ LOG.sessionsOpened( sessionOpenCount.get() ); | |
+ LOG.sessionsClosed( sessionCloseCount.get() ); | |
+ LOG.transactions( transactionCount.get() ); | |
+ LOG.successfulTransactions( committedTransactionCount.get() ); | |
+ LOG.optimisticLockFailures( optimisticFailureCount.get() ); | |
+ LOG.flushes( flushCount.get() ); | |
+ LOG.connectionsObtained( connectCount.get() ); | |
+ LOG.statementsPrepared( prepareStatementCount.get() ); | |
+ LOG.statementsClosed( closeStatementCount.get() ); | |
+ LOG.secondLevelCachePuts( secondLevelCachePutCount.get() ); | |
+ LOG.secondLevelCacheHits( secondLevelCacheHitCount.get() ); | |
+ LOG.secondLevelCacheMisses( secondLevelCacheMissCount.get() ); | |
+ LOG.entitiesLoaded( entityLoadCount.get() ); | |
+ LOG.entitiesUpdated( entityUpdateCount.get() ); | |
+ LOG.entitiesInserted( entityInsertCount.get() ); | |
+ LOG.entitiesDeleted( entityDeleteCount.get() ); | |
+ LOG.entitiesFetched( entityFetchCount.get() ); | |
+ LOG.collectionsLoaded( collectionLoadCount.get() ); | |
+ LOG.collectionsUpdated( collectionUpdateCount.get() ); | |
+ LOG.collectionsRemoved( collectionRemoveCount.get() ); | |
+ LOG.collectionsRecreated( collectionRecreateCount.get() ); | |
+ LOG.collectionsFetched( collectionFetchCount.get() ); | |
+ LOG.naturalIdCachePuts( naturalIdCachePutCount.get() ); | |
+ LOG.naturalIdCacheHits( naturalIdCacheHitCount.get() ); | |
+ LOG.naturalIdCacheMisses( naturalIdCacheMissCount.get() ); | |
+ LOG.naturalIdMaxQueryTime( naturalIdQueryExecutionMaxTime.get() ); | |
+ LOG.naturalIdQueriesExecuted( naturalIdQueryExecutionCount.get() ); | |
+ LOG.queriesExecuted( queryExecutionCount.get() ); | |
+ LOG.queryCachePuts( queryCachePutCount.get() ); | |
+ LOG.timestampCachePuts( updateTimestampsCachePutCount.get() ); | |
+ LOG.timestampCacheHits( updateTimestampsCacheHitCount.get() ); | |
+ LOG.timestampCacheMisses( updateTimestampsCacheMissCount.get() ); | |
+ LOG.queryCacheHits( queryCacheHitCount.get() ); | |
+ LOG.queryCacheMisses( queryCacheMissCount.get() ); | |
+ LOG.maxQueryTime( queryExecutionMaxTime.get() ); | |
} | |
/** | |
* Are statistics logged | |
*/ | |
+ @Override | |
public boolean isStatisticsEnabled() { | |
return isStatisticsEnabled; | |
} | |
@@ -583,6 +757,7 @@ | |
/** | |
* Enable statistics logs (this is a dynamic parameter) | |
*/ | |
+ @Override | |
public void setStatisticsEnabled(boolean b) { | |
isStatisticsEnabled = b; | |
} | |
@@ -591,6 +766,7 @@ | |
* @return Returns the max query execution time, | |
* for all queries | |
*/ | |
+ @Override | |
public long getQueryExecutionMaxTime() { | |
return queryExecutionMaxTime.get(); | |
} | |
@@ -598,13 +774,15 @@ | |
/** | |
* Get all executed query strings | |
*/ | |
+ @Override | |
public String[] getQueries() { | |
- return new String[]{}; // ArrayHelper.toStringArray( queryStatistics.keySet() ); | |
+ return ArrayHelper.toStringArray( queryStatistics.keySet() ); | |
} | |
/** | |
* Get the names of all entities | |
*/ | |
+ @Override | |
public String[] getEntityNames() { | |
if ( sessionFactory == null ) { | |
return ArrayHelper.toStringArray( entityStatistics.keySet() ); | |
@@ -617,6 +795,7 @@ | |
/** | |
* Get the names of all collection roles | |
*/ | |
+ @Override | |
public String[] getCollectionRoleNames() { | |
if ( sessionFactory == null ) { | |
return ArrayHelper.toStringArray( collectionStatistics.keySet() ); | |
@@ -629,6 +808,7 @@ | |
/** | |
* Get all second-level cache region names | |
*/ | |
+ @Override | |
public String[] getSecondLevelCacheRegionNames() { | |
if ( sessionFactory == null ) { | |
return ArrayHelper.toStringArray( secondLevelCacheStatistics.keySet() ); | |
@@ -637,48 +817,49 @@ | |
return ArrayHelper.toStringArray( sessionFactory.getAllSecondLevelCacheRegions().keySet() ); | |
} | |
} | |
- | |
+ @Override | |
public void endTransaction(boolean success) { | |
transactionCount.getAndIncrement(); | |
if ( success ) { | |
committedTransactionCount.getAndIncrement(); | |
} | |
} | |
- | |
+ @Override | |
public long getSuccessfulTransactionCount() { | |
return committedTransactionCount.get(); | |
} | |
- | |
+ @Override | |
public long getTransactionCount() { | |
return transactionCount.get(); | |
} | |
- | |
+ @Override | |
public void closeStatement() { | |
closeStatementCount.getAndIncrement(); | |
} | |
- | |
+ @Override | |
public void prepareStatement() { | |
prepareStatementCount.getAndIncrement(); | |
} | |
- | |
+ @Override | |
public long getCloseStatementCount() { | |
return closeStatementCount.get(); | |
} | |
- | |
+ @Override | |
public long getPrepareStatementCount() { | |
return prepareStatementCount.get(); | |
} | |
- | |
+ @Override | |
public void optimisticFailure(String entityName) { | |
optimisticFailureCount.getAndIncrement(); | |
( (ConcurrentEntityStatisticsImpl) getEntityStatistics( entityName ) ).incrementOptimisticFailureCount(); | |
} | |
- | |
+ @Override | |
public long getOptimisticFailureCount() { | |
return optimisticFailureCount.get(); | |
} | |
- public String toString() { | |
+ @Override | |
+ public String toString() { | |
return new StringBuilder() | |
.append( "Statistics[" ) | |
.append( "start time=" ).append( startTime ) | |
@@ -704,17 +885,24 @@ | |
.append( ",collections removed=" ).append( collectionRemoveCount ) | |
.append( ",collections recreated=" ).append( collectionRecreateCount ) | |
.append( ",collections fetched=" ).append( collectionFetchCount ) | |
+ .append( ",naturalId queries executed to database=" ).append( naturalIdQueryExecutionCount ) | |
+ .append( ",naturalId cache puts=" ).append( naturalIdCachePutCount ) | |
+ .append( ",naturalId cache hits=" ).append( naturalIdCacheHitCount ) | |
+ .append( ",naturalId cache misses=" ).append( naturalIdCacheMissCount ) | |
+ .append( ",naturalId max query time=" ).append( naturalIdQueryExecutionMaxTime ) | |
.append( ",queries executed to database=" ).append( queryExecutionCount ) | |
.append( ",query cache puts=" ).append( queryCachePutCount ) | |
.append( ",query cache hits=" ).append( queryCacheHitCount ) | |
.append( ",query cache misses=" ).append( queryCacheMissCount ) | |
+ .append(",update timestamps cache puts=").append(updateTimestampsCachePutCount) | |
+ .append(",update timestamps cache hits=").append(updateTimestampsCacheHitCount) | |
+ .append(",update timestamps cache misses=").append(updateTimestampsCacheMissCount) | |
.append( ",max query time=" ).append( queryExecutionMaxTime ) | |
.append( ']' ) | |
.toString(); | |
} | |
- | |
+ @Override | |
public String getQueryExecutionMaxTimeQueryString() { | |
return queryExecutionMaxTimeQueryString; | |
} | |
- | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment