Yes, there is a way, yes, there is an API that I designed to meet that, using Aspect-Oriented Programming. I don’t want to go into details about the paradigm here, but we will meet your need.
First Option - Green Aspect Utils
This is my framework with Aspects, including Log with Offing level. If you want to use my Framework, access this link:
https://github.com/FilipeGMiranda/Green-Aspect-Utils
Just add the @Loggableobject logo annotation to your method in this way:
@LoggableObject(logMode={LoggableObject.LogModes.PROFILE})
private int seuMetodo(String a, Integer b, String y, Object o, String c){
//Conputacoes e execucao de seus algoritmos
return 1;
}
Note: To use my framework you will need the least of Maven
When you run this program, you will see this information that you want.
Second Option, just use a Profiling tool such as Jconsole, Jprofile
Jconsole is in the C: Program Files (x86) Java folder jdk1.7.0_51 bin
Third Option - Write your own Profiling code
That will be something in this template:
public static void seuMethod() {
// sua logica
}
public static void main(String[] args) {
// Memória total
System.out.println("Memória total: "
+ Runtime.getRuntime().totalMemory());
// Memória livre
System.out.println("Memória livre: "
+ Runtime.getRuntime().freeMemory());
// Tempo de inicio
long initialTime = System.nanoTime();
seuMethod();
System.out.println("Tempo de execução total --> "
+ (System.nanoTime() - initialTime));
System.out.println("Memória total: "
+ Runtime.getRuntime().totalMemory());
// Memória livre
System.out.println("Memória livre: "
+ Runtime.getRuntime().freeMemory());
}
Read the code comments, should help you
Note the use of methods before and after the execution of your methods.
- Runtime.getRuntime(). freeMemory()
- Runtime.getRuntime(). totalMemory()
Grateful for the Help Felipe!
– Alysson Chicó
That’s why we’re here, let me know if everything works normally. And follow me on Github, to track the evolution of the API
– Filipe Miranda