This article mainly introduces examples of btrace's method of locating production faults. The article introduces it in detail through the example code. I believe it has certain reference value for everyone. Friends who need it can take a look below.
Preface
Many times we need to know more details about the running of the program, but it is impossible to print all the running details in the program during development. Go to the log. Usually what you can do at this time is to modify the code, redeploy, and then observe again. However, this method is not very good for online applications. On the other hand, if you encounter code that is difficult to change, such as other referenced External packages and so on are very troublesome. BTrace is a tool that can dynamically view program running details without changing the code or restarting the application. The following article introduces the method of btrace to locate production faults. , friends in need can refer to it.
Phenomena
Some requests are very slow through the data access layer and cause the processing thread to be blocked, and the exception cannot be detected from the monitoring.
Write btrace script
@BTrace public class DBProxyTrace { @OnMethod(clazz = "xxx.xxx.QueryHandler", method = "query", location = @Location(Kind.RETURN)) public static void trace2(String sql, @Duration long duration) { if (duration/1000000 > 10 * 1000) { com.sun.btrace.BTraceUtils.println(duration/1000000 + "ms"); com.sun.btrace.BTraceUtils.println("this task executes more than 10s. the sql is : " + sql); com.sun.btrace.BTraceUtils.println("jstack is : "); com.sun.btrace.BTraceUtils.jstack(); } } }
Judge the SQL and stack information that is executed for more than 10 seconds.
Compile the script DBProxyTrace.Java and confirm that there is no problem with the script.
./bin/btracec -cp build/ java/DBProxyTrace.java
Execute script DBProxyTrace.class
./bin/btrace -cp build/ 17342 DBProxyTrace.class
Information
10468ms this task executes more than 10s. the sql is : rollback jstack is : xxx.QueryHandler.query(QueryHandler.java:106) xxx.net.AbstractConnection.onReadData(AbstractConnection.java:245) xxx.net.NIOReactor$RW.run(NIOReactor.java:77) java.lang.Thread.run(Thread.java:745)
Location
Blocked in transaction rollback.
Use jstack for further positioning.
Print JVM stack
"$_NIOREACTOR-7-RW" prio=10 tid=0x00007f069856f000 nid=0xde1 waiting for monitor entry [0x00007f0677011000] java.lang.Thread.State: BLOCKED (on object monitor) at Oracle.jdbc.driver.PhysicalConnection.rollback(PhysicalConnection.java:1167) - waiting to lock <0x000000068086fbc0> (a oracle.jdbc.driver.T4CConnection)
Conclusion
Blocked The oracle driver rollback action is actually because the oracle driver adds a lock on the bottom layer to ensure the serial request response, and this channel is blocked by slow statements, so the rollback is blocked.
Summary
The above is the content of the example of btrace's method of locating production faults. For more related content, please pay attention to the PHP Chinese website (www.php .cn)!

There are subtle differences in Java's performance on different operating systems. 1) The JVM implementations are different, such as HotSpot and OpenJDK, which affect performance and garbage collection. 2) The file system structure and path separator are different, so it needs to be processed using the Java standard library. 3) Differential implementation of network protocols affects network performance. 4) The appearance and behavior of GUI components vary on different systems. By using standard libraries and virtual machine testing, the impact of these differences can be reduced and Java programs can be ensured to run smoothly.

Javaoffersrobustobject-orientedprogramming(OOP)andtop-notchsecurityfeatures.1)OOPinJavaincludesclasses,objects,inheritance,polymorphism,andencapsulation,enablingflexibleandmaintainablesystems.2)SecurityfeaturesincludetheJavaVirtualMachine(JVM)forsand

JavaScriptandJavahavedistinctstrengths:JavaScriptexcelsindynamictypingandasynchronousprogramming,whileJavaisrobustwithstrongOOPandtyping.1)JavaScript'sdynamicnatureallowsforrapiddevelopmentandprototyping,withasync/awaitfornon-blockingI/O.2)Java'sOOPf

JavaachievesplatformindependencethroughtheJavaVirtualMachine(JVM)andbytecode.1)TheJVMinterpretsbytecode,allowingthesamecodetorunonanyplatformwithaJVM.2)BytecodeiscompiledfromJavasourcecodeandisplatform-independent.However,limitationsincludepotentialp

Java'splatformindependencemeansapplicationscanrunonanyplatformwithaJVM,enabling"WriteOnce,RunAnywhere."However,challengesincludeJVMinconsistencies,libraryportability,andperformancevariations.Toaddressthese:1)Usecross-platformtestingtools,2)

JVM'sperformanceiscompetitivewithotherruntimes,offeringabalanceofspeed,safety,andproductivity.1)JVMusesJITcompilationfordynamicoptimizations.2)C offersnativeperformancebutlacksJVM'ssafetyfeatures.3)Pythonisslowerbuteasiertouse.4)JavaScript'sJITisles

JavaachievesplatformindependencethroughtheJavaVirtualMachine(JVM),allowingcodetorunonanyplatformwithaJVM.1)Codeiscompiledintobytecode,notmachine-specificcode.2)BytecodeisinterpretedbytheJVM,enablingcross-platformexecution.3)Developersshouldtestacross

TheJVMisanabstractcomputingmachinecrucialforrunningJavaprogramsduetoitsplatform-independentarchitecture.Itincludes:1)ClassLoaderforloadingclasses,2)RuntimeDataAreafordatastorage,3)ExecutionEnginewithInterpreter,JITCompiler,andGarbageCollectorforbytec


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

Dreamweaver Mac version
Visual web development tools

SublimeText3 Chinese version
Chinese version, very easy to use

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 English version
Recommended: Win version, supports code prompts!
