2 Minutes To Code (β Version)

Simon - 2 minute tutorial

How to profile multiple events/method calls for statistically relevant data

The previous example introduces you to Simon apis by recording a single event.

However, practically you would use Simon to record thousands and millions of events for profiling the application as shown in the example below where the api/even doVitalTask() is called a thousand times and then the statistics collected are read from Simon.
package com.techfundaes.simonBag;

import org.javasimon.SimonManager;
import org.javasimon.Split;
import org.javasimon.Stopwatch;
import org.javasimon.StopwatchSample;

public class SimonUseReal
{
	public static void main(String[] args)
	{
		Stopwatch stopwatch = SimonManager.getStopwatch("use.real");
		
		Split split = null;
		for(int i = 0; i < 1000; i++)
		{
			split = stopwatch.start();
			doVitalTask();
			split.stop();
		}
		
		System.out.println(stopwatch.getCounter());
		System.out.println(stopwatch.getMax()/1000/1000);
		System.out.println(stopwatch.getMin()/1000/1000);
		System.out.printf("%.2f%n", stopwatch.getMean()/1000/1000);
		System.out.println(stopwatch.getTotal()/1000/1000);
	}

	private static void doVitalTask()
	{
		try
		{
			Thread.sleep(100);
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}
	
	
}