[AspectJ] Récupérer le temps d'exécution d'un java.sql.Statement.executeQuery (JDBC)
Bonjour à vous,
Après pas mal de recherche, je suis un peu coincé sur une fonction me permettant de récupérer le temps d'une requête SQL via JDBC.
Voici mon code actuel :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
private static HashMap<String, Long> resultSQL = new HashMap<String, Long>();
pointcut getSQL(String sql) : call(public * java.sql.Statement.executeQuery(String)) && args(sql);
before(String sql) : getSQL(sql) {
if(debug) {
resultSQL.put(sql, System.currentTimeMillis());
}
}
after(String sql) : getSQL(sql) {
if(debug) {
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
long debut = resultSQL.get(sql);
long fin = System.currentTimeMillis();
System.err.println("CORE : [" + dateFormat.format(date) + "] " + Thread.currentThread().getStackTrace()[2].toString() + " : " + (fin-debut) + " ms : " + sql);
resultSQL.remove(sql);
}
} |
Actuellement, je passe par un HashMap pour connaitre le temps avant la requête que je peux récupérer dans mon "after" et ainsi connaitre le temps d'exécution qui comprend le temps de executeQuery + la récupération du temps de départ dans mon HashMap.
Je pense qu'il y a moyen de réaliser l'opération autrement, et j'ai trouvé mais il me met une erreur :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| pointcut resultSet(String sql) : execution(public java.sql.ResultSet java.sql.Statement.executeQuery(String)) && args(sql);
Object around(String sql) : resultSet(sql) {
long debut = System.currentTimeMillis();
Object ret = proceed(sql);
long fin = System.currentTimeMillis();
if(debug) {
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
System.err.println("CORE : [" + dateFormat.format(date) + "] " + Thread.currentThread().getStackTrace()[1].toString() + " : " + (fin-debut) + " ms");
}
return ret;
} |
À la ligne où est définit mon
Code:
Object around(String sql) : resultSet(sql) {
j'obtiens ce message (avertissement)
Citation:
advice defined in net.gamsys.utils.LogAspectCore has not been applied [Xlint:adviceDidNotMatch]
Du coup, je ne récupère aucun message.
Avez-vous une idée?
Si il manque des informations, n'hésitez pas à demander ;)
Merci à vous.