use of com.alibaba.druid.stat.JdbcDataSourceStat in project druid by alibaba.
the class StatFilter method connection_rollback.
@Override
public void connection_rollback(FilterChain chain, ConnectionProxy connection) throws SQLException {
chain.connection_rollback(connection);
JdbcDataSourceStat dataSourceStat = chain.getDataSource().getDataSourceStat();
dataSourceStat.getConnectionStat().incrementConnectionRollbackCount();
dataSourceStat.getConnectionStat().incrementConnectionRollbackCount();
}
use of com.alibaba.druid.stat.JdbcDataSourceStat 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.JdbcDataSourceStat in project druid by alibaba.
the class StatFilter method connection_commit.
@Override
public void connection_commit(FilterChain chain, ConnectionProxy connection) throws SQLException {
chain.connection_commit(connection);
JdbcDataSourceStat dataSourceStat = chain.getDataSource().getDataSourceStat();
dataSourceStat.getConnectionStat().incrementConnectionCommitCount();
}
use of com.alibaba.druid.stat.JdbcDataSourceStat 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);
}
use of com.alibaba.druid.stat.JdbcDataSourceStat in project druid by alibaba.
the class JdbcDataSourceStatTest method test_max_10.
public void test_max_10() throws Exception {
Properties connectProperties = new Properties();
connectProperties.put(Constants.DRUID_STAT_SQL_MAX_SIZE, 10);
JdbcDataSourceStat stat = new JdbcDataSourceStat("", "", "mysql", connectProperties);
for (int i = 0; i < 1000 * 1; ++i) {
stat.createSqlStat("select " + i);
}
Assert.assertEquals(10, stat.getSqlStatMap().size());
}
Aggregations