I'm trying to implement stopwatch class that will wrap all the required methods that i'm trying to measure
The main purpose is to create an framwork that when ever you want to measure the execution time of a method you will change the exiting code from:
<Classname> x = A();
or
A();
To:
<Classname> x = PSW.startWatch(MethodToWatch.B).invoke("123123123", A());
or
PSW.startWatch(MethodToWatch.B).invoke("123123123", A());
This is the code:
public class PerformanceStopWatch {
private long start;
private long end;
private String uniqueID;
private MethodToWatch methodName;
public enum MethodToWatch {
A,
B
}
public PerformanceStopWatch startWatch(MethodToWatch methodName) {
this.methodName = methodName;
start();
return this;
}
public void invoke(String uniqeID) {
this.uniqueID = uniqeID;
stop();
}
public void invoke(UUID machineId, void a) {
invoke(machineId);
}
private void start() {
start = System.nanoTime();
}
private void stop() {
end = System.nanoTime();
System.out.println("[PerformanceStopWatch|"+methodName.name()+"] - Unique ID: "+ uniqueID + " Took: <"+(end-start)+"> Nanosec");
}
}
public void a() {
PerformanceStopWatch PSW = new PerformanceStopWatch();
..
..
..
PSW.startWatch(MethodToWatch.B).invoke("123123123", b());
}
public void b() {
...
...
..
}
The problem is that the compiler dose not allow me to use
public void invoke(UUID machineId, void a) {
}
void is illegle type.
any idea?