Grails Events and Profiling
I had to debug an issue today where my integration tests were bleeding into my functional tests by way of the database. After some fiddling and googling I ran into this, setting-grails-functional-test-database. Which left me curious about what other events were available to listen for in _Events.groovy. So I ran git grep 'event(' in grails-core. There did not seem to be many events of interest to catch, but I did notice some similar code calling;
profile(name) { /* block of code */ }Which I thought was interesting and so I went searching for how to enable that, and low and behold, adding
-Dgrails.script.profile=true to a grails command will spit out a host of profiling information, particularly about startup. It also does a nice job of painting what the overall load order of your application is, possibly even clearer then setting debug 'grails' in Config.groovy.
Just as a rough reference I decided to see if I could shell out a unique list of valid events. It’s funny how unix grows on you, I had never used a columns command before, but it seemed likely so I tried col<tab> and sure enough both column and columns existed.
$ git grep 'event(' |\
ruby -pe '$_.sub!(/.+event\(.(\w+).+/){$1.sub(/Start|End/,"*")}' |\
sort -u | egrep -v 'ventName|A' | column -c 72
ConfigureTomcat PackagePlugin* TestCase*
CreatedFile Packaging* TestCompile*
CreateWar* PluginLoad* TestFailure
Doc* PluginUninstalled TestPhase*
DocSkip SetClasspath TestPhases*
Exiting Stats* TestProduceReports
GenerateController* StatusError TestSuite*
GenerateViews* StatusFinal WebXml*
InstallPlugin* StatusUpdate
IntegrateWithInit Test*
Note that this is only the list of events directly specified by a string at the point of call for event. I also made the list shorter by appending * to any event that had both a Start or End version.
