[PATCH]add expr_matcher hit pattern statistics

This commit is contained in:
liuwentan
2023-12-27 12:04:15 +08:00
parent 102c8ac0f8
commit 6d5fea298a
36 changed files with 1643 additions and 1080 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -11,7 +11,7 @@
#define MODULE_IPPORT_PLUGIN_GTEST module_name_str("maat.ipport_plugin_gtest")
#define ARRAY_SIZE 10
#define PERF_SCAN_COUNT 1000 * 1000
#define PERF_scan_times 1000 * 1000
const char *table_info_path = "./ipport_plugin_table_info.conf";
const char *log_file = "./ipport_plugin_gtest.log";
@@ -252,15 +252,18 @@ void *ipport_plugin_scan_thread(void *arg)
return is_all_hit;
}
static void test_add_ipport_plugin_command(struct maat *maat_inst, const char *table_name,
static int test_add_ipport_plugin_command(struct maat *maat_inst, const char *table_name,
long long item_id, const char *ip_str, int port1, int port2)
{
int table_id = maat_get_table_id(maat_inst, table_name);
assert(table_id >= 0);
enum table_type table_type = table_manager_get_table_type(maat_inst->tbl_mgr, table_id);
assert(table_type == TABLE_TYPE_IPPORT_PLUGIN);
if (table_id < 0) {
return -1;
}
enum table_type table_type = table_manager_get_table_type(maat_inst->tbl_mgr, table_id);
if (table_type != TABLE_TYPE_IPPORT_PLUGIN) {
return -1;
}
char table_line[1024] = {0};
sprintf(table_line, "%lld\t4\t%s\t%d\t%d\t1", item_id, ip_str, port1, port2);
@@ -272,17 +275,22 @@ static void test_add_ipport_plugin_command(struct maat *maat_inst, const char *t
line_rule.expire_after = 0;
maat_cmd_set_line(maat_inst, &line_rule);
return 0;
}
static void test_del_ipport_plugin_command(struct maat *maat_inst, const char *table_name,
static int test_del_ipport_plugin_command(struct maat *maat_inst, const char *table_name,
long long item_id, const char *ip_str, int port1, int port2)
{
int table_id = maat_get_table_id(maat_inst, table_name);
assert(table_id >= 0);
enum table_type table_type = table_manager_get_table_type(maat_inst->tbl_mgr, table_id);
assert(table_type == TABLE_TYPE_IPPORT_PLUGIN);
if (table_id < 0) {
return -1;
}
enum table_type table_type = table_manager_get_table_type(maat_inst->tbl_mgr, table_id);
if (table_type != TABLE_TYPE_IPPORT_PLUGIN) {
return -1;
}
char table_line[1024] = {0};
sprintf(table_line, "%lld\t4\t%s\t%d\t%d\t0", item_id, ip_str, port1, port2);
@@ -294,6 +302,8 @@ static void test_del_ipport_plugin_command(struct maat *maat_inst, const char *t
line_rule.expire_after = 0;
maat_cmd_set_line(maat_inst, &line_rule);
return 0;
}
void *ipport_plugin_update_thread(void *arg)
@@ -303,16 +313,29 @@ void *ipport_plugin_update_thread(void *arg)
const char *table_name = param->table_name;
const int CMD_EXPR_NUM = 256;
long long item_id = 9000000;
int ret = 0;
for (int i = 0; i < CMD_EXPR_NUM; i++) {
test_add_ipport_plugin_command(maat_inst, table_name, item_id, g_ip_str, i+201, i+201);
ret = test_add_ipport_plugin_command(maat_inst, table_name, item_id, g_ip_str, i+201, i+201);
if (ret < 0) {
log_fatal(param->logger, MODULE_IPPORT_PLUGIN_GTEST,
"[%s:%d]add ipport rule(item_id:%lld) for table:%s failed.",
__FUNCTION__, __LINE__, item_id, table_name);
continue;
}
item_id++;
usleep(100 * 1000);
}
item_id = 9000000;
for (int i = 0; i < CMD_EXPR_NUM; i++) {
test_del_ipport_plugin_command(maat_inst, table_name, item_id, g_ip_str, i+201, i+201);
ret = test_del_ipport_plugin_command(maat_inst, table_name, item_id, g_ip_str, i+201, i+201);
if (ret < 0) {
log_fatal(param->logger, MODULE_IPPORT_PLUGIN_GTEST,
"[%s:%d]del ipport rule(item_id:%lld) for table:%s failed.",
__FUNCTION__, __LINE__, item_id, table_name);
continue;
}
usleep(100 * 1000);
item_id++;
}
@@ -364,7 +387,7 @@ TEST_F(IPPortPluginTable, WITHOUT_SAME_IP) {
thread_params[i].thread_id = i;
thread_params[i].table_name = table_name;
thread_params[i].port = 10;
thread_params[i].test_count = PERF_SCAN_COUNT;
thread_params[i].test_count = PERF_scan_times;
thread_params[i].time_elapse_ms = 0;
thread_params[i].logger = logger;
}
@@ -385,7 +408,7 @@ TEST_F(IPPortPluginTable, WITHOUT_SAME_IP) {
}
maat_free(maat_inst);
scan_per_second = PERF_SCAN_COUNT * 1000 / time_elapse_ms;
scan_per_second = PERF_scan_times * 1000 / time_elapse_ms;
log_info(maat_inst->logger, MODULE_IPPORT_PLUGIN_GTEST,
"IpportPluginScan without same ip match rate speed %lld lookups/s/thread",
scan_per_second);
@@ -432,7 +455,7 @@ TEST_F(IPPortPluginTable, WITH_256SAME_IP) {
thread_params[i].thread_id = i;
thread_params[i].table_name = table_name;
thread_params[i].port = 10;
thread_params[i].test_count = PERF_SCAN_COUNT;
thread_params[i].test_count = PERF_scan_times;
thread_params[i].time_elapse_ms = 0;
thread_params[i].logger = logger;
}
@@ -453,7 +476,7 @@ TEST_F(IPPortPluginTable, WITH_256SAME_IP) {
}
maat_free(maat_inst);
scan_per_second = PERF_SCAN_COUNT * 1000 / time_elapse_ms;
scan_per_second = PERF_scan_times * 1000 / time_elapse_ms;
log_info(maat_inst->logger, MODULE_IPPORT_PLUGIN_GTEST,
"IpportPluginScan with 256 same ip match rate speed %lld lookups/s/thread",
scan_per_second);
@@ -466,4 +489,4 @@ int main(int argc, char ** argv)
ret = RUN_ALL_TESTS();
return ret;
}
}

View File

@@ -124,7 +124,7 @@
"match_method": "sub",
"case_sensitive": "yes",
"is_hexbin": "no",
"pattern": "pat"
"pattern": "directed graph"
}
]
},
@@ -178,7 +178,7 @@
},
{
"expr_id": 113,
"pattern_num": 1,
"pattern_num": 2,
"patterns": [
{
"pattern_type": "literal",
@@ -186,6 +186,13 @@
"case_sensitive": "yes",
"is_hexbin": "no",
"pattern": "a finite or infinite"
},
{
"pattern_type": "literal",
"match_method": "sub",
"case_sensitive": "yes",
"is_hexbin": "no",
"pattern": "directed path"
}
]
},
@@ -201,6 +208,33 @@
"pattern": "query=(.*)"
}
]
},
{
"expr_id": 115,
"pattern_num": 3,
"patterns": [
{
"pattern_type": "literal",
"match_method": "sub",
"case_sensitive": "yes",
"is_hexbin": "no",
"pattern": "one"
},
{
"pattern_type": "literal",
"match_method": "sub",
"case_sensitive": "yes",
"is_hexbin": "no",
"pattern": "two"
},
{
"pattern_type": "literal",
"match_method": "sub",
"case_sensitive": "yes",
"is_hexbin": "no",
"pattern": "three"
}
]
}
]
}

View File

@@ -9005,8 +9005,8 @@ TEST_F(MaatCmdTest, HitGroup) {
&n_hit_result, state);
EXPECT_EQ(ret, MAAT_SCAN_OK);
size_t scan_count = maat_state_get_scan_count(state);
EXPECT_EQ(scan_count, 1);
size_t scan_times = maat_state_get_scan_count(state);
EXPECT_EQ(scan_times, 1);
struct maat_hit_group hit_groups[128];
memset(hit_groups, 0, sizeof(hit_groups));
@@ -9052,8 +9052,8 @@ TEST_F(MaatCmdTest, HitGroup) {
&n_hit_result, state);
EXPECT_EQ(ret, MAAT_SCAN_OK);
scan_count = maat_state_get_scan_count(state);
EXPECT_EQ(scan_count, 2);
scan_times = maat_state_get_scan_count(state);
EXPECT_EQ(scan_times, 2);
memset(hit_groups, 0, sizeof(hit_groups));
n_hit_group = maat_state_get_direct_hit_group_cnt(state);
@@ -9088,8 +9088,8 @@ TEST_F(MaatCmdTest, HitGroup) {
ret = maat_stream_scan(stream, keywords1, strlen(keywords1), results, ARRAY_SIZE,
&n_hit_result, state);
EXPECT_EQ(ret, MAAT_SCAN_HALF_HIT);
scan_count = maat_state_get_scan_count(state);
EXPECT_EQ(scan_count, 3);
scan_times = maat_state_get_scan_count(state);
EXPECT_EQ(scan_times, 3);
int ip_table_id = maat_get_table_id(maat_inst, ip_table_name);
ASSERT_GT(ip_table_id, 0);
@@ -9105,8 +9105,8 @@ TEST_F(MaatCmdTest, HitGroup) {
&n_hit_result, state);
EXPECT_EQ(ret, MAAT_SCAN_OK);
scan_count = maat_state_get_scan_count(state);
EXPECT_EQ(scan_count, 4);
scan_times = maat_state_get_scan_count(state);
EXPECT_EQ(scan_times, 4);
memset(hit_groups, 0, sizeof(hit_groups));
n_hit_group = maat_state_get_direct_hit_group_cnt(state);
@@ -9125,23 +9125,28 @@ TEST_F(MaatCmdTest, HitGroup) {
ARRAY_SIZE, &n_hit_result, state);
EXPECT_EQ(ret, MAAT_SCAN_HALF_HIT);
scan_count = maat_state_get_scan_count(state);
EXPECT_EQ(scan_count, 5);
scan_times = maat_state_get_scan_count(state);
EXPECT_EQ(scan_times, 5);
memset(hit_groups, 0, sizeof(hit_groups));
n_hit_group = maat_state_get_direct_hit_group_cnt(state);
maat_state_get_direct_hit_groups(state, hit_groups, n_hit_group);
EXPECT_EQ(n_hit_group, 1);
EXPECT_EQ(n_hit_group, 2);
EXPECT_EQ(hit_groups[0].item_id, item5_id);
EXPECT_EQ(hit_groups[0].group_id, group1_id);
EXPECT_EQ(hit_groups[0].vtable_id, keywords_table_id); //physical table(keywords_table) vtable_id is 0
EXPECT_EQ(hit_groups[1].item_id, item4_id);
EXPECT_EQ(hit_groups[1].group_id, group4_id);
EXPECT_EQ(hit_groups[1].vtable_id, keywords_table_id); //physical table(keywords_table) vtable_id is 0
n_last_hit_group = maat_state_get_last_hit_group_id_cnt(state);
maat_state_get_last_hit_group_ids(state, last_hit_group_ids, 128);
EXPECT_EQ(n_last_hit_group, 2);
EXPECT_EQ(n_last_hit_group, 3);
EXPECT_EQ(last_hit_group_ids[0], group1_id);
EXPECT_EQ(last_hit_group_ids[1], group11_id);
EXPECT_EQ(last_hit_group_ids[1], group4_id);
EXPECT_EQ(last_hit_group_ids[2], group11_id);
maat_stream_free(stream);
maat_state_free(state);
@@ -9263,8 +9268,8 @@ TEST_F(MaatCmdTest, HitPathBasic) {
&n_hit_result, state);
EXPECT_EQ(ret, MAAT_SCAN_OK);
size_t scan_count = maat_state_get_scan_count(state);
EXPECT_EQ(scan_count, 1);
size_t scan_times = maat_state_get_scan_count(state);
EXPECT_EQ(scan_times, 1);
struct maat_hit_path hit_path[128];
memset(hit_path, 0, sizeof(hit_path));
@@ -9306,8 +9311,8 @@ TEST_F(MaatCmdTest, HitPathBasic) {
&n_hit_result, state);
EXPECT_EQ(ret, MAAT_SCAN_OK);
scan_count = maat_state_get_scan_count(state);
EXPECT_EQ(scan_count, 2);
scan_times = maat_state_get_scan_count(state);
EXPECT_EQ(scan_times, 2);
n_read = maat_state_get_hit_paths(state, hit_path, sizeof(hit_path));
EXPECT_EQ(n_read, 4);
@@ -9364,8 +9369,8 @@ that the edges be all directed in the same direction.";
&n_hit_result, state);
EXPECT_EQ(ret, MAAT_SCAN_OK);
scan_count = maat_state_get_scan_count(state);
EXPECT_EQ(scan_count, 3);
scan_times = maat_state_get_scan_count(state);
EXPECT_EQ(scan_times, 3);
n_read = maat_state_get_hit_paths(state, hit_path, sizeof(hit_path));
EXPECT_EQ(n_read, 5);
@@ -9394,8 +9399,8 @@ that the edges be all directed in the same direction.";
&n_hit_result, state);
EXPECT_EQ(ret, MAAT_SCAN_OK);
scan_count = maat_state_get_scan_count(state);
EXPECT_EQ(scan_count, 4);
scan_times = maat_state_get_scan_count(state);
EXPECT_EQ(scan_times, 4);
n_read = maat_state_get_hit_paths(state, hit_path, sizeof(hit_path));
EXPECT_EQ(n_read, 6);
@@ -9418,8 +9423,8 @@ that the edges be all directed in the same direction.";
&n_hit_result, state);
EXPECT_EQ(ret, MAAT_SCAN_OK);
scan_count = maat_state_get_scan_count(state);
EXPECT_EQ(scan_count, 5);
scan_times = maat_state_get_scan_count(state);
EXPECT_EQ(scan_times, 5);
n_read = maat_state_get_hit_paths(state, hit_path, sizeof(hit_path));
EXPECT_EQ(n_read, 7);
@@ -9927,8 +9932,8 @@ TEST_F(MaatCmdTest, HitPathHasNotGroup) {
&n_hit_result, state);
EXPECT_EQ(ret, MAAT_SCAN_OK);
size_t scan_count = maat_state_get_scan_count(state);
EXPECT_EQ(scan_count, 1);
size_t scan_times = maat_state_get_scan_count(state);
EXPECT_EQ(scan_times, 1);
struct maat_hit_path hit_path[128];
memset(hit_path, 0, sizeof(hit_path));
@@ -9972,8 +9977,8 @@ TEST_F(MaatCmdTest, HitPathHasNotGroup) {
&n_hit_result, state);
EXPECT_EQ(ret, MAAT_SCAN_OK);
scan_count = maat_state_get_scan_count(state);
EXPECT_EQ(scan_count, 2);
scan_times = maat_state_get_scan_count(state);
EXPECT_EQ(scan_times, 2);
n_read = maat_state_get_hit_paths(state, hit_path, sizeof(hit_path));
EXPECT_EQ(n_read, 4);
@@ -10031,8 +10036,8 @@ TEST_F(MaatCmdTest, HitPathHasNotGroup) {
&n_hit_result, state);
EXPECT_EQ(ret, MAAT_SCAN_OK);
scan_count = maat_state_get_scan_count(state);
EXPECT_EQ(scan_count, 3);
scan_times = maat_state_get_scan_count(state);
EXPECT_EQ(scan_times, 3);
n_read = maat_state_get_hit_paths(state, hit_path, sizeof(hit_path));
EXPECT_EQ(n_read, 5);
@@ -10062,8 +10067,8 @@ TEST_F(MaatCmdTest, HitPathHasNotGroup) {
&n_hit_result, state);
EXPECT_EQ(ret, MAAT_SCAN_OK);
scan_count = maat_state_get_scan_count(state);
EXPECT_EQ(scan_count, 4);
scan_times = maat_state_get_scan_count(state);
EXPECT_EQ(scan_times, 4);
n_read = maat_state_get_hit_paths(state, hit_path, sizeof(hit_path));
EXPECT_EQ(n_read, 6);
@@ -10087,8 +10092,8 @@ TEST_F(MaatCmdTest, HitPathHasNotGroup) {
&n_hit_result, state);
EXPECT_EQ(ret, MAAT_SCAN_OK);
scan_count = maat_state_get_scan_count(state);
EXPECT_EQ(scan_count, 5);
scan_times = maat_state_get_scan_count(state);
EXPECT_EQ(scan_times, 5);
n_read = maat_state_get_hit_paths(state, hit_path, sizeof(hit_path));
EXPECT_EQ(n_read, 7);

View File

@@ -15,14 +15,14 @@
#define ARRAY_SIZE 10
#define WAIT_FOR_EFFECTIVE_S 2
#define PERF_THREAD_NUM 5
#define PERF_SCAN_COUNT 1000 * 1000
#define PERF_SCAN_TIMES 1000 * 1000
const char *table_info_path = "./table_info.conf";
const char *json_filename = "maat_json.json";
struct thread_param {
int thread_id;
int test_count;
int test_times;
struct maat *maat_inst;
const char *table_name;
long long time_elapse_ms;
@@ -449,7 +449,7 @@ void *perf_string_scan_thread(void *arg)
struct timespec start, end;
clock_gettime(CLOCK_MONOTONIC, &start);
for (int i = 0; i < param->test_count; i++) {
for (int i = 0; i < param->test_times; i++) {
int ret = maat_scan_string(maat_inst, table_id, scan_data, strlen(scan_data),
results, ARRAY_SIZE, &n_hit_result, state);
if (ret == MAAT_SCAN_HIT) {
@@ -462,7 +462,7 @@ void *perf_string_scan_thread(void *arg)
param->time_elapse_ms = (end.tv_sec - start.tv_sec) * 1000 +
(end.tv_nsec - start.tv_nsec) / 1000000;
int *is_all_hit = ALLOC(int, 1);
*is_all_hit = (hit_times == param->test_count ? 1 : 0);
*is_all_hit = (hit_times == param->test_times ? 1 : 0);
log_info(param->logger, MODULE_FRAMEWORK_PERF_GTEST,
"thread_id:%d string_scan time_elapse:%lldms hit_times:%d",
param->thread_id, param->time_elapse_ms, hit_times);
@@ -505,31 +505,31 @@ TEST_F(MaatPerfStringScan, LiteralMultiThread) {
thread_params[i].maat_inst = maat_inst;
thread_params[i].thread_id = i;
thread_params[i].table_name = table_name;
thread_params[i].test_count = PERF_SCAN_COUNT;
thread_params[i].test_times = PERF_SCAN_TIMES;
thread_params[i].time_elapse_ms = 0;
thread_params[i].logger = logger;
if (i < PERF_THREAD_NUM) {
pthread_create(&threads[i], NULL, perf_string_scan_thread, thread_params+i);
} else {
thread_params[i].test_count = 0;
thread_params[i].test_times = 0;
pthread_create(&threads[i], NULL, perf_string_update_thread, thread_params+i);
}
}
long long time_elapse_ms = 0;
long long scan_count = 0;
long long scan_times = 0;
long long scan_per_second = 0;
for (i = 0; i < PERF_THREAD_NUM + 1; i++) {
pthread_join(threads[i], (void **)&is_all_hit);
time_elapse_ms += thread_params[i].time_elapse_ms;
scan_count += thread_params[i].test_count;
scan_times += thread_params[i].test_times;
EXPECT_EQ(*is_all_hit, 1);
*is_all_hit = 0;
free(is_all_hit);
}
scan_per_second = scan_count * 1000 / time_elapse_ms;
scan_per_second = scan_times * 1000 / time_elapse_ms;
log_info(maat_inst->logger, MODULE_FRAMEWORK_PERF_GTEST,
"StringScan match rate on %d-threads speed %lld lookups/s/thread",
PERF_THREAD_NUM, scan_per_second);
@@ -599,7 +599,7 @@ void *perf_regex_scan_thread(void *arg)
maat_register_thread(maat_inst);
clock_gettime(CLOCK_MONOTONIC, &start);
for (int i = 0; i < param->test_count; i++) {
for (int i = 0; i < param->test_times; i++) {
int ret = maat_scan_string(maat_inst, table_id, scan_data, strlen(scan_data),
results, ARRAY_SIZE, &n_hit_result, state);
if (ret == MAAT_SCAN_HIT) {
@@ -612,7 +612,7 @@ void *perf_regex_scan_thread(void *arg)
param->time_elapse_ms = (end.tv_sec - start.tv_sec) * 1000 +
(end.tv_nsec - start.tv_nsec) / 1000000;
int *is_all_hit = ALLOC(int, 1);
*is_all_hit = (hit_times == param->test_count ? 1 : 0);
*is_all_hit = (hit_times == param->test_times ? 1 : 0);
log_info(param->logger, MODULE_FRAMEWORK_PERF_GTEST,
"thread_id:%d regex_scan time_elapse:%lldms hit_times:%d",
param->thread_id, param->time_elapse_ms, hit_times);
@@ -655,31 +655,31 @@ TEST_F(MaatPerfRegexScan, RegexMultiThread) {
thread_params[i].maat_inst = maat_inst;
thread_params[i].thread_id = i;
thread_params[i].table_name = table_name;
thread_params[i].test_count = PERF_SCAN_COUNT;
thread_params[i].test_times = PERF_SCAN_TIMES;
thread_params[i].time_elapse_ms = 0;
thread_params[i].logger = logger;
if (i < PERF_THREAD_NUM) {
pthread_create(&threads[i], NULL, perf_regex_scan_thread, thread_params+i);
} else {
thread_params[i].test_count = 0;
thread_params[i].test_times = 0;
pthread_create(&threads[i], NULL, perf_regex_update_thread, thread_params+i);
}
}
long long time_elapse_ms = 0;
long long scan_count = 0;
long long scan_times = 0;
long long scan_per_second = 0;
for (i = 0; i < PERF_THREAD_NUM + 1; i++) {
pthread_join(threads[i], (void **)&is_all_hit);
time_elapse_ms += thread_params[i].time_elapse_ms;
scan_count += thread_params[i].test_count;
scan_times += thread_params[i].test_times;
EXPECT_EQ(*is_all_hit, 1);
*is_all_hit = 0;
free(is_all_hit);
}
scan_per_second = scan_count * 1000 / time_elapse_ms;
scan_per_second = scan_times * 1000 / time_elapse_ms;
log_info(maat_inst->logger, MODULE_FRAMEWORK_PERF_GTEST,
"RegexScan match rate on %d-threads speed %lld lookups/s/thread",
@@ -701,7 +701,7 @@ void *perf_integer_scan_thread(void *arg)
maat_register_thread(maat_inst);
clock_gettime(CLOCK_MONOTONIC, &start);
for (int i = 0; i < param->test_count; i++) {
for (int i = 0; i < param->test_times; i++) {
int ret = maat_scan_integer(maat_inst, table_id, 3000, results,
ARRAY_SIZE, &n_hit_result, state);
if (ret == MAAT_SCAN_HIT) {
@@ -714,7 +714,7 @@ void *perf_integer_scan_thread(void *arg)
param->time_elapse_ms = (end.tv_sec - start.tv_sec) * 1000 +
(end.tv_nsec - start.tv_nsec) / 1000000;
int *is_all_hit = ALLOC(int, 1);
*is_all_hit = (hit_times == param->test_count ? 1 : 0);
*is_all_hit = (hit_times == param->test_times ? 1 : 0);
log_info(param->logger, MODULE_FRAMEWORK_PERF_GTEST,
"thread_id:%d integer_scan time_elapse:%lldms hit_times:%d",
param->thread_id, param->time_elapse_ms, hit_times);
@@ -804,7 +804,7 @@ void *perf_stream_scan_thread(void *arg)
maat_register_thread(maat_inst);
clock_gettime(CLOCK_MONOTONIC, &start);
for (int i = 0; i < param->test_count; i++) {
for (int i = 0; i < param->test_times; i++) {
ret = maat_stream_scan(sp, scan_data, strlen(scan_data), results, ARRAY_SIZE,
&n_hit_result, state);
if (ret == MAAT_SCAN_HIT) {
@@ -819,7 +819,7 @@ void *perf_stream_scan_thread(void *arg)
param->time_elapse_ms = (end.tv_sec - start.tv_sec) * 1000 +
(end.tv_nsec - start.tv_nsec) / 1000000;
int *is_all_hit = ALLOC(int, 1);
*is_all_hit = ((hit_times == param->test_count) ? 1 : 0);
*is_all_hit = ((hit_times == param->test_times) ? 1 : 0);
log_info(param->logger, MODULE_FRAMEWORK_PERF_GTEST,
"thread_id:%d stream_scan time_elapse:%lldms hit_times:%d",
@@ -843,7 +843,7 @@ TEST_F(MaatPerfStreamScan, MultiThread) {
thread_params[i].maat_inst = maat_inst;
thread_params[i].thread_id = i;
thread_params[i].table_name = table_name;
thread_params[i].test_count = PERF_SCAN_COUNT;
thread_params[i].test_times = PERF_SCAN_TIMES;
thread_params[i].time_elapse_ms = 0;
thread_params[i].logger = logger;
@@ -853,17 +853,17 @@ TEST_F(MaatPerfStreamScan, MultiThread) {
}
long long time_elapse_ms = 0;
long long scan_count = 0;
long long scan_times = 0;
long long scan_per_second = 0;
for (i = 0; i < PERF_THREAD_NUM; i++) {
pthread_join(threads[i], (void **)&is_all_hit);
time_elapse_ms += thread_params[i].time_elapse_ms;
scan_count += thread_params[i].test_count;
scan_times += thread_params[i].test_times;
//maybe expr_runtime rebuild in stream_scan, so should not expect is_all_hit always 1
EXPECT_EQ(*is_all_hit, 1);
free(is_all_hit);
}
scan_per_second = scan_count * 1000 / time_elapse_ms;
scan_per_second = scan_times * 1000 / time_elapse_ms;
log_info(maat_inst->logger, MODULE_FRAMEWORK_PERF_GTEST,
"StreamScan match rate on %d-threads speed %lld lookups/s/thread",
@@ -939,7 +939,7 @@ void *perf_ip_scan_thread(void *arg)
maat_register_thread(maat_inst);
clock_gettime(CLOCK_MONOTONIC, &start);
for (int i = 0; i < param->test_count; i++) {
for (int i = 0; i < param->test_times; i++) {
int ret = maat_scan_ipv4(maat_inst, table_id, ip_addr, port, 6,
results, ARRAY_SIZE, &n_hit_result, state);
if (ret == MAAT_SCAN_HIT) {
@@ -952,7 +952,7 @@ void *perf_ip_scan_thread(void *arg)
param->time_elapse_ms = (end.tv_sec - start.tv_sec) * 1000 +
(end.tv_nsec - start.tv_nsec) / 1000000;
int *is_all_hit = ALLOC(int, 1);
*is_all_hit = (hit_times == param->test_count ? 1 : 0);
*is_all_hit = (hit_times == param->test_times ? 1 : 0);
log_info(param->logger, MODULE_FRAMEWORK_PERF_GTEST,
"thread_id:%d ip_scan time_elapse:%lldms hit_times:%d",
param->thread_id, param->time_elapse_ms, hit_times);
@@ -1006,31 +1006,31 @@ TEST_F(MaatPerfIPScan, MultiThread)
thread_params[i].maat_inst = maat_inst;
thread_params[i].thread_id = i;
thread_params[i].table_name = table_name;
thread_params[i].test_count = PERF_SCAN_COUNT;
thread_params[i].test_times = PERF_SCAN_TIMES;
thread_params[i].time_elapse_ms = 0;
thread_params[i].logger = logger;
if (i < PERF_THREAD_NUM) {
pthread_create(&threads[i], NULL, perf_ip_scan_thread, thread_params+i);
} else {
thread_params[i].test_count = 0;
thread_params[i].test_times = 0;
pthread_create(&threads[i], NULL, perf_ip_update_thread, thread_params+i);
}
}
long long time_elapse_ms = 0;
long long scan_count = 0;
long long scan_times = 0;
long long scan_per_second = 0;
for (i = 0; i < PERF_THREAD_NUM + 1; i++) {
pthread_join(threads[i], (void **)&is_all_hit);
time_elapse_ms += thread_params[i].time_elapse_ms;
scan_count += thread_params[i].test_count;
scan_times += thread_params[i].test_times;
EXPECT_EQ(*is_all_hit, 1);
*is_all_hit = 0;
free(is_all_hit);
}
scan_per_second = scan_count * 1000 / time_elapse_ms;
scan_per_second = scan_times * 1000 / time_elapse_ms;
log_info(maat_inst->logger, MODULE_FRAMEWORK_PERF_GTEST,
"IPScan match rate on %d-threads speed %lld lookups/s/thread",
@@ -1101,31 +1101,31 @@ TEST_F(MaatPerfIntegerScan, MultiThread) {
thread_params[i].maat_inst = maat_inst;
thread_params[i].thread_id = i;
thread_params[i].table_name = table_name;
thread_params[i].test_count = PERF_SCAN_COUNT;
thread_params[i].test_times = PERF_SCAN_TIMES;
thread_params[i].time_elapse_ms = 0;
thread_params[i].logger = logger;
if (i < PERF_THREAD_NUM) {
pthread_create(&threads[i], NULL, perf_integer_scan_thread, thread_params+i);
} else {
thread_params[i].test_count = 0;
thread_params[i].test_times = 0;
pthread_create(&threads[i], NULL, perf_integer_update_thread, thread_params+i);
}
}
long long time_elapse_ms = 0;
long long scan_count = 0;
long long scan_times = 0;
long long scan_per_second = 0;
for (i = 0; i < PERF_THREAD_NUM + 1; i++) {
pthread_join(threads[i], (void **)&is_all_hit);
time_elapse_ms += thread_params[i].time_elapse_ms;
scan_count += thread_params[i].test_count;
scan_times += thread_params[i].test_times;
EXPECT_EQ(*is_all_hit, 1);
*is_all_hit = 0;
free(is_all_hit);
}
scan_per_second = scan_count * 1000 / time_elapse_ms;
scan_per_second = scan_times * 1000 / time_elapse_ms;
log_info(maat_inst->logger, MODULE_FRAMEWORK_PERF_GTEST,
"IntegerScan match rate on %d-threads speed %lld lookups/s/thread",
@@ -1195,7 +1195,7 @@ void *perf_flag_scan_thread(void *arg)
int table_id = maat_get_table_id(maat_inst, table_name);
clock_gettime(CLOCK_MONOTONIC, &start);
for (int i = 0; i < param->test_count; i++) {
for (int i = 0; i < param->test_times; i++) {
int ret = maat_scan_flag(maat_inst, table_id, scan_data, results,
ARRAY_SIZE, &n_hit_result, state);
if (ret == MAAT_SCAN_HIT) {
@@ -1208,7 +1208,7 @@ void *perf_flag_scan_thread(void *arg)
param->time_elapse_ms = (end.tv_sec - start.tv_sec) * 1000 +
(end.tv_nsec - start.tv_nsec) / 1000000;
int *is_all_hit = ALLOC(int, 1);
*is_all_hit = (hit_times == param->test_count ? 1 : 0);
*is_all_hit = (hit_times == param->test_times ? 1 : 0);
log_info(param->logger, MODULE_FRAMEWORK_PERF_GTEST,
"thread_id:%d flag_scan time_elapse:%lldms hit_times:%d",
param->thread_id, param->time_elapse_ms, hit_times);
@@ -1249,31 +1249,31 @@ TEST_F(MaatPerfFlagScan, MultiThread) {
thread_params[i].maat_inst = maat_inst;
thread_params[i].thread_id = i;
thread_params[i].table_name = table_name;
thread_params[i].test_count = PERF_SCAN_COUNT;
thread_params[i].test_times = PERF_SCAN_TIMES;
thread_params[i].time_elapse_ms = 0;
thread_params[i].logger = logger;
if (i < PERF_THREAD_NUM) {
pthread_create(&threads[i], NULL, perf_flag_scan_thread, thread_params+i);
} else {
thread_params[i].test_count = 0;
thread_params[i].test_times = 0;
pthread_create(&threads[i], NULL, perf_flag_update_thread, thread_params+i);
}
}
long long time_elapse_ms = 0;
long long scan_count = 0;
long long scan_times = 0;
long long scan_per_second = 0;
for (i = 0; i < PERF_THREAD_NUM + 1; i++) {
pthread_join(threads[i], (void **)&is_all_hit);
time_elapse_ms += thread_params[i].time_elapse_ms;
scan_count += thread_params[i].test_count;
scan_times += thread_params[i].test_times;
EXPECT_EQ(*is_all_hit, 1);
*is_all_hit = 0;
free(is_all_hit);
}
scan_per_second = scan_count * 1000 / time_elapse_ms;
scan_per_second = scan_times * 1000 / time_elapse_ms;
log_info(maat_inst->logger, MODULE_FRAMEWORK_PERF_GTEST,
"FlagScan match rate on %d-threads speed %lld lookups/s/thread",
@@ -1382,7 +1382,7 @@ void* perf_fqdn_plugin_scan_thread(void *arg)
struct timespec start, end;
clock_gettime(CLOCK_MONOTONIC, &start);
for (i = 0; i < param->test_count; i++) {
for (i = 0; i < param->test_times; i++) {
ret = maat_fqdn_plugin_table_get_ex_data(maat_inst, table_id,
"r3---sn-i3belne6.example2.com",
@@ -1396,7 +1396,7 @@ void* perf_fqdn_plugin_scan_thread(void *arg)
param->time_elapse_ms = (end.tv_sec - start.tv_sec) * 1000 +
(end.tv_nsec - start.tv_nsec) / 1000000;
int* is_all_hit = (int*)malloc(sizeof(int));
*is_all_hit = (hit_times == param->test_count) ? 1 : 0;
*is_all_hit = (hit_times == param->test_times) ? 1 : 0;
log_info(param->logger, MODULE_FRAMEWORK_PERF_GTEST,
"thread_id:%d fqdn_plugin_get_ex_data time_elapse:%lldms hit_times:%d",
param->thread_id, param->time_elapse_ms, hit_times);
@@ -1477,31 +1477,31 @@ TEST_F(MaatPerfFQDNPluginScan, MultiThread) {
thread_params[i].maat_inst = maat_inst;
thread_params[i].thread_id = i;
thread_params[i].table_name = table_name;
thread_params[i].test_count = PERF_SCAN_COUNT;
thread_params[i].test_times = PERF_SCAN_TIMES;
thread_params[i].time_elapse_ms = 0;
thread_params[i].logger = logger;
if (i < PERF_THREAD_NUM) {
pthread_create(&threads[i], NULL, perf_fqdn_plugin_scan_thread, thread_params + i);
} else {
thread_params[i].test_count = 0;
thread_params[i].test_times = 0;
pthread_create(&threads[i], NULL, perf_fqdn_plugin_update_thread, thread_params + i);
}
}
long long time_elapse_ms = 0;
long long scan_count = 0;
long long scan_times = 0;
long long scan_per_second = 0;
for (i = 0; i < PERF_THREAD_NUM + 1; i++) {
pthread_join(threads[i], (void **)&is_all_hit);
time_elapse_ms += thread_params[i].time_elapse_ms;
scan_count += thread_params[i].test_count;
scan_times += thread_params[i].test_times;
EXPECT_EQ(*is_all_hit, 1);
*is_all_hit = 0;
free(is_all_hit);
}
scan_per_second = scan_count * 1000 / time_elapse_ms;
scan_per_second = scan_times * 1000 / time_elapse_ms;
log_info(maat_inst->logger, MODULE_FRAMEWORK_PERF_GTEST,
"FQDNPluginScan match rate on %d-threads speed %lld lookups/s/thread",
@@ -1613,7 +1613,7 @@ void* perf_bool_plugin_scan_thread(void *arg)
unsigned long long items_4[]={7, 0, 1, 2, 3, 4, 5, 6, 7, 7, 7};
clock_gettime(CLOCK_MONOTONIC, &start);
for (i = 0; i < param->test_count; i++) {
for (i = 0; i < param->test_times; i++) {
ret = maat_bool_plugin_table_get_ex_data(maat_inst, table_id, items_4,
sizeof(items_4)/sizeof(unsigned long long),
@@ -1627,7 +1627,7 @@ void* perf_bool_plugin_scan_thread(void *arg)
param->time_elapse_ms = (end.tv_sec - start.tv_sec) * 1000 +
(end.tv_nsec - start.tv_nsec) / 1000000;
int* is_all_hit = (int*)malloc(sizeof(int));
*is_all_hit = (hit_times == param->test_count) ? 1 : 0;
*is_all_hit = (hit_times == param->test_times) ? 1 : 0;
log_info(param->logger, MODULE_FRAMEWORK_PERF_GTEST,
"thread_id:%d bool_plugin_get_ex_data time_elapse:%lldms hit_times:%d",
@@ -1685,31 +1685,31 @@ TEST_F(MaatPerfBoolPluginScan, MultiThread) {
thread_params[i].maat_inst = maat_inst;
thread_params[i].thread_id = i;
thread_params[i].table_name = table_name;
thread_params[i].test_count = PERF_SCAN_COUNT;
thread_params[i].test_times = PERF_SCAN_TIMES;
thread_params[i].time_elapse_ms = 0;
thread_params[i].logger = logger;
if (i < PERF_THREAD_NUM) {
pthread_create(&threads[i], NULL, perf_bool_plugin_scan_thread, thread_params + i);
} else {
thread_params[i].test_count = 0;
thread_params[i].test_times = 0;
pthread_create(&threads[i], NULL, perf_bool_plugin_update_thread, thread_params + i);
}
}
long long time_elapse_ms = 0;
long long scan_count = 0;
long long scan_times = 0;
long long scan_per_second = 0;
for (i = 0; i < PERF_THREAD_NUM + 1; i++) {
pthread_join(threads[i], (void **)&is_all_hit);
time_elapse_ms += thread_params[i].time_elapse_ms;
scan_count += thread_params[i].test_count;
scan_times += thread_params[i].test_times;
EXPECT_EQ(*is_all_hit, 1);
*is_all_hit = 0;
free(is_all_hit);
}
scan_per_second = scan_count * 1000 / time_elapse_ms;
scan_per_second = scan_times * 1000 / time_elapse_ms;
log_info(maat_inst->logger, MODULE_FRAMEWORK_PERF_GTEST,
"BoolPluginScan match rate on %d-threads speed %lld lookups/s/thread",
@@ -1990,7 +1990,7 @@ static void *perf_ipport_plugin_scan_thread(void *arg)
inet_pton(AF_INET, "192.168.100.1", &ipv4.ipv4);
uint16_t port = htons(215);
for (i = 0; i < param->test_count; i++) {
for (i = 0; i < param->test_times; i++) {
ret = maat_ipport_plugin_table_get_ex_data(maat_inst, table_id, &ipv4,
port, (void**)results, 4);
if (ret > 0) {
@@ -1999,7 +1999,7 @@ static void *perf_ipport_plugin_scan_thread(void *arg)
}
int *is_all_hit = (int *)malloc(sizeof(int));
*is_all_hit = (hit_times == param->test_count) ? 1 : 0;
*is_all_hit = (hit_times == param->test_times) ? 1 : 0;
log_info(maat_inst->logger, MODULE_FRAMEWORK_PERF_GTEST,
"ipport_plugin_get_ex_data hit_times:%d", hit_times);
@@ -2056,14 +2056,14 @@ TEST_F(MaatPerfIPPortPluginScan, MultiThread) {
thread_params[i].maat_inst = maat_inst;
thread_params[i].thread_id = i;
thread_params[i].table_name = table_name;
thread_params[i].test_count = PERF_SCAN_COUNT;
thread_params[i].test_times = PERF_SCAN_TIMES;
thread_params[i].time_elapse_ms = 0;
thread_params[i].logger = logger;
if (i < PERF_THREAD_NUM) {
pthread_create(&threads[i], NULL, perf_ipport_plugin_scan_thread, thread_params+i);
} else {
thread_params[i].test_count = 0;
thread_params[i].test_times = 0;
pthread_create(&threads[i], NULL, perf_ipport_plugin_update_thread, thread_params+i);
}
}
@@ -2084,4 +2084,4 @@ int main(int argc, char ** argv)
ret=RUN_ALL_TESTS();
return ret;
}
}