Quantcast
Channel: MySQL Forums - Connector/J, JDBC and Java
Viewing all articles
Browse latest Browse all 884

Profiling / recording query timing data with QueryInterceptor (no replies)

$
0
0
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
}

Viewing all articles
Browse latest Browse all 884

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>