How can we locate these page requests when the system execution is inefficient when accessing page requests?
Java has a very effective dynamic tracking tool-btrace URL: https://kenai.com/projects/btrace/downloads
For example, you want to locate our controller code which methods are slow:
1. We can write the following classes:
Package demo;
Import Com.sun.btrace.annotations.BTrace;
Import Com.sun.btrace.annotations.Kind;
Import com.sun.btrace.annotations.Location;
Import Com.sun.btrace.annotations.OnMethod;
Import Com.sun.btrace.annotations.TLS;
Import static com.sun.btrace.btraceutils.*;
@BTrace
public class Btracetest {
@TLS
private static long starttime;
@OnMethod (clazz= "/com\\.hotent\\. *\\.. *\\.controller\\. */", method="/.+/", [email protected] (kind.entry))
public static void Startexecute () {
Starttime=timemillis ();
}
@OnMethod (clazz= "/com\\.hotent\\. *\\.. *\\.controller\\. */", method="/.+/", [email protected] (Kind.return))
public static void EndExecute () {
Long Timecost=timemillis ()-starttime;
Print (strcat (strcat (Name (Probeclass ()), "."), Probemethod ());
Print (Strcat (", Time Taken:", str (timecost)));
println ("]");
}
}
2. Use JPS to view the application server process.
8512 of them are our Tomcat process.
3. Copy the code you just made to the Btrace download directory.
4. Execute the command as follows
BTRACE.BAT-CP bulid 8512 Demo/btracetest.java
5. The results of the implementation are as follows :
The access page console will print the execution time for each controller method.
Use Btrace to locate slow problems in the system