use of com.alibaba.druid.stat.JdbcSqlStat in project druid by alibaba.
the class StatFilter method statementPrepareAfter.
@Override
public void statementPrepareAfter(PreparedStatementProxy statement) {
JdbcDataSourceStat dataSourceStat = statement.getConnectionProxy().getDirectDataSource().getDataSourceStat();
dataSourceStat.getStatementStat().incrementPrepareCounter();
JdbcSqlStat sqlStat = createSqlStat(statement, statement.getSql());
statement.setSqlStat(sqlStat);
}
use of com.alibaba.druid.stat.JdbcSqlStat in project druid by alibaba.
the class StatFilter method internalAfterStatementExecute.
private final void internalAfterStatementExecute(StatementProxy statement, boolean firstResult, int... updateCountArray) {
final long nowNano = System.nanoTime();
final long nanos = nowNano - statement.getLastExecuteStartNano();
JdbcDataSourceStat dataSourceStat = statement.getConnectionProxy().getDirectDataSource().getDataSourceStat();
dataSourceStat.getStatementStat().afterExecute(nanos);
final JdbcSqlStat sqlStat = statement.getSqlStat();
if (sqlStat != null) {
sqlStat.incrementExecuteSuccessCount();
sqlStat.decrementRunningCount();
sqlStat.addExecuteTime(statement.getLastExecuteType(), firstResult, nanos);
statement.setLastExecuteTimeNano(nanos);
if ((!statement.isFirstResultSet()) && statement.getLastExecuteType() == StatementExecuteType.Execute) {
try {
int updateCount = statement.getUpdateCount();
sqlStat.addUpdateCount(updateCount);
} catch (SQLException e) {
LOG.error("getUpdateCount error", e);
}
} else {
for (int updateCount : updateCountArray) {
sqlStat.addUpdateCount(updateCount);
sqlStat.addFetchRowCount(0);
StatFilterContext.getInstance().addUpdateCount(updateCount);
}
}
long millis = nanos / (1000 * 1000);
if (millis >= slowSqlMillis) {
String slowParameters = buildSlowParameters(statement);
sqlStat.setLastSlowParameters(slowParameters);
if (logSlowSql) {
LOG.error("slow sql " + millis + " millis. " + statement.getLastExecuteSql() + "" + slowParameters);
}
}
}
String sql = statement.getLastExecuteSql();
StatFilterContext.getInstance().executeAfter(sql, nanos, null);
Profiler.release(nanos);
}
use of com.alibaba.druid.stat.JdbcSqlStat in project druid by alibaba.
the class StatFilter method resultSet_close.
@Override
public void resultSet_close(FilterChain chain, ResultSetProxy resultSet) throws SQLException {
long nanos = System.nanoTime() - resultSet.getConstructNano();
int fetchRowCount = resultSet.getFetchRowCount();
JdbcDataSourceStat dataSourceStat = chain.getDataSource().getDataSourceStat();
dataSourceStat.getResultSetStat().afterClose(nanos);
dataSourceStat.getResultSetStat().addFetchRowCount(fetchRowCount);
dataSourceStat.getResultSetStat().incrementCloseCounter();
StatFilterContext.getInstance().addFetchRowCount(fetchRowCount);
String sql = resultSet.getSql();
if (sql != null) {
JdbcSqlStat sqlStat = resultSet.getSqlStat();
if (sqlStat != null && resultSet.getCloseCount() == 0) {
sqlStat.addFetchRowCount(fetchRowCount);
long stmtExecuteNano = resultSet.getStatementProxy().getLastExecuteTimeNano();
sqlStat.addResultSetHoldTimeNano(stmtExecuteNano, nanos);
if (resultSet.getReadStringLength() > 0) {
sqlStat.addStringReadLength(resultSet.getReadStringLength());
}
if (resultSet.getReadBytesLength() > 0) {
sqlStat.addReadBytesLength(resultSet.getReadBytesLength());
}
if (resultSet.getOpenInputStreamCount() > 0) {
sqlStat.addInputStreamOpenCount(resultSet.getOpenInputStreamCount());
}
if (resultSet.getOpenReaderCount() > 0) {
sqlStat.addReaderOpenCount(resultSet.getOpenReaderCount());
}
}
}
chain.resultSet_close(resultSet);
StatFilterContext.getInstance().resultSet_close(nanos);
}
use of com.alibaba.druid.stat.JdbcSqlStat in project druid by alibaba.
the class StatFilter method blobOpenAfter.
private void blobOpenAfter(JdbcDataSourceStat dataSourceStat, StatementProxy stmt, Blob blob) {
dataSourceStat.incrementBlobOpenCount();
if (stmt != null) {
JdbcSqlStat sqlStat = stmt.getSqlStat();
if (sqlStat != null) {
sqlStat.incrementBlobOpenCount();
}
}
StatFilterContext.getInstance().blob_open();
}
use of com.alibaba.druid.stat.JdbcSqlStat in project druid by alibaba.
the class StatFilter method internalBeforeStatementExecute.
private final void internalBeforeStatementExecute(StatementProxy statement, String sql) {
JdbcDataSourceStat dataSourceStat = statement.getConnectionProxy().getDirectDataSource().getDataSourceStat();
dataSourceStat.getStatementStat().beforeExecute();
final ConnectionProxy connection = statement.getConnectionProxy();
final JdbcConnectionStat.Entry connectionCounter = getConnectionInfo(connection);
statement.setLastExecuteStartNano();
connectionCounter.setLastSql(sql);
if (connectionStackTraceEnable) {
connectionCounter.setLastStatementStatckTrace(new Exception());
}
// //////////SQL
JdbcSqlStat sqlStat = statement.getSqlStat();
if (sqlStat == null || sqlStat.isRemoved()) {
sqlStat = createSqlStat(statement, sql);
statement.setSqlStat(sqlStat);
}
JdbcStatContext statContext = JdbcStatManager.getInstance().getStatContext();
if (statContext != null) {
sqlStat.setName(statContext.getName());
sqlStat.setFile(statContext.getFile());
}
boolean inTransaction = false;
try {
inTransaction = !statement.getConnectionProxy().getAutoCommit();
} catch (SQLException e) {
LOG.error("getAutoCommit error", e);
}
if (sqlStat != null) {
sqlStat.setExecuteLastStartTime(System.currentTimeMillis());
sqlStat.incrementRunningCount();
if (inTransaction) {
sqlStat.incrementInTransactionCount();
}
}
StatFilterContext.getInstance().executeBefore(sql, inTransaction);
Profiler.enter(sql, Profiler.PROFILE_TYPE_SQL);
}
Aggregations