minor refresh of the Statistics API
- added getStart() returning an Instance - removed a left-over @MXBean annotation - refreshed some Javadoc - fixed some warnings
This commit is contained in:
parent
fda6e96c5e
commit
f7b4a94c45
|
@ -9,7 +9,7 @@ package org.hibernate.stat;
|
|||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Second level cache statistics of a specific region
|
||||
* Second-level cache statistics of a specific region.
|
||||
*
|
||||
* @author Gavin King
|
||||
*/
|
||||
|
@ -43,7 +43,7 @@ public interface CacheRegionStatistics extends Serializable {
|
|||
|
||||
/**
|
||||
* The number of elements currently in memory within the cache provider.
|
||||
*
|
||||
* <p>
|
||||
* This is an optional value contingent upon the underlying cache provider
|
||||
* providing extended stats support via
|
||||
* {@link org.hibernate.cache.spi.ExtendedStatisticsSupport}. If the provider
|
||||
|
@ -54,7 +54,7 @@ public interface CacheRegionStatistics extends Serializable {
|
|||
|
||||
/**
|
||||
* The number of elements currently stored to disk within the cache provider.
|
||||
*
|
||||
* <p>
|
||||
* This is an optional value contingent upon the underlying cache provider
|
||||
* providing extended stats support via
|
||||
* {@link org.hibernate.cache.spi.ExtendedStatisticsSupport}. If the provider
|
||||
|
@ -65,7 +65,7 @@ public interface CacheRegionStatistics extends Serializable {
|
|||
|
||||
/**
|
||||
* The size that the in-memory elements take up within the cache provider.
|
||||
*
|
||||
* <p>
|
||||
* This is an optional value contingent upon the underlying cache provider
|
||||
* providing extended stats support via
|
||||
* {@link org.hibernate.cache.spi.ExtendedStatisticsSupport}. If the provider
|
||||
|
|
|
@ -9,7 +9,7 @@ package org.hibernate.stat;
|
|||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Collection related statistics
|
||||
* Collection-related statistics.
|
||||
*
|
||||
* @author Gavin King
|
||||
* @author Steve Ebersole
|
||||
|
|
|
@ -9,7 +9,7 @@ package org.hibernate.stat;
|
|||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Entity related statistics
|
||||
* Entity-related statistics.
|
||||
*
|
||||
* @author Gavin King
|
||||
* @author Steve Ebersole
|
||||
|
|
|
@ -9,12 +9,13 @@ package org.hibernate.stat;
|
|||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Statistics pertaining to the execution of the "natural id resolution" query.
|
||||
* Statistics pertaining to the execution of queries which resolve a natural
|
||||
* id lookup against the database.
|
||||
*
|
||||
* @apiNote The natural-id resolution data is allowed to be stored in the
|
||||
* second level cache, and if so stored will have available caching stats as
|
||||
* well available via {@link Statistics#getDomainDataRegionStatistics} using the
|
||||
* configured region name
|
||||
* second-level cache, and if so stored will have available caching stats as
|
||||
* well available via {@link Statistics#getDomainDataRegionStatistics} using
|
||||
* the configured region name
|
||||
*
|
||||
* todo (6.0) : consider a means to get the cache Region statistics for:
|
||||
* 1) an entity by name
|
||||
|
|
|
@ -9,9 +9,11 @@ package org.hibernate.stat;
|
|||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Query statistics (HQL and SQL)
|
||||
* <p/>
|
||||
* Note that for a cached query, the cache miss is equals to the db count
|
||||
* Statistics relating to a particular query written in HQL or SQL.
|
||||
* <p>
|
||||
* Note that for a cached query, the number of cache missed is the
|
||||
* same as the number of queries actually executed against the
|
||||
* database.
|
||||
*
|
||||
* @author Gavin King
|
||||
* @author Steve Ebersole
|
||||
|
@ -23,7 +25,8 @@ public interface QueryStatistics extends Serializable {
|
|||
long getExecutionCount();
|
||||
|
||||
/**
|
||||
* How many ResultSet rows have been processed for this query ?
|
||||
* How many {@link java.sql.ResultSet} rows have been processed
|
||||
* for this query
|
||||
*/
|
||||
long getExecutionRowCount();
|
||||
|
||||
|
@ -43,7 +46,8 @@ public interface QueryStatistics extends Serializable {
|
|||
long getExecutionMinTime();
|
||||
|
||||
/**
|
||||
* How long, cumulatively, have all executions of this query taken?
|
||||
* How long, cumulatively, have all executions of this query
|
||||
* taken?
|
||||
*/
|
||||
long getExecutionTotalTime();
|
||||
|
||||
|
@ -77,7 +81,8 @@ public interface QueryStatistics extends Serializable {
|
|||
long getCachePutCount();
|
||||
|
||||
/**
|
||||
* The number of query plans successfully fetched from the cache.
|
||||
* The number of query plans successfully fetched from the
|
||||
* cache.
|
||||
*/
|
||||
default long getPlanCacheHitCount() {
|
||||
//For backward compatibility
|
||||
|
@ -93,7 +98,8 @@ public interface QueryStatistics extends Serializable {
|
|||
}
|
||||
|
||||
/**
|
||||
* The overall time spent to compile the plan for this particular query.
|
||||
* The overall time spent to compile the plan for this
|
||||
* particular query.
|
||||
*/
|
||||
default long getPlanCompilationTotalMicroseconds() {
|
||||
//For backward compatibility
|
||||
|
|
|
@ -9,28 +9,29 @@ package org.hibernate.stat;
|
|||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Information about the first-level (session) cache
|
||||
* for a particular session instance
|
||||
* Information about the first-level (session) cache for a particular
|
||||
* instance of {@link org.hibernate.Session}.
|
||||
*
|
||||
* @author Gavin King
|
||||
*/
|
||||
public interface SessionStatistics {
|
||||
/**
|
||||
* Get the number of entity instances associated with the session
|
||||
* The number of entity instances associated with the session.
|
||||
*/
|
||||
int getEntityCount();
|
||||
/**
|
||||
* Get the number of collection instances associated with the session
|
||||
* The number of collection instances associated with the session.
|
||||
*/
|
||||
int getCollectionCount();
|
||||
|
||||
/**
|
||||
* Get the set of all {@code EntityKey}s
|
||||
* @see org.hibernate.engine.spi.EntityKey
|
||||
* The set of all {@link org.hibernate.engine.spi.EntityKey}s
|
||||
* currently held within the persistence context.
|
||||
*/
|
||||
Set<?> getEntityKeys();
|
||||
/**
|
||||
* Get the set of all {@code CollectionKey}s
|
||||
* @see org.hibernate.engine.spi.CollectionKey
|
||||
* The set of all {@link org.hibernate.engine.spi.CollectionKey}s
|
||||
* currently held within the persistence context.
|
||||
*/
|
||||
Set<?> getCollectionKeys();
|
||||
|
||||
|
|
|
@ -6,373 +6,400 @@
|
|||
*/
|
||||
package org.hibernate.stat;
|
||||
|
||||
import javax.management.MXBean;
|
||||
import java.time.Instant;
|
||||
|
||||
/**
|
||||
* Exposes statistics for a particular {@link org.hibernate.SessionFactory}. Beware of milliseconds metrics, they
|
||||
* are dependent of the JVM precision: you may then encounter a 10 ms approximation depending on you OS platform.
|
||||
* Please refer to the JVM documentation for more information.
|
||||
* Exposes statistics collected from all sessions belonging to a
|
||||
* particular {@link org.hibernate.SessionFactory}.
|
||||
* <p>
|
||||
* Collection of statistics is enabled if the configuration property
|
||||
* {@link org.hibernate.cfg.AvailableSettings#GENERATE_STATISTICS} is
|
||||
* set to {@code true}. It may be dynamically enabled or disabled at
|
||||
* runtime by calling {@link #setStatisticsEnabled(boolean)}.
|
||||
*
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
@MXBean
|
||||
public interface Statistics {
|
||||
|
||||
/**
|
||||
* The default value of the configuration property
|
||||
* {@link org.hibernate.cfg.AvailableSettings#QUERY_STATISTICS_MAX_SIZE}.
|
||||
*/
|
||||
int DEFAULT_QUERY_STATISTICS_MAX_SIZE = 5000;
|
||||
|
||||
/**
|
||||
* Are statistics enabled
|
||||
* Is collection of statistics enabled?
|
||||
*/
|
||||
boolean isStatisticsEnabled();
|
||||
|
||||
/**
|
||||
* Enable statistics logs (this is a dynamic parameter)
|
||||
* Enable or disable statistics collection.
|
||||
*/
|
||||
void setStatisticsEnabled(boolean b);
|
||||
void setStatisticsEnabled(boolean enabled);
|
||||
|
||||
/**
|
||||
* reset all statistics
|
||||
* Reset all statistics.
|
||||
*/
|
||||
void clear();
|
||||
|
||||
/**
|
||||
* log in info level the main statistics
|
||||
* Log the main statistics at level {@code INFO}.
|
||||
*/
|
||||
void logSummary();
|
||||
|
||||
|
||||
/**
|
||||
* find entity statistics per name
|
||||
* Obtain the statistics for the entity with the given name.
|
||||
*
|
||||
* @param entityName entity name
|
||||
* @return EntityStatistics object
|
||||
* @param entityName the entity name
|
||||
*/
|
||||
EntityStatistics getEntityStatistics(String entityName);
|
||||
|
||||
/**
|
||||
* Get collection statistics per role
|
||||
* Obtain the statistics for the collection with the given role.
|
||||
*
|
||||
* @param role collection role
|
||||
* @return CollectionStatistics
|
||||
* @param role the collection role
|
||||
*/
|
||||
CollectionStatistics getCollectionStatistics(String role);
|
||||
|
||||
/**
|
||||
* Natural id resolution query statistics for an entity type
|
||||
* Obtain the natural id resolution statistics for the entity
|
||||
* type with the given name.
|
||||
*
|
||||
* @param entityName The entity name that is the root of the hierarchy containing the
|
||||
* natural id
|
||||
* @return NaturalIdCacheStatistics
|
||||
* @param entityName The entity name that is the root of the
|
||||
* hierarchy containing the natural id
|
||||
*/
|
||||
NaturalIdStatistics getNaturalIdStatistics(String entityName);
|
||||
|
||||
/**
|
||||
* Query statistics from query string (HQL or SQL)
|
||||
* Obtain the query statistics for the given query string.
|
||||
*
|
||||
* @param queryString query string
|
||||
* @return QueryStatistics
|
||||
* @param queryString the query string, written in HQL or SQL
|
||||
*/
|
||||
QueryStatistics getQueryStatistics(String queryString);
|
||||
|
||||
/**
|
||||
* Second-level cache statistics per domain data (entity, collection, natural-id) region
|
||||
* Obtain the second-level cache statistics for the given cache
|
||||
* region.
|
||||
*
|
||||
* @param regionName The unqualified region name
|
||||
*
|
||||
* @return The stats for the named region, or {@code null} if the second level cache is
|
||||
* not enabled
|
||||
* @return the statistics for the named region, or {@code null}
|
||||
* if the second-level cache is not enabled
|
||||
*
|
||||
* @throws IllegalArgumentException if the region name could not be resolved
|
||||
* @throws IllegalArgumentException if there is no region with the given name
|
||||
*/
|
||||
CacheRegionStatistics getDomainDataRegionStatistics(String regionName);
|
||||
|
||||
/**
|
||||
* Second-level cache statistics per query region
|
||||
* Obtain the second-level cache statistics for the given query
|
||||
* cache region.
|
||||
*
|
||||
* @param regionName The unqualified region name
|
||||
*
|
||||
* @return Stats for the named region, or {@code null} if (1) query result caching is
|
||||
* not enabled or (2) no query region exists with that name
|
||||
* @return the statistics for the named region, or {@code null}
|
||||
* if either query result caching is not enabled, or no
|
||||
* query cache region exists with the given name
|
||||
*/
|
||||
CacheRegionStatistics getQueryRegionStatistics(String regionName);
|
||||
|
||||
/**
|
||||
* Get statistics for either a domain-data or query-result region - this
|
||||
* method checks both, preferring domain data region if one. Think of it
|
||||
* as a cascading check to:<ol>
|
||||
* Obtain the statistics for either a domain data or query result
|
||||
* cache region.
|
||||
* <p>
|
||||
* This method checks both, preferring the domain data region if
|
||||
* there is one. Think of it as a cascading check to:<ol>
|
||||
* <li>{@link #getDomainDataRegionStatistics}</li>
|
||||
* <li>{@link #getQueryRegionStatistics}</li>
|
||||
* </ol>
|
||||
* Note that returning null is preferred here over throwing an exception when
|
||||
* no region exists with that name.
|
||||
* Note that null is returned instead of throwing an exception when
|
||||
* no region exists with the given name.
|
||||
*
|
||||
* @param regionName The unqualified region name
|
||||
*
|
||||
* @return Stats for the named region, or {@code null} if no such region exists
|
||||
* @return the statistics for the named region, or {@code null} if
|
||||
* there is no region with the given name
|
||||
*/
|
||||
CacheRegionStatistics getCacheRegionStatistics(String regionName);
|
||||
|
||||
/**
|
||||
* Get global number of entity deletes
|
||||
* @return entity deletion count
|
||||
* The global number of entity deletes.
|
||||
*/
|
||||
long getEntityDeleteCount();
|
||||
|
||||
/**
|
||||
* Get global number of entity inserts
|
||||
* @return entity insertion count
|
||||
* The global number of entity inserts.
|
||||
*/
|
||||
long getEntityInsertCount();
|
||||
|
||||
/**
|
||||
* Get global number of entity loads
|
||||
* @return entity load (from DB)
|
||||
* The global number of entity loads.
|
||||
*/
|
||||
long getEntityLoadCount();
|
||||
|
||||
/**
|
||||
* Get global number of entity fetches
|
||||
* @return entity fetch (from DB)
|
||||
* The global number of entity fetches.
|
||||
*/
|
||||
long getEntityFetchCount();
|
||||
|
||||
/**
|
||||
* Get global number of entity updates
|
||||
* @return entity update
|
||||
* The global number of entity updates.
|
||||
*/
|
||||
long getEntityUpdateCount();
|
||||
|
||||
/**
|
||||
* Get global number of executed queries
|
||||
* @return query execution count
|
||||
* The global number of executed queries.
|
||||
*/
|
||||
long getQueryExecutionCount();
|
||||
|
||||
/**
|
||||
* Get the time in milliseconds of the slowest query.
|
||||
* The time in milliseconds of the slowest query.
|
||||
*/
|
||||
long getQueryExecutionMaxTime();
|
||||
|
||||
/**
|
||||
* Get the query string for the slowest query.
|
||||
* The query string for the slowest query.
|
||||
*/
|
||||
String getQueryExecutionMaxTimeQueryString();
|
||||
|
||||
/**
|
||||
* Get the global number of cached queries successfully retrieved from cache
|
||||
* The global number of cached queries successfully retrieved from
|
||||
* the cache.
|
||||
*/
|
||||
long getQueryCacheHitCount();
|
||||
|
||||
/**
|
||||
* Get the global number of cached queries *not* found in cache
|
||||
* The global number of cached queries <em>not</em>not found in the
|
||||
* cache.
|
||||
*/
|
||||
long getQueryCacheMissCount();
|
||||
|
||||
/**
|
||||
* Get the global number of cacheable queries put in cache
|
||||
* The global number of cacheable queries put in cache.
|
||||
*/
|
||||
long getQueryCachePutCount();
|
||||
|
||||
/**
|
||||
* Get the global number of natural id queries executed against the database
|
||||
* The global number of natural id queries executed against the
|
||||
* database.
|
||||
*/
|
||||
long getNaturalIdQueryExecutionCount();
|
||||
|
||||
/**
|
||||
* Get the global maximum query time for natural id queries executed against the database
|
||||
* The global maximum query time for natural id queries executed
|
||||
* against the database.
|
||||
*/
|
||||
long getNaturalIdQueryExecutionMaxTime();
|
||||
|
||||
/**
|
||||
* Get the region for the maximum natural id query time
|
||||
* The region for the maximum natural id query time.
|
||||
*/
|
||||
String getNaturalIdQueryExecutionMaxTimeRegion();
|
||||
|
||||
/**
|
||||
* Get the entity for the maximum natural id query time
|
||||
* The entity name for the maximum natural id query time.
|
||||
*/
|
||||
String getNaturalIdQueryExecutionMaxTimeEntity();
|
||||
|
||||
/**
|
||||
* Get the global number of cached natural id lookups successfully retrieved from cache
|
||||
* The global number of cached natural id lookups successfully
|
||||
* retrieved from the cache.
|
||||
*/
|
||||
long getNaturalIdCacheHitCount();
|
||||
|
||||
/**
|
||||
* Get the global number of cached natural id lookups *not* found in cache
|
||||
* The global number of cached natural id lookups <em>not</em> found
|
||||
* in the cache.
|
||||
*/
|
||||
long getNaturalIdCacheMissCount();
|
||||
|
||||
/**
|
||||
* Get the global number of cacheable natural id lookups put in cache
|
||||
* The global number of cacheable natural id lookups put in cache.
|
||||
*/
|
||||
long getNaturalIdCachePutCount();
|
||||
|
||||
/**
|
||||
* Get the global number of timestamps successfully retrieved from cache
|
||||
* The global number of timestamps successfully retrieved from cache.
|
||||
*/
|
||||
long getUpdateTimestampsCacheHitCount();
|
||||
|
||||
/**
|
||||
* Get the global number of timestamp requests that were not found in the cache
|
||||
* The global number of timestamp requests that were not found in the
|
||||
* cache.
|
||||
*/
|
||||
long getUpdateTimestampsCacheMissCount();
|
||||
|
||||
/**
|
||||
* Get the global number of timestamps put in cache
|
||||
* The global number of timestamps put in cache.
|
||||
*/
|
||||
long getUpdateTimestampsCachePutCount();
|
||||
|
||||
/**
|
||||
* Get the global number of flush operations executed (either manual or automatic).
|
||||
* The global number of flush operations executed, including automatic
|
||||
* (either manual or automatic).
|
||||
*/
|
||||
long getFlushCount();
|
||||
|
||||
/**
|
||||
* Get the global number of connections asked by the sessions
|
||||
* (the actual number of connections used may be much smaller depending
|
||||
* whether you use a connection pool or not)
|
||||
* The global number of connections requested by sessions.
|
||||
* <p>
|
||||
* The actual number of connections used may be much smaller, assuming
|
||||
* that a connection pool is in use.
|
||||
*/
|
||||
long getConnectCount();
|
||||
|
||||
/**
|
||||
* Global number of cacheable entities/collections successfully retrieved from the cache
|
||||
* The global number of cacheable entities and collections successfully
|
||||
* retrieved from the cache.
|
||||
*/
|
||||
long getSecondLevelCacheHitCount();
|
||||
|
||||
/**
|
||||
* Global number of cacheable entities/collections not found in the cache and loaded from the database.
|
||||
* The global number of cacheable entities collections not found in the
|
||||
* cache and loaded from the database.
|
||||
*/
|
||||
long getSecondLevelCacheMissCount();
|
||||
|
||||
/**
|
||||
* Global number of cacheable entities/collections put in the cache
|
||||
* The global number of cacheable entities and collections put in the
|
||||
* cache.
|
||||
*/
|
||||
long getSecondLevelCachePutCount();
|
||||
|
||||
/**
|
||||
* Global number of sessions closed
|
||||
* The global number of sessions closed.
|
||||
*/
|
||||
long getSessionCloseCount();
|
||||
|
||||
/**
|
||||
* Global number of sessions opened
|
||||
* The global number of sessions opened.
|
||||
*/
|
||||
long getSessionOpenCount();
|
||||
|
||||
/**
|
||||
* Global number of collections loaded
|
||||
* The global number of collections loaded.
|
||||
*/
|
||||
long getCollectionLoadCount();
|
||||
|
||||
/**
|
||||
* Global number of collections fetched
|
||||
* The global number of collections fetched.
|
||||
*/
|
||||
long getCollectionFetchCount();
|
||||
|
||||
/**
|
||||
* Global number of collections updated
|
||||
* The global number of collections updated.
|
||||
*/
|
||||
long getCollectionUpdateCount();
|
||||
|
||||
/**
|
||||
* Global number of collections removed
|
||||
* The global number of collections removed.
|
||||
*/
|
||||
//even on inverse="true"
|
||||
long getCollectionRemoveCount();
|
||||
|
||||
/**
|
||||
* Global number of collections recreated
|
||||
* The global number of collections recreated
|
||||
*/
|
||||
long getCollectionRecreateCount();
|
||||
|
||||
/**
|
||||
* The milliseconds (JVM standard {@link System#currentTimeMillis()})
|
||||
* since the initial creation of this Statistics
|
||||
* instance or the last time {@link #clear()} was called.
|
||||
*
|
||||
* @apiNote This time(stamp) is
|
||||
* The {@link Instant} at which this instance of {@code Statistics}
|
||||
* was created, or since the last time {@link #clear()} was called.
|
||||
*/
|
||||
Instant getStart();
|
||||
|
||||
/**
|
||||
* The {@linkplain Instant#toEpochMilli()} milliseconds}) since the
|
||||
* initial creation of this instance, or since the last time
|
||||
* {@link #clear()} was called.
|
||||
*
|
||||
* @deprecated use {@link #getStart()}
|
||||
*/
|
||||
@Deprecated(since = "6.0")
|
||||
long getStartTime();
|
||||
|
||||
/**
|
||||
* Get all executed query strings.
|
||||
*
|
||||
* The maximum number of queries tracked by the Hibernate statistics is given by the {@code hibernate.statistics.query_max_size} property.
|
||||
* All executed query strings.
|
||||
* <p>
|
||||
* The maximum number of queries tracked by the Hibernate statistics
|
||||
* is determined by the configuration property
|
||||
* {@link org.hibernate.cfg.AvailableSettings#QUERY_STATISTICS_MAX_SIZE}.
|
||||
*/
|
||||
String[] getQueries();
|
||||
|
||||
/**
|
||||
* Get the names of all entities
|
||||
* The names of all entities.
|
||||
*/
|
||||
String[] getEntityNames();
|
||||
|
||||
/**
|
||||
* Get the names of all collection roles
|
||||
* The names of all collection roles.
|
||||
*/
|
||||
String[] getCollectionRoleNames();
|
||||
|
||||
/**
|
||||
* Get all second-level cache region names. Note: for backwards
|
||||
* compatibility this method returns just the names of regions
|
||||
* storing domain data, not query result regions
|
||||
* All second-level cache region names. For backwards compatibility,
|
||||
* this method returns just the names of regions storing domain data,
|
||||
* not query result cache regions.
|
||||
*/
|
||||
String[] getSecondLevelCacheRegionNames();
|
||||
|
||||
/**
|
||||
* The number of transactions we know to have been successful
|
||||
* The number of transactions we know to have been successful.
|
||||
*/
|
||||
long getSuccessfulTransactionCount();
|
||||
|
||||
/**
|
||||
* The number of transactions we know to have completed
|
||||
* The number of transactions we know to have completed.
|
||||
*/
|
||||
long getTransactionCount();
|
||||
|
||||
/**
|
||||
* The number of prepared statements that were acquired
|
||||
* The number of prepared statements that were acquired.
|
||||
*/
|
||||
long getPrepareStatementCount();
|
||||
|
||||
/**
|
||||
* The number of prepared statements that were released
|
||||
* The number of prepared statements that were released.
|
||||
*/
|
||||
long getCloseStatementCount();
|
||||
|
||||
/**
|
||||
* The number of Hibernate {@code StaleObjectStateException}s or JPA {@code OptimisticLockException}s
|
||||
* that occurred.
|
||||
* The number of Hibernate {@code StaleObjectStateException}s or JPA
|
||||
* {@code OptimisticLockException}s that have occurred.
|
||||
*/
|
||||
long getOptimisticFailureCount();
|
||||
|
||||
|
||||
/**
|
||||
* Second-level cache statistics per region
|
||||
* Second-level cache statistics per region.
|
||||
*
|
||||
* @param regionName qualified region name
|
||||
*
|
||||
* @return SecondLevelCacheStatistics or {@code null} if the second level cache is not enabled
|
||||
* @return the statistics object, or {@code null} if the second-level
|
||||
* cache is not enabled
|
||||
*
|
||||
* @throws IllegalArgumentException if the region name could not be resolved
|
||||
* @throws IllegalArgumentException if there is no region with the given name
|
||||
*
|
||||
* @deprecated (since 5.3) Use {@link #getDomainDataRegionStatistics} instead
|
||||
* @deprecated Use {@link #getDomainDataRegionStatistics}
|
||||
*/
|
||||
@Deprecated
|
||||
@Deprecated(since = "5.3")
|
||||
SecondLevelCacheStatistics getSecondLevelCacheStatistics(String regionName);
|
||||
|
||||
/**
|
||||
* Natural id cache statistics per region
|
||||
* Natural id cache statistics per region.
|
||||
*
|
||||
* @param regionName region name
|
||||
* @return NaturalIdCacheStatistics
|
||||
*
|
||||
* @deprecated (since 5.3) Use {@link #getNaturalIdStatistics} or
|
||||
* {@link #getDomainDataRegionStatistics} instead depending on need
|
||||
* @deprecated Use {@link #getNaturalIdStatistics} or
|
||||
* {@link #getDomainDataRegionStatistics}
|
||||
*/
|
||||
@Deprecated
|
||||
@Deprecated(since = "5.3")
|
||||
NaturalIdCacheStatistics getNaturalIdCacheStatistics(String regionName);
|
||||
|
||||
/**
|
||||
* Get the global number of query plans successfully retrieved from cache
|
||||
* The global number of query plans successfully retrieved from cache.
|
||||
*/
|
||||
default long getQueryPlanCacheHitCount() {
|
||||
//For backward compatibility
|
||||
|
@ -380,7 +407,7 @@ public interface Statistics {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the global number of query plans lookups *not* found in cache
|
||||
* The global number of query plans lookups <em>not</em> found in cache.
|
||||
*/
|
||||
default long getQueryPlanCacheMissCount() {
|
||||
//For backward compatibility
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
package org.hibernate.stat.internal;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.concurrent.atomic.LongAdder;
|
||||
|
@ -32,7 +33,6 @@ import static org.hibernate.internal.CoreLogging.messageLogger;
|
|||
* @author Alex Snaps
|
||||
* @author Sanne Grinovero
|
||||
*/
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public class StatisticsImpl implements StatisticsImplementor, Service {
|
||||
|
||||
private static final CoreMessageLogger LOG = messageLogger( StatisticsImpl.class );
|
||||
|
@ -44,7 +44,7 @@ public class StatisticsImpl implements StatisticsImplementor, Service {
|
|||
private final boolean queryCacheEnabled;
|
||||
|
||||
private volatile boolean isStatisticsEnabled;
|
||||
private volatile long startTime;
|
||||
private volatile Instant startTime;
|
||||
|
||||
private final LongAdder sessionOpenCount = new LongAdder();
|
||||
private final LongAdder sessionCloseCount = new LongAdder();
|
||||
|
@ -96,9 +96,9 @@ public class StatisticsImpl implements StatisticsImplementor, Service {
|
|||
|
||||
private final LongAdder optimisticFailureCount = new LongAdder();
|
||||
|
||||
private final StatsNamedContainer<EntityStatisticsImpl> entityStatsMap = new StatsNamedContainer();
|
||||
private final StatsNamedContainer<NaturalIdStatisticsImpl> naturalIdQueryStatsMap = new StatsNamedContainer();
|
||||
private final StatsNamedContainer<CollectionStatisticsImpl> collectionStatsMap = new StatsNamedContainer();
|
||||
private final StatsNamedContainer<EntityStatisticsImpl> entityStatsMap = new StatsNamedContainer<>();
|
||||
private final StatsNamedContainer<NaturalIdStatisticsImpl> naturalIdQueryStatsMap = new StatsNamedContainer<>();
|
||||
private final StatsNamedContainer<CollectionStatisticsImpl> collectionStatsMap = new StatsNamedContainer<>();
|
||||
|
||||
/**
|
||||
* Keyed by query string
|
||||
|
@ -110,18 +110,19 @@ public class StatisticsImpl implements StatisticsImplementor, Service {
|
|||
*/
|
||||
private final StatsNamedContainer<CacheRegionStatisticsImpl> l2CacheStatsMap = new StatsNamedContainer<>();
|
||||
|
||||
private final StatsNamedContainer<DeprecatedNaturalIdCacheStatisticsImpl> deprecatedNaturalIdStatsMap = new StatsNamedContainer();
|
||||
private final StatsNamedContainer<DeprecatedNaturalIdCacheStatisticsImpl> deprecatedNaturalIdStatsMap
|
||||
= new StatsNamedContainer<>();
|
||||
|
||||
public StatisticsImpl(SessionFactoryImplementor sessionFactory) {
|
||||
Objects.requireNonNull( sessionFactory );
|
||||
SessionFactoryOptions sessionFactoryOptions = sessionFactory.getSessionFactoryOptions();
|
||||
this.queryStatsMap = new StatsNamedContainer(
|
||||
this.queryStatsMap = new StatsNamedContainer<>(
|
||||
sessionFactory != null ?
|
||||
sessionFactoryOptions.getQueryStatisticsMaxSize() :
|
||||
Statistics.DEFAULT_QUERY_STATISTICS_MAX_SIZE,
|
||||
20
|
||||
);
|
||||
resetStartTime();
|
||||
resetStart();
|
||||
metamodel = sessionFactory.getMetamodel();
|
||||
cache = sessionFactory.getCache();
|
||||
cacheRegionPrefix = sessionFactoryOptions.getCacheRegionPrefix();
|
||||
|
@ -191,16 +192,21 @@ public class StatisticsImpl implements StatisticsImplementor, Service {
|
|||
queryPlanCacheHitCount.reset();
|
||||
queryPlanCacheMissCount.reset();
|
||||
|
||||
resetStartTime();
|
||||
resetStart();
|
||||
}
|
||||
|
||||
private void resetStartTime() {
|
||||
startTime = System.currentTimeMillis();
|
||||
private void resetStart() {
|
||||
startTime = Instant.now();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Instant getStart() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getStartTime() {
|
||||
return startTime;
|
||||
return startTime.toEpochMilli();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -209,8 +215,8 @@ public class StatisticsImpl implements StatisticsImplementor, Service {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setStatisticsEnabled(boolean b) {
|
||||
isStatisticsEnabled = b;
|
||||
public void setStatisticsEnabled(boolean enabled) {
|
||||
isStatisticsEnabled = enabled;
|
||||
}
|
||||
|
||||
|
||||
|
@ -875,7 +881,7 @@ public class StatisticsImpl implements StatisticsImplementor, Service {
|
|||
@Override
|
||||
public void logSummary() {
|
||||
LOG.loggingStatistics();
|
||||
LOG.startTime( startTime );
|
||||
LOG.startTime( startTime.toEpochMilli() );
|
||||
LOG.sessionsOpened( sessionOpenCount.sum() );
|
||||
LOG.sessionsClosed( sessionCloseCount.sum() );
|
||||
LOG.transactions( transactionCount.sum() );
|
||||
|
@ -917,48 +923,46 @@ public class StatisticsImpl implements StatisticsImplementor, Service {
|
|||
|
||||
@Override
|
||||
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( 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( ",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( ",query plan cache hits=" ).append( queryPlanCacheHitCount )
|
||||
.append( ",query plan cache misses=" ).append( queryPlanCacheMissCount )
|
||||
.append( ']' )
|
||||
.toString();
|
||||
return "Statistics[" +
|
||||
"start time=" + startTime +
|
||||
",sessions opened=" + sessionOpenCount +
|
||||
",sessions closed=" + sessionCloseCount +
|
||||
",transactions=" + transactionCount +
|
||||
",successful transactions=" + committedTransactionCount +
|
||||
",optimistic lock failures=" + optimisticFailureCount +
|
||||
",flushes=" + flushCount +
|
||||
",connections obtained=" + connectCount +
|
||||
",statements prepared=" + prepareStatementCount +
|
||||
",statements closed=" + closeStatementCount +
|
||||
",second level cache puts=" + secondLevelCachePutCount +
|
||||
",second level cache hits=" + secondLevelCacheHitCount +
|
||||
",second level cache misses=" + secondLevelCacheMissCount +
|
||||
",entities loaded=" + entityLoadCount +
|
||||
",entities updated=" + entityUpdateCount +
|
||||
",entities inserted=" + entityInsertCount +
|
||||
",entities deleted=" + entityDeleteCount +
|
||||
",entities fetched=" + entityFetchCount +
|
||||
",collections loaded=" + collectionLoadCount +
|
||||
",collections updated=" + collectionUpdateCount +
|
||||
",collections removed=" + collectionRemoveCount +
|
||||
",collections recreated=" + collectionRecreateCount +
|
||||
",collections fetched=" + collectionFetchCount +
|
||||
",naturalId queries executed to database=" + naturalIdQueryExecutionCount +
|
||||
",naturalId cache puts=" + naturalIdCachePutCount +
|
||||
",naturalId cache hits=" + naturalIdCacheHitCount +
|
||||
",naturalId cache misses=" + naturalIdCacheMissCount +
|
||||
",naturalId max query time=" + naturalIdQueryExecutionMaxTime +
|
||||
",queries executed to database=" + queryExecutionCount +
|
||||
",query cache puts=" + queryCachePutCount +
|
||||
",query cache hits=" + queryCacheHitCount +
|
||||
",query cache misses=" + queryCacheMissCount +
|
||||
",update timestamps cache puts=" + updateTimestampsCachePutCount +
|
||||
",update timestamps cache hits=" + updateTimestampsCacheHitCount +
|
||||
",update timestamps cache misses=" + updateTimestampsCacheMissCount +
|
||||
",max query time=" + queryExecutionMaxTime +
|
||||
",query plan cache hits=" + queryPlanCacheHitCount +
|
||||
",query plan cache misses=" + queryPlanCacheMissCount +
|
||||
']';
|
||||
}
|
||||
|
||||
private EntityStatisticsImpl instantiateEntityStatistics(final String entityName) {
|
||||
|
|
|
@ -32,7 +32,7 @@ public final class StatsNamedContainer<V> {
|
|||
* Creates a bounded container - based on BoundedConcurrentHashMap
|
||||
*/
|
||||
public StatsNamedContainer(int capacity, int concurrencyLevel) {
|
||||
this.map = new BoundedConcurrentHashMap( capacity, concurrencyLevel, BoundedConcurrentHashMap.Eviction.LRU );
|
||||
this.map = new BoundedConcurrentHashMap<>( capacity, concurrencyLevel, BoundedConcurrentHashMap.Eviction.LRU );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -63,6 +63,7 @@ public final class StatsNamedContainer<V> {
|
|||
* Most notably, the ConcurrentHashMap implementation might block other accesses for the sake of making
|
||||
* sure the function is invoked at most once: we don't need this guarantee, and prefer to reduce risk of blocking.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public V getOrCompute(final String key, final Function<String, V> function) {
|
||||
final Object v1 = map.get( key );
|
||||
if ( v1 != null ) {
|
||||
|
|
Loading…
Reference in New Issue