use of com.actiontech.dble.statistic.SQLRecord in project dble by actiontech.
the class ShowSQLSlow method execute.
public static void execute(ManagerConnection c, boolean isClear) {
ByteBuffer buffer = c.allocate();
// write header
buffer = HEADER.write(buffer, c, true);
// write fields
for (FieldPacket field : FIELDS) {
buffer = field.write(buffer, c, true);
}
// write eof
buffer = EOF.write(buffer, c, true);
// write rows
byte packetId = EOF.getPacketId();
Map<String, UserStat> statMap = UserStatAnalyzer.getInstance().getUserStatMap();
for (UserStat userStat : statMap.values()) {
String user = userStat.getUser();
List<SQLRecord> keyList = userStat.getSqlRecorder().getRecords();
for (SQLRecord key : keyList) {
if (key != null) {
RowDataPacket row = getRow(user, key, c.getCharset().getResults());
row.setPacketId(++packetId);
buffer = row.write(buffer, c, true);
}
}
if (isClear) {
userStat.clearSqlSlow();
}
}
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.setPacketId(++packetId);
buffer = lastEof.write(buffer, c, true);
// write buffer
c.write(buffer);
}
use of com.actiontech.dble.statistic.SQLRecord in project dble by actiontech.
the class UserStat method update.
/**
* @param sqlType
* @param sql
* @param startTime
*/
public void update(int sqlType, String sql, long sqlRows, long netInBytes, long netOutBytes, long startTime, long endTime, int resultSetSize) {
// -----------------------------------------------------
int invoking = runningCount.incrementAndGet();
for (; ; ) {
int max = concurrentMax.get();
if (invoking > max) {
if (concurrentMax.compareAndSet(max, invoking)) {
break;
}
} else {
break;
}
}
// -----------------------------------------------------
// slow sql
long executeTime = endTime - startTime;
if (executeTime >= sqlSlowTime) {
SQLRecord record = new SQLRecord();
record.setExecuteTime(executeTime);
record.setStatement(sql);
record.setStartTime(startTime);
this.sqlRecorder.add(record);
}
// sqlRwStat
this.sqlRwStat.setConcurrentMax(concurrentMax.get());
this.sqlRwStat.add(sqlType, sql, executeTime, netInBytes, netOutBytes, startTime, endTime);
// sqlLastStatSQL
this.sqlLastStat.add(sql, executeTime, startTime, endTime);
// sqlHighStat
this.sqlHighStat.addSql(sql, executeTime, startTime, endTime);
// sqlLargeStat large than 10000 rows
if (sqlType == ServerParse.SELECT && sqlRows > 10000) {
this.sqlLargeStat.add(sql, sqlRows, executeTime, startTime, endTime);
}
// big size sql
if (resultSetSize >= DbleServer.getInstance().getConfig().getSystem().getMaxResultSet()) {
this.sqlResultSizeRecorder.addSql(sql, resultSetSize);
}
// after
// -----------------------------------------------------
runningCount.decrementAndGet();
}
Aggregations