Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
output every grails event with timing
diff --git a/scripts/_GrailsEvents.groovy b/scripts/_GrailsEvents.groovy
index bc0b479..bb8f13e 100644
--- a/scripts/_GrailsEvents.groovy
+++ b/scripts/_GrailsEvents.groovy
@@ -49,13 +49,19 @@ binding.addBuildListener(eventListener)
// Set up the classpath for the event hooks.
classpath()
// Now load them.
eventListener.classLoader = new GroovyClassLoader(classLoader)
eventListener.initialize()
+long eventInitStart = new Date().time
+
// Send a scripting event notification to any and all event hooks in plugins/user scripts
event = {String name, args ->
try {
+ grailsConsole.addStatus "#### (${new Date().time - eventInitStart}) $name $args"
+ grailsConsole.lastMessage = ""
eventListener.triggerEvent(name, * args)
}
catch(e) {
@tednaleid

This comment has been minimized.

Copy link
Owner Author

commented Aug 28, 2012

ex output:

| #### (2) SetClasspath [java.net.URLClassLoader@799dbc3b]
| Compiling 1 source files.
| #### (3857) TestPhasesStart [[unit, integration, functional, other]]
| #### (3893) TestPhaseStart [unit]
| #### (3893) TestCompileStart [org.codehaus.groovy.grails.test.junit4.JUnit4GrailsTestType@33c26386]
| #### (3941) TestCompileEnd [org.codehaus.groovy.grails.test.junit4.JUnit4GrailsTestType@33c26386]
| #### (4480) TestSuiteStart [unit]
| #### (4992) TestCaseStart [com.entagen.triplemap.domain.UserRoleTest]
| #### (5034) TestStart [testEquals]
| #### (6368) TestEnd [testEquals]
| #### (6368) TestStart [testEquals_differentUser]
| #### (6479) TestEnd [testEquals_differentUser]
| #### (6479) TestStart [testEquals_differentRole]
| #### (6609) TestEnd [testEquals_differentRole]
....
| #### (67607) TestPhaseEnd [integration]
| #### (67608) TestPhaseStart [other]
| #### (67609) TestPhaseEnd [other]
| #### (67609) TestProduceReports []
| Tests PASSED - view reports in target/test-reports
| #### (68087) TestPhasesEnd []
@burtbeckwith

This comment has been minimized.

Copy link

commented Aug 28, 2012

Cool stuff. One nit - new Date().time == System.currentTimeMillis(), no need to instantiate and toss a Date

@tednaleid

This comment has been minimized.

Copy link
Owner Author

commented Aug 28, 2012

@burtbeckwith pull requests/forks accepted :)

@burtbeckwith

This comment has been minimized.

Copy link

commented Aug 28, 2012

That's ok, it's correct here: grails/grails-core@22dbc51 :)

@tednaleid

This comment has been minimized.

Copy link
Owner Author

commented Aug 29, 2012

Sweet! I've actually found this info really helpful/interesting, thanks for adding it into grails core.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.