Copyright (c) 2012 Jesse Rosalia
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"),
to deal in the Sof...
If you think the Android project ormada listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package org.ormada.util;
/*www.java2s.com*//**
* A basic method profiler, that will log accumulated method time and print out total time and time per n number of calls,
* where n is a definible threshold.
*
* @author Jesse Rosalia
*
*/publicclass Profiler {
privatelong enterTime = 0;
privatelong accumulatedTime = 0;
privateint counter = 0;
privateint counterThresholds = 0;
private String prefix;
public Profiler(String prefix, int counterThreshold) {
this.prefix = prefix;
this.counterThresholds = counterThreshold;
}
publicvoid enter() {
enterTime = System.currentTimeMillis();
}
publicvoid exit() {
long exitTime = System.currentTimeMillis();
accumulatedTime += exitTime - enterTime;
if (++this.counter == this.counterThresholds) {
System.out.println(this.prefix + ": Elapsed time in ms: " + accumulatedTime + ", " + ((float)accumulatedTime)/this.counterThresholds + "/" + this.counterThresholds + " calls");
this.counter = 0;
this.accumulatedTime = 0;
}
}
}