HHH-12521 Take advantage of Java 8 improvements to optimise Statistics

This commit is contained in:
Sanne Grinovero 2018-04-25 21:52:14 +01:00
parent fb7c1a4598
commit 90b058507e
9 changed files with 278 additions and 287 deletions

View File

@ -6,7 +6,7 @@
*/ */
package org.hibernate.stat.internal; package org.hibernate.stat.internal;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.LongAdder;
import java.util.function.Supplier; import java.util.function.Supplier;
import org.hibernate.cache.spi.Region; import org.hibernate.cache.spi.Region;
@ -21,10 +21,9 @@ public abstract class AbstractCacheableDataStatistics implements CacheableDataSt
private static final Logger log = Logger.getLogger( AbstractCacheableDataStatistics.class ); private static final Logger log = Logger.getLogger( AbstractCacheableDataStatistics.class );
private final String cacheRegionName; private final String cacheRegionName;
private final LongAdder cacheHitCount;
private final AtomicLong cacheHitCount; private final LongAdder cacheMissCount;
private final AtomicLong cacheMissCount; private final LongAdder cachePutCount;
private final AtomicLong cachePutCount;
public AbstractCacheableDataStatistics(Supplier<Region> regionSupplier) { public AbstractCacheableDataStatistics(Supplier<Region> regionSupplier) {
final Region region = regionSupplier.get(); final Region region = regionSupplier.get();
@ -36,9 +35,9 @@ public abstract class AbstractCacheableDataStatistics implements CacheableDataSt
} }
else { else {
this.cacheRegionName = region.getName(); this.cacheRegionName = region.getName();
this.cacheHitCount = new AtomicLong(); this.cacheHitCount = new LongAdder();
this.cacheMissCount = new AtomicLong(); this.cacheMissCount = new LongAdder();
this.cachePutCount = new AtomicLong(); this.cachePutCount = new LongAdder();
} }
} }
@ -52,7 +51,7 @@ public abstract class AbstractCacheableDataStatistics implements CacheableDataSt
return NOT_CACHED_COUNT; return NOT_CACHED_COUNT;
} }
return cacheHitCount.get(); return cacheHitCount.sum();
} }
public long getCachePutCount() { public long getCachePutCount() {
@ -60,7 +59,7 @@ public abstract class AbstractCacheableDataStatistics implements CacheableDataSt
return NOT_CACHED_COUNT; return NOT_CACHED_COUNT;
} }
return cachePutCount.get(); return cachePutCount.sum();
} }
public long getCacheMissCount() { public long getCacheMissCount() {
@ -68,7 +67,7 @@ public abstract class AbstractCacheableDataStatistics implements CacheableDataSt
return NOT_CACHED_COUNT; return NOT_CACHED_COUNT;
} }
return cacheMissCount.get(); return cacheMissCount.sum();
} }
public void incrementCacheHitCount() { public void incrementCacheHitCount() {
@ -76,7 +75,7 @@ public abstract class AbstractCacheableDataStatistics implements CacheableDataSt
throw new IllegalStateException( "Illegal attempt to increment cache hit count for non-cached data" ); throw new IllegalStateException( "Illegal attempt to increment cache hit count for non-cached data" );
} }
cacheHitCount.getAndIncrement(); cacheHitCount.increment();
} }
public void incrementCacheMissCount() { public void incrementCacheMissCount() {
@ -84,7 +83,7 @@ public abstract class AbstractCacheableDataStatistics implements CacheableDataSt
throw new IllegalStateException( "Illegal attempt to increment cache miss count for non-cached data" ); throw new IllegalStateException( "Illegal attempt to increment cache miss count for non-cached data" );
} }
cacheMissCount.getAndIncrement(); cacheMissCount.increment();
} }
public void incrementCachePutCount() { public void incrementCachePutCount() {
@ -92,7 +91,7 @@ public abstract class AbstractCacheableDataStatistics implements CacheableDataSt
throw new IllegalStateException( "Illegal attempt to increment cache put count for non-cached data" ); throw new IllegalStateException( "Illegal attempt to increment cache put count for non-cached data" );
} }
cachePutCount.getAndIncrement(); cachePutCount.increment();
} }
protected void appendCacheStats(StringBuilder buf) { protected void appendCacheStats(StringBuilder buf) {

View File

@ -7,7 +7,7 @@
package org.hibernate.stat.internal; package org.hibernate.stat.internal;
import java.io.Serializable; import java.io.Serializable;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.LongAdder;
import org.hibernate.cache.spi.ExtendedStatisticsSupport; import org.hibernate.cache.spi.ExtendedStatisticsSupport;
import org.hibernate.cache.spi.Region; import org.hibernate.cache.spi.Region;
@ -22,9 +22,9 @@ import org.hibernate.stat.SecondLevelCacheStatistics;
public class CacheRegionStatisticsImpl implements CacheRegionStatistics, SecondLevelCacheStatistics, Serializable { public class CacheRegionStatisticsImpl implements CacheRegionStatistics, SecondLevelCacheStatistics, Serializable {
private final transient Region region; private final transient Region region;
private AtomicLong hitCount = new AtomicLong(); private final LongAdder hitCount = new LongAdder();
private AtomicLong missCount = new AtomicLong(); private final LongAdder missCount = new LongAdder();
private AtomicLong putCount = new AtomicLong(); private final LongAdder putCount = new LongAdder();
CacheRegionStatisticsImpl(Region region) { CacheRegionStatisticsImpl(Region region) {
this.region = region; this.region = region;
@ -37,17 +37,17 @@ public class CacheRegionStatisticsImpl implements CacheRegionStatistics, SecondL
@Override @Override
public long getHitCount() { public long getHitCount() {
return hitCount.get(); return hitCount.sum();
} }
@Override @Override
public long getMissCount() { public long getMissCount() {
return missCount.get(); return missCount.sum();
} }
@Override @Override
public long getPutCount() { public long getPutCount() {
return putCount.get(); return putCount.sum();
} }
@Override @Override
@ -75,15 +75,15 @@ public class CacheRegionStatisticsImpl implements CacheRegionStatistics, SecondL
} }
void incrementHitCount() { void incrementHitCount() {
hitCount.getAndIncrement(); hitCount.increment();
} }
void incrementMissCount() { void incrementMissCount() {
missCount.getAndIncrement(); missCount.increment();
} }
void incrementPutCount() { void incrementPutCount() {
putCount.getAndIncrement(); putCount.increment();
} }
@Override @Override

View File

@ -7,7 +7,7 @@
package org.hibernate.stat.internal; package org.hibernate.stat.internal;
import java.io.Serializable; import java.io.Serializable;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.LongAdder;
import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.stat.CollectionStatistics; import org.hibernate.stat.CollectionStatistics;
@ -18,13 +18,13 @@ import org.hibernate.stat.CollectionStatistics;
* @author Alex Snaps * @author Alex Snaps
*/ */
public class CollectionStatisticsImpl extends AbstractCacheableDataStatistics implements CollectionStatistics, Serializable { public class CollectionStatisticsImpl extends AbstractCacheableDataStatistics implements CollectionStatistics, Serializable {
private final String collectionRole;
private AtomicLong loadCount = new AtomicLong(); private final String collectionRole;
private AtomicLong fetchCount = new AtomicLong(); private final LongAdder loadCount = new LongAdder();
private AtomicLong updateCount = new AtomicLong(); private final LongAdder fetchCount = new LongAdder();
private AtomicLong removeCount = new AtomicLong(); private final LongAdder updateCount = new LongAdder();
private AtomicLong recreateCount = new AtomicLong(); private final LongAdder removeCount = new LongAdder();
private final LongAdder recreateCount = new LongAdder();
CollectionStatisticsImpl(CollectionPersister persister) { CollectionStatisticsImpl(CollectionPersister persister) {
super( super(
@ -37,43 +37,43 @@ public class CollectionStatisticsImpl extends AbstractCacheableDataStatistics im
} }
public long getLoadCount() { public long getLoadCount() {
return loadCount.get(); return loadCount.sum();
} }
public long getFetchCount() { public long getFetchCount() {
return fetchCount.get(); return fetchCount.sum();
} }
public long getRecreateCount() { public long getRecreateCount() {
return recreateCount.get(); return recreateCount.sum();
} }
public long getRemoveCount() { public long getRemoveCount() {
return removeCount.get(); return removeCount.sum();
} }
public long getUpdateCount() { public long getUpdateCount() {
return updateCount.get(); return updateCount.sum();
} }
void incrementLoadCount() { void incrementLoadCount() {
loadCount.getAndIncrement(); loadCount.increment();
} }
void incrementFetchCount() { void incrementFetchCount() {
fetchCount.getAndIncrement(); fetchCount.increment();
} }
void incrementUpdateCount() { void incrementUpdateCount() {
updateCount.getAndIncrement(); updateCount.increment();
} }
void incrementRecreateCount() { void incrementRecreateCount() {
recreateCount.getAndIncrement(); recreateCount.increment();
} }
void incrementRemoveCount() { void incrementRemoveCount() {
removeCount.getAndIncrement(); removeCount.increment();
} }
public String toString() { public String toString() {

View File

@ -46,15 +46,12 @@ public class DeprecatedNaturalIdCacheStatisticsImpl implements NaturalIdCacheSta
private final Lock readLock; private final Lock readLock;
private final Lock writeLock; private final Lock writeLock;
{
final ReadWriteLock lock = new ReentrantReadWriteLock();
this.readLock = lock.readLock();
this.writeLock = lock.writeLock();
}
DeprecatedNaturalIdCacheStatisticsImpl(String regionName, Set<NaturalIdDataAccess> accessStrategies) { DeprecatedNaturalIdCacheStatisticsImpl(String regionName, Set<NaturalIdDataAccess> accessStrategies) {
this.regionName = regionName; this.regionName = regionName;
this.accessStrategies = accessStrategies; this.accessStrategies = accessStrategies;
final ReadWriteLock lock = new ReentrantReadWriteLock();
this.readLock = lock.readLock();
this.writeLock = lock.writeLock();
} }
/** /**

View File

@ -7,7 +7,7 @@
package org.hibernate.stat.internal; package org.hibernate.stat.internal;
import java.io.Serializable; import java.io.Serializable;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.LongAdder;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.stat.EntityStatistics; import org.hibernate.stat.EntityStatistics;
@ -18,14 +18,14 @@ import org.hibernate.stat.EntityStatistics;
* @author Alex Snaps * @author Alex Snaps
*/ */
public class EntityStatisticsImpl extends AbstractCacheableDataStatistics implements EntityStatistics, Serializable { public class EntityStatisticsImpl extends AbstractCacheableDataStatistics implements EntityStatistics, Serializable {
private final String rootEntityName;
private AtomicLong loadCount = new AtomicLong(); private final String rootEntityName;
private AtomicLong updateCount = new AtomicLong(); private final LongAdder loadCount = new LongAdder();
private AtomicLong insertCount = new AtomicLong(); private final LongAdder updateCount = new LongAdder();
private AtomicLong deleteCount = new AtomicLong(); private final LongAdder insertCount = new LongAdder();
private AtomicLong fetchCount = new AtomicLong(); private final LongAdder deleteCount = new LongAdder();
private AtomicLong optimisticFailureCount = new AtomicLong(); private final LongAdder fetchCount = new LongAdder();
private final LongAdder optimisticFailureCount = new LongAdder();
EntityStatisticsImpl(EntityPersister rootEntityDescriptor) { EntityStatisticsImpl(EntityPersister rootEntityDescriptor) {
super( super(
@ -37,51 +37,51 @@ public class EntityStatisticsImpl extends AbstractCacheableDataStatistics implem
} }
public long getDeleteCount() { public long getDeleteCount() {
return deleteCount.get(); return deleteCount.sum();
} }
public long getInsertCount() { public long getInsertCount() {
return insertCount.get(); return insertCount.sum();
} }
public long getLoadCount() { public long getLoadCount() {
return loadCount.get(); return loadCount.sum();
} }
public long getUpdateCount() { public long getUpdateCount() {
return updateCount.get(); return updateCount.sum();
} }
public long getFetchCount() { public long getFetchCount() {
return fetchCount.get(); return fetchCount.sum();
} }
public long getOptimisticFailureCount() { public long getOptimisticFailureCount() {
return optimisticFailureCount.get(); return optimisticFailureCount.sum();
} }
void incrementLoadCount() { void incrementLoadCount() {
loadCount.getAndIncrement(); loadCount.increment();
} }
void incrementFetchCount() { void incrementFetchCount() {
fetchCount.getAndIncrement(); fetchCount.increment();
} }
void incrementUpdateCount() { void incrementUpdateCount() {
updateCount.getAndIncrement(); updateCount.increment();
} }
void incrementInsertCount() { void incrementInsertCount() {
insertCount.getAndIncrement(); insertCount.increment();
} }
void incrementDeleteCount() { void incrementDeleteCount() {
deleteCount.getAndIncrement(); deleteCount.increment();
} }
void incrementOptimisticFailureCount() { void incrementOptimisticFailureCount() {
optimisticFailureCount.getAndIncrement(); optimisticFailureCount.increment();
} }
public String toString() { public String toString() {

View File

@ -8,6 +8,7 @@ package org.hibernate.stat.internal;
import java.io.Serializable; import java.io.Serializable;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.LongAdder;
import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock;
@ -21,10 +22,8 @@ import org.hibernate.stat.NaturalIdStatistics;
* @author Eric Dalquist * @author Eric Dalquist
*/ */
public class NaturalIdStatisticsImpl extends AbstractCacheableDataStatistics implements NaturalIdStatistics, Serializable { public class NaturalIdStatisticsImpl extends AbstractCacheableDataStatistics implements NaturalIdStatistics, Serializable {
private static final long serialVersionUID = 1L;
private final String rootEntityName; private final String rootEntityName;
private final AtomicLong executionCount = new AtomicLong(); private final AtomicLong executionCount = new AtomicLong();
private final AtomicLong executionMaxTime = new AtomicLong(); private final AtomicLong executionMaxTime = new AtomicLong();
private final AtomicLong executionMinTime = new AtomicLong( Long.MAX_VALUE ); private final AtomicLong executionMinTime = new AtomicLong( Long.MAX_VALUE );
@ -33,12 +32,6 @@ public class NaturalIdStatisticsImpl extends AbstractCacheableDataStatistics imp
private final Lock readLock; private final Lock readLock;
private final Lock writeLock; private final Lock writeLock;
{
final ReadWriteLock lock = new ReentrantReadWriteLock();
this.readLock = lock.readLock();
this.writeLock = lock.writeLock();
}
NaturalIdStatisticsImpl(EntityPersister rootEntityDescriptor) { NaturalIdStatisticsImpl(EntityPersister rootEntityDescriptor) {
super( super(
() -> rootEntityDescriptor.getNaturalIdCacheAccessStrategy() != null () -> rootEntityDescriptor.getNaturalIdCacheAccessStrategy() != null
@ -46,6 +39,9 @@ public class NaturalIdStatisticsImpl extends AbstractCacheableDataStatistics imp
: null : null
); );
this.rootEntityName = rootEntityDescriptor.getRootEntityName(); this.rootEntityName = rootEntityDescriptor.getRootEntityName();
final ReadWriteLock lock = new ReentrantReadWriteLock();
this.readLock = lock.readLock();
this.writeLock = lock.writeLock();
} }
/** /**
@ -86,7 +82,7 @@ public class NaturalIdStatisticsImpl extends AbstractCacheableDataStatistics imp
} }
/** /**
* min time in ms taken by the excution of this query onto the DB * min time in ms taken by the execution of this query onto the DB
*/ */
@Override @Override
public long getExecutionMinTime() { public long getExecutionMinTime() {

View File

@ -7,6 +7,7 @@
package org.hibernate.stat.internal; package org.hibernate.stat.internal;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.LongAdder;
import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock;
@ -27,11 +28,11 @@ public class QueryStatisticsImpl implements QueryStatistics {
private final String query; private final String query;
private final AtomicLong cacheHitCount = new AtomicLong(); private final LongAdder cacheHitCount = new LongAdder();
private final AtomicLong cacheMissCount = new AtomicLong(); private final LongAdder cacheMissCount = new LongAdder();
private final AtomicLong cachePutCount = new AtomicLong(); private final LongAdder cachePutCount = new LongAdder();
private final AtomicLong executionCount = new AtomicLong(); private final LongAdder executionCount = new LongAdder();
private final AtomicLong executionRowCount = new AtomicLong(); private final LongAdder executionRowCount = new LongAdder();
private final AtomicLong executionMaxTime = new AtomicLong(); private final AtomicLong executionMaxTime = new AtomicLong();
private final AtomicLong executionMinTime = new AtomicLong(Long.MAX_VALUE); private final AtomicLong executionMinTime = new AtomicLong(Long.MAX_VALUE);
private final AtomicLong totalExecutionTime = new AtomicLong(); private final AtomicLong totalExecutionTime = new AtomicLong();
@ -39,36 +40,33 @@ public class QueryStatisticsImpl implements QueryStatistics {
private final Lock readLock; private final Lock readLock;
private final Lock writeLock; private final Lock writeLock;
{
ReadWriteLock lock = new ReentrantReadWriteLock();
readLock = lock.readLock();
writeLock = lock.writeLock();
}
QueryStatisticsImpl(String query) { QueryStatisticsImpl(String query) {
this.query = query; this.query = query;
ReadWriteLock lock = new ReentrantReadWriteLock();
this.readLock = lock.readLock();
this.writeLock = lock.writeLock();
} }
/** /**
* queries executed to the DB * queries executed to the DB
*/ */
public long getExecutionCount() { public long getExecutionCount() {
return executionCount.get(); return executionCount.sum();
} }
/** /**
* Queries retrieved successfully from the cache * Queries retrieved successfully from the cache
*/ */
public long getCacheHitCount() { public long getCacheHitCount() {
return cacheHitCount.get(); return cacheHitCount.sum();
} }
public long getCachePutCount() { public long getCachePutCount() {
return cachePutCount.get(); return cachePutCount.sum();
} }
public long getCacheMissCount() { public long getCacheMissCount() {
return cacheMissCount.get(); return cacheMissCount.sum();
} }
/** /**
@ -81,7 +79,7 @@ public class QueryStatisticsImpl implements QueryStatistics {
* is not known at execution time. * is not known at execution time.
*/ */
public long getExecutionRowCount() { public long getExecutionRowCount() {
return executionRowCount.get(); return executionRowCount.sum();
} }
/** /**
@ -101,9 +99,9 @@ public class QueryStatisticsImpl implements QueryStatistics {
writeLock.lock(); writeLock.lock();
try { try {
double avgExecutionTime = 0; double avgExecutionTime = 0;
if ( executionCount.get() > 0 ) { final long ec = executionCount.sum();
avgExecutionTime = totalExecutionTime.get() / (double) executionCount if ( ec > 0 ) {
.get(); avgExecutionTime = totalExecutionTime.get() / (double) ec;
} }
return avgExecutionTime; return avgExecutionTime;
} }
@ -147,11 +145,11 @@ public class QueryStatisticsImpl implements QueryStatistics {
readLock.lock(); readLock.lock();
try { try {
// Less chances for a context switch // Less chances for a context switch
for (long old = executionMinTime.get(); (time < old) && !executionMinTime.compareAndSet(old, time); old = executionMinTime.get()) {} for ( long old = executionMinTime.get(); (time < old) && !executionMinTime.compareAndSet(old, time); old = executionMinTime.get() ) {}
for (long old = executionMaxTime.get(); (time > old) && !executionMaxTime.compareAndSet(old, time); old = executionMaxTime.get()) {} for ( long old = executionMaxTime.get(); (time > old) && !executionMaxTime.compareAndSet(old, time); old = executionMaxTime.get() ) {}
executionCount.getAndIncrement(); executionCount.increment();
executionRowCount.addAndGet(rows); executionRowCount.add( rows );
totalExecutionTime.addAndGet(time); totalExecutionTime.addAndGet( time );
} }
finally { finally {
readLock.unlock(); readLock.unlock();
@ -161,19 +159,19 @@ public class QueryStatisticsImpl implements QueryStatistics {
void incrementCacheHitCount() { void incrementCacheHitCount() {
log.tracef( "QueryStatistics - cache hit : %s", query ); log.tracef( "QueryStatistics - cache hit : %s", query );
cacheHitCount.getAndIncrement(); cacheHitCount.increment();
} }
void incrementCacheMissCount() { void incrementCacheMissCount() {
log.tracef( "QueryStatistics - cache miss : %s", query ); log.tracef( "QueryStatistics - cache miss : %s", query );
cacheMissCount.getAndIncrement(); cacheMissCount.increment();
} }
void incrementCachePutCount() { void incrementCachePutCount() {
log.tracef( "QueryStatistics - cache put : %s", query ); log.tracef( "QueryStatistics - cache put : %s", query );
cachePutCount.getAndIncrement(); cachePutCount.increment();
} }
public String toString() { public String toString() {

View File

@ -9,6 +9,7 @@ package org.hibernate.stat.internal;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.LongAdder;
import org.hibernate.cache.spi.QueryResultsCache; import org.hibernate.cache.spi.QueryResultsCache;
import org.hibernate.cache.spi.QueryResultsRegion; import org.hibernate.cache.spi.QueryResultsRegion;
@ -32,57 +33,57 @@ import static org.hibernate.internal.CoreLogging.messageLogger;
public class StatisticsImpl implements StatisticsImplementor, Service { public class StatisticsImpl implements StatisticsImplementor, Service {
private static final CoreMessageLogger LOG = messageLogger( StatisticsImpl.class ); private static final CoreMessageLogger LOG = messageLogger( StatisticsImpl.class );
private SessionFactoryImplementor sessionFactory; private final SessionFactoryImplementor sessionFactory;
private volatile boolean isStatisticsEnabled; private volatile boolean isStatisticsEnabled;
private volatile long startTime; private volatile long startTime;
private AtomicLong sessionOpenCount = new AtomicLong(); private final LongAdder sessionOpenCount = new LongAdder();
private AtomicLong sessionCloseCount = new AtomicLong(); private final LongAdder sessionCloseCount = new LongAdder();
private AtomicLong flushCount = new AtomicLong(); private final LongAdder flushCount = new LongAdder();
private AtomicLong connectCount = new AtomicLong(); private final LongAdder connectCount = new LongAdder();
private AtomicLong prepareStatementCount = new AtomicLong(); private final LongAdder prepareStatementCount = new LongAdder();
private AtomicLong closeStatementCount = new AtomicLong(); private final LongAdder closeStatementCount = new LongAdder();
private AtomicLong entityLoadCount = new AtomicLong(); private final LongAdder entityLoadCount = new LongAdder();
private AtomicLong entityUpdateCount = new AtomicLong(); private final LongAdder entityUpdateCount = new LongAdder();
private AtomicLong entityInsertCount = new AtomicLong(); private final LongAdder entityInsertCount = new LongAdder();
private AtomicLong entityDeleteCount = new AtomicLong(); private final LongAdder entityDeleteCount = new LongAdder();
private AtomicLong entityFetchCount = new AtomicLong(); private final LongAdder entityFetchCount = new LongAdder();
private AtomicLong collectionLoadCount = new AtomicLong(); private final LongAdder collectionLoadCount = new LongAdder();
private AtomicLong collectionUpdateCount = new AtomicLong(); private final LongAdder collectionUpdateCount = new LongAdder();
private AtomicLong collectionRemoveCount = new AtomicLong(); private final LongAdder collectionRemoveCount = new LongAdder();
private AtomicLong collectionRecreateCount = new AtomicLong(); private final LongAdder collectionRecreateCount = new LongAdder();
private AtomicLong collectionFetchCount = new AtomicLong(); private final LongAdder collectionFetchCount = new LongAdder();
private AtomicLong secondLevelCacheHitCount = new AtomicLong(); private final LongAdder secondLevelCacheHitCount = new LongAdder();
private AtomicLong secondLevelCacheMissCount = new AtomicLong(); private final LongAdder secondLevelCacheMissCount = new LongAdder();
private AtomicLong secondLevelCachePutCount = new AtomicLong(); private final LongAdder secondLevelCachePutCount = new LongAdder();
private AtomicLong naturalIdCacheHitCount = new AtomicLong(); private final LongAdder naturalIdCacheHitCount = new LongAdder();
private AtomicLong naturalIdCacheMissCount = new AtomicLong(); private final LongAdder naturalIdCacheMissCount = new LongAdder();
private AtomicLong naturalIdCachePutCount = new AtomicLong(); private final LongAdder naturalIdCachePutCount = new LongAdder();
private AtomicLong naturalIdQueryExecutionCount = new AtomicLong(); private final LongAdder naturalIdQueryExecutionCount = new LongAdder();
private AtomicLong naturalIdQueryExecutionMaxTime = new AtomicLong(); private final AtomicLong naturalIdQueryExecutionMaxTime = new AtomicLong();
private volatile String naturalIdQueryExecutionMaxTimeRegion; private volatile String naturalIdQueryExecutionMaxTimeRegion;
private volatile String naturalIdQueryExecutionMaxTimeEntity; private volatile String naturalIdQueryExecutionMaxTimeEntity;
private AtomicLong queryExecutionCount = new AtomicLong(); private final LongAdder queryExecutionCount = new LongAdder();
private AtomicLong queryExecutionMaxTime = new AtomicLong(); private final AtomicLong queryExecutionMaxTime = new AtomicLong();
private volatile String queryExecutionMaxTimeQueryString; private volatile String queryExecutionMaxTimeQueryString;
private AtomicLong queryCacheHitCount = new AtomicLong(); private final LongAdder queryCacheHitCount = new LongAdder();
private AtomicLong queryCacheMissCount = new AtomicLong(); private final LongAdder queryCacheMissCount = new LongAdder();
private AtomicLong queryCachePutCount = new AtomicLong(); private final LongAdder queryCachePutCount = new LongAdder();
private AtomicLong updateTimestampsCacheHitCount = new AtomicLong(); private final LongAdder updateTimestampsCacheHitCount = new LongAdder();
private AtomicLong updateTimestampsCacheMissCount = new AtomicLong(); private final LongAdder updateTimestampsCacheMissCount = new LongAdder();
private AtomicLong updateTimestampsCachePutCount = new AtomicLong(); private final LongAdder updateTimestampsCachePutCount = new LongAdder();
private AtomicLong committedTransactionCount = new AtomicLong(); private final LongAdder committedTransactionCount = new LongAdder();
private AtomicLong transactionCount = new AtomicLong(); private final LongAdder transactionCount = new LongAdder();
private AtomicLong optimisticFailureCount = new AtomicLong(); private final LongAdder optimisticFailureCount = new LongAdder();
private final ConcurrentMap<String,EntityStatisticsImpl> entityStatsMap = new ConcurrentHashMap(); private final ConcurrentMap<String,EntityStatisticsImpl> entityStatsMap = new ConcurrentHashMap();
private final ConcurrentMap<String,NaturalIdStatisticsImpl> naturalIdQueryStatsMap = new ConcurrentHashMap(); private final ConcurrentMap<String,NaturalIdStatisticsImpl> naturalIdQueryStatsMap = new ConcurrentHashMap();
@ -103,7 +104,7 @@ public class StatisticsImpl implements StatisticsImplementor, Service {
@SuppressWarnings({ "UnusedDeclaration" }) @SuppressWarnings({ "UnusedDeclaration" })
public StatisticsImpl() { public StatisticsImpl() {
clear(); this( null );
} }
public StatisticsImpl(SessionFactoryImplementor sessionFactory) { public StatisticsImpl(SessionFactoryImplementor sessionFactory) {
@ -115,53 +116,53 @@ public class StatisticsImpl implements StatisticsImplementor, Service {
* reset all statistics * reset all statistics
*/ */
public void clear() { public void clear() {
secondLevelCacheHitCount.set( 0 ); secondLevelCacheHitCount.reset();
secondLevelCacheMissCount.set( 0 ); secondLevelCacheMissCount.reset();
secondLevelCachePutCount.set( 0 ); secondLevelCachePutCount.reset();
naturalIdCacheHitCount.set( 0 ); naturalIdCacheHitCount.reset();
naturalIdCacheMissCount.set( 0 ); naturalIdCacheMissCount.reset();
naturalIdCachePutCount.set( 0 ); naturalIdCachePutCount.reset();
naturalIdQueryExecutionCount.set( 0 ); naturalIdQueryExecutionCount.reset();
naturalIdQueryExecutionMaxTime.set( 0 ); naturalIdQueryExecutionMaxTime.set( 0L );
naturalIdQueryExecutionMaxTimeRegion = null; naturalIdQueryExecutionMaxTimeRegion = null;
naturalIdQueryExecutionMaxTimeEntity = null; naturalIdQueryExecutionMaxTimeEntity = null;
sessionCloseCount.set( 0 ); sessionCloseCount.reset();
sessionOpenCount.set( 0 ); sessionOpenCount.reset();
flushCount.set( 0 ); flushCount.reset();
connectCount.set( 0 ); connectCount.reset();
prepareStatementCount.set( 0 ); prepareStatementCount.reset();
closeStatementCount.set( 0 ); closeStatementCount.reset();
entityDeleteCount.set( 0 ); entityDeleteCount.reset();
entityInsertCount.set( 0 ); entityInsertCount.reset();
entityUpdateCount.set( 0 ); entityUpdateCount.reset();
entityLoadCount.set( 0 ); entityLoadCount.reset();
entityFetchCount.set( 0 ); entityFetchCount.reset();
collectionRemoveCount.set( 0 ); collectionRemoveCount.reset();
collectionUpdateCount.set( 0 ); collectionUpdateCount.reset();
collectionRecreateCount.set( 0 ); collectionRecreateCount.reset();
collectionLoadCount.set( 0 ); collectionLoadCount.reset();
collectionFetchCount.set( 0 ); collectionFetchCount.reset();
queryExecutionCount.set( 0 ); queryExecutionCount.reset();
queryCacheHitCount.set( 0 ); queryCacheHitCount.reset();
queryExecutionMaxTime.set( 0 ); queryExecutionMaxTime.set( 0L );
queryExecutionMaxTimeQueryString = null; queryExecutionMaxTimeQueryString = null;
queryCacheMissCount.set( 0 ); queryCacheMissCount.reset();
queryCachePutCount.set( 0 ); queryCachePutCount.reset();
updateTimestampsCacheMissCount.set( 0 ); updateTimestampsCacheMissCount.reset();
updateTimestampsCacheHitCount.set( 0 ); updateTimestampsCacheHitCount.reset();
updateTimestampsCachePutCount.set( 0 ); updateTimestampsCachePutCount.reset();
transactionCount.set( 0 ); transactionCount.reset();
committedTransactionCount.set( 0 ); committedTransactionCount.reset();
optimisticFailureCount.set( 0 ); optimisticFailureCount.reset();
entityStatsMap.clear(); entityStatsMap.clear();
collectionStatsMap.clear(); collectionStatsMap.clear();
@ -217,87 +218,87 @@ public class StatisticsImpl implements StatisticsImplementor, Service {
@Override @Override
public long getEntityLoadCount() { public long getEntityLoadCount() {
return entityLoadCount.get(); return entityLoadCount.sum();
} }
@Override @Override
public long getEntityFetchCount() { public long getEntityFetchCount() {
return entityFetchCount.get(); return entityFetchCount.sum();
} }
@Override @Override
public long getEntityDeleteCount() { public long getEntityDeleteCount() {
return entityDeleteCount.get(); return entityDeleteCount.sum();
} }
@Override @Override
public long getEntityInsertCount() { public long getEntityInsertCount() {
return entityInsertCount.get(); return entityInsertCount.sum();
} }
@Override @Override
public long getEntityUpdateCount() { public long getEntityUpdateCount() {
return entityUpdateCount.get(); return entityUpdateCount.sum();
} }
@Override @Override
public long getOptimisticFailureCount() { public long getOptimisticFailureCount() {
return optimisticFailureCount.get(); return optimisticFailureCount.sum();
} }
@Override @Override
public void loadEntity(String entityName) { public void loadEntity(String entityName) {
entityLoadCount.getAndIncrement(); entityLoadCount.increment();
getEntityStatistics( entityName ).incrementLoadCount(); getEntityStatistics( entityName ).incrementLoadCount();
} }
@Override @Override
public void fetchEntity(String entityName) { public void fetchEntity(String entityName) {
entityFetchCount.getAndIncrement(); entityFetchCount.increment();
getEntityStatistics( entityName ).incrementFetchCount(); getEntityStatistics( entityName ).incrementFetchCount();
} }
@Override @Override
public void updateEntity(String entityName) { public void updateEntity(String entityName) {
entityUpdateCount.getAndIncrement(); entityUpdateCount.increment();
getEntityStatistics( entityName ).incrementUpdateCount(); getEntityStatistics( entityName ).incrementUpdateCount();
} }
@Override @Override
public void insertEntity(String entityName) { public void insertEntity(String entityName) {
entityInsertCount.getAndIncrement(); entityInsertCount.increment();
getEntityStatistics( entityName ).incrementInsertCount(); getEntityStatistics( entityName ).incrementInsertCount();
} }
@Override @Override
public void deleteEntity(String entityName) { public void deleteEntity(String entityName) {
entityDeleteCount.getAndIncrement(); entityDeleteCount.increment();
getEntityStatistics( entityName ).incrementDeleteCount(); getEntityStatistics( entityName ).incrementDeleteCount();
} }
@Override @Override
public void optimisticFailure(String entityName) { public void optimisticFailure(String entityName) {
optimisticFailureCount.getAndIncrement(); optimisticFailureCount.increment();
getEntityStatistics( entityName ).incrementOptimisticFailureCount(); getEntityStatistics( entityName ).incrementOptimisticFailureCount();
} }
@Override @Override
public void entityCachePut(NavigableRole entityName, String regionName) { public void entityCachePut(NavigableRole entityName, String regionName) {
secondLevelCachePutCount.getAndIncrement(); secondLevelCachePutCount.increment();
getDomainDataRegionStatistics( regionName ).incrementPutCount(); getDomainDataRegionStatistics( regionName ).incrementPutCount();
getEntityStatistics( entityName.getFullPath() ).incrementCachePutCount(); getEntityStatistics( entityName.getFullPath() ).incrementCachePutCount();
} }
@Override @Override
public void entityCacheHit(NavigableRole entityName, String regionName) { public void entityCacheHit(NavigableRole entityName, String regionName) {
secondLevelCacheHitCount.getAndIncrement(); secondLevelCacheHitCount.increment();
getDomainDataRegionStatistics( regionName ).incrementHitCount(); getDomainDataRegionStatistics( regionName ).incrementHitCount();
getEntityStatistics( entityName.getFullPath() ).incrementCacheHitCount(); getEntityStatistics( entityName.getFullPath() ).incrementCacheHitCount();
} }
@Override @Override
public void entityCacheMiss(NavigableRole entityName, String regionName) { public void entityCacheMiss(NavigableRole entityName, String regionName) {
secondLevelCacheMissCount.getAndIncrement(); secondLevelCacheMissCount.increment();
getDomainDataRegionStatistics( regionName ).incrementMissCount(); getDomainDataRegionStatistics( regionName ).incrementMissCount();
getEntityStatistics( entityName.getFullPath() ).incrementCacheMissCount(); getEntityStatistics( entityName.getFullPath() ).incrementCacheMissCount();
} }
@ -330,76 +331,76 @@ public class StatisticsImpl implements StatisticsImplementor, Service {
@Override @Override
public long getCollectionLoadCount() { public long getCollectionLoadCount() {
return collectionLoadCount.get(); return collectionLoadCount.sum();
} }
@Override @Override
public long getCollectionFetchCount() { public long getCollectionFetchCount() {
return collectionFetchCount.get(); return collectionFetchCount.sum();
} }
@Override @Override
public long getCollectionUpdateCount() { public long getCollectionUpdateCount() {
return collectionUpdateCount.get(); return collectionUpdateCount.sum();
} }
@Override @Override
public long getCollectionRemoveCount() { public long getCollectionRemoveCount() {
return collectionRemoveCount.get(); return collectionRemoveCount.sum();
} }
@Override @Override
public long getCollectionRecreateCount() { public long getCollectionRecreateCount() {
return collectionRecreateCount.get(); return collectionRecreateCount.sum();
} }
@Override @Override
public void loadCollection(String role) { public void loadCollection(String role) {
collectionLoadCount.getAndIncrement(); collectionLoadCount.increment();
getCollectionStatistics( role ).incrementLoadCount(); getCollectionStatistics( role ).incrementLoadCount();
} }
@Override @Override
public void fetchCollection(String role) { public void fetchCollection(String role) {
collectionFetchCount.getAndIncrement(); collectionFetchCount.increment();
getCollectionStatistics( role ).incrementFetchCount(); getCollectionStatistics( role ).incrementFetchCount();
} }
@Override @Override
public void updateCollection(String role) { public void updateCollection(String role) {
collectionUpdateCount.getAndIncrement(); collectionUpdateCount.increment();
getCollectionStatistics( role ).incrementUpdateCount(); getCollectionStatistics( role ).incrementUpdateCount();
} }
@Override @Override
public void recreateCollection(String role) { public void recreateCollection(String role) {
collectionRecreateCount.getAndIncrement(); collectionRecreateCount.increment();
getCollectionStatistics( role ).incrementRecreateCount(); getCollectionStatistics( role ).incrementRecreateCount();
} }
@Override @Override
public void removeCollection(String role) { public void removeCollection(String role) {
collectionRemoveCount.getAndIncrement(); collectionRemoveCount.increment();
getCollectionStatistics( role ).incrementRemoveCount(); getCollectionStatistics( role ).incrementRemoveCount();
} }
@Override @Override
public void collectionCachePut(NavigableRole collectionRole, String regionName) { public void collectionCachePut(NavigableRole collectionRole, String regionName) {
secondLevelCachePutCount.getAndIncrement(); secondLevelCachePutCount.increment();
getDomainDataRegionStatistics( regionName ).incrementPutCount(); getDomainDataRegionStatistics( regionName ).incrementPutCount();
getCollectionStatistics( collectionRole.getFullPath() ).incrementCachePutCount(); getCollectionStatistics( collectionRole.getFullPath() ).incrementCachePutCount();
} }
@Override @Override
public void collectionCacheHit(NavigableRole collectionRole, String regionName) { public void collectionCacheHit(NavigableRole collectionRole, String regionName) {
secondLevelCacheHitCount.getAndIncrement(); secondLevelCacheHitCount.increment();
getDomainDataRegionStatistics( regionName ).incrementHitCount(); getDomainDataRegionStatistics( regionName ).incrementHitCount();
getCollectionStatistics( collectionRole.getFullPath() ).incrementCacheHitCount(); getCollectionStatistics( collectionRole.getFullPath() ).incrementCacheHitCount();
} }
@Override @Override
public void collectionCacheMiss(NavigableRole collectionRole, String regionName) { public void collectionCacheMiss(NavigableRole collectionRole, String regionName) {
secondLevelCacheMissCount.getAndIncrement(); secondLevelCacheMissCount.increment();
getDomainDataRegionStatistics( regionName ).incrementMissCount(); getDomainDataRegionStatistics( regionName ).incrementMissCount();
getCollectionStatistics( collectionRole.getFullPath() ).incrementCacheMissCount(); getCollectionStatistics( collectionRole.getFullPath() ).incrementCacheMissCount();
} }
@ -439,7 +440,7 @@ public class StatisticsImpl implements StatisticsImplementor, Service {
@Override @Override
public long getNaturalIdQueryExecutionCount() { public long getNaturalIdQueryExecutionCount() {
return naturalIdQueryExecutionCount.get(); return naturalIdQueryExecutionCount.sum();
} }
@Override @Override
@ -459,24 +460,24 @@ public class StatisticsImpl implements StatisticsImplementor, Service {
@Override @Override
public long getNaturalIdCacheHitCount() { public long getNaturalIdCacheHitCount() {
return naturalIdCacheHitCount.get(); return naturalIdCacheHitCount.sum();
} }
@Override @Override
public long getNaturalIdCacheMissCount() { public long getNaturalIdCacheMissCount() {
return naturalIdCacheMissCount.get(); return naturalIdCacheMissCount.sum();
} }
@Override @Override
public long getNaturalIdCachePutCount() { public long getNaturalIdCachePutCount() {
return naturalIdCachePutCount.get(); return naturalIdCachePutCount.sum();
} }
@Override @Override
public void naturalIdCachePut( public void naturalIdCachePut(
NavigableRole rootEntityName, NavigableRole rootEntityName,
String regionName) { String regionName) {
naturalIdCachePutCount.getAndIncrement(); naturalIdCachePutCount.increment();
getDomainDataRegionStatistics( regionName ).incrementPutCount(); getDomainDataRegionStatistics( regionName ).incrementPutCount();
@ -489,7 +490,7 @@ public class StatisticsImpl implements StatisticsImplementor, Service {
public void naturalIdCacheHit( public void naturalIdCacheHit(
NavigableRole rootEntityName, NavigableRole rootEntityName,
String regionName) { String regionName) {
naturalIdCacheHitCount.getAndIncrement(); naturalIdCacheHitCount.increment();
getDomainDataRegionStatistics( regionName ).incrementHitCount(); getDomainDataRegionStatistics( regionName ).incrementHitCount();
@ -502,7 +503,7 @@ public class StatisticsImpl implements StatisticsImplementor, Service {
public void naturalIdCacheMiss( public void naturalIdCacheMiss(
NavigableRole rootEntityName, NavigableRole rootEntityName,
String regionName) { String regionName) {
naturalIdCacheMissCount.getAndIncrement(); naturalIdCacheMissCount.increment();
getDomainDataRegionStatistics( regionName ).incrementMissCount(); getDomainDataRegionStatistics( regionName ).incrementMissCount();
@ -519,7 +520,7 @@ public class StatisticsImpl implements StatisticsImplementor, Service {
@Override @Override
public void naturalIdQueryExecuted(String rootEntityName, long time) { public void naturalIdQueryExecuted(String rootEntityName, long time) {
naturalIdQueryExecutionCount.getAndIncrement(); naturalIdQueryExecutionCount.increment();
boolean isLongestQuery; boolean isLongestQuery;
//noinspection StatementWithEmptyBody //noinspection StatementWithEmptyBody
@ -642,47 +643,47 @@ public class StatisticsImpl implements StatisticsImplementor, Service {
@Override @Override
public long getSecondLevelCacheHitCount() { public long getSecondLevelCacheHitCount() {
return secondLevelCacheHitCount.get(); return secondLevelCacheHitCount.sum();
} }
@Override @Override
public long getSecondLevelCacheMissCount() { public long getSecondLevelCacheMissCount() {
return secondLevelCacheMissCount.get(); return secondLevelCacheMissCount.sum();
} }
@Override @Override
public long getSecondLevelCachePutCount() { public long getSecondLevelCachePutCount() {
return secondLevelCachePutCount.get(); return secondLevelCachePutCount.sum();
} }
@Override @Override
public long getUpdateTimestampsCacheHitCount() { public long getUpdateTimestampsCacheHitCount() {
return updateTimestampsCacheHitCount.get(); return updateTimestampsCacheHitCount.sum();
} }
@Override @Override
public long getUpdateTimestampsCacheMissCount() { public long getUpdateTimestampsCacheMissCount() {
return updateTimestampsCacheMissCount.get(); return updateTimestampsCacheMissCount.sum();
} }
@Override @Override
public long getUpdateTimestampsCachePutCount() { public long getUpdateTimestampsCachePutCount() {
return updateTimestampsCachePutCount.get(); return updateTimestampsCachePutCount.sum();
} }
@Override @Override
public void updateTimestampsCacheHit() { public void updateTimestampsCacheHit() {
updateTimestampsCacheHitCount.getAndIncrement(); updateTimestampsCacheHitCount.increment();
} }
@Override @Override
public void updateTimestampsCacheMiss() { public void updateTimestampsCacheMiss() {
updateTimestampsCacheMissCount.getAndIncrement(); updateTimestampsCacheMissCount.increment();
} }
@Override @Override
public void updateTimestampsCachePut() { public void updateTimestampsCachePut() {
updateTimestampsCachePutCount.getAndIncrement(); updateTimestampsCachePutCount.increment();
} }
@ -704,22 +705,22 @@ public class StatisticsImpl implements StatisticsImplementor, Service {
@Override @Override
public long getQueryExecutionCount() { public long getQueryExecutionCount() {
return queryExecutionCount.get(); return queryExecutionCount.sum();
} }
@Override @Override
public long getQueryCacheHitCount() { public long getQueryCacheHitCount() {
return queryCacheHitCount.get(); return queryCacheHitCount.sum();
} }
@Override @Override
public long getQueryCacheMissCount() { public long getQueryCacheMissCount() {
return queryCacheMissCount.get(); return queryCacheMissCount.sum();
} }
@Override @Override
public long getQueryCachePutCount() { public long getQueryCachePutCount() {
return queryCachePutCount.get(); return queryCachePutCount.sum();
} }
@Override @Override
@ -735,7 +736,7 @@ public class StatisticsImpl implements StatisticsImplementor, Service {
@Override @Override
public void queryExecuted(String hql, int rows, long time) { public void queryExecuted(String hql, int rows, long time) {
LOG.hql(hql, time, (long) rows ); LOG.hql(hql, time, (long) rows );
queryExecutionCount.getAndIncrement(); queryExecutionCount.increment();
boolean isLongestQuery; boolean isLongestQuery;
//noinspection StatementWithEmptyBody //noinspection StatementWithEmptyBody
@ -758,7 +759,7 @@ public class StatisticsImpl implements StatisticsImplementor, Service {
public void queryCacheHit(String hql, String regionName) { public void queryCacheHit(String hql, String regionName) {
LOG.tracef( "Statistics#queryCacheHit( `%s`, `%s` )", hql, regionName ); LOG.tracef( "Statistics#queryCacheHit( `%s`, `%s` )", hql, regionName );
queryCacheHitCount.getAndIncrement(); queryCacheHitCount.increment();
getQueryRegionStats( regionName ).incrementHitCount(); getQueryRegionStats( regionName ).incrementHitCount();
@ -779,7 +780,7 @@ public class StatisticsImpl implements StatisticsImplementor, Service {
public void queryCacheMiss(String hql, String regionName) { public void queryCacheMiss(String hql, String regionName) {
LOG.tracef( "Statistics#queryCacheMiss( `%s`, `%s` )", hql, regionName ); LOG.tracef( "Statistics#queryCacheMiss( `%s`, `%s` )", hql, regionName );
queryCacheMissCount.getAndIncrement(); queryCacheMissCount.increment();
getQueryRegionStats( regionName ).incrementMissCount(); getQueryRegionStats( regionName ).incrementMissCount();
@ -792,7 +793,7 @@ public class StatisticsImpl implements StatisticsImplementor, Service {
public void queryCachePut(String hql, String regionName) { public void queryCachePut(String hql, String regionName) {
LOG.tracef( "Statistics#queryCachePut( `%s`, `%s` )", hql, regionName ); LOG.tracef( "Statistics#queryCachePut( `%s`, `%s` )", hql, regionName );
queryCachePutCount.getAndIncrement(); queryCachePutCount.increment();
getQueryRegionStats( regionName ).incrementPutCount(); getQueryRegionStats( regionName ).incrementPutCount();
@ -808,79 +809,79 @@ public class StatisticsImpl implements StatisticsImplementor, Service {
@Override @Override
public long getSessionOpenCount() { public long getSessionOpenCount() {
return sessionOpenCount.get(); return sessionOpenCount.sum();
} }
@Override @Override
public long getSessionCloseCount() { public long getSessionCloseCount() {
return sessionCloseCount.get(); return sessionCloseCount.sum();
} }
@Override @Override
public long getFlushCount() { public long getFlushCount() {
return flushCount.get(); return flushCount.sum();
} }
@Override @Override
public long getConnectCount() { public long getConnectCount() {
return connectCount.get(); return connectCount.sum();
} }
@Override @Override
public long getSuccessfulTransactionCount() { public long getSuccessfulTransactionCount() {
return committedTransactionCount.get(); return committedTransactionCount.sum();
} }
@Override @Override
public long getTransactionCount() { public long getTransactionCount() {
return transactionCount.get(); return transactionCount.sum();
} }
@Override @Override
public long getCloseStatementCount() { public long getCloseStatementCount() {
return closeStatementCount.get(); return closeStatementCount.sum();
} }
@Override @Override
public long getPrepareStatementCount() { public long getPrepareStatementCount() {
return prepareStatementCount.get(); return prepareStatementCount.sum();
} }
@Override @Override
public void openSession() { public void openSession() {
sessionOpenCount.getAndIncrement(); sessionOpenCount.increment();
} }
@Override @Override
public void closeSession() { public void closeSession() {
sessionCloseCount.getAndIncrement(); sessionCloseCount.increment();
} }
@Override @Override
public void flush() { public void flush() {
flushCount.getAndIncrement(); flushCount.increment();
} }
@Override @Override
public void connect() { public void connect() {
connectCount.getAndIncrement(); connectCount.increment();
} }
@Override @Override
public void prepareStatement() { public void prepareStatement() {
prepareStatementCount.getAndIncrement(); prepareStatementCount.increment();
} }
@Override @Override
public void closeStatement() { public void closeStatement() {
closeStatementCount.getAndIncrement(); closeStatementCount.increment();
} }
@Override @Override
public void endTransaction(boolean success) { public void endTransaction(boolean success) {
transactionCount.getAndIncrement(); transactionCount.increment();
if ( success ) { if ( success ) {
committedTransactionCount.getAndIncrement(); committedTransactionCount.increment();
} }
} }
@ -890,40 +891,40 @@ public class StatisticsImpl implements StatisticsImplementor, Service {
public void logSummary() { public void logSummary() {
LOG.loggingStatistics(); LOG.loggingStatistics();
LOG.startTime( startTime ); LOG.startTime( startTime );
LOG.sessionsOpened( sessionOpenCount.get() ); LOG.sessionsOpened( sessionOpenCount.sum() );
LOG.sessionsClosed( sessionCloseCount.get() ); LOG.sessionsClosed( sessionCloseCount.sum() );
LOG.transactions( transactionCount.get() ); LOG.transactions( transactionCount.sum() );
LOG.successfulTransactions( committedTransactionCount.get() ); LOG.successfulTransactions( committedTransactionCount.sum() );
LOG.optimisticLockFailures( optimisticFailureCount.get() ); LOG.optimisticLockFailures( optimisticFailureCount.sum() );
LOG.flushes( flushCount.get() ); LOG.flushes( flushCount.sum() );
LOG.connectionsObtained( connectCount.get() ); LOG.connectionsObtained( connectCount.sum() );
LOG.statementsPrepared( prepareStatementCount.get() ); LOG.statementsPrepared( prepareStatementCount.sum() );
LOG.statementsClosed( closeStatementCount.get() ); LOG.statementsClosed( closeStatementCount.sum() );
LOG.secondLevelCachePuts( secondLevelCachePutCount.get() ); LOG.secondLevelCachePuts( secondLevelCachePutCount.sum() );
LOG.secondLevelCacheHits( secondLevelCacheHitCount.get() ); LOG.secondLevelCacheHits( secondLevelCacheHitCount.sum() );
LOG.secondLevelCacheMisses( secondLevelCacheMissCount.get() ); LOG.secondLevelCacheMisses( secondLevelCacheMissCount.sum() );
LOG.entitiesLoaded( entityLoadCount.get() ); LOG.entitiesLoaded( entityLoadCount.sum() );
LOG.entitiesUpdated( entityUpdateCount.get() ); LOG.entitiesUpdated( entityUpdateCount.sum() );
LOG.entitiesInserted( entityInsertCount.get() ); LOG.entitiesInserted( entityInsertCount.sum() );
LOG.entitiesDeleted( entityDeleteCount.get() ); LOG.entitiesDeleted( entityDeleteCount.sum() );
LOG.entitiesFetched( entityFetchCount.get() ); LOG.entitiesFetched( entityFetchCount.sum() );
LOG.collectionsLoaded( collectionLoadCount.get() ); LOG.collectionsLoaded( collectionLoadCount.sum() );
LOG.collectionsUpdated( collectionUpdateCount.get() ); LOG.collectionsUpdated( collectionUpdateCount.sum() );
LOG.collectionsRemoved( collectionRemoveCount.get() ); LOG.collectionsRemoved( collectionRemoveCount.sum() );
LOG.collectionsRecreated( collectionRecreateCount.get() ); LOG.collectionsRecreated( collectionRecreateCount.sum() );
LOG.collectionsFetched( collectionFetchCount.get() ); LOG.collectionsFetched( collectionFetchCount.sum() );
LOG.naturalIdCachePuts( naturalIdCachePutCount.get() ); LOG.naturalIdCachePuts( naturalIdCachePutCount.sum() );
LOG.naturalIdCacheHits( naturalIdCacheHitCount.get() ); LOG.naturalIdCacheHits( naturalIdCacheHitCount.sum() );
LOG.naturalIdCacheMisses( naturalIdCacheMissCount.get() ); LOG.naturalIdCacheMisses( naturalIdCacheMissCount.sum() );
LOG.naturalIdMaxQueryTime( naturalIdQueryExecutionMaxTime.get() ); LOG.naturalIdMaxQueryTime( naturalIdQueryExecutionMaxTime.get() );
LOG.naturalIdQueriesExecuted( naturalIdQueryExecutionCount.get() ); LOG.naturalIdQueriesExecuted( naturalIdQueryExecutionCount.sum() );
LOG.queriesExecuted( queryExecutionCount.get() ); LOG.queriesExecuted( queryExecutionCount.sum() );
LOG.queryCachePuts( queryCachePutCount.get() ); LOG.queryCachePuts( queryCachePutCount.sum() );
LOG.timestampCachePuts( updateTimestampsCachePutCount.get() ); LOG.timestampCachePuts( updateTimestampsCachePutCount.sum() );
LOG.timestampCacheHits( updateTimestampsCacheHitCount.get() ); LOG.timestampCacheHits( updateTimestampsCacheHitCount.sum() );
LOG.timestampCacheMisses( updateTimestampsCacheMissCount.get() ); LOG.timestampCacheMisses( updateTimestampsCacheMissCount.sum() );
LOG.queryCacheHits( queryCacheHitCount.get() ); LOG.queryCacheHits( queryCacheHitCount.sum() );
LOG.queryCacheMisses( queryCacheMissCount.get() ); LOG.queryCacheMisses( queryCacheMissCount.sum() );
LOG.maxQueryTime( queryExecutionMaxTime.get() ); LOG.maxQueryTime( queryExecutionMaxTime.get() );
} }

View File

@ -65,9 +65,9 @@ public class StatisticsInitiator implements SessionFactoryServiceInitiator<Stati
Object configValue, Object configValue,
ServiceRegistryImplementor registry) { ServiceRegistryImplementor registry) {
StatisticsFactory statisticsFactory; final StatisticsFactory statisticsFactory;
if ( configValue == null ) { if ( configValue == null ) {
statisticsFactory = DEFAULT_STATS_BUILDER; statisticsFactory = null; //We'll use the default
} }
else if ( StatisticsFactory.class.isInstance( configValue ) ) { else if ( StatisticsFactory.class.isInstance( configValue ) ) {
statisticsFactory = (StatisticsFactory) configValue; statisticsFactory = (StatisticsFactory) configValue;
@ -88,18 +88,18 @@ public class StatisticsInitiator implements SessionFactoryServiceInitiator<Stati
); );
} }
} }
final StatisticsImplementor statistics;
StatisticsImplementor statistics = statisticsFactory.buildStatistics( sessionFactory ); if ( statisticsFactory == null ) {
// Default:
statistics = new StatisticsImpl( sessionFactory );
}
else {
statistics = statisticsFactory.buildStatistics( sessionFactory );
}
final boolean enabled = sessionFactory.getSettings().isStatisticsEnabled(); final boolean enabled = sessionFactory.getSettings().isStatisticsEnabled();
statistics.setStatisticsEnabled( enabled ); statistics.setStatisticsEnabled( enabled );
LOG.debugf( "Statistics initialized [enabled=%s]", enabled ); LOG.debugf( "Statistics initialized [enabled=%s]", enabled );
return statistics; return statistics;
} }
private static StatisticsFactory DEFAULT_STATS_BUILDER = new StatisticsFactory() {
@Override
public StatisticsImplementor buildStatistics(SessionFactoryImplementor sessionFactory) {
return new StatisticsImpl( sessionFactory );
}
};
} }