No description, website, or topics provided.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Java Mini Profiler

JMP is a mini-profiler for Java inspired by mvc-mini-profile (and Jeff Atwood's blog post).


Quick start

1. Add the following repo/dependencies to your maven pom -



2. Add to your web.xml the servlet and filter.


3. Add somewhere in your jsp.


4. Add some code to profile using the syntax below.

	Step step = MiniProfiler.step("Some things happening");
	// do some work	

5. Load your web-application and watch the profile in the top left corner as shown below.


SQL Profiling

This allows you to see how long your queries are taking and the actual query itself. This is implemented using a JDBC data-source proxy.

1. Include the following in your maven to include the sql dependency.


2. Configure the original dataSource so it is wrapped by Example shown below.

	<jee:jndi-lookup id="dataSourceActual" jndi-name="java:comp/env/jdbc/dataSource" />

   	<bean id="dataSourceProxy" class="">
    	<constructor-arg ref="dataSourceActual" />
	<bean id="dataSource" class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy">
        <property name="targetDataSource">
            <ref bean="dataSourceProxy" />

JSP Profiling

It is often beneficial to profile around jsp statements. A good example is when you are using Spring's Open Session In View (OSIV) pattern.

1. Include the following taglib in your JSP.

	<%@ taglib prefix="profiler" uri="" %>

2. Use the jmp tag to profile around bits of JSP code.

<profiler:jmp description="Profiling some jsp code">

jsp stuff here...


AOP Public Method Profiling

The real power of JMP comes alive with the use of aspect oriented programming. To enable AOP profiling ensure aop is enabled.

There are two options available.

1. The first options is to profile around all public methods of your project - this is the most powerful option and gives the most benefit.

To use it - create an aspect class in your project - an example is shown below.

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;


public class JMPFullAspect {

	@Pointcut(value="execution(public * *(..))")
	public void anyPublicMethod() {
    private void inYourPackage() {}
	@Around("anyPublicMethod() && inYourPackage()")
	public Object profile(ProceedingJoinPoint pjp) throws Throwable {
		String desc = pjp.getSignature().toShortString();
		if (desc.endsWith("()")) {
			desc = desc.substring(0, desc.length()-2);
		} else if (desc.endsWith("(..)")) {
			desc = desc.substring(0, desc.length()-4);
		String packageName = pjp.getSignature().toLongString().split(" ")[2];
		String tag = null;
		// optional tag for roll-up of timings e.g. around dao layer
		if (packageName.startsWith("your.package.dao")) {
			tag = "DAO Layer";
		try (Step step = MiniProfiler.step(desc, tag);) {			
			return pjp.proceed();

You also need to enable AOP if not already enabled.

	<aop:aspectj-autoproxy proxy-target-class="true"/>

2. Another option is to use the @Profiler annotation - simply annotate your method as below.

	public void yourMethod() {
		// do some things

You also need to enable this aspect by including a spring context in your web.xml.

			...other contexts


  • If not using jsp/jstl - the 'mini_profile_includes' attribute is set on request object via setAttribute)
  • jQuery is required to be loaded before including '${mini_profile_includes}' in your JSP.