Tuesday, November 24, 2015

JAMon - nice and simple java monitor for measuring code performance in Java

General information

Official site: http://jamonapi.sourceforge.net/
A SourceForge project

Maven dependency

Place in pom.xml:
    <dependencies>
        <dependency>
            <groupId>com.jamonapi</groupId>
            <artifactId>jamon</artifactId>
            <version>2.81</version>
        </dependency>
    </dependencies>

Example 1

Code:

import com.jamonapi.*;


public class MonitorTest {
    public static void main(String[] args) throws Exception {
        Monitor mon=null;
        for (int i=1; i<=10; i++) {
            mon = MonitorFactory.start("myFirstMonitor");
            Thread.sleep(100+i);
            mon.stop();
        }
        System.out.println(mon);  // toString() method called
    }
}
Output:

Example 2

Code:
import com.jamonapi.*;

public class Main {

    protected static void monitorSomething() throws InterruptedException{
        Monitor mon=null;
        for (int i=1; i<=10; i++) {
            mon = MonitorFactory.start("myFirstMonitor");
            Thread.sleep(100+i);
            mon.stop();
        }
        MonitorFactory.start("mySecondMonitor")
                      .stop();
       
    }
   
    protected static void printPerformanceMeasurements(){
        for( Object monitor: MonitorFactory.getMap().values() ){
            System.out.println( monitor ); 
        }
    }
   
    public static void main(String[] args) throws InterruptedException {
        monitorSomething();
        printPerformanceMeasurements();
    }
}

Output:
 JAMon Label=myFirstMonitor, Units=ms.: (LastValue=110.0, Hits=10.0, Avg=105.5, Total=1055.0, Min=101.0, Max=110.0, Active=0.0, Avg Active=1.0, Max Active=1.0, First Access=Wed Nov 25 10:31:21 EET 2015, Last Access=Wed Nov 25 10:31:22 EET 2015)
JAMon Label=mySecondMonitor, Units=ms.: (LastValue=0.0, Hits=1.0, Avg=0.0, Total=0.0, Min=0.0, Max=0.0, Active=0.0, Avg Active=1.0, Max Active=1.0, First Access=Wed Nov 25 10:31:22 EET 2015, Last Access=Wed Nov 25 10:31:22 EET 2015)
JAMon Label=com.jamonapi.Exceptions, Units=Exception: (LastValue=0.0, Hits=0.0, Avg=0.0, Total=0.0, Min=1.7976931348623157E308, Max=-1.7976931348623157E308, Active=0.0, Avg Active=0.0, Max Active=0.0, First Access=Thu Jan 01 02:00:00 EET 1970, Last Access=Thu Jan 01 02:00:00 EET 1970)



Final words

There are some informational videos on youtube.com about JAMon. They are in form of presentation.

No comments:

Post a Comment