0

Is it possible to monitor different processing steps using the same JAMon Monitor class? For example, in the code example I would like to measure execution time of "Point1" and "Point2". However, the example returns only statistics about the second step. Of course I can create several objects of type Monitor. But maybe there is a cleaner way?

Monitor mon = null;     
for(int i =0; i < 1000; i++){
    //Part1
    mon = MonitorFactory.start("Point 1");
    Thread.sleep(2);
    mon.stop();     
    
    //Part2
    mon = MonitorFactory.start("Point 2");
    mon.stop();
}
    
System.out.println(mon.toString());

Output:

JAMon Label=Point 2, Units=ms.: (LastValue=0.0, Hits=1000.0, Avg=0.001, Total=1.0, Min=0.0, Max=1.0, Active=0.0, Avg Active=1.0, Max Active=1.0, First Access=Wed Jun 17 10:40:44 CEST 2015, Last Access=Wed Jun 17 10:40:46 CEST 2015)

Desired Output:

JAMon Label=Point 1, Units=ms.: (LastValue=0.0, Hits=1000.0, Avg=0.001, Total=1.0, Min=0.0, Max=1.0, Active=0.0, Avg Active=1.0, Max Active=1.0, First Access=Wed Jun 17 10:40:44 CEST 2015, Last Access=Wed Jun 17 10:40:46 CEST 2015)

JAMon Label=Point 2, Units=ms.: (LastValue=0.0, Hits=1000.0, Avg=0.001, Total=1.0, Min=0.0, Max=1.0, Active=0.0, Avg Active=1.0, Max Active=1.0, First Access=Wed Jun 17 10:40:44 CEST 2015, Last Access=Wed Jun 17 10:40:46 CEST 2015)

Community
  • 1
  • 1
user3776894
  • 183
  • 1
  • 8

2 Answers2

0

You could change the monitor toString() call to an explicit getMonitor(...) call.

Monitor mon = null;   

for(int i =0; i < 1000; i++){
  //Part1
  mon = MonitorFactory.start("Point 1");
  Thread.sleep(2);
  mon.stop();     

  //Part2
  mon = MonitorFactory.start("Point 2");
  mon.stop();
}

System.out.println(MonitorFactory.getMonitor("Point 1").toString());
System.out.println(MonitorFactory.getMonitor("Point 2").toString());

Or you could create 2 monitors.

Monitor mon1 = null;   
Monitor mon2 = null;     

for(int i =0; i < 1000; i++){
  //Part1
  mon1 = MonitorFactory.start("Point 1");
  Thread.sleep(2);
  mon1.stop();     

  //Part2
  mon2 = MonitorFactory.start("Point 2");
  mon2.stop();
}

System.out.println(mon1.toString());
System.out.println(mon2.toString());
0

There is a better way than the other answer:

for( Object monitor: MonitorFactory.getMap().values() ){
    System.out.println( monitor ); 
}

This will print all used monitors untill now. In all threads. Exactly what you want.

You could check completed example of code and output here.

JRr
  • 1,552
  • 1
  • 19
  • 23