Skip to content

Print SQL execution and time

Purpose

Pain point: When we test the business, we need to view the actual SQL execution and time consumption. Many upper-level drivers have multiple ways to enable printing, and many of them require code modification or configuration modification for printing.

DebugTools uses bytebuddy to print SQL and time consumption at runtime by modifying the database driver bytecode at the jdbc layer, thereby avoiding the impact of different upper-level database connection pools on SQL printing.

Theoretically supports all database drivers connected through Jdbc:

Use

Idea

Configure to open or close in setting -> Other Settings -> DebugTools

print_sql_setting

Success will output Print xxx(mysql/oracle/...) log bytecode enhancement in the log successful

print_sql_success

The printing effect is as follows:

text
Execute consume Time: 3 ms; Execute SQL:Execute consume Time: 3 ms; Execute SQL: 
SELECT
    id,
    name,
    age,
    version 
FROM
    dp_user 
WHERE
    id=1

TIP

Since DebugTools prints SQL in bytecode, you need to restart the application to take effect after modifying the configuration.

Agent

Start the application by using java -javaagent:/path/to/your/debug-tools-agent-{version}.jar -jar your-app.jar

agent download address

https://download.debug-tools.cc/debug-tools-agent.jar

Warning

It is best not to use it in a production environment

Because DebugTools implements SQL printing by modifying the database driver bytecode, there may be incompatibility or other unconsidered situations, and there may be risks in the production environment.