Created
December 18, 2021 22:10
-
-
Save jbachorik/b00ffbeb3861bca8a3e7677c81b42512 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import org.openjdk.btrace.core.BTraceUtils; | |
| import org.openjdk.btrace.core.annotations.*; | |
| import org.openjdk.btrace.core.jfr.JfrEvent; | |
| import static org.openjdk.btrace.core.BTraceUtils.*; | |
| import static org.openjdk.btrace.core.BTraceUtils.Jfr.*; | |
| @BTrace | |
| public class TracePreparedQuery { | |
| @Event( | |
| name = "jdbc.PreparedQuery", | |
| label = "Prepared Query", | |
| description = "Execution of a prepared query", | |
| category = "Hibernate", | |
| stacktrace = true, | |
| fields = { | |
| @Event.Field(type = Event.FieldType.STRING, name = "wrappedStatement", label = "SQL Query", description = "The executed SQL query") | |
| } | |
| ) | |
| private static JfrEvent.Factory preparedQueryEventFactory; | |
| @Event( | |
| name = "jdbc.BindParameter", | |
| label = "Prepared Statement Bind Parameter", | |
| description = "Bind parameter of a prepared query", | |
| category = "Hibernate", | |
| stacktrace = true, | |
| fields = { | |
| @Event.Field(type = Event.FieldType.STRING, name = "bindParameter", label = "Bind Parameter", description = "The bind parameter"), | |
| @Event.Field(type = Event.FieldType.INT, name = "index", label = "Index", description = "The parameter index") | |
| } | |
| ) | |
| private static JfrEvent.Factory bindParameterEventFactory; | |
| @OnMethod(clazz = "io.agroal.pool.wrapper.PreparedStatementWrapper", method = "executeQuery") | |
| public static void onPreparedStatement(@Self Object thiz) { | |
| JfrEvent event = prepareEvent(preparedQueryEventFactory); | |
| setEventField(event, "wrappedStatement", str(get(field(classOf(thiz), "wrappedStatement"), thiz))); | |
| commit(event); | |
| } | |
| @OnMethod(clazz = "org.hibernate.type.descriptor.sql.BasicBinder", method = "bind", type = "void (java.sql.PreparedStatement, java.lang.Object, int, org.hibernate.type.descriptor.WrapperOptions") | |
| public static void onBinding(Object preparedStatement, Object parameter, int index, Object wrapperOptions) { | |
| JfrEvent event = prepareEvent(bindParameterEventFactory); | |
| setEventField(event, "bindParameter", str(parameter); | |
| setEventField(event, "index", index); | |
| commit(event); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment