Profiling / recording query timing data with QueryInterceptor
Hey all,
I am working on rewriting our statement interceptor that logs executed statements into circular memory buffer against MySQL Connector 8.x.
I would need to know the creation time of the query object when passed into the postProcess method or be able to inject some information via a context object available in a pre* method.
Currently I am using a ThreadLocal object to store a unix timestamp however this feels like a hack.
There don't seem to be a great deal of examples on how to use QueryInterceptor , is there something I have overlooked?
Cheers,
Johno
private final ThreadLocal<Long> timeLocal = new ThreadLocal<>();
@Override
public <T extends Resultset> T preProcess(Supplier<String> supplier, Query query) {
timeLocal.set(TimeSource.now());
return null; // don't allow result set substitution
}
@Override
public <T extends Resultset> T postProcess(Supplier<String> supplier, Query query, T t, ServerSession serverSession) {
final Long timeMillis = timeLocal.get();
if (timeMillis == null) {
return null;
}
timeLocal.remove();
final String sql = supplier.get();
if (sql == null || sql.startsWith("SET autocommit=")) {
return null; // don't allow result set substitution
}
getLogCollectorForSchema(schema).addEntry(sql, (TimeSource.now() - timeMillis));
return null; // don't allow result set substitution
}
Subject
Written By
Posted
Profiling / recording query timing data with QueryInterceptor
October 08, 2019 12:48AM
November 04, 2019 09:56AM
November 08, 2019 05:17PM
November 13, 2019 04:50AM
November 13, 2019 10:40AM
November 19, 2019 09:39AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.