use of com.actiontech.dble.statistic.stat.SqlFrequency in project dble by actiontech.
the class ShowSQLHigh 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<SqlFrequency> list = userStat.getSqlHigh().getSqlFrequency(isClear);
if (list != null) {
int i = 1;
for (SqlFrequency sqlFrequency : list) {
if (sqlFrequency != null) {
RowDataPacket row = getRow(i, user, sqlFrequency.getSql(), sqlFrequency.getCount(), sqlFrequency.getAvgTime(), sqlFrequency.getMaxTime(), sqlFrequency.getMinTime(), sqlFrequency.getExecuteTime(), sqlFrequency.getLastTime(), c.getCharset().getResults());
row.setPacketId(++packetId);
buffer = row.write(buffer, c, true);
i++;
}
}
}
}
// 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.stat.SqlFrequency in project dble by actiontech.
the class TestConcurrentSafety method testUserSqlHighStat.
@Test
@Ignore
public void testUserSqlHighStat() throws InterruptedException {
final UserSqlHighStat userSqlHighStat = new UserSqlHighStat();
Thread[] thread = new Thread[THREAD_COUNT];
Thread[] thread2 = new Thread[THREAD_COUNT];
Thread[] thread3 = new Thread[THREAD_COUNT];
for (int i = 0; i < THREAD_COUNT; i++) {
thread[i] = new Thread() {
@Override
public void run() {
for (int j = 0; j < LOOP_COUNT; j++) {
userSqlHighStat.addSql(sql, 10L, 1L, 11L);
}
}
};
thread2[i] = new Thread() {
@Override
public void run() {
for (int j = 0; j < LOOP_COUNT; j++) {
userSqlHighStat.addSql(sql2, 10L, 1L, 11L);
}
}
};
thread3[i] = new Thread() {
@Override
public void run() {
for (int j = 0; j < LOOP_COUNT; j++) {
userSqlHighStat.addSql(sql4, 10L, 1L, 11L);
}
}
};
}
for (int i = 0; i < THREAD_COUNT; i++) {
thread[i].start();
thread2[i].start();
thread3[i].start();
}
for (int i = 0; i < THREAD_COUNT; i++) {
thread[i].join();
thread2[i].join();
thread3[i].join();
}
List<SqlFrequency> sqlFrequency = userSqlHighStat.getSqlFrequency(true);
Assert.assertTrue(sqlFrequency.size() == 2);
Assert.assertTrue(sqlFrequency.get(0).getCount() == 2 * THREAD_COUNT * LOOP_COUNT);
Assert.assertTrue(sqlFrequency.get(1).getCount() == THREAD_COUNT * LOOP_COUNT);
}
Aggregations