Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit b38e746b408c87cc7884d7fc4f33c0bdc9e46909 @tomdcc committed Dec 14, 2012
Showing with 21,029 additions and 0 deletions.
  1. +6 −0 .gitignore
  2. +143 −0 MiniprofilerGrailsPlugin.groovy
  3. +6 −0 application.properties
  4. +37 −0 grails-app/conf/BuildConfig.groovy
  5. +24 −0 grails-app/conf/Config.groovy
  6. +32 −0 grails-app/conf/DataSource.groovy
  7. +19 −0 grails-app/conf/MiniprofilerUrlMappings.groovy
  8. +13 −0 grails-app/conf/UrlMappings.groovy
  9. +21 −0 grails-app/controllers/com/energizedwork/miniprofiler/ProfilerDataController.groovy
  10. +41 −0 grails-app/taglib/MiniProfilerTagLib.groovy
  11. +54 −0 grails-app/views/error.gsp
  12. BIN lib/log4jdbc4-1.2.jar
  13. +10 −0 scripts/_Install.groovy
  14. +5 −0 scripts/_Uninstall.groovy
  15. +10 −0 scripts/_Upgrade.groovy
  16. +142 −0 src/groovy/com/energizedwork/miniprofiler/MiniProfiler.groovy
  17. +66 −0 src/groovy/com/energizedwork/miniprofiler/MiniProfilerAppender.groovy
  18. +5 −0 src/groovy/com/energizedwork/miniprofiler/ProfileLevel.groovy
  19. +20 −0 src/groovy/com/energizedwork/miniprofiler/ProfilerProvider.groovy
  20. +91 −0 src/groovy/com/energizedwork/miniprofiler/ServletRequestProfilerProvider.groovy
  21. +55 −0 src/groovy/com/energizedwork/miniprofiler/SqlTiming.groovy
  22. +102 −0 src/groovy/com/energizedwork/miniprofiler/Timing.groovy
  23. +45 −0 src/java/com/energizedwork/miniprofiler/MiniProfilerFilter.java
  24. +13 −0 src/java/com/energizedwork/miniprofiler/MiniprofilerCondition.java
  25. +48 −0 src/java/com/energizedwork/miniprofiler/NullSpyLogDelegator.java
  26. +15 −0 src/java/com/energizedwork/miniprofiler/ProfilingDataSource.java
  27. +29 −0 src/java/com/energizedwork/miniprofiler/ProfilingDecorator.java
  28. +22 −0 src/java/com/energizedwork/miniprofiler/ProfilingGrailsDecoratorSelector.java
  29. +26 −0 src/java/com/energizedwork/miniprofiler/ProfilingGrailsPageFilter.java
  30. +22 −0 src/java/com/energizedwork/miniprofiler/ProfilingGrailsViewResolver.java
  31. +33 −0 src/java/com/energizedwork/miniprofiler/ProfilingGroovyPagesServlet.java
  32. +57 −0 src/java/com/energizedwork/miniprofiler/ProfilingSpyLogDelegator.java
  33. +20 −0 src/java/com/energizedwork/miniprofiler/ProfilingView.java
  34. +8 −0 test/projects/test13/application.properties
  35. +7 −0 test/projects/test13/grails-app/conf/BootStrap.groovy
  36. +38 −0 test/projects/test13/grails-app/conf/BuildConfig.groovy
  37. +90 −0 test/projects/test13/grails-app/conf/Config.groovy
  38. +32 −0 test/projects/test13/grails-app/conf/DataSource.groovy
  39. +13 −0 test/projects/test13/grails-app/conf/UrlMappings.groovy
  40. +3 −0 test/projects/test13/grails-app/conf/spring/resources.groovy
  41. +7 −0 test/projects/test13/grails-app/controllers/test13/BookController.groovy
  42. +11 −0 test/projects/test13/grails-app/domain/test13/Book.groovy
  43. +55 −0 test/projects/test13/grails-app/i18n/messages.properties
  44. +56 −0 test/projects/test13/grails-app/i18n/messages_da.properties
  45. +55 −0 test/projects/test13/grails-app/i18n/messages_de.properties
  46. +30 −0 test/projects/test13/grails-app/i18n/messages_es.properties
  47. +19 −0 test/projects/test13/grails-app/i18n/messages_fr.properties
  48. +19 −0 test/projects/test13/grails-app/i18n/messages_it.properties
  49. +19 −0 test/projects/test13/grails-app/i18n/messages_ja.properties
  50. +55 −0 test/projects/test13/grails-app/i18n/messages_nl.properties
  51. +34 −0 test/projects/test13/grails-app/i18n/messages_pt_BR.properties
  52. +34 −0 test/projects/test13/grails-app/i18n/messages_pt_PT.properties
  53. +31 −0 test/projects/test13/grails-app/i18n/messages_ru.properties
  54. +35 −0 test/projects/test13/grails-app/i18n/messages_th.properties
  55. +18 −0 test/projects/test13/grails-app/i18n/messages_zh_CN.properties
  56. +54 −0 test/projects/test13/grails-app/views/error.gsp
  57. +100 −0 test/projects/test13/grails-app/views/index.gsp
  58. +18 −0 test/projects/test13/grails-app/views/layouts/main.gsp
  59. +17 −0 test/projects/test13/test/unit/test13/BookControllerTests.groovy
  60. +17 −0 test/projects/test13/test/unit/test13/BookTests.groovy
  61. +42 −0 test/projects/test13/web-app/WEB-INF/applicationContext.xml
  62. +14 −0 test/projects/test13/web-app/WEB-INF/sitemesh.xml
  63. +563 −0 test/projects/test13/web-app/WEB-INF/tld/c.tld
  64. +671 −0 test/projects/test13/web-app/WEB-INF/tld/fmt.tld
  65. +550 −0 test/projects/test13/web-app/WEB-INF/tld/grails.tld
  66. +311 −0 test/projects/test13/web-app/WEB-INF/tld/spring.tld
  67. +273 −0 test/projects/test13/web-app/css/main.css
  68. BIN test/projects/test13/web-app/images/favicon.ico
  69. BIN test/projects/test13/web-app/images/grails_logo.jpg
  70. BIN test/projects/test13/web-app/images/grails_logo.png
  71. BIN test/projects/test13/web-app/images/leftnav_btm.png
  72. BIN test/projects/test13/web-app/images/leftnav_midstretch.png
  73. BIN test/projects/test13/web-app/images/leftnav_top.png
  74. BIN test/projects/test13/web-app/images/skin/database_add.png
  75. BIN test/projects/test13/web-app/images/skin/database_delete.png
  76. BIN test/projects/test13/web-app/images/skin/database_edit.png
  77. BIN test/projects/test13/web-app/images/skin/database_save.png
  78. BIN test/projects/test13/web-app/images/skin/database_table.png
  79. BIN test/projects/test13/web-app/images/skin/exclamation.png
  80. BIN test/projects/test13/web-app/images/skin/house.png
  81. BIN test/projects/test13/web-app/images/skin/information.png
  82. BIN test/projects/test13/web-app/images/skin/shadow.jpg
  83. BIN test/projects/test13/web-app/images/skin/sorted_asc.gif
  84. BIN test/projects/test13/web-app/images/skin/sorted_desc.gif
  85. BIN test/projects/test13/web-app/images/spinner.gif
  86. BIN test/projects/test13/web-app/images/springsource.png
  87. +13 −0 test/projects/test13/web-app/js/application.js
  88. +42 −0 web-app/WEB-INF/applicationContext.xml
  89. +14 −0 web-app/WEB-INF/sitemesh.xml
  90. +563 −0 web-app/WEB-INF/tld/c.tld
  91. +671 −0 web-app/WEB-INF/tld/fmt.tld
  92. +550 −0 web-app/WEB-INF/tld/grails.tld
  93. +311 −0 web-app/WEB-INF/tld/spring.tld
  94. +426 −0 web-app/js/MiniProfilerHandler.cs
  95. +1 −0 web-app/js/include.partial.html
  96. +1 −0 web-app/js/includes.css
  97. +897 −0 web-app/js/includes.js
  98. +468 −0 web-app/js/includes.less
  99. +219 −0 web-app/js/includes.tmpl
  100. +4 −0 web-app/js/jquery.1.7.1.js
  101. +486 −0 web-app/js/jquery.tmpl.js
  102. +9 −0 web-app/js/list.css
  103. +38 −0 web-app/js/list.js
  104. +34 −0 web-app/js/list.tmpl
  105. +7 −0 web-app/js/prototype/animation.js
  106. +136 −0 web-app/js/prototype/builder.js
  107. +965 −0 web-app/js/prototype/controls.js
  108. +974 −0 web-app/js/prototype/dragdrop.js
  109. +1,123 −0 web-app/js/prototype/effects.js
  110. +4,874 −0 web-app/js/prototype/prototype.js
  111. +2,691 −0 web-app/js/prototype/rico.js
  112. +68 −0 web-app/js/prototype/scriptaculous.js
  113. +275 −0 web-app/js/prototype/slider.js
  114. +59 −0 web-app/js/prototype/sound.js
  115. +568 −0 web-app/js/prototype/unittest.js
  116. +11 −0 web-app/js/share.html
@@ -0,0 +1,6 @@
+.classpath
+.project
+.settings/
+*.iml
+.idea/
+target/
@@ -0,0 +1,143 @@
+import com.energizedwork.miniprofiler.MiniProfilerAppender
+import com.energizedwork.miniprofiler.MiniProfilerFilter
+import com.energizedwork.miniprofiler.MiniprofilerCondition
+import com.energizedwork.miniprofiler.NullSpyLogDelegator
+import com.energizedwork.miniprofiler.ProfilerProvider
+import com.energizedwork.miniprofiler.ProfilingDataSource
+import com.energizedwork.miniprofiler.ProfilingGrailsViewResolver
+import com.energizedwork.miniprofiler.ProfilingSpyLogDelegator
+import com.energizedwork.miniprofiler.ServletRequestProfilerProvider
+import net.sf.ehcache.store.MemoryStoreEvictionPolicy
+import net.sf.log4jdbc.SpyLogFactory
+import org.codehaus.groovy.grails.commons.spring.BeanConfiguration
+import org.springframework.cache.ehcache.EhCacheFactoryBean
+
+import java.lang.reflect.Field
+import java.lang.reflect.Modifier
+
+class MiniprofilerGrailsPlugin {
+ def version = "0.1"
+ def grailsVersion = "1.3.9 > *"
+ def dependsOn = [:]
+ def pluginExcludes = [
+ "grails-app/views/error.gsp"
+ ]
+
+ def loadAfter = ['profiler'] // as we want to modify a couple of things that it creates
+
+ def author = "Tom Dunstan"
+ def authorEmail = "grails@tomd.cc"
+ def title = "Mini Profiler plugin for grails"
+ def description = '''\\
+Shows timing and sql query information in a head-up display in a grails web page, useful for debugging
+database and other performance problems.
+'''
+
+ // URL to the plugin's documentation
+ def documentation = "http://grails.org/plugin/miniprofiler"
+ def scm = [url: 'https://github.com/tomdcc/grails-miniprofiler']
+
+
+ // place right on the outside
+ def getWebXmlFilterOrder() {
+ def FilterManager = getClass().getClassLoader().loadClass('grails.plugin.webxml.FilterManager')
+ [miniProfilerFilter: FilterManager.GRAILS_WEB_REQUEST_POSITION + 1]
+ }
+
+ def doWithWebDescriptor = { webXml ->
+ if (isProfilingDisabled(application)) return
+
+ // Add the profiler filter to the web app.
+ def filterDef = webXml.'filter'
+ filterDef[filterDef.size() - 1] + {
+ 'filter' {
+ 'filter-name'('miniProfilerFilter')
+ 'filter-class'(MiniProfilerFilter.name)
+ }
+ }
+
+ // This filter should come before the standard profiler filter, otherwise we'll miss some events
+ def filterMapping = webXml.'filter-mapping'.find { it.'filter-name'.text() == "charEncodingFilter" }
+ filterMapping + {
+ 'filter-mapping' {
+ 'filter-name'("miniProfilerFilter")
+ 'url-pattern'("/*")
+ }
+ }
+
+ // now the fun part - override the grails page filter with one which profiles layout rendering
+ def pageFilterMapping = webXml.'filter'.find { it.'filter-name'.text() == 'sitemesh' }
+ pageFilterMapping.'filter-class'[0] = 'com.energizedwork.miniprofiler.ProfilingGrailsPageFilter'
+
+ // and override the gsp servlet so we can see specific gsp timings
+ def gspServlet = webXml.'servlet'.find { it.'servlet-name'.text() == 'gsp' }
+ gspServlet.'servlet-class'[0] = 'com.energizedwork.miniprofiler.ProfilingGroovyPagesServlet'
+ }
+
+ private boolean isProfilingDisabled(application) {
+ application.config.grails?.profiler?.disable as boolean
+ }
+
+ def doWithSpring = {
+ if (isProfilingDisabled(application)) return
+
+ // make log4jdbc not spam the logs while we're starting up and don't have the real log catcher ready yet
+ setuplLog4JdbcLogger(null)
+
+ // just switch profiling on for all requests by default
+ profilerCondition(MiniprofilerCondition)
+
+ // replace data source with our proxying one
+ BeanConfiguration dataSourceConfig = springConfig.getBeanConfig('dataSource')
+ springConfig.addBeanConfiguration("dataSourceOriginal", dataSourceConfig)
+
+ dataSource(ProfilingDataSource) {
+ targetDataSource = dataSourceOriginal
+ }
+
+ profilingCache(EhCacheFactoryBean) {
+ cacheName = 'miniprofilerCache'
+ maxElementsInMemory = 1000
+ maxElementsOnDisk = 0
+ memoryStoreEvictionPolicy = MemoryStoreEvictionPolicy.LRU
+ overflowToDisk = false
+ eternal = false
+ timeToLive = 3600
+ }
+
+ profilerProvider(ServletRequestProfilerProvider) {
+ cache = profilingCache
+ }
+
+ miniProfilerAppender(MiniProfilerAppender) {
+ profilerProvider = profilerProvider
+ }
+
+ BeanConfiguration viewResolverConfig = springConfig.getBeanConfig('jspViewResolver')
+ springConfig.addBeanConfiguration("jspViewResolverOriginal", viewResolverConfig)
+
+ jspViewResolver(ProfilingGrailsViewResolver) {
+ wrapped = jspViewResolverOriginal
+ }
+
+ }
+
+ private void setuplLog4JdbcLogger(ProfilerProvider profilerProvider) {
+ // work around hardcoded delegator in log4jdbc, this probably won't work if you're running under
+ // a SecurityManager
+ Field field = SpyLogFactory.getDeclaredField('logger')
+ field.setAccessible(true);
+ Field modifiersField = Field.class.getDeclaredField("modifiers");
+ modifiersField.setAccessible(true);
+ modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
+ field.set(null, profilerProvider ? new ProfilingSpyLogDelegator(profilerProvider) : new NullSpyLogDelegator())
+
+ }
+
+ def doWithApplicationContext = { applicationContext ->
+ setuplLog4JdbcLogger(applicationContext.profilerProvider)
+ // only send profiler data to miniprofiler, don't log to file etc
+ applicationContext.profilerLog.appenderNames = ['miniProfilerAppender']
+ }
+
+}
@@ -0,0 +1,6 @@
+#Grails Metadata file
+#Mon Dec 10 09:18:40 GMT 2012
+app.grails.version=1.3.9
+app.name=miniprofiler
+plugins.hibernate=1.3.9
+plugins.tomcat=1.3.9
@@ -0,0 +1,37 @@
+grails.project.class.dir = "target/classes"
+grails.project.test.class.dir = "target/test-classes"
+grails.project.test.reports.dir = "target/test-reports"
+//grails.project.war.file = "target/${appName}-${appVersion}.war"
+
+//plugin.location.profiler = "../grails-profiler-clean"
+
+grails.project.dependency.resolution = {
+ // inherit Grails' default dependencies
+ inherits("global") {
+ // uncomment to disable ehcache
+ // excludes 'ehcache'
+ }
+ log "warn" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
+ repositories {
+ grailsPlugins()
+ grailsHome()
+ grailsCentral()
+
+ // uncomment the below to enable remote dependency resolution
+ // from public Maven repositories
+ //mavenLocal()
+ //mavenCentral()
+ //mavenRepo "http://snapshots.repository.codehaus.org"
+ //mavenRepo "http://repository.codehaus.org"
+ //mavenRepo "http://download.java.net/maven/2/"
+ //mavenRepo "http://repository.jboss.com/maven2/"
+ }
+ dependencies {
+ // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
+
+ // runtime 'mysql:mysql-connector-java:5.1.13'
+ }
+ plugins {
+ compile ':profiler:0.4'
+ }
+}
@@ -0,0 +1,24 @@
+// configuration for plugin testing - will not be included in the plugin zip
+
+log4j = {
+ // Example of changing the log pattern for the default console
+ // appender:
+ //
+ //appenders {
+ // console name:'stdout', layout:pattern(conversionPattern: '%c{2} %m%n')
+ //}
+
+ error 'org.codehaus.groovy.grails.web.servlet', // controllers
+ 'org.codehaus.groovy.grails.web.pages', // GSP
+ 'org.codehaus.groovy.grails.web.sitemesh', // layouts
+ 'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping
+ 'org.codehaus.groovy.grails.web.mapping', // URL mapping
+ 'org.codehaus.groovy.grails.commons', // core / classloading
+ 'org.codehaus.groovy.grails.plugins', // plugins
+ 'org.codehaus.groovy.grails.orm.hibernate', // hibernate integration
+ 'org.springframework',
+ 'org.hibernate',
+ 'net.sf.ehcache.hibernate'
+
+ warn 'org.mortbay.log'
+}
@@ -0,0 +1,32 @@
+dataSource {
+ pooled = true
+ driverClassName = "org.hsqldb.jdbcDriver"
+ username = "sa"
+ password = ""
+}
+hibernate {
+ cache.use_second_level_cache = true
+ cache.use_query_cache = true
+ cache.provider_class = 'net.sf.ehcache.hibernate.EhCacheProvider'
+}
+// environment specific settings
+environments {
+ development {
+ dataSource {
+ dbCreate = "create-drop" // one of 'create', 'create-drop','update'
+ url = "jdbc:hsqldb:mem:devDB"
+ }
+ }
+ test {
+ dataSource {
+ dbCreate = "update"
+ url = "jdbc:hsqldb:mem:testDb"
+ }
+ }
+ production {
+ dataSource {
+ dbCreate = "update"
+ url = "jdbc:hsqldb:file:prodDb;shutdown=true"
+ }
+ }
+}
@@ -0,0 +1,19 @@
+import org.codehaus.groovy.grails.commons.ApplicationHolder
+import org.codehaus.groovy.grails.commons.GrailsApplication
+
+class MiniprofilerUrlMappings {
+ static mappings = { args ->
+ GrailsApplication app = ApplicationHolder.application
+ def disableProfiling = app.config.grails.profiler.disable
+ if (disableProfiling) {
+ return
+ }
+
+ "/plugins/$plugin/js/$action"(controller: "profilerData") {
+ constraints {
+ plugin(matches:/miniprofiler-.*/)
+ }
+ }
+
+ }
+}
@@ -0,0 +1,13 @@
+class UrlMappings {
+
+ static mappings = {
+ "/$controller/$action?/$id?"{
+ constraints {
+ // apply constraints here
+ }
+ }
+
+ "/"(view:"/index")
+ "500"(view:'/error')
+ }
+}
@@ -0,0 +1,21 @@
+package com.energizedwork.miniprofiler
+
+import grails.converters.JSON
+import net.sf.ehcache.Element
+
+import javax.servlet.http.HttpServletResponse
+
+class ProfilerDataController {
+
+ def profilingCache
+
+ def results = {
+ // TODO: refactor cache specific code into storage abstraction ala c# miniprofiler
+ Element profilerElement = profilingCache.get(params.id)
+ if(!profilerElement || profilerElement.expired) {
+ response.sendError(HttpServletResponse.SC_NOT_FOUND)
+ }
+ def profiler = profilerElement.value
+ render (profiler.toJSON() as JSON)
+ }
+}
@@ -0,0 +1,41 @@
+import com.energizedwork.miniprofiler.MiniProfiler
+
+class MiniProfilerTagLib {
+
+ static namespace = "miniprofiler"
+
+ def bufferedAppender
+ def grailsApplication
+ def pluginManager
+ def profilerProvider
+
+ def javascript = { attrs ->
+ MiniProfiler profiler = profilerProvider.current
+ if (!profiler) return
+
+ def path = g.resource(dir: 'js', plugin: 'miniprofiler') + '/'
+ def plugin = pluginManager.getGrailsPlugin('miniprofiler')
+ def version = plugin.version
+// ids = ids.ToJson(),
+ def ids = profiler.id
+// position = (position ?? MiniProfiler.Settings.PopupRenderPosition).ToString().ToLower(),
+ def position = "left"
+// showTrivial = showTrivial ?? MiniProfiler.Settings.PopupShowTrivial ? "true" : "false",
+ def showTrivial = true
+// showChildren = showTimeWithChildren ?? MiniProfiler.Settings.PopupShowTimeWithChildren ? "true" : "false",
+ def showChildren = false
+// maxTracesToShow = maxTracesToShow ?? MiniProfiler.Settings.PopupMaxTracesToShow,
+ def maxTracesToShow = 15
+// showControls = showControls ?? MiniProfiler.Settings.ShowControls ? "true" : "false",
+ def showControls = false
+// currentId = profiler.Id,
+ def currentId = profiler.id
+// authorized = authorized ? "true" : "false",
+ def authorized = true
+// useExistingjQuery = useExistingjQuery ?? MiniProfiler.Settings.UseExistingjQuery ? "true" : "false"
+ def useExistingjQuery = false
+
+ out << """<script async type="text/javascript" id="mini-profiler" src="${path}includes.js?v=${version}" data-version="${version}" data-path="${path}" data-current-id="${currentId}" data-ids="${ids}" data-position="${position}" data-trivial="${showTrivial}" data-children="${showChildren}" data-max-traces="${maxTracesToShow}" data-controls="${showControls}" data-authorized="${authorized}"></script>"""
+
+ }
+}
Oops, something went wrong.

0 comments on commit b38e746

Please sign in to comment.