Last active
December 16, 2015 20:10
-
-
Save ishults/10560085 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static final String START_TIME = 'Hibernate_Start_Time' | |
def sessionFactory | |
// ... | |
logHibernateStats(controller: '*', action: '*') { | |
before = { | |
String enabledString = grailsApplication.config.logHibernateStats | |
Statistics stats = sessionFactory.statistics | |
if (enabledString == 'ALWAYS' || (enabledString == 'ALLOWED' && params.logHibernateStats)) { | |
log.info "\n### In action: $controllerName/$actionName ###" | |
if (!stats.statisticsEnabled) { | |
stats.statisticsEnabled = true | |
} | |
request[START_TIME] = System.currentTimeMillis() | |
} else if (enabledString == 'ALLOWED' && stats.statisticsEnabled) { | |
stats.statisticsEnabled = false // We assume no one else is using stats | |
} | |
} | |
afterView = { | |
String enabledString = grailsApplication.config.logHibernateStats | |
if (enabledString == 'ALWAYS' || (enabledString == 'ALLOWED' && params.logHibernateStats)) { | |
Long end = System.currentTimeMillis() | |
Long start = request[START_TIME] | |
Statistics stats = sessionFactory.statistics | |
log.info """ | |
############## Hibernate Stats ############## | |
Action: /${controllerName}/${actionName} | |
Transaction Count: ${stats.transactionCount} | |
Flush Count: ${stats.flushCount} | |
Prepared Statement Count: ${stats.prepareStatementCount} | |
Total time: ${end - start} ms | |
############################################# | |
""" | |
stats.clear() // We assume no one else is using stats | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment