use of com.sun.gjc.util.SQLTrace in project Payara by payara.
the class JdbcStatsProvider method getfreqUsedSqlQueries.
@ManagedAttribute(id = "frequsedsqlqueries")
public ListStatistic getfreqUsedSqlQueries() {
List<SQLTrace> sqlTraces = freqSqlTraceCache.getTopQueries();
freqUsedSqlQueries = new ListStatisticImpl("frequsedsqlqueries", "List", "Most frequently used sql queries");
for (SQLTrace trace : sqlTraces) {
CountStatisticImpl stat = new CountStatisticImpl(trace.getQueryName(), "Count", "");
stat.setCount(trace.getNumExecutions());
freqUsedSqlQueries.add(stat);
}
return freqUsedSqlQueries;
}
use of com.sun.gjc.util.SQLTrace in project Payara by payara.
the class FrequentSQLTraceCache method checkAndUpdateCache.
/**
* Request for adding a sql query in the form of SQLTrace to this cache.
* If the query is already found
* in the list, the number of times it is executed is incremented by one
* along with the timestamp.
* If the query is a new one, it is added to the list.
*
* @param cacheObj
*/
@Override
public void checkAndUpdateCache(SQLTrace cacheObj) {
if (cacheObj != null) {
SQLTrace trace = cache.get(cacheObj.getQueryName());
if (trace != null) {
// If already found in the cache
trace.setNumExecutions(trace.getNumExecutions() + 1);
trace.setLastUsageTime(System.currentTimeMillis());
} else {
if (cache.size() < maxStoredEntries) {
cache.put(cacheObj.getQueryName(), cacheObj);
} else {
if (_logger.isLoggable(Level.CONFIG)) {
_logger.log(Level.CONFIG, "Frequent SQL Trace Cache full, {0} not stored.", cacheObj.getQueryName());
} else {
_logger.log(Level.INFO, "Frequent SQL Trace Cache full, enable CONFIG log level for more info.");
}
}
}
}
}
use of com.sun.gjc.util.SQLTrace in project Payara by payara.
the class JdbcStatsProvider method traceSQLEvent.
/**
* Whenever a sql statement that is traced is to be cache for monitoring
* purpose, the SQLTrace object is created for the specified sql and
* updated in the SQLTraceCache. This is used to update the
* frequently used and slowest sql queries.
*
* @param poolName
* @param appName
* @param sql
* @param moduleName
* @param executionTime
*/
@ProbeListener(JdbcRAConstants.SQL_TRACING_DOTTED_NAME + JdbcRAConstants.TRACE_SQL)
public void traceSQLEvent(@ProbeParam("poolName") String poolName, @ProbeParam("appName") String appName, @ProbeParam("moduleName") String moduleName, @ProbeParam("sql") String sql, @ProbeParam("executionTime") long executionTime) {
PoolInfo poolInfo = new PoolInfo(poolName, appName, moduleName);
if (this.poolInfo.equals(poolInfo)) {
if (freqSqlTraceCache != null) {
if (sql != null) {
SQLTrace cacheObj = new SQLTrace(sql, 1, System.currentTimeMillis());
freqSqlTraceCache.checkAndUpdateCache(cacheObj);
}
}
// the cache
if (slowSqlTraceCache != null && sql != null) {
SQLTrace cacheObj = new SlowSqlTrace(sql, 1, System.currentTimeMillis(), executionTime);
slowSqlTraceCache.checkAndUpdateCache(cacheObj);
}
}
}
Aggregations