Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

103 lines (76 sloc) 3.856 kb

Profiler Plugin

Build Status

Investigating the performance of an application is an important step in improving its usability. The Profiler Plugin makes it easy to collect timing information for several aspects of an application:

  • Requests
  • Controller actions
  • Service methods
  • View generation

Installation

grails install-plugin profiler

How to use it

Once the plugin is installed, all you need to do to profile a request is add the "profiler=on" or "profiler=1" parameter to it. For example, to profile a simple GET request:

http://localhost:8080/myapp/book/list?profiler=1

You may not see any profiling information yet because it depends on your Log4J configuration. All profiling information is logged at the INFO level to the "com.linkedin.grails.ProfilerPlugin" logger, so this simple configuration will have the profiling messages appear in your console:

log4j {
    ...
    logger {
        ...
        com.linkedin.grails = "info"
    }
    ...
}

It is also possible to place the profiling information in your HTML pages by using this GSP tag:

<g:profilerOutput />

This will simply write out the profiling information collected so far for the current request. For best results it should be included in the layout inside an HTML comment. If you use it directly within a view, the profiling information will lack the timing for the view generation itself.

For more information, go to the plugin portal page.

Disabling the profiler

You can set a configuration option to completely disable the plugin:

grails.profiler.disable = true

This is particularly useful on a per-environment basis, in case you don't want the impact of profiling in production or even development.

Advanced usage

The plugin is designed around a set of Spring beans that can be used directly from within your code if you require. The most useful beans are documented here with their bean names.

profilerCondition

This bean implements the com.linkedin.grails.profiler.ProfilerCondition interface and determines whether profiling is active for the current request or not. The default implementation checks the "profiler" parameter, but you can provide your own implementation in resource.groovy for example.

Method Description
doProfiling() Returns true if profiling should be enabled for the current request, otherwise false.

profilerLog

This is the main bean. It sends log messages to all registered appenders while profiling is active. Otherwise it does nothing.

Method Description
startProfiling(String) Starts the profiler and assigns the given label to the log messages.
stopProfiling() Stops the profiler.
isProfiling() Returns true if the profiler is currently active, otherwise false.
logEntry(Class, String) Logs entry to an action/method/whatever.
logExit(Class, String) Logs exit from an action/method/whatever. There should be one call to logExit() for every logEntry().

bufferedAppender

A special appender that stores its log messages in a buffer so that it can be retrieved from code. Inject the bean into your own and get the output whenever you like!

Method Description
getOutput() Returns the log output currently stored in this appender's buffer.
Jump to Line
Something went wrong with that request. Please try again.