In the project, the monitoring program in the development phase can use breakpoints to complete debugging. For online projects, when monitoring is required:
1. Log analysis,
2. JConsole tool
3. Btrace traces and monitors threads
Install Btrace: In the Windows environment, you can directly use the jvisualvm tool that comes with jdk to install the Btrace plug-in. The specific operations are as follows:
1. Enter the jdk installation directory, enter the bin directory, find jvisualvm.exe, open it, search for the plugin BTrace Workbench in the toolbar->tools->plugin, and then install it
2. Start Tomcat where your program is located, you will find a Tomcat menu icon in the jvisualvm.exe window, right-click -> select Trace application
3. If you want to monitor the execution time of the program, copy the following code into the Btrace form
package my.app.btrace;
import static com.sun.btrace.BTraceUtils.*;
import com.sun.btrace.annotations.*;
@BTrace
public class TraceProductManageImpl {
@OnMethod(clazz = "/com.odianyun.+business.+/", method = "/.+/", location = @Location(Kind.RETURN))
public static void traceExecute(@ProbeClassName String name,@ProbeMethodName String method,@Duration long time){
long durationTime = time/1000000;
if(durationTime > 0){
String output = strcat(name,".");
output = strcat(output,method);
output = strcat(output,"#");
output = strcat(output,str(probeLine()));
output = strcat(output,">>");
output = strcat(output,str(durationTime));
output = strcat(output,">>ThreadId:");
output = strcat(output,str(threadId(currentThread())));
println(output);
}
}
}
If you want to monitor the parameters of the program, run the call tree and replace it with the following code:
ackage my.app.btrace;
import static com.sun.btrace.BTraceUtils.println;
import static com.sun.btrace.BTraceUtils.size;
import static com.sun.btrace.BTraceUtils.str;
import static com.sun.btrace.BTraceUtils.strcat;
import java.util.List;
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.ProbeClassName;
import com.sun.btrace.annotations.ProbeMethodName;
import com.sun.btrace.annotations.Return;
import com.sun.btrace.annotations.Self;
@BTrace
/**
* Get program parameters
* @author Michael
*/
public class TraceProductManageParam {
@OnMethod(clazz = "com.odianyun.frontier.guide.business.read.manage.impl.PromotionManageImpl", method = "getMerchantProductCurrentPromotionPriceBatch", location = @Location(Kind.RETURN))
public static void traceExecute(@ProbeClassName String name,@ProbeMethodName String method,@Self Object self, List<Long> mpIds, Long companyId, @Return List<?> ret){
String output = strcat(name,".");
output = strcat(output,method);
output = strcat(output,">inputItems:");
output = strcat(output, str(mpIds));
output = strcat(output,">outputSize:");
output = strcat(output, str(size(ret)));
println(output);
}
}