Example usage for org.hibernate.stat Statistics setStatisticsEnabled

List of usage examples for org.hibernate.stat Statistics setStatisticsEnabled

Introduction

In this page you can find the example usage for org.hibernate.stat Statistics setStatisticsEnabled.

Prototype

void setStatisticsEnabled(boolean b);

Source Link

Document

Enable statistics logs (this is a dynamic parameter)

Usage

From source file:com.abiquo.server.core.common.persistence.HibernateSessionAllocationChecker.java

License:Open Source License

public HibernateSessionAllocationChecker(EntityManagerFactory factory) {
    assert factory != null;

    this.factory = factory;

    EntityManager em = factory.createEntityManager();
    try {/*  ww w . j  a  v a  2 s .c  om*/
        Session session = (Session) em.getDelegate();
        Statistics statistics = session.getSessionFactory().getStatistics();
        this.statisticsEnabledOnEntry = statistics.isStatisticsEnabled();
        statistics.setStatisticsEnabled(true);
        this.outstandingSessionsOnEntry = statistics.getSessionOpenCount() - statistics.getSessionCloseCount();
        try {
            this.openMySqlConnectionsOnEntry = getMySqlConnectionCount(session.connection());
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    } finally {
        em.close();
    }
}

From source file:com.abiquo.server.core.common.persistence.HibernateSessionAllocationChecker.java

License:Open Source License

private void ensureResultObtained() {
    if (!resultObtained) {
        EntityManager em = factory.createEntityManager();
        try {/*from www .  j  a  v  a2s  .co  m*/
            Session session = (Session) em.getDelegate();
            Statistics statistics = session.getSessionFactory().getStatistics();

            assert statistics
                    .isStatisticsEnabled() : "Somebody else disabled the statistics: DON'T do, or do not use this component";

            long outstandingSessionsOnExit = statistics.getSessionOpenCount()
                    - statistics.getSessionCloseCount();
            this.sessionsNotReleasedAfterCreation = outstandingSessionsOnExit - this.outstandingSessionsOnEntry;

            assert sessionsNotReleasedAfterCreation >= 0 : "Somebody else played with the statistics (maybe cleared/disabled them?): DON'T do, or do not use this component";
            // System.err.println( "OUTSTANDING SESSIONS: " +
            // sessionsNotReleasedAfterCreation);

            try {
                this.mySqlConnectionsNoReleasedAfterCreation = getMySqlConnectionCount(session.connection())
                        - this.openMySqlConnectionsOnEntry;
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }

            // Reset statistics to the state they were before we started to
            // be interested in open/closed session count
            statistics.setStatisticsEnabled(this.statisticsEnabledOnEntry);
        } finally {
            em.close();
        }
        resultObtained = true;
    }

}

From source file:com.evolveum.midpoint.repo.sql.AddGetObjectTest.java

License:Apache License

@Test(enabled = false)
public <T extends ObjectType> void perfTest() throws Exception {
    Statistics stats = getFactory().getStatistics();
    stats.setStatisticsEnabled(true);

    final File OBJECTS_FILE = new File("./src/test/resources/10k-users.xml");
    List<PrismObject<? extends Objectable>> elements = prismContext.parseObjects(OBJECTS_FILE);

    long previousCycle = 0;
    long time = System.currentTimeMillis();
    for (int i = 0; i < elements.size(); i++) {
        if (i % 500 == 0) {
            LOGGER.info("Previous cycle time {}. Next cycle: {}",
                    new Object[] { (System.currentTimeMillis() - time - previousCycle), i });
            previousCycle = System.currentTimeMillis() - time;
        }//from  ww w  .  j  av  a 2  s .  co  m

        PrismObject<T> object = (PrismObject<T>) elements.get(i);
        repositoryService.addObject(object, null, new OperationResult("add performance test"));
    }
    LOGGER.info("Time to add objects ({}): {}",
            new Object[] { elements.size(), (System.currentTimeMillis() - time) });

    stats.logSummary();
}

From source file:com.openkm.servlet.admin.HibernateStatsServlet.java

License:Open Source License

/**
 * Activate stats// www . jav  a2  s.  c om
 */
private void activate(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    Statistics stats = HibernateUtil.getSessionFactory().getStatistics();

    if (!stats.isStatisticsEnabled()) {
        stats.setStatisticsEnabled(true);
    }
}

From source file:com.openkm.servlet.admin.HibernateStatsServlet.java

License:Open Source License

/**
 * Deactivate stats/*from   w  w w  . ja  v  a  2 s. com*/
 */
private void deactivate(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    Statistics stats = HibernateUtil.getSessionFactory().getStatistics();

    if (stats.isStatisticsEnabled()) {
        stats.setStatisticsEnabled(false);
    }
}

From source file:com.zutubi.pulse.master.xwork.actions.admin.debug.HibernateStatisticsAction.java

License:Apache License

public String toggle() throws Exception {
    Statistics stats = sessionFactory.getStatistics();
    stats.setStatisticsEnabled(!stats.isStatisticsEnabled());

    return "toggled";
}

From source file:dao.proyectoHelper.java

public static void reportConeciones() {
    Statistics stats = HibernateUtil.getSessionFactory().getStatistics();
    stats.setStatisticsEnabled(true);

    System.out.println("recuento de conexin: " + stats.getConnectCount());

    //Numero de transacciones completadas (falladas y satisfactorias)
    System.out.println("recuento Trx: " + stats.getTransactionCount());

    //Numero de transacciones completadas (solo satisfactorias)
    System.out.println("Succ trx count: " + stats.getSuccessfulTransactionCount());

    // Numero de sesiones que el codigo ha abierto
    System.out.println("sesiones abiertas: " + stats.getSessionOpenCount());

    // Numero de sesiones que el codigo ha cerrado
    System.out.println("sesiones  cerradas: " + stats.getSessionCloseCount());

    // Numero total de queries ejecutados
    System.out.println("No. queries: " + stats.getQueryExecutionCount());
    //            esta();
}

From source file:de.iew.framework.hibernate.statistics.StatisticsLogger.java

License:Apache License

public void logStatistics() {
    Statistics statistics = this.sessionFactory.getStatistics();
    statistics.setStatisticsEnabled(true);
    StringBuilder sb = new StringBuilder("\nStatistics");
    sb.append("\nCloseStatementCount: ").append(statistics.getCloseStatementCount());

    sb.append("\nEntityDeleteCount: ").append(statistics.getEntityDeleteCount());
    sb.append("\nEntityInsertCount: ").append(statistics.getEntityInsertCount());
    sb.append("\nEntityLoadCount: ").append(statistics.getEntityLoadCount());
    sb.append("\nEntityFetchCount: ").append(statistics.getEntityFetchCount());
    sb.append("\nEntityUpdateCount: ").append(statistics.getEntityUpdateCount());
    sb.append("\nQueryExecutionCount: ").append(statistics.getQueryExecutionCount());
    sb.append("\nQueryExecutionMaxTime: ").append(statistics.getQueryExecutionMaxTime());
    sb.append("\nQueryExecutionMaxTimeQueryString: ").append(statistics.getQueryExecutionMaxTimeQueryString());
    sb.append("\nQueryCacheHitCount: ").append(statistics.getQueryCacheHitCount());
    sb.append("\nQueryCacheMissCount: ").append(statistics.getQueryCacheMissCount());
    sb.append("\nQueryCachePutCount: ").append(statistics.getQueryCachePutCount());
    sb.append("\nNaturalIdQueryExecutionCount: ").append(statistics.getNaturalIdQueryExecutionCount());
    sb.append("\nNaturalIdQueryExecutionMaxTime: ").append(statistics.getNaturalIdQueryExecutionMaxTime());
    sb.append("\nNaturalIdQueryExecutionMaxTimeRegion: ")
            .append(statistics.getNaturalIdQueryExecutionMaxTimeRegion());
    sb.append("\nNaturalIdCacheHitCount: ").append(statistics.getNaturalIdCacheHitCount());
    sb.append("\nNaturalIdCacheMissCount: ").append(statistics.getNaturalIdCacheMissCount());
    sb.append("\nNaturalIdCachePutCount: ").append(statistics.getNaturalIdCachePutCount());
    sb.append("\nUpdateTimestampsCacheHitCount: ").append(statistics.getUpdateTimestampsCacheHitCount());
    sb.append("\nUpdateTimestampsCacheMissCount: ").append(statistics.getUpdateTimestampsCacheMissCount());
    sb.append("\nUpdateTimestampsCachePutCount: ").append(statistics.getUpdateTimestampsCachePutCount());
    sb.append("\nFlushCount: ").append(statistics.getFlushCount());
    sb.append("\nConnectCount: ").append(statistics.getConnectCount());
    sb.append("\nSecondLevelCacheHitCount: ").append(statistics.getSecondLevelCacheHitCount());
    sb.append("\nSecondLevelCacheMissCount: ").append(statistics.getSecondLevelCacheMissCount());
    sb.append("\nSecondLevelCachePutCount: ").append(statistics.getSecondLevelCachePutCount());
    sb.append("\nSessionCloseCount: ").append(statistics.getSessionCloseCount());
    sb.append("\nSessionOpenCount: ").append(statistics.getSessionOpenCount());
    sb.append("\nCollectionLoadCount: ").append(statistics.getCollectionLoadCount());
    sb.append("\nCollectionFetchCount: ").append(statistics.getCollectionFetchCount());
    sb.append("\nCollectionUpdateCount: ").append(statistics.getCollectionUpdateCount());
    sb.append("\nCollectionRemoveCount: ").append(statistics.getCollectionRemoveCount());
    sb.append("\nCollectionRecreateCount: ").append(statistics.getCollectionRecreateCount());
    sb.append("\nStartTime: ").append(statistics.getStartTime());
    sb.append("\nQueries: ").append(statistics.getQueries());
    sb.append("\nEntityNames: ").append(statistics.getEntityNames());
    sb.append("\nCollectionRoleNames: ").append(statistics.getCollectionRoleNames());
    sb.append("\nSecondLevelCacheRegionNames: ").append(statistics.getSecondLevelCacheRegionNames());
    sb.append("\nSuccessfulTransactionCount: ").append(statistics.getSuccessfulTransactionCount());
    sb.append("\nTransactionCount: ").append(statistics.getTransactionCount());
    sb.append("\nPrepareStatementCount: ").append(statistics.getPrepareStatementCount());
    sb.append("\nCloseStatementCount: ").append(statistics.getCloseStatementCount());
    sb.append("\nOptimisticFailureCount: ").append(statistics.getOptimisticFailureCount());

    if (log.isDebugEnabled()) {
        log.debug(sb);//from  w w w.ja  v a  2 s . c  om
    }

}

From source file:org.apache.karaf.jpa.hibernate.impl.StatisticsPublisher.java

License:Apache License

private void publishStatistics(ServiceReference<EntityManagerFactory> reference, EntityManagerFactory emf) {
    String persitenceProvider = (String) reference.getProperty("osgi.unit.provider");
    if (!"org.hibernate.ejb.HibernatePersistence".equals(persitenceProvider)) {
        return;//from  w  ww.j  a  v a 2  s . c  o m
    }
    if (reference.getProperty("org.apache.aries.jpa.proxy.factory") != null) {
        return;
    }
    try {
        EntityManager em = emf.createEntityManager();
        SessionFactory sessionFactory = em.unwrap(Session.class).getSessionFactory();
        final Statistics statistics = sessionFactory.getStatistics();
        statistics.setStatisticsEnabled(true);
        mbeanServer.registerMBean(getStatisticsMBean(statistics), getOName(reference));
    } catch (Exception e) {
        LOG.warn("Error publishing StatisticsMXBean" + e.getMessage(), e);
    }
}

From source file:org.beangle.ems.dev.hibernate.web.action.CacheAction.java

License:Open Source License

public String index() {
    Statistics statistics = sessionFactory.getStatistics();
    Date lastUpdate = new Date();
    Date activation = null;//from  w w w  . ja v  a  2 s . c o  m
    Date deactivation = null;

    List<Long> generalStatistics = CollectUtils.newArrayList(18);
    final String action = get("do");
    final StringBuilder info = new StringBuilder(512);

    if ("activate".equals(action) && !statistics.isStatisticsEnabled()) {
        statistics.setStatisticsEnabled(true);
        activation = new Date();
        getSession().put("hibernate.stat.activation", activation);
        getSession().remove("hibernate.stat.deactivation");
        info.append("Statistics enabled\n");
    } else if ("deactivate".equals(action) && statistics.isStatisticsEnabled()) {
        statistics.setStatisticsEnabled(false);
        deactivation = new Date();
        getSession().put("hibernate.stat.deactivation", deactivation);
        activation = (Date) getSession().get("hibernate.stat.activation");
        info.append("Statistics disabled\n");
    } else if ("clear".equals(action)) {
        activation = null;
        deactivation = null;
        statistics.clear();
        getSession().remove("hibernate.stat.activation");
        getSession().remove("hibernate.stat.deactivation");
        generalStatistics.clear();
        info.append("Statistics cleared\n");
    } else {
        activation = (Date) getSession().get("hibernate.stat.activation");
        deactivation = (Date) getSession().get("hibernate.stat.deactivation");
    }

    if (info.length() > 0)
        addMessage(info.toString());

    boolean active = statistics.isStatisticsEnabled();
    if (active) {
        generalStatistics.add(statistics.getConnectCount());
        generalStatistics.add(statistics.getFlushCount());

        generalStatistics.add(statistics.getPrepareStatementCount());
        generalStatistics.add(statistics.getCloseStatementCount());

        generalStatistics.add(statistics.getSessionCloseCount());
        generalStatistics.add(statistics.getSessionOpenCount());

        generalStatistics.add(statistics.getTransactionCount());
        generalStatistics.add(statistics.getSuccessfulTransactionCount());
        generalStatistics.add(statistics.getOptimisticFailureCount());
    }
    put("active", active);
    put("lastUpdate", lastUpdate);
    if (null != activation) {
        if (null != deactivation) {
            put("duration", deactivation.getTime() - activation.getTime());
        } else {
            put("duration", lastUpdate.getTime() - activation.getTime());
        }
    }
    put("activation", activation);
    put("deactivation", deactivation);
    put("generalStatistics", generalStatistics);
    return forward();
}