From the official site
A small and free library, that helps locating performance problems in existing Java applications.
JETM enables developers to track down performance issues on demand, either programmatic or declarative with minimal impact on application performance, even in production.
jetm is pretty cool and has a lot of features.
- rrd support
- jmx support
- web container integration
- spring framework integration
You can follow the tutorial trail here. The following codes are taken from one of the tutorial with minor modification.
public class BusinessService {
private static final EtmMonitor etmMonitor = EtmManager.getEtmMonitor();
public void someMethod() {
EtmPoint point = etmMonitor.createPoint("BusinessService:someMethod");
try {
Thread.sleep((long)(10d * Math.random()));
nestedMethod();
} catch (InterruptedException e ) {
} finally {
point.collect();
}
}
public void nestedMethod() {
EtmPoint point = etmMonitor.createPoint("BusinessService:nestedMethod");
try {
Thread.sleep((long)(15d * Math.random()));
} catch (InterruptedException e) {
} finally {
point.collect();
}
}
public static void main(String[] args) {
BasicEtmConfigurator.configure(true);
//etmMonitor = EtmManager.getEtmMonitor();
etmMonitor.start();
BusinessService bizz = new BusinessService();
bizz.someMethod();
bizz.someMethod();
bizz.someMethod();
bizz.someMethod();
bizz.nestedMethod();
etmMonitor.render(new SimpleTextRenderer());
etmMonitor.stop();
}
}
Hit the run button in eclipse.
EtmMonitor info [INFO] JETM 1.2.3 started.
|--------------------------------|---|---------|-------|--------|--------|
| Measurement Point | # | Average | Min | Max | Total |
|--------------------------------|---|---------|-------|--------|--------|
| BusinessService:nestedMethod | 1 | 4.121 | 4.121 | 4.121 | 4.121 |
|--------------------------------|---|---------|-------|--------|--------|
| BusinessService:someMethod | 4 | 12.611 | 6.196 | 16.347 | 50.442 |
| BusinessService:nestedMethod | 4 | 5.381 | 0.017 | 10.194 | 21.523 |
|--------------------------------|---|---------|-------|--------|--------|
EtmMonitor info [INFO] Shutting down JETM.
So we saw that nestedMethod execute once and four time for someMethod. The result showing a minimum and maximum for the execution with an avarage. Last column shown the total. Pretty neat for a small java library.
No comments:
Post a Comment