[PATCH]add expr_matcher hit pattern statistics
This commit is contained in:
@@ -404,6 +404,9 @@ static void hs_lit_stream_reset(struct hs_lit_stream *hs_lit_stream)
|
||||
scratches[hs_lit_stream->thread_id],
|
||||
matched_event_cb, hs_lit_stream->matched_pat);
|
||||
}
|
||||
|
||||
utarray_clear(hs_lit_stream->matched_pat->pattern_ids);
|
||||
bloom_reset(hs_lit_stream->matched_pat->ref_bloom);
|
||||
}
|
||||
|
||||
static void hs_regex_stream_reset(struct hs_regex_stream *hs_regex_stream)
|
||||
@@ -418,6 +421,9 @@ static void hs_regex_stream_reset(struct hs_regex_stream *hs_regex_stream)
|
||||
scratches[hs_regex_stream->thread_id],
|
||||
matched_event_cb, hs_regex_stream->matched_pat);
|
||||
}
|
||||
|
||||
utarray_clear(hs_regex_stream->matched_pat->pattern_ids);
|
||||
bloom_reset(hs_regex_stream->matched_pat->ref_bloom);
|
||||
}
|
||||
|
||||
static int gather_hit_pattern_id(struct matched_pattern *matched_pat,
|
||||
@@ -436,8 +442,6 @@ static int gather_hit_pattern_id(struct matched_pattern *matched_pat,
|
||||
}
|
||||
|
||||
*n_pattern_id = array_index;
|
||||
utarray_clear(matched_pat->pattern_ids);
|
||||
bloom_reset(matched_pat->ref_bloom);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -282,8 +282,6 @@ static int gather_hit_pattern_id(struct matched_pattern *matched_pat,
|
||||
}
|
||||
|
||||
*n_pattern_id = array_index;
|
||||
utarray_clear(matched_pat->pattern_ids);
|
||||
bloom_reset(matched_pat->ref_bloom);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -365,6 +363,9 @@ int rs_lit_engine_scan(void *rs_lit_engine, int thread_id,
|
||||
struct rs_lit_stream *rs_lit_stream = rs_lit_inst->streams[thread_id];
|
||||
assert(rs_lit_stream != NULL);
|
||||
|
||||
utarray_clear(rs_lit_stream->matched_pat->pattern_ids);
|
||||
bloom_reset(rs_lit_stream->matched_pat->ref_bloom);
|
||||
|
||||
if (rs_lit_inst->rs_db != NULL) {
|
||||
int ret = rs_scan(rs_lit_inst->rs_db, thread_id, data, data_len,
|
||||
0, matched_event_cb, rs_lit_stream->matched_pat);
|
||||
@@ -536,6 +537,9 @@ int rs_regex_engine_scan(void *rs_regex_engine, int thread_id,
|
||||
struct rs_regex_stream *rs_regex_stream = rs_regex_inst->streams[thread_id];
|
||||
assert(rs_regex_stream != NULL);
|
||||
|
||||
utarray_clear(rs_regex_stream->matched_pat->pattern_ids);
|
||||
bloom_reset(rs_regex_stream->matched_pat->ref_bloom);
|
||||
|
||||
if (rs_regex_inst->rs_db != NULL) {
|
||||
int ret = rs_scan(rs_regex_inst->rs_db, thread_id, data, data_len,
|
||||
0, matched_event_cb, rs_regex_stream->matched_pat);
|
||||
|
||||
@@ -270,9 +270,10 @@ void expr_matcher_free(struct expr_matcher *matcher)
|
||||
FREE(matcher);
|
||||
}
|
||||
|
||||
struct expr_matcher *expr_matcher_new(struct expr_rule *rules, size_t n_rule,
|
||||
enum expr_engine_type engine_type,
|
||||
size_t n_thread, struct log_handle *logger)
|
||||
struct expr_matcher *
|
||||
expr_matcher_new(struct expr_rule *rules, size_t n_rule,
|
||||
enum expr_engine_type engine_type,
|
||||
size_t n_thread, struct log_handle *logger)
|
||||
{
|
||||
if (NULL == rules || 0 == n_rule || 0 == n_thread ||
|
||||
(engine_type != EXPR_ENGINE_TYPE_HS &&
|
||||
@@ -443,7 +444,8 @@ next:
|
||||
int expr_matcher_match(struct expr_matcher *matcher, int thread_id,
|
||||
const char *data, size_t data_len,
|
||||
struct expr_scan_result *result_array,
|
||||
size_t array_size, size_t *n_hit_result)
|
||||
size_t array_size, size_t *n_hit_result,
|
||||
size_t *n_hit_pattern)
|
||||
{
|
||||
if (NULL == matcher || thread_id < 0 || NULL == data || 0 == data_len
|
||||
|| NULL == result_array || 0 == array_size || NULL == n_hit_result) {
|
||||
@@ -451,21 +453,21 @@ int expr_matcher_match(struct expr_matcher *matcher, int thread_id,
|
||||
}
|
||||
|
||||
int err_count = 0;
|
||||
unsigned long long lit_pattern_ids[MAX_HIT_PATTERN_NUM];
|
||||
unsigned long long regex_pattern_ids[MAX_HIT_PATTERN_NUM];
|
||||
size_t n_lit_pattern = 0;
|
||||
size_t n_regex_pattern = 0;
|
||||
size_t n_pattern = 0;
|
||||
unsigned long long lit_pat_ids[MAX_HIT_PATTERN_NUM];
|
||||
unsigned long long regex_pat_ids[MAX_HIT_PATTERN_NUM];
|
||||
size_t lit_pat_cnt = 0;
|
||||
size_t regex_pat_cnt = 0;
|
||||
size_t pat_cnt = 0;
|
||||
|
||||
int ret = engine_ops[matcher->engine_type].engine_scan(matcher->lit_runtime, thread_id,
|
||||
data, data_len, lit_pattern_ids,
|
||||
MAX_HIT_PATTERN_NUM, &n_lit_pattern);
|
||||
data, data_len, lit_pat_ids,
|
||||
MAX_HIT_PATTERN_NUM, &lit_pat_cnt);
|
||||
if (ret < 0) {
|
||||
err_count++;
|
||||
}
|
||||
|
||||
ret = hs_regex_engine_scan(matcher->regex_runtime, thread_id, data, data_len,
|
||||
regex_pattern_ids, MAX_HIT_PATTERN_NUM, &n_regex_pattern);
|
||||
regex_pat_ids, MAX_HIT_PATTERN_NUM, ®ex_pat_cnt);
|
||||
if (ret < 0) {
|
||||
err_count++;
|
||||
}
|
||||
@@ -474,20 +476,22 @@ int expr_matcher_match(struct expr_matcher *matcher, int thread_id,
|
||||
return -1;
|
||||
}
|
||||
|
||||
n_pattern = n_lit_pattern + n_regex_pattern;
|
||||
if (n_pattern > MAX_HIT_PATTERN_NUM) {
|
||||
n_pattern = MAX_HIT_PATTERN_NUM;
|
||||
pat_cnt = lit_pat_cnt + regex_pat_cnt;
|
||||
*n_hit_pattern = pat_cnt;
|
||||
|
||||
if (pat_cnt > MAX_HIT_PATTERN_NUM) {
|
||||
pat_cnt = MAX_HIT_PATTERN_NUM;
|
||||
}
|
||||
|
||||
size_t j = 0;
|
||||
for (size_t i = n_lit_pattern; i < n_pattern; i++, j++) {
|
||||
lit_pattern_ids[i] = regex_pattern_ids[j];
|
||||
for (size_t i = lit_pat_cnt; i < pat_cnt; i++, j++) {
|
||||
lit_pat_ids[i] = regex_pat_ids[j];
|
||||
}
|
||||
|
||||
struct bool_expr_match *match_buff = matcher->bool_match_buffs[thread_id];
|
||||
|
||||
return expr_matcher_bool_matcher_match(matcher->bm, match_buff, MAX_HIT_PATTERN_NUM,
|
||||
lit_pattern_ids, n_pattern, result_array,
|
||||
lit_pat_ids, pat_cnt, result_array,
|
||||
array_size, n_hit_result);
|
||||
}
|
||||
|
||||
@@ -534,29 +538,31 @@ expr_matcher_stream_open(struct expr_matcher *matcher, int thread_id)
|
||||
int expr_matcher_stream_match(struct expr_matcher_stream *stream,
|
||||
const char *data, size_t data_len,
|
||||
struct expr_scan_result *result_array,
|
||||
size_t array_size, size_t *n_hit_result)
|
||||
size_t array_size, size_t *n_hit_result,
|
||||
size_t *n_hit_pattern)
|
||||
{
|
||||
if (NULL == stream || NULL == data || 0 == data_len || NULL == result_array
|
||||
|| 0 == array_size || NULL == n_hit_result) {
|
||||
if (NULL == stream || NULL == data || 0 == data_len ||
|
||||
NULL == result_array || 0 == array_size ||
|
||||
NULL == n_hit_result) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int err_count = 0;
|
||||
unsigned long long lit_pattern_ids[MAX_HIT_PATTERN_NUM];
|
||||
unsigned long long regex_pattern_ids[MAX_HIT_PATTERN_NUM];
|
||||
size_t n_lit_pattern = 0;
|
||||
size_t n_regex_pattern = 0;
|
||||
size_t n_pattern = 0;
|
||||
unsigned long long lit_pat_ids[MAX_HIT_PATTERN_NUM];
|
||||
unsigned long long regex_pat_ids[MAX_HIT_PATTERN_NUM];
|
||||
size_t lit_pat_cnt = 0;
|
||||
size_t regex_pat_cnt = 0;
|
||||
size_t pat_cnt = 0;
|
||||
|
||||
int ret = engine_ops[stream->engine_type].scan_stream(stream->lit_stream, data, data_len,
|
||||
lit_pattern_ids, MAX_HIT_PATTERN_NUM,
|
||||
&n_lit_pattern);
|
||||
lit_pat_ids, MAX_HIT_PATTERN_NUM,
|
||||
&lit_pat_cnt);
|
||||
if (ret < 0) {
|
||||
err_count++;
|
||||
}
|
||||
|
||||
ret = hs_regex_stream_scan(stream->regex_stream, data, data_len, regex_pattern_ids,
|
||||
MAX_HIT_PATTERN_NUM, &n_regex_pattern);
|
||||
ret = hs_regex_stream_scan(stream->regex_stream, data, data_len, regex_pat_ids,
|
||||
MAX_HIT_PATTERN_NUM, ®ex_pat_cnt);
|
||||
if (ret < 0) {
|
||||
err_count++;
|
||||
}
|
||||
@@ -565,22 +571,23 @@ int expr_matcher_stream_match(struct expr_matcher_stream *stream,
|
||||
return -1;
|
||||
}
|
||||
|
||||
n_pattern = n_lit_pattern + n_regex_pattern;
|
||||
if (n_pattern > MAX_HIT_PATTERN_NUM) {
|
||||
n_pattern = MAX_HIT_PATTERN_NUM;
|
||||
pat_cnt = lit_pat_cnt + regex_pat_cnt;
|
||||
*n_hit_pattern = pat_cnt;
|
||||
if (pat_cnt > MAX_HIT_PATTERN_NUM) {
|
||||
pat_cnt = MAX_HIT_PATTERN_NUM;
|
||||
}
|
||||
|
||||
size_t j = 0;
|
||||
for (size_t i = n_lit_pattern; i < n_pattern; i++, j++) {
|
||||
lit_pattern_ids[i] = regex_pattern_ids[j];
|
||||
for (size_t i = lit_pat_cnt; i < pat_cnt; i++, j++) {
|
||||
lit_pat_ids[i] = regex_pat_ids[j];
|
||||
}
|
||||
|
||||
struct expr_matcher *matcher = stream->ref_matcher;
|
||||
struct bool_expr_match *match_buff = matcher->bool_match_buffs[stream->thread_id];
|
||||
|
||||
return expr_matcher_bool_matcher_match(matcher->bm, match_buff, MAX_HIT_PATTERN_NUM,
|
||||
lit_pattern_ids, n_pattern, result_array,
|
||||
array_size, n_hit_result);
|
||||
lit_pat_ids, pat_cnt, result_array, array_size,
|
||||
n_hit_result);
|
||||
}
|
||||
|
||||
void expr_matcher_stream_close(struct expr_matcher_stream *stream)
|
||||
|
||||
@@ -88,9 +88,10 @@ int expr_matcher_verify_regex_expression(const char *regex_expr,
|
||||
* @param n_worker_threads: the number of scan threads which will call adapter_rs_scan()
|
||||
*
|
||||
*/
|
||||
struct expr_matcher *expr_matcher_new(struct expr_rule *rules, size_t n_rule,
|
||||
enum expr_engine_type type, size_t n_thread,
|
||||
struct log_handle *logger);
|
||||
struct expr_matcher *
|
||||
expr_matcher_new(struct expr_rule *rules, size_t n_rule,
|
||||
enum expr_engine_type type, size_t n_thread,
|
||||
struct log_handle *logger);
|
||||
|
||||
void expr_matcher_free(struct expr_matcher *matcher);
|
||||
|
||||
@@ -107,7 +108,8 @@ void expr_matcher_free(struct expr_matcher *matcher);
|
||||
int expr_matcher_match(struct expr_matcher *matcher, int thread_id,
|
||||
const char *data, size_t data_len,
|
||||
struct expr_scan_result *result_array,
|
||||
size_t array_size, size_t *n_hit_result);
|
||||
size_t array_size, size_t *n_hit_result,
|
||||
size_t *n_hit_pattern);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
@@ -121,7 +123,8 @@ expr_matcher_stream_open(struct expr_matcher *matcher, int thread_id);
|
||||
int expr_matcher_stream_match(struct expr_matcher_stream *stream,
|
||||
const char *data, size_t data_len,
|
||||
struct expr_scan_result *result_array,
|
||||
size_t array_size, size_t *n_hit_result);
|
||||
size_t array_size, size_t *n_hit_result,
|
||||
size_t *n_hit_pattern);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
|
||||
@@ -57,9 +57,9 @@ int bool_plugin_runtime_get_ex_data(void *bool_plugin_runtime, unsigned long lon
|
||||
|
||||
long long bool_plugin_runtime_update_err_count(void *bool_plugin_runtime);
|
||||
|
||||
void bool_plugin_runtime_scan_inc(void *bool_plugin_runtime, int thread_id);
|
||||
void bool_plugin_runtime_scan_times_inc(void *bool_plugin_runtime, int thread_id);
|
||||
|
||||
long long bool_plugin_runtime_scan_count(void *bool_plugin_runtime);
|
||||
long long bool_plugin_runtime_scan_times(void *bool_plugin_runtime);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -52,33 +52,39 @@ long long expr_runtime_get_version(void *expr_runtime);
|
||||
int expr_runtime_scan(struct expr_runtime *expr_rt, int thread_id, const char *data,
|
||||
size_t data_len, int vtable_id, struct maat_state *state);
|
||||
|
||||
struct expr_matcher_stream *expr_runtime_stream_open(struct expr_runtime *expr_rt, int thread_id);
|
||||
struct expr_runtime_stream *expr_runtime_stream_open(struct expr_runtime *expr_rt, int thread_id);
|
||||
|
||||
int expr_runtime_stream_scan(struct expr_runtime *expr_rt, struct expr_matcher_stream *s_handle,
|
||||
const char *data, size_t data_len, int vtable_id, struct maat_state *state);
|
||||
int expr_runtime_stream_scan(struct expr_runtime_stream *expr_rt_stream, const char *data,
|
||||
size_t data_len, int vtable_id, struct maat_state *state);
|
||||
|
||||
void expr_runtime_stream_close(struct expr_runtime *expr_rt, int thread_id,
|
||||
struct expr_matcher_stream *stream);
|
||||
void expr_runtime_stream_close(struct expr_runtime_stream *expr_rt_stream);
|
||||
|
||||
int expr_runtime_set_scan_district(struct expr_runtime *expr_rt, const char *district,
|
||||
size_t district_len, long long *district_id);
|
||||
|
||||
void expr_runtime_hit_inc(struct expr_runtime *expr_rt, int thread_id);
|
||||
|
||||
void expr_runtime_perf_stat(struct expr_runtime *flag_rt, size_t scan_len,
|
||||
struct timespec *start, struct timespec *end,
|
||||
int thread_id);
|
||||
|
||||
long long expr_runtime_scan_count(void *expr_runtime);
|
||||
long long expr_runtime_scan_times(void *expr_runtime);
|
||||
|
||||
long long expr_runtime_scan_cpu_time(void *expr_runtime);
|
||||
|
||||
long long expr_runtime_hit_count(void *expr_runtime);
|
||||
long long expr_runtime_scan_bytes(struct expr_runtime *expr_rt);
|
||||
|
||||
long long expr_runtime_hit_times(void *expr_runtime);
|
||||
|
||||
void expr_runtime_hit_times_inc(struct expr_runtime *expr_rt, int thread_id);
|
||||
|
||||
void expr_runtime_stream_hit_times_inc(struct expr_runtime_stream *expr_rt_stream,
|
||||
int thread_id);
|
||||
|
||||
long long expr_runtime_hit_item_num(void *expr_runtime);
|
||||
|
||||
long long expr_runtime_hit_pattern_num(void *expr_runtime);
|
||||
|
||||
long long expr_runtime_update_err_count(void *expr_runtime);
|
||||
|
||||
long long expr_runtime_scan_bytes(struct expr_runtime *expr_rt);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -53,16 +53,20 @@ int flag_runtime_scan(struct flag_runtime *flag_rt, int thread_id, long long fla
|
||||
int flag_runtime_set_scan_district(struct flag_runtime *flag_rt, const char *district,
|
||||
size_t district_len, long long *district_id);
|
||||
|
||||
void flag_runtime_hit_inc(struct flag_runtime *flag_rt, int thread_id);
|
||||
|
||||
|
||||
void flag_runtime_perf_stat(struct flag_runtime *flag_rt, struct timespec *start,
|
||||
struct timespec *end, int thread_id);
|
||||
|
||||
long long flag_runtime_scan_count(void *flag_runtime);
|
||||
long long flag_runtime_scan_times(void *flag_runtime);
|
||||
|
||||
long long flag_runtime_scan_cpu_time(void *flag_runtime);
|
||||
|
||||
long long flag_runtime_hit_count(void *flag_runtime);
|
||||
long long flag_runtime_hit_times(void *flag_runtime);
|
||||
|
||||
void flag_runtime_hit_times_inc(struct flag_runtime *flag_rt, int thread_id);
|
||||
|
||||
long long flag_runtime_hit_item_num(void *flag_runtime);
|
||||
|
||||
long long flag_runtime_update_err_count(void *flag_runtime);
|
||||
|
||||
|
||||
@@ -61,9 +61,9 @@ void fqdn_rule_free(struct FQDN_rule *fqdn_rule);
|
||||
|
||||
long long fqdn_plugin_runtime_update_err_count(void *fqdn_plugin_runtime);
|
||||
|
||||
void fqdn_plugin_runtime_scan_inc(void *fqdn_plugin_runtime, int thread_id);
|
||||
void fqdn_plugin_runtime_scan_times_inc(void *fqdn_plugin_runtime, int thread_id);
|
||||
|
||||
long long fqdn_plugin_runtime_scan_count(void *fqdn_plugin_runtime);
|
||||
long long fqdn_plugin_runtime_scan_times(void *fqdn_plugin_runtime);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -52,16 +52,18 @@ int interval_runtime_scan(struct interval_runtime *interval_rt, int thread_id,
|
||||
int interval_runtime_set_scan_district(struct interval_runtime *interval_rt, const char *district,
|
||||
size_t district_len, long long *district_id);
|
||||
|
||||
void interval_runtime_hit_inc(struct interval_runtime *interval_rt, int thread_id);
|
||||
|
||||
void interval_runtime_perf_stat(struct interval_runtime *interval_rt, struct timespec *start,
|
||||
struct timespec *end, int thread_id);
|
||||
|
||||
long long interval_runtime_scan_count(void *interval_runtime);
|
||||
long long interval_runtime_scan_times(void *interval_runtime);
|
||||
|
||||
long long interval_runtime_scan_cpu_time(void *interval_runtime);
|
||||
|
||||
long long interval_runtime_hit_count(void *interval_runtime);
|
||||
void interval_runtime_hit_times_inc(struct interval_runtime *interval_rt, int thread_id);
|
||||
|
||||
long long interval_runtime_hit_times(void *interval_runtime);
|
||||
|
||||
long long interval_runtime_hit_item_num(void *interval_runtime);
|
||||
|
||||
long long interval_runtime_update_err_cnt(void *interval_runtime);
|
||||
|
||||
|
||||
@@ -45,16 +45,18 @@ int ip_runtime_scan(struct ip_runtime *ip_rt, int thread_id, int ip_type,
|
||||
uint8_t *ip_addr, uint16_t port, int proto,
|
||||
int vtable_id, struct maat_state *state);
|
||||
|
||||
void ip_runtime_hit_inc(struct ip_runtime *ip_rt, int thread_id);
|
||||
|
||||
void ip_runtime_perf_stat(struct ip_runtime *ip_rt, struct timespec *start,
|
||||
struct timespec *end, int thread_id);
|
||||
|
||||
long long ip_runtime_scan_count(void *ip_runtime);
|
||||
long long ip_runtime_scan_times(void *ip_runtime);
|
||||
|
||||
long long ip_runtime_scan_cpu_time(void *ip_runtime);
|
||||
|
||||
long long ip_runtime_hit_count(void *ip_runtime);
|
||||
void ip_runtime_hit_times_inc(struct ip_runtime *ip_rt, int thread_id);
|
||||
|
||||
long long ip_runtime_hit_times(void *ip_runtime);
|
||||
|
||||
long long ip_runtime_hit_item_num(void *ip_runtime);
|
||||
|
||||
long long ip_runtime_update_err_count(void *ip_runtime);
|
||||
|
||||
|
||||
@@ -57,9 +57,9 @@ int ip_plugin_runtime_get_ex_data(void *ip_plugin_runtime, const struct ip_addr
|
||||
|
||||
long long ip_plugin_runtime_update_err_count(void *ip_plugin_runtime);
|
||||
|
||||
void ip_plugin_runtime_scan_inc(void *ip_plugin_rt, int thread_id);
|
||||
void ip_plugin_runtime_scan_times_inc(void *ip_plugin_rt, int thread_id);
|
||||
|
||||
long long ip_plugin_runtime_scan_count(void *ip_plugin_runtime);
|
||||
long long ip_plugin_runtime_scan_times(void *ip_plugin_runtime);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -59,9 +59,9 @@ int ipport_plugin_runtime_get_ex_data(void *ipport_plugin_runtime, const struct
|
||||
|
||||
long long ipport_plugin_runtime_update_err_count(void *ipport_plugin_runtime);
|
||||
|
||||
void ipport_plugin_runtime_scan_inc(void *ipport_plugin_rt, int thread_id);
|
||||
void ipport_plugin_runtime_scan_times_inc(void *ipport_plugin_rt, int thread_id);
|
||||
|
||||
long long ipport_plugin_runtime_scan_count(void *ipport_plugin_runtime);
|
||||
long long ipport_plugin_runtime_scan_times(void *ipport_plugin_runtime);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -73,9 +73,9 @@ const char *plugin_runtime_cached_row_get(void *plugin_runtime, size_t index);
|
||||
void *plugin_runtime_get_ex_data(void *plugin_runtime, void *plugin_schema,
|
||||
const char *key, size_t key_len);
|
||||
|
||||
void plugin_runtime_scan_inc(void *plugin_runtime, int thread_id);
|
||||
void plugin_runtime_scan_times_inc(void *plugin_runtime, int thread_id);
|
||||
|
||||
long long plugin_runtime_scan_count(void *plugin_runtime);
|
||||
long long plugin_runtime_scan_times(void *plugin_runtime);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -153,8 +153,8 @@ struct maat_stat {
|
||||
|
||||
|
||||
long long *thread_call_cnt;
|
||||
long long *stream_num;
|
||||
long long *hit_cnt;
|
||||
long long *stream_cnt;
|
||||
long long *hit_compile_cnt;
|
||||
long long *maat_state_cnt;
|
||||
long long *compile_state_cnt;
|
||||
long long *maat_state_free_cnt;
|
||||
@@ -191,7 +191,7 @@ struct maat {
|
||||
struct maat_state {
|
||||
struct maat *maat_inst;
|
||||
struct compile_state *compile_state;
|
||||
int scan_cnt;
|
||||
int Nth_scan;
|
||||
int district_id; //-1: Any District; -2: Unkonwn District;
|
||||
uint16_t thread_id;
|
||||
int16_t compile_table_id;
|
||||
|
||||
@@ -58,7 +58,7 @@ void table_manager_runtime_destroy(struct table_manager *tbl_mgr);
|
||||
void table_manager_destroy(struct table_manager *tbl_mgr);
|
||||
|
||||
size_t table_manager_table_size(struct table_manager *tbl_mgr);
|
||||
size_t table_manager_table_count(struct table_manager *tbl_mgr);
|
||||
size_t table_manager_table_num(struct table_manager *tbl_mgr);
|
||||
|
||||
int table_manager_get_table_id(struct table_manager *tbl_mgr, const char *table_name);
|
||||
/**
|
||||
@@ -105,13 +105,14 @@ void table_manager_commit_runtime(struct table_manager *tbl_mgr, int table_id,
|
||||
|
||||
long long table_manager_runtime_rule_count(struct table_manager *tbl_mgr, int table_id);
|
||||
|
||||
long long table_manager_runtime_scan_count(struct table_manager *tbl_mgr, int table_id);
|
||||
long long table_manager_runtime_scan_times(struct table_manager *tbl_mgr, int table_id);
|
||||
|
||||
long long table_manager_runtime_scan_cpu_time(struct table_manager *tbl_mgr, int table_id);
|
||||
|
||||
long long table_manager_runtime_hit_count(struct table_manager *tbl_mgr, int table_id);
|
||||
long long table_manager_runtime_hit_item_num(struct table_manager *tbl_mgr, int table_id);
|
||||
|
||||
long long table_manager_runtime_update_err_count(struct table_manager *tbl_mgr, int table_id);
|
||||
long long table_manager_runtime_update_err_count(struct table_manager *tbl_mgr,
|
||||
int table_id);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
160
src/maat_api.c
160
src/maat_api.c
@@ -57,7 +57,7 @@ enum logic_not_flag {
|
||||
|
||||
struct maat_stream {
|
||||
struct maat *ref_maat_inst;
|
||||
struct expr_matcher_stream *handle; //each physical table open one stream
|
||||
struct expr_runtime_stream *expr_rt_stream; //each physical table open one stream
|
||||
long long last_full_version;
|
||||
long long expr_rt_version;
|
||||
struct log_handle *logger;
|
||||
@@ -888,7 +888,7 @@ void *maat_plugin_table_get_ex_data(struct maat *maat_inst, int table_id,
|
||||
|
||||
int thread_id = _get_tid(maat_inst);
|
||||
if (thread_id >= 0 && thread_id < maat_inst->opts.nr_worker_thread) {
|
||||
plugin_runtime_scan_inc(runtime, thread_id);
|
||||
plugin_runtime_scan_times_inc(runtime, thread_id);
|
||||
}
|
||||
|
||||
void *ret = NULL;
|
||||
@@ -922,7 +922,7 @@ int maat_ip_plugin_table_get_ex_data(struct maat *maat_inst, int table_id,
|
||||
|
||||
int thread_id = _get_tid(maat_inst);
|
||||
if (thread_id >= 0 && thread_id < maat_inst->opts.nr_worker_thread) {
|
||||
ip_plugin_runtime_scan_inc(ip_plugin_rt, thread_id);
|
||||
ip_plugin_runtime_scan_times_inc(ip_plugin_rt, thread_id);
|
||||
}
|
||||
|
||||
return ip_plugin_runtime_get_ex_data(ip_plugin_rt, ip_addr, ex_data_array, array_size);
|
||||
@@ -949,7 +949,7 @@ int maat_ipport_plugin_table_get_ex_data(struct maat *maat_inst, int table_id,
|
||||
|
||||
int thread_id = _get_tid(maat_inst);
|
||||
if (thread_id >= 0 && thread_id < maat_inst->opts.nr_worker_thread) {
|
||||
ipport_plugin_runtime_scan_inc(ipport_plugin_rt, thread_id);
|
||||
ipport_plugin_runtime_scan_times_inc(ipport_plugin_rt, thread_id);
|
||||
}
|
||||
|
||||
return ipport_plugin_runtime_get_ex_data(ipport_plugin_rt, ip_addr, port,
|
||||
@@ -977,7 +977,7 @@ int maat_fqdn_plugin_table_get_ex_data(struct maat *maat_inst, int table_id,
|
||||
|
||||
int thread_id = _get_tid(maat_inst);
|
||||
if (thread_id >= 0 && thread_id < maat_inst->opts.nr_worker_thread) {
|
||||
fqdn_plugin_runtime_scan_inc(fqdn_plugin_rt, thread_id);
|
||||
fqdn_plugin_runtime_scan_times_inc(fqdn_plugin_rt, thread_id);
|
||||
}
|
||||
|
||||
return fqdn_plugin_runtime_get_ex_data(fqdn_plugin_rt, fqdn, ex_data_array, array_size);
|
||||
@@ -1004,7 +1004,7 @@ int maat_bool_plugin_table_get_ex_data(struct maat *maat_inst, int table_id,
|
||||
|
||||
int thread_id = _get_tid(maat_inst);
|
||||
if (thread_id >= 0 && thread_id < maat_inst->opts.nr_worker_thread) {
|
||||
bool_plugin_runtime_scan_inc(bool_plugin_rt, thread_id);
|
||||
bool_plugin_runtime_scan_times_inc(bool_plugin_rt, thread_id);
|
||||
}
|
||||
|
||||
return bool_plugin_runtime_get_ex_data(bool_plugin_rt, item_ids, n_item,
|
||||
@@ -1035,7 +1035,7 @@ static int flag_scan(struct table_manager *tbl_mgr, int thread_id, long long fla
|
||||
return group_hit_cnt;
|
||||
}
|
||||
|
||||
flag_runtime_hit_inc((struct flag_runtime *)flag_rt, thread_id);
|
||||
flag_runtime_hit_times_inc((struct flag_runtime *)flag_rt, thread_id);
|
||||
|
||||
return group_hit_cnt;
|
||||
}
|
||||
@@ -1065,7 +1065,7 @@ static int interval_scan(struct table_manager *tbl_mgr, int thread_id, long long
|
||||
return group_hit_cnt;
|
||||
}
|
||||
|
||||
interval_runtime_hit_inc((struct interval_runtime *)interval_rt, thread_id);
|
||||
interval_runtime_hit_times_inc((struct interval_runtime *)interval_rt, thread_id);
|
||||
|
||||
return group_hit_cnt;
|
||||
}
|
||||
@@ -1091,7 +1091,7 @@ static int ipv4_scan(struct table_manager *tbl_mgr, int thread_id, uint32_t ip_a
|
||||
return group_hit_cnt;
|
||||
}
|
||||
|
||||
ip_runtime_hit_inc((struct ip_runtime *)ip_rt, thread_id);
|
||||
ip_runtime_hit_times_inc((struct ip_runtime *)ip_rt, thread_id);
|
||||
|
||||
return group_hit_cnt;
|
||||
}
|
||||
@@ -1117,7 +1117,7 @@ static int ipv6_scan(struct table_manager *tbl_mgr, int thread_id,
|
||||
return group_hit_cnt;
|
||||
}
|
||||
|
||||
ip_runtime_hit_inc((struct ip_runtime *)ip_rt, thread_id);
|
||||
ip_runtime_hit_times_inc((struct ip_runtime *)ip_rt, thread_id);
|
||||
|
||||
return group_hit_cnt;
|
||||
}
|
||||
@@ -1148,43 +1148,7 @@ static int string_scan(struct table_manager *tbl_mgr, int thread_id,
|
||||
return group_hit_cnt;
|
||||
}
|
||||
|
||||
expr_runtime_hit_inc((struct expr_runtime *)expr_rt, thread_id);
|
||||
|
||||
return group_hit_cnt;
|
||||
}
|
||||
|
||||
static int expr_stream_scan(struct maat_stream *stream, const char *data,
|
||||
size_t data_len, struct maat_state *state)
|
||||
{
|
||||
if (NULL == stream || NULL == data) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
enum table_type table_type = TABLE_TYPE_INVALID;
|
||||
struct table_manager *tbl_mgr = stream->ref_maat_inst->tbl_mgr;
|
||||
table_type = table_manager_get_table_type(tbl_mgr, stream->phy_table_id);
|
||||
if (table_type == TABLE_TYPE_EXPR_PLUS &&
|
||||
DISTRICT_FLAG_UNSET == state->district_flag) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (table_type != TABLE_TYPE_EXPR && table_type != TABLE_TYPE_EXPR_PLUS) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
void *expr_rt = table_manager_get_runtime(tbl_mgr, stream->phy_table_id);
|
||||
if (NULL == expr_rt) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int group_hit_cnt = expr_runtime_stream_scan((struct expr_runtime *)expr_rt,
|
||||
stream->handle, data, data_len,
|
||||
stream->vtable_id, state);
|
||||
if (group_hit_cnt <= 0) {
|
||||
return group_hit_cnt;
|
||||
}
|
||||
|
||||
expr_runtime_hit_inc((struct expr_runtime *)expr_rt, stream->thread_id);
|
||||
expr_runtime_hit_times_inc((struct expr_runtime *)expr_rt, thread_id);
|
||||
|
||||
return group_hit_cnt;
|
||||
}
|
||||
@@ -1222,7 +1186,7 @@ int maat_scan_flag(struct maat *maat_inst, int table_id,
|
||||
clock_gettime(CLOCK_MONOTONIC, &start);
|
||||
}
|
||||
|
||||
state->scan_cnt++;
|
||||
state->Nth_scan++;
|
||||
|
||||
struct maat_runtime *maat_rt = maat_inst->maat_rt;
|
||||
if (NULL == maat_rt) {
|
||||
@@ -1267,7 +1231,8 @@ int maat_scan_flag(struct maat *maat_inst, int table_id,
|
||||
}
|
||||
|
||||
if (sum_hit_compile_cnt > 0) {
|
||||
alignment_int64_array_add(maat_inst->stat->hit_cnt, state->thread_id, 1);
|
||||
alignment_int64_array_add(maat_inst->stat->hit_compile_cnt, state->thread_id,
|
||||
sum_hit_compile_cnt);
|
||||
}
|
||||
|
||||
void *flag_rt = table_manager_get_runtime(maat_inst->tbl_mgr, phy_table_id);
|
||||
@@ -1306,7 +1271,7 @@ int maat_scan_integer(struct maat *maat_inst, int table_id,
|
||||
clock_gettime(CLOCK_MONOTONIC, &start);
|
||||
}
|
||||
|
||||
state->scan_cnt++;
|
||||
state->Nth_scan++;
|
||||
|
||||
struct maat_runtime *maat_rt = maat_inst->maat_rt;
|
||||
if (NULL == maat_rt) {
|
||||
@@ -1351,7 +1316,8 @@ int maat_scan_integer(struct maat *maat_inst, int table_id,
|
||||
}
|
||||
|
||||
if (sum_hit_compile_cnt > 0) {
|
||||
alignment_int64_array_add(maat_inst->stat->hit_cnt, state->thread_id, 1);
|
||||
alignment_int64_array_add(maat_inst->stat->hit_compile_cnt, state->thread_id,
|
||||
sum_hit_compile_cnt);
|
||||
}
|
||||
|
||||
void *interval_rt = table_manager_get_runtime(maat_inst->tbl_mgr, phy_table_id);
|
||||
@@ -1390,7 +1356,7 @@ int maat_scan_ipv4(struct maat *maat_inst, int table_id, uint32_t ip_addr,
|
||||
clock_gettime(CLOCK_MONOTONIC, &start);
|
||||
}
|
||||
|
||||
state->scan_cnt++;
|
||||
state->Nth_scan++;
|
||||
|
||||
struct maat_runtime *maat_rt = maat_inst->maat_rt;
|
||||
if (NULL == maat_rt) {
|
||||
@@ -1435,7 +1401,8 @@ int maat_scan_ipv4(struct maat *maat_inst, int table_id, uint32_t ip_addr,
|
||||
}
|
||||
|
||||
if (sum_hit_compile_cnt > 0) {
|
||||
alignment_int64_array_add(maat_inst->stat->hit_cnt, state->thread_id, 1);
|
||||
alignment_int64_array_add(maat_inst->stat->hit_compile_cnt, state->thread_id,
|
||||
sum_hit_compile_cnt);
|
||||
}
|
||||
|
||||
void *ip_rt = table_manager_get_runtime(maat_inst->tbl_mgr, phy_table_id);
|
||||
@@ -1476,7 +1443,7 @@ int maat_scan_ipv6(struct maat *maat_inst, int table_id,
|
||||
clock_gettime(CLOCK_MONOTONIC, &start);
|
||||
}
|
||||
|
||||
state->scan_cnt++;
|
||||
state->Nth_scan++;
|
||||
|
||||
struct maat_runtime *maat_rt = maat_inst->maat_rt;
|
||||
if (NULL == maat_rt) {
|
||||
@@ -1521,7 +1488,8 @@ int maat_scan_ipv6(struct maat *maat_inst, int table_id,
|
||||
}
|
||||
|
||||
if (sum_hit_compile_cnt > 0) {
|
||||
alignment_int64_array_add(maat_inst->stat->hit_cnt, state->thread_id, 1);
|
||||
alignment_int64_array_add(maat_inst->stat->hit_compile_cnt, state->thread_id,
|
||||
sum_hit_compile_cnt);
|
||||
}
|
||||
|
||||
void *ip_rt = table_manager_get_runtime(maat_inst->tbl_mgr, phy_table_id);
|
||||
@@ -1562,7 +1530,7 @@ int maat_scan_string(struct maat *maat_inst, int table_id,
|
||||
clock_gettime(CLOCK_MONOTONIC, &start);
|
||||
}
|
||||
|
||||
state->scan_cnt++;
|
||||
state->Nth_scan++;
|
||||
|
||||
struct maat_runtime *maat_rt = maat_inst->maat_rt;
|
||||
if (NULL == maat_rt) {
|
||||
@@ -1607,7 +1575,8 @@ int maat_scan_string(struct maat *maat_inst, int table_id,
|
||||
}
|
||||
|
||||
if (sum_hit_compile_cnt > 0) {
|
||||
alignment_int64_array_add(maat_inst->stat->hit_cnt, state->thread_id, 1);
|
||||
alignment_int64_array_add(maat_inst->stat->hit_compile_cnt, state->thread_id,
|
||||
sum_hit_compile_cnt);
|
||||
}
|
||||
|
||||
void *expr_rt = table_manager_get_runtime(maat_inst->tbl_mgr, phy_table_id);
|
||||
@@ -1654,7 +1623,7 @@ static void maat_state_add_hit_group(struct maat_state *state, int table_id,
|
||||
}
|
||||
|
||||
compile_state_update(state->compile_state, maat_inst, table_id,
|
||||
state->compile_table_id, state->scan_cnt,
|
||||
state->compile_table_id, state->Nth_scan,
|
||||
hit_items, n_hit_item);
|
||||
}
|
||||
|
||||
@@ -1677,7 +1646,7 @@ static void maat_state_activate_hit_not_group(struct maat_state *state, int tabl
|
||||
}
|
||||
|
||||
compile_state_not_logic_update(state->compile_state, compile_rt, maat_inst,
|
||||
table_id, state->scan_cnt);
|
||||
table_id, state->Nth_scan);
|
||||
}
|
||||
|
||||
int maat_scan_group(struct maat *maat_inst, int table_id,
|
||||
@@ -1692,7 +1661,7 @@ int maat_scan_group(struct maat *maat_inst, int table_id,
|
||||
return -1;
|
||||
}
|
||||
|
||||
state->scan_cnt++;
|
||||
state->Nth_scan++;
|
||||
|
||||
struct maat_runtime *maat_rt = maat_inst->maat_rt;
|
||||
if (NULL == maat_rt) {
|
||||
@@ -1708,7 +1677,8 @@ int maat_scan_group(struct maat *maat_inst, int table_id,
|
||||
|
||||
maat_runtime_ref_dec(maat_rt, state->thread_id);
|
||||
if (hit_compile_cnt > 0) {
|
||||
alignment_int64_array_add(maat_inst->stat->hit_cnt, state->thread_id, 1);
|
||||
alignment_int64_array_add(maat_inst->stat->hit_compile_cnt, state->thread_id,
|
||||
hit_compile_cnt);
|
||||
return MAAT_SCAN_HIT;
|
||||
}
|
||||
|
||||
@@ -1743,7 +1713,8 @@ int maat_scan_not_logic(struct maat *maat_inst, int table_id,
|
||||
|
||||
maat_runtime_ref_dec(maat_rt, state->thread_id);
|
||||
if (hit_compile_cnt > 0) {
|
||||
alignment_int64_array_add(maat_inst->stat->hit_cnt, state->thread_id, 1);
|
||||
alignment_int64_array_add(maat_inst->stat->hit_compile_cnt, state->thread_id,
|
||||
hit_compile_cnt);
|
||||
return MAAT_SCAN_HIT;
|
||||
}
|
||||
|
||||
@@ -1789,13 +1760,16 @@ struct maat_stream *maat_stream_new(struct maat *maat_inst, int table_id,
|
||||
stream->expr_rt_version = expr_runtime_get_version(expr_rt);
|
||||
|
||||
maat_runtime_ref_inc(maat_inst->maat_rt, state->thread_id);
|
||||
struct expr_matcher_stream *handle = expr_runtime_stream_open((struct expr_runtime *)expr_rt,
|
||||
state->thread_id);
|
||||
if (NULL == handle) {
|
||||
|
||||
struct expr_runtime_stream *expr_rt_stream = NULL;
|
||||
expr_rt_stream = expr_runtime_stream_open((struct expr_runtime *)expr_rt,
|
||||
state->thread_id);
|
||||
if (NULL == expr_rt_stream) {
|
||||
goto error;
|
||||
}
|
||||
alignment_int64_array_add(maat_inst->stat->stream_num, stream->thread_id, 1);
|
||||
stream->handle = handle;
|
||||
|
||||
alignment_int64_array_add(maat_inst->stat->stream_cnt, stream->thread_id, 1);
|
||||
stream->expr_rt_stream = expr_rt_stream;
|
||||
|
||||
return stream;
|
||||
|
||||
@@ -1804,6 +1778,36 @@ error:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int expr_stream_scan(struct maat_stream *stream, const char *data,
|
||||
size_t data_len, struct maat_state *state)
|
||||
{
|
||||
if (NULL == stream || NULL == data) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
enum table_type table_type = TABLE_TYPE_INVALID;
|
||||
struct table_manager *tbl_mgr = stream->ref_maat_inst->tbl_mgr;
|
||||
table_type = table_manager_get_table_type(tbl_mgr, stream->phy_table_id);
|
||||
if (table_type == TABLE_TYPE_EXPR_PLUS &&
|
||||
DISTRICT_FLAG_UNSET == state->district_flag) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (table_type != TABLE_TYPE_EXPR && table_type != TABLE_TYPE_EXPR_PLUS) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int group_hit_cnt = expr_runtime_stream_scan(stream->expr_rt_stream, data,
|
||||
data_len, stream->vtable_id, state);
|
||||
if (group_hit_cnt <= 0) {
|
||||
return group_hit_cnt;
|
||||
}
|
||||
|
||||
expr_runtime_stream_hit_times_inc(stream->expr_rt_stream, stream->thread_id);
|
||||
|
||||
return group_hit_cnt;
|
||||
}
|
||||
|
||||
int maat_stream_scan(struct maat_stream *maat_stream, const char *data, int data_len,
|
||||
long long *results, size_t n_result, size_t *n_hit_result,
|
||||
struct maat_state *state)
|
||||
@@ -1818,7 +1822,7 @@ int maat_stream_scan(struct maat_stream *maat_stream, const char *data, int data
|
||||
clock_gettime(CLOCK_MONOTONIC, &start);
|
||||
}
|
||||
|
||||
state->scan_cnt++;
|
||||
state->Nth_scan++;
|
||||
|
||||
struct maat *maat_inst = maat_stream->ref_maat_inst;
|
||||
if (maat_stream->last_full_version != maat_inst->last_full_version) {
|
||||
@@ -1850,7 +1854,8 @@ int maat_stream_scan(struct maat_stream *maat_stream, const char *data, int data
|
||||
}
|
||||
|
||||
if (sum_hit_compile_cnt > 0) {
|
||||
alignment_int64_array_add(maat_inst->stat->hit_cnt, maat_stream->thread_id, 1);
|
||||
alignment_int64_array_add(maat_inst->stat->hit_compile_cnt, maat_stream->thread_id,
|
||||
sum_hit_compile_cnt);
|
||||
}
|
||||
|
||||
if (1 == maat_inst->opts.perf_on) {
|
||||
@@ -1871,12 +1876,12 @@ int maat_stream_scan(struct maat_stream *maat_stream, const char *data, int data
|
||||
|
||||
void maat_stream_free(struct maat_stream *maat_stream)
|
||||
{
|
||||
if (NULL == maat_stream || NULL == maat_stream->handle) {
|
||||
if (NULL == maat_stream) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct maat *maat_inst = maat_stream->ref_maat_inst;
|
||||
void *expr_rt = table_manager_get_runtime(maat_inst->tbl_mgr,
|
||||
void *expr_rt = table_manager_get_runtime(maat_inst->tbl_mgr,
|
||||
maat_stream->phy_table_id);
|
||||
assert(expr_rt != NULL);
|
||||
|
||||
@@ -1888,8 +1893,13 @@ void maat_stream_free(struct maat_stream *maat_stream)
|
||||
maat_inst->stat->zombie_rs_stream--;
|
||||
}
|
||||
|
||||
alignment_int64_array_add(maat_inst->stat->stream_num, maat_stream->thread_id, -1);
|
||||
expr_runtime_stream_close(expr_rt, maat_stream->thread_id, maat_stream->handle);
|
||||
alignment_int64_array_add(maat_inst->stat->stream_cnt, maat_stream->thread_id, -1);
|
||||
|
||||
if (maat_stream->expr_rt_stream != NULL) {
|
||||
expr_runtime_stream_close(maat_stream->expr_rt_stream);
|
||||
maat_stream->expr_rt_stream = NULL;
|
||||
}
|
||||
|
||||
FREE(maat_stream);
|
||||
}
|
||||
|
||||
@@ -1921,7 +1931,7 @@ void maat_state_reset(struct maat_state *state)
|
||||
state->compile_table_id = 0;
|
||||
state->district_flag = DISTRICT_FLAG_UNSET;
|
||||
state->district_id = DISTRICT_ANY;
|
||||
state->scan_cnt = 0;
|
||||
state->Nth_scan = 0;
|
||||
|
||||
if (state->compile_state != NULL) {
|
||||
compile_state_reset(state->compile_state);
|
||||
@@ -2098,7 +2108,7 @@ size_t maat_state_get_scan_count(struct maat_state *state)
|
||||
return 0;
|
||||
}
|
||||
|
||||
return state->scan_cnt;
|
||||
return state->Nth_scan;
|
||||
}
|
||||
|
||||
int maat_state_get_direct_hit_groups(struct maat_state *state,
|
||||
|
||||
@@ -39,7 +39,7 @@ struct bool_plugin_runtime {
|
||||
|
||||
long long rule_num;
|
||||
long long update_err_cnt;
|
||||
long long *scan_cnt;
|
||||
long long *scan_times;
|
||||
};
|
||||
|
||||
/* bool plugin schema API */
|
||||
@@ -199,7 +199,7 @@ void *bool_plugin_runtime_new(void *bool_plugin_schema, size_t max_thread_num,
|
||||
bool_plugin_rt->n_worker_thread = max_thread_num;
|
||||
bool_plugin_rt->ref_garbage_bin = garbage_bin;
|
||||
bool_plugin_rt->logger = logger;
|
||||
bool_plugin_rt->scan_cnt = alignment_int64_array_alloc(max_thread_num);
|
||||
bool_plugin_rt->scan_times = alignment_int64_array_alloc(max_thread_num);
|
||||
|
||||
return bool_plugin_rt;
|
||||
}
|
||||
@@ -221,9 +221,9 @@ void bool_plugin_runtime_free(void *bool_plugin_runtime)
|
||||
bool_plugin_rt->ex_data_rt = NULL;
|
||||
}
|
||||
|
||||
if (bool_plugin_rt->scan_cnt != NULL) {
|
||||
alignment_int64_array_free(bool_plugin_rt->scan_cnt);
|
||||
bool_plugin_rt->scan_cnt = NULL;
|
||||
if (bool_plugin_rt->scan_times != NULL) {
|
||||
alignment_int64_array_free(bool_plugin_rt->scan_times);
|
||||
bool_plugin_rt->scan_times = NULL;
|
||||
}
|
||||
|
||||
FREE(bool_plugin_rt);
|
||||
@@ -583,26 +583,26 @@ long long bool_plugin_runtime_update_err_count(void *bool_plugin_runtime)
|
||||
return bool_plugin_rt->update_err_cnt;
|
||||
}
|
||||
|
||||
void bool_plugin_runtime_scan_inc(void *bool_plugin_runtime, int thread_id)
|
||||
void bool_plugin_runtime_scan_times_inc(void *bool_plugin_runtime, int thread_id)
|
||||
{
|
||||
if (NULL == bool_plugin_runtime || thread_id < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct bool_plugin_runtime *bool_plugin_rt = (struct bool_plugin_runtime *)bool_plugin_runtime;
|
||||
alignment_int64_array_add(bool_plugin_rt->scan_cnt, thread_id, 1);
|
||||
alignment_int64_array_add(bool_plugin_rt->scan_times, thread_id, 1);
|
||||
}
|
||||
|
||||
long long bool_plugin_runtime_scan_count(void *bool_plugin_runtime)
|
||||
long long bool_plugin_runtime_scan_times(void *bool_plugin_runtime)
|
||||
{
|
||||
if (NULL == bool_plugin_runtime) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct bool_plugin_runtime *bool_plugin_rt = (struct bool_plugin_runtime *)bool_plugin_runtime;
|
||||
long long sum = alignment_int64_array_sum(bool_plugin_rt->scan_cnt,
|
||||
long long sum = alignment_int64_array_sum(bool_plugin_rt->scan_times,
|
||||
bool_plugin_rt->n_worker_thread);
|
||||
alignment_int64_array_reset(bool_plugin_rt->scan_cnt, bool_plugin_rt->n_worker_thread);
|
||||
alignment_int64_array_reset(bool_plugin_rt->scan_times, bool_plugin_rt->n_worker_thread);
|
||||
|
||||
return sum;
|
||||
}
|
||||
@@ -25,8 +25,7 @@
|
||||
|
||||
#define MAX_CONFIG_LINE (1024 * 16)
|
||||
|
||||
struct cm_table_info_t
|
||||
{
|
||||
struct cm_table_info_t {
|
||||
char table_name[MAX_NAME_STR_LEN];
|
||||
char cfg_path[NAME_MAX];
|
||||
int cfg_num;
|
||||
@@ -45,8 +44,8 @@ static int cm_read_cfg_index_file(const char *path, struct cm_table_info_t *idx,
|
||||
while (!feof(fp)) {
|
||||
memset(line, 0, sizeof(line));
|
||||
fgets(line, sizeof(line), fp);
|
||||
ret = sscanf(line, "%s\t%d\t%s\t%s", idx[i].table_name, &(idx[i].cfg_num),
|
||||
idx[i].cfg_path ,idx[i].encrypt_algo);
|
||||
ret = sscanf(line, "%s\t%d\t%s\t%s", idx[i].table_name,
|
||||
&(idx[i].cfg_num), idx[i].cfg_path, idx[i].encrypt_algo);
|
||||
|
||||
//jump over empty line
|
||||
if (!(ret == 3 || ret == 4) || idx[i].cfg_num == 0) {
|
||||
@@ -140,7 +139,7 @@ static int cm_read_table_file(struct cm_table_info_t *index,
|
||||
}
|
||||
} else {
|
||||
// not encrypted
|
||||
ret = load_file_to_memory(index->cfg_path, (unsigned char **)&file_buff, &file_sz);
|
||||
ret = load_file_to_memory(index->cfg_path, (unsigned char**)&file_buff, &file_sz);
|
||||
if (ret < 0) {
|
||||
log_fatal(logger, MODULE_CONFIG_MONITOR, "[%s:%d] open %s failed.",
|
||||
__FUNCTION__, __LINE__, index->cfg_path);
|
||||
@@ -193,12 +192,8 @@ static int cm_read_table_file(struct cm_table_info_t *index,
|
||||
#define ENLARGE_STEP 1024
|
||||
int my_scandir(const char *dir, struct dirent ***namelist,
|
||||
int(*filter)(const struct dirent *),
|
||||
int(*compar)(const void *, const void *))
|
||||
int(*compare)(const void *, const void *))
|
||||
{
|
||||
int n = 0;
|
||||
int DIR_ENT_SIZE = ENLARGE_STEP;
|
||||
struct dirent entry, *result;
|
||||
|
||||
if ((NULL == dir) || (NULL == namelist)) {
|
||||
return -1;
|
||||
}
|
||||
@@ -207,25 +202,25 @@ int my_scandir(const char *dir, struct dirent ***namelist,
|
||||
if (NULL == od) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct dirent **list = ALLOC(struct dirent *, DIR_ENT_SIZE);
|
||||
while (0 == readdir_r(od, &entry, &result)) {
|
||||
if (NULL == result) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (filter && !filter(&entry)) {
|
||||
int num = 0;
|
||||
int DIR_ENT_SIZE = ENLARGE_STEP;
|
||||
struct dirent *entry = NULL;
|
||||
struct dirent **list = ALLOC(struct dirent *, DIR_ENT_SIZE);
|
||||
|
||||
while ((entry = readdir(od)) != NULL) {
|
||||
if (filter && !filter(entry)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
struct dirent *p = ALLOC(struct dirent, 1);
|
||||
memcpy((void *)p, (void *)(&entry), sizeof(struct dirent));
|
||||
list[n] = p;
|
||||
|
||||
n++;
|
||||
if (n >= DIR_ENT_SIZE) {
|
||||
DIR_ENT_SIZE += ENLARGE_STEP;
|
||||
struct dirent **tmp_list = (struct dirent **)realloc((void*)list,
|
||||
struct dirent *p = ALLOC(struct dirent, 1);
|
||||
memcpy((void *)p, (void *)entry, sizeof(struct dirent));
|
||||
list[num] = p;
|
||||
|
||||
num++;
|
||||
if (num >= DIR_ENT_SIZE) {
|
||||
DIR_ENT_SIZE += ENLARGE_STEP;
|
||||
struct dirent **tmp_list = (struct dirent **)realloc((void *)list,
|
||||
DIR_ENT_SIZE * sizeof(struct dirent *));
|
||||
if (tmp_list != NULL) {
|
||||
list = tmp_list;
|
||||
@@ -234,17 +229,18 @@ int my_scandir(const char *dir, struct dirent ***namelist,
|
||||
closedir(od);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
entry = readdir(od);
|
||||
}
|
||||
|
||||
closedir(od);
|
||||
closedir(od);
|
||||
*namelist = list;
|
||||
|
||||
if (compar) {
|
||||
qsort((void *)*namelist, n, sizeof(struct dirent *), compar);
|
||||
if (compare) {
|
||||
qsort((void *)*namelist, num, sizeof(struct dirent *), compare);
|
||||
}
|
||||
|
||||
return n;
|
||||
return num;
|
||||
}
|
||||
|
||||
static int filter_fn(const struct dirent *ent)
|
||||
@@ -372,11 +368,13 @@ void config_monitor_traverse(long long current_version, const char *idx_dir,
|
||||
|
||||
memset(table_array, 0, sizeof(table_array));
|
||||
|
||||
int update_type = get_new_idx_path(current_version, idx_dir, &idx_path_array, &idx_path_num, logger);
|
||||
int update_type = get_new_idx_path(current_version, idx_dir, &idx_path_array,
|
||||
&idx_path_num, logger);
|
||||
if (update_type != MAAT_UPDATE_TYPE_INVALID) {
|
||||
for (i = 0; i < idx_path_num; i++) {
|
||||
log_info(logger, MODULE_CONFIG_MONITOR, "load %s", idx_path_array[i]);
|
||||
int table_num = cm_read_cfg_index_file(idx_path_array[i], table_array, MAX_TABLE_NUM, logger);
|
||||
int table_num = cm_read_cfg_index_file(idx_path_array[i], table_array,
|
||||
MAX_TABLE_NUM, logger);
|
||||
if (table_num < 0) {
|
||||
log_fatal(logger, MODULE_CONFIG_MONITOR,
|
||||
"[%s:%d] load %s failed, abandon update",
|
||||
@@ -386,7 +384,9 @@ void config_monitor_traverse(long long current_version, const char *idx_dir,
|
||||
|
||||
char str_not_care[256] = {0};
|
||||
const char *table_filename = path2filename(idx_path_array[i]);
|
||||
sscanf(table_filename, "%[a-zA-Z]_config_index.%lld", str_not_care, &new_version);
|
||||
sscanf(table_filename, "%[a-zA-Z]_config_index.%lld",
|
||||
str_not_care, &new_version);
|
||||
|
||||
if (start_fn != NULL) {
|
||||
start_fn(new_version, update_type, u_param);
|
||||
}
|
||||
@@ -424,11 +424,11 @@ int load_maat_json_file(struct maat *maat_inst, const char *json_filename,
|
||||
"Maat initial with JSON file %s, formating...",
|
||||
json_filename);
|
||||
|
||||
if (strlen(maat_inst->opts.decrypt_key) && strlen(maat_inst->opts.decrypt_algo)) {
|
||||
if (strlen(maat_inst->opts.decrypt_key) &&
|
||||
strlen(maat_inst->opts.decrypt_algo)) {
|
||||
ret = decrypt_open(json_filename, maat_inst->opts.decrypt_key,
|
||||
maat_inst->opts.decrypt_algo,
|
||||
(unsigned char **)&decrypted_buff,
|
||||
&decrypted_buff_sz,
|
||||
maat_inst->opts.decrypt_algo,
|
||||
&decrypted_buff, &decrypted_buff_sz,
|
||||
err_str, err_str_sz);
|
||||
if (ret < 0) {
|
||||
log_fatal(maat_inst->logger, MODULE_CONFIG_MONITOR,
|
||||
|
||||
192
src/maat_expr.c
192
src/maat_expr.c
@@ -92,15 +92,23 @@ struct expr_runtime {
|
||||
struct maat_kv_store *district_map;
|
||||
struct maat_kv_store *tmp_district_map;
|
||||
|
||||
long long *scan_cnt;
|
||||
long long *scan_times;
|
||||
long long *scan_cpu_time;
|
||||
long long *hit_cnt;
|
||||
long long update_err_cnt;
|
||||
long long *scan_bytes;
|
||||
|
||||
long long *hit_times;
|
||||
long long *hit_item_num;
|
||||
long long *hit_pattern_num;
|
||||
|
||||
long long update_err_cnt;
|
||||
};
|
||||
|
||||
static enum expr_type int_to_expr_type(int expr_type)
|
||||
{
|
||||
struct expr_runtime_stream {
|
||||
struct expr_runtime *ref_expr_rt;
|
||||
struct expr_matcher_stream *handle;
|
||||
};
|
||||
|
||||
static enum expr_type int_to_expr_type(int expr_type) {
|
||||
enum expr_type type = EXPR_TYPE_INVALID;
|
||||
|
||||
switch (expr_type) {
|
||||
@@ -512,11 +520,14 @@ void *expr_runtime_new(void *expr_schema, size_t max_thread_num,
|
||||
expr_rt->engine_type = schema->engine_type;
|
||||
}
|
||||
|
||||
expr_rt->hit_cnt = alignment_int64_array_alloc(max_thread_num);
|
||||
expr_rt->scan_cnt = alignment_int64_array_alloc(max_thread_num);
|
||||
expr_rt->scan_times = alignment_int64_array_alloc(max_thread_num);
|
||||
expr_rt->scan_bytes = alignment_int64_array_alloc(max_thread_num);
|
||||
expr_rt->scan_cpu_time = alignment_int64_array_alloc(max_thread_num);
|
||||
|
||||
expr_rt->hit_times = alignment_int64_array_alloc(max_thread_num);
|
||||
expr_rt->hit_item_num = alignment_int64_array_alloc(max_thread_num);
|
||||
expr_rt->hit_pattern_num = alignment_int64_array_alloc(max_thread_num);
|
||||
|
||||
return expr_rt;
|
||||
}
|
||||
|
||||
@@ -544,9 +555,9 @@ void expr_runtime_free(void *expr_runtime)
|
||||
expr_rt->district_map = NULL;
|
||||
}
|
||||
|
||||
if (expr_rt->scan_cnt != NULL) {
|
||||
alignment_int64_array_free(expr_rt->scan_cnt);
|
||||
expr_rt->scan_cnt = NULL;
|
||||
if (expr_rt->scan_times != NULL) {
|
||||
alignment_int64_array_free(expr_rt->scan_times);
|
||||
expr_rt->scan_times = NULL;
|
||||
}
|
||||
|
||||
if (expr_rt->scan_cpu_time != NULL) {
|
||||
@@ -554,16 +565,26 @@ void expr_runtime_free(void *expr_runtime)
|
||||
expr_rt->scan_cpu_time = NULL;
|
||||
}
|
||||
|
||||
if (expr_rt->hit_cnt != NULL) {
|
||||
alignment_int64_array_free(expr_rt->hit_cnt);
|
||||
expr_rt->hit_cnt = NULL;
|
||||
}
|
||||
|
||||
if (expr_rt->scan_bytes != NULL) {
|
||||
alignment_int64_array_free(expr_rt->scan_bytes);
|
||||
expr_rt->scan_bytes = NULL;
|
||||
}
|
||||
|
||||
if (expr_rt->hit_times != NULL) {
|
||||
alignment_int64_array_free(expr_rt->hit_times);
|
||||
expr_rt->hit_times = NULL;
|
||||
}
|
||||
|
||||
if (expr_rt->hit_item_num != NULL) {
|
||||
alignment_int64_array_free(expr_rt->hit_item_num);
|
||||
expr_rt->hit_item_num = NULL;
|
||||
}
|
||||
|
||||
if (expr_rt->hit_pattern_num != NULL) {
|
||||
alignment_int64_array_free(expr_rt->hit_pattern_num);
|
||||
expr_rt->hit_pattern_num = NULL;
|
||||
}
|
||||
|
||||
FREE(expr_rt);
|
||||
}
|
||||
|
||||
@@ -1015,15 +1036,27 @@ int expr_runtime_scan(struct expr_runtime *expr_rt, int thread_id,
|
||||
}
|
||||
|
||||
size_t n_hit_item = 0;
|
||||
size_t n_hit_pattern = 0;
|
||||
struct expr_scan_result hit_results[MAX_HIT_ITEM_NUM];
|
||||
int ret = expr_matcher_match(expr_rt->matcher, thread_id, data, data_len,
|
||||
hit_results, MAX_HIT_ITEM_NUM, &n_hit_item);
|
||||
hit_results, MAX_HIT_ITEM_NUM, &n_hit_item,
|
||||
&n_hit_pattern);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (n_hit_pattern > 0) {
|
||||
alignment_int64_array_add(expr_rt->hit_pattern_num, state->thread_id,
|
||||
n_hit_pattern);
|
||||
}
|
||||
|
||||
if (n_hit_item > 0) {
|
||||
alignment_int64_array_add(expr_rt->hit_item_num, state->thread_id,
|
||||
n_hit_item);
|
||||
}
|
||||
|
||||
struct maat_item hit_maat_items[n_hit_item];
|
||||
size_t real_hit_item_cnt = 0;
|
||||
size_t real_hit_item_num = 0;
|
||||
|
||||
if (0 == n_hit_item) {
|
||||
goto next;
|
||||
@@ -1041,10 +1074,10 @@ int expr_runtime_scan(struct expr_runtime *expr_rt, int thread_id,
|
||||
continue;
|
||||
}
|
||||
|
||||
hit_maat_items[real_hit_item_cnt].item_id = item_id;
|
||||
hit_maat_items[real_hit_item_cnt].group_id = expr_item->group_id;
|
||||
hit_maat_items[real_hit_item_num].item_id = item_id;
|
||||
hit_maat_items[real_hit_item_num].group_id = expr_item->group_id;
|
||||
|
||||
real_hit_item_cnt++;
|
||||
real_hit_item_num++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1056,45 +1089,59 @@ next:
|
||||
}
|
||||
|
||||
return compile_state_update(state->compile_state, state->maat_inst, vtable_id,
|
||||
state->compile_table_id, state->scan_cnt,
|
||||
hit_maat_items, real_hit_item_cnt);
|
||||
state->compile_table_id, state->Nth_scan,
|
||||
hit_maat_items, real_hit_item_num);
|
||||
}
|
||||
|
||||
struct expr_matcher_stream *
|
||||
struct expr_runtime_stream *
|
||||
expr_runtime_stream_open(struct expr_runtime *expr_rt, int thread_id)
|
||||
{
|
||||
if (NULL == expr_rt || thread_id < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct expr_matcher_stream *stream = expr_matcher_stream_open(expr_rt->matcher,
|
||||
thread_id);
|
||||
if (NULL == stream) {
|
||||
struct expr_runtime_stream *expr_rt_stream = ALLOC(struct expr_runtime_stream, 1);
|
||||
|
||||
expr_rt_stream->ref_expr_rt = expr_rt;
|
||||
expr_rt_stream->handle = expr_matcher_stream_open(expr_rt->matcher, thread_id);
|
||||
if (NULL == expr_rt_stream->handle) {
|
||||
FREE(expr_rt_stream);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return stream;
|
||||
return expr_rt_stream;
|
||||
}
|
||||
|
||||
int expr_runtime_stream_scan(struct expr_runtime *expr_rt,
|
||||
struct expr_matcher_stream *s_handle,
|
||||
int expr_runtime_stream_scan(struct expr_runtime_stream *expr_rt_stream,
|
||||
const char *data, size_t data_len,
|
||||
int vtable_id, struct maat_state *state)
|
||||
{
|
||||
struct expr_runtime *expr_rt = expr_rt_stream->ref_expr_rt;
|
||||
if (0 == expr_rt->rule_num) {
|
||||
//empty expr table
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t n_hit_item = 0;
|
||||
size_t n_hit_pattern = 0;
|
||||
struct expr_scan_result hit_results[MAX_HIT_ITEM_NUM];
|
||||
|
||||
int ret = expr_matcher_stream_match(s_handle, data, data_len, hit_results,
|
||||
MAX_HIT_ITEM_NUM, &n_hit_item);
|
||||
int ret = expr_matcher_stream_match(expr_rt_stream->handle, data, data_len, hit_results,
|
||||
MAX_HIT_ITEM_NUM, &n_hit_item, &n_hit_pattern);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (n_hit_pattern > 0) {
|
||||
alignment_int64_array_add(expr_rt->hit_pattern_num, state->thread_id,
|
||||
n_hit_pattern);
|
||||
}
|
||||
|
||||
if (n_hit_item > 0) {
|
||||
alignment_int64_array_add(expr_rt->hit_item_num, state->thread_id,
|
||||
n_hit_item);
|
||||
}
|
||||
|
||||
struct maat_item hit_maat_items[n_hit_item];
|
||||
struct expr_item *expr_item = NULL;
|
||||
size_t real_hit_item_cnt = 0;
|
||||
@@ -1126,27 +1173,22 @@ next:
|
||||
}
|
||||
|
||||
return compile_state_update(state->compile_state, state->maat_inst, vtable_id,
|
||||
state->compile_table_id, state->scan_cnt,
|
||||
state->compile_table_id, state->Nth_scan,
|
||||
hit_maat_items, real_hit_item_cnt);
|
||||
}
|
||||
|
||||
void expr_runtime_stream_close(struct expr_runtime *expr_rt, int thread_id,
|
||||
struct expr_matcher_stream *stream)
|
||||
void expr_runtime_stream_close(struct expr_runtime_stream *expr_rt_stream)
|
||||
{
|
||||
if (NULL == expr_rt || thread_id < 0 || NULL == stream) {
|
||||
if (NULL == expr_rt_stream) {
|
||||
return;
|
||||
}
|
||||
|
||||
expr_matcher_stream_close(stream);
|
||||
}
|
||||
|
||||
void expr_runtime_hit_inc(struct expr_runtime *expr_rt, int thread_id)
|
||||
{
|
||||
if (NULL == expr_rt || thread_id < 0) {
|
||||
return;
|
||||
expr_rt_stream->ref_expr_rt = NULL;
|
||||
if (expr_rt_stream->handle != NULL) {
|
||||
expr_matcher_stream_close(expr_rt_stream->handle);
|
||||
}
|
||||
|
||||
alignment_int64_array_add(expr_rt->hit_cnt, thread_id, 1);
|
||||
FREE(expr_rt_stream);
|
||||
}
|
||||
|
||||
void expr_runtime_perf_stat(struct expr_runtime *expr_rt, size_t scan_len,
|
||||
@@ -1157,7 +1199,7 @@ void expr_runtime_perf_stat(struct expr_runtime *expr_rt, size_t scan_len,
|
||||
return;
|
||||
}
|
||||
|
||||
alignment_int64_array_add(expr_rt->scan_cnt, thread_id, 1);
|
||||
alignment_int64_array_add(expr_rt->scan_times, thread_id, 1);
|
||||
alignment_int64_array_add(expr_rt->scan_bytes, thread_id, scan_len);
|
||||
|
||||
if (start != NULL && end != NULL) {
|
||||
@@ -1167,16 +1209,16 @@ void expr_runtime_perf_stat(struct expr_runtime *expr_rt, size_t scan_len,
|
||||
}
|
||||
}
|
||||
|
||||
long long expr_runtime_scan_count(void *expr_runtime)
|
||||
long long expr_runtime_scan_times(void *expr_runtime)
|
||||
{
|
||||
if (NULL == expr_runtime) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct expr_runtime *expr_rt = (struct expr_runtime *)expr_runtime;
|
||||
long long sum = alignment_int64_array_sum(expr_rt->scan_cnt,
|
||||
long long sum = alignment_int64_array_sum(expr_rt->scan_times,
|
||||
expr_rt->n_worker_thread);
|
||||
alignment_int64_array_reset(expr_rt->scan_cnt, expr_rt->n_worker_thread);
|
||||
alignment_int64_array_reset(expr_rt->scan_times, expr_rt->n_worker_thread);
|
||||
|
||||
return sum;
|
||||
}
|
||||
@@ -1195,16 +1237,66 @@ long long expr_runtime_scan_cpu_time(void *expr_runtime)
|
||||
return sum;
|
||||
}
|
||||
|
||||
long long expr_runtime_hit_count(void *expr_runtime)
|
||||
void expr_runtime_hit_times_inc(struct expr_runtime *expr_rt, int thread_id)
|
||||
{
|
||||
if (NULL == expr_rt || thread_id < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
alignment_int64_array_add(expr_rt->hit_times, thread_id, 1);
|
||||
}
|
||||
|
||||
void expr_runtime_stream_hit_times_inc(struct expr_runtime_stream *expr_rt_stream,
|
||||
int thread_id)
|
||||
{
|
||||
if (NULL == expr_rt_stream || thread_id < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct expr_runtime *expr_rt = expr_rt_stream->ref_expr_rt;
|
||||
alignment_int64_array_add(expr_rt->hit_times, thread_id, 1);
|
||||
}
|
||||
|
||||
long long expr_runtime_hit_times(void *expr_runtime)
|
||||
{
|
||||
if (NULL == expr_runtime) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct expr_runtime *expr_rt = (struct expr_runtime *)expr_runtime;
|
||||
long long sum = alignment_int64_array_sum(expr_rt->hit_cnt,
|
||||
long long sum = alignment_int64_array_sum(expr_rt->hit_times,
|
||||
expr_rt->n_worker_thread);
|
||||
alignment_int64_array_reset(expr_rt->hit_cnt, expr_rt->n_worker_thread);
|
||||
alignment_int64_array_reset(expr_rt->hit_times,
|
||||
expr_rt->n_worker_thread);
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
long long expr_runtime_hit_item_num(void *expr_runtime)
|
||||
{
|
||||
if (NULL == expr_runtime) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct expr_runtime *expr_rt = (struct expr_runtime *)expr_runtime;
|
||||
long long sum = alignment_int64_array_sum(expr_rt->hit_item_num,
|
||||
expr_rt->n_worker_thread);
|
||||
alignment_int64_array_reset(expr_rt->hit_item_num, expr_rt->n_worker_thread);
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
long long expr_runtime_hit_pattern_num(void *expr_runtime)
|
||||
{
|
||||
if (NULL == expr_runtime) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct expr_runtime *expr_rt = (struct expr_runtime *)expr_runtime;
|
||||
long long sum = alignment_int64_array_sum(expr_rt->hit_pattern_num,
|
||||
expr_rt->n_worker_thread);
|
||||
alignment_int64_array_reset(expr_rt->hit_pattern_num,
|
||||
expr_rt->n_worker_thread);
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
114
src/maat_flag.c
114
src/maat_flag.c
@@ -56,10 +56,13 @@ struct flag_runtime {
|
||||
struct maat_kv_store *district_map;
|
||||
struct maat_kv_store *tmp_district_map;
|
||||
|
||||
long long update_err_cnt;
|
||||
long long *scan_cnt;
|
||||
long long *scan_times;
|
||||
long long *scan_cpu_time;
|
||||
long long *hit_cnt;
|
||||
|
||||
long long *hit_times;
|
||||
long long *hit_item_num;
|
||||
|
||||
long long update_err_cnt;
|
||||
};
|
||||
|
||||
void *flag_schema_new(cJSON *json, struct table_manager *tbl_mgr,
|
||||
@@ -192,10 +195,12 @@ void *flag_runtime_new(void *flag_schema, size_t max_thread_num,
|
||||
flag_rt->logger = logger;
|
||||
flag_rt->district_map = maat_kv_store_new();
|
||||
|
||||
flag_rt->hit_cnt = alignment_int64_array_alloc(max_thread_num);
|
||||
flag_rt->scan_cnt = alignment_int64_array_alloc(max_thread_num);
|
||||
flag_rt->scan_times = alignment_int64_array_alloc(max_thread_num);
|
||||
flag_rt->scan_cpu_time = alignment_int64_array_alloc(max_thread_num);
|
||||
|
||||
flag_rt->hit_times = alignment_int64_array_alloc(max_thread_num);
|
||||
flag_rt->hit_item_num = alignment_int64_array_alloc(max_thread_num);
|
||||
|
||||
return flag_rt;
|
||||
}
|
||||
|
||||
@@ -223,14 +228,9 @@ void flag_runtime_free(void *flag_runtime)
|
||||
flag_rt->district_map = NULL;
|
||||
}
|
||||
|
||||
if (flag_rt->hit_cnt != NULL) {
|
||||
alignment_int64_array_free(flag_rt->hit_cnt);
|
||||
flag_rt->hit_cnt = NULL;
|
||||
}
|
||||
|
||||
if (flag_rt->scan_cnt != NULL) {
|
||||
alignment_int64_array_free(flag_rt->scan_cnt);
|
||||
flag_rt->scan_cnt = NULL;
|
||||
if (flag_rt->scan_times != NULL) {
|
||||
alignment_int64_array_free(flag_rt->scan_times);
|
||||
flag_rt->scan_times = NULL;
|
||||
}
|
||||
|
||||
if (flag_rt->scan_cpu_time != NULL) {
|
||||
@@ -238,6 +238,16 @@ void flag_runtime_free(void *flag_runtime)
|
||||
flag_rt->scan_cpu_time = NULL;
|
||||
}
|
||||
|
||||
if (flag_rt->hit_times != NULL) {
|
||||
alignment_int64_array_free(flag_rt->hit_times);
|
||||
flag_rt->hit_times = NULL;
|
||||
}
|
||||
|
||||
if (flag_rt->hit_item_num != NULL) {
|
||||
alignment_int64_array_free(flag_rt->hit_item_num);
|
||||
flag_rt->hit_item_num = NULL;
|
||||
}
|
||||
|
||||
FREE(flag_rt);
|
||||
}
|
||||
|
||||
@@ -562,6 +572,11 @@ int flag_runtime_scan(struct flag_runtime *flag_rt, int thread_id,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (n_hit_item > 0) {
|
||||
alignment_int64_array_add(flag_rt->hit_item_num, state->thread_id,
|
||||
n_hit_item);
|
||||
}
|
||||
|
||||
struct maat_item hit_maat_items[n_hit_item];
|
||||
size_t real_hit_item_cnt = 0;
|
||||
|
||||
@@ -595,19 +610,10 @@ next:
|
||||
}
|
||||
|
||||
return compile_state_update(state->compile_state, state->maat_inst, vtable_id,
|
||||
state->compile_table_id, state->scan_cnt,
|
||||
state->compile_table_id, state->Nth_scan,
|
||||
hit_maat_items, real_hit_item_cnt);
|
||||
}
|
||||
|
||||
void flag_runtime_hit_inc(struct flag_runtime *flag_rt, int thread_id)
|
||||
{
|
||||
if (NULL == flag_rt || thread_id < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
alignment_int64_array_add(flag_rt->hit_cnt, thread_id, 1);
|
||||
}
|
||||
|
||||
void flag_runtime_perf_stat(struct flag_runtime *flag_rt, struct timespec *start,
|
||||
struct timespec *end, int thread_id)
|
||||
{
|
||||
@@ -615,7 +621,7 @@ void flag_runtime_perf_stat(struct flag_runtime *flag_rt, struct timespec *start
|
||||
return;
|
||||
}
|
||||
|
||||
alignment_int64_array_add(flag_rt->scan_cnt, thread_id, 1);
|
||||
alignment_int64_array_add(flag_rt->scan_times, thread_id, 1);
|
||||
|
||||
if (start != NULL && end != NULL) {
|
||||
long long consume_time = (end->tv_sec - start->tv_sec) * 1000000000 +
|
||||
@@ -624,16 +630,56 @@ void flag_runtime_perf_stat(struct flag_runtime *flag_rt, struct timespec *start
|
||||
}
|
||||
}
|
||||
|
||||
long long flag_runtime_scan_count(void *flag_runtime)
|
||||
long long flag_runtime_hit_times(void *flag_runtime)
|
||||
{
|
||||
if (NULL == flag_runtime) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct flag_runtime *flag_rt = (struct flag_runtime *)flag_runtime;
|
||||
long long sum = alignment_int64_array_sum(flag_rt->scan_cnt,
|
||||
long long sum = alignment_int64_array_sum(flag_rt->hit_times,
|
||||
flag_rt->n_worker_thread);
|
||||
alignment_int64_array_reset(flag_rt->scan_cnt, flag_rt->n_worker_thread);
|
||||
alignment_int64_array_reset(flag_rt->hit_times,
|
||||
flag_rt->n_worker_thread);
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
void flag_runtime_hit_times_inc(struct flag_runtime *flag_rt, int thread_id)
|
||||
{
|
||||
if (NULL == flag_rt || thread_id < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
alignment_int64_array_add(flag_rt->hit_times, thread_id, 1);
|
||||
}
|
||||
|
||||
long long flag_runtime_hit_item_num(void *flag_runtime)
|
||||
{
|
||||
if (NULL == flag_runtime) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct flag_runtime *flag_rt = (struct flag_runtime *)flag_runtime;
|
||||
long long sum = alignment_int64_array_sum(flag_rt->hit_item_num,
|
||||
flag_rt->n_worker_thread);
|
||||
alignment_int64_array_reset(flag_rt->hit_item_num,
|
||||
flag_rt->n_worker_thread);
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
long long flag_runtime_scan_times(void *flag_runtime)
|
||||
{
|
||||
if (NULL == flag_runtime) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct flag_runtime *flag_rt = (struct flag_runtime *)flag_runtime;
|
||||
long long sum = alignment_int64_array_sum(flag_rt->scan_times,
|
||||
flag_rt->n_worker_thread);
|
||||
alignment_int64_array_reset(flag_rt->scan_times,
|
||||
flag_rt->n_worker_thread);
|
||||
|
||||
return sum;
|
||||
}
|
||||
@@ -652,20 +698,6 @@ long long flag_runtime_scan_cpu_time(void *flag_runtime)
|
||||
return sum;
|
||||
}
|
||||
|
||||
long long flag_runtime_hit_count(void *flag_runtime)
|
||||
{
|
||||
if (NULL == flag_runtime) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct flag_runtime *flag_rt = (struct flag_runtime *)flag_runtime;
|
||||
long long sum = alignment_int64_array_sum(flag_rt->hit_cnt,
|
||||
flag_rt->n_worker_thread);
|
||||
alignment_int64_array_reset(flag_rt->hit_cnt, flag_rt->n_worker_thread);
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
long long flag_runtime_update_err_count(void *flag_runtime)
|
||||
{
|
||||
if (NULL == flag_runtime) {
|
||||
|
||||
@@ -40,7 +40,7 @@ struct fqdn_plugin_runtime {
|
||||
|
||||
long long rule_num;
|
||||
long long update_err_cnt;
|
||||
long long *scan_cnt;
|
||||
long long *scan_times;
|
||||
};
|
||||
|
||||
void *fqdn_plugin_schema_new(cJSON *json, struct table_manager *tbl_mgr,
|
||||
@@ -198,7 +198,7 @@ void *fqdn_plugin_runtime_new(void *fqdn_plugin_schema, size_t max_thread_num,
|
||||
fqdn_plugin_rt->n_worker_thread = max_thread_num;
|
||||
fqdn_plugin_rt->ref_garbage_bin = garbage_bin;
|
||||
fqdn_plugin_rt->logger = logger;
|
||||
fqdn_plugin_rt->scan_cnt = alignment_int64_array_alloc(max_thread_num);
|
||||
fqdn_plugin_rt->scan_times = alignment_int64_array_alloc(max_thread_num);
|
||||
|
||||
return fqdn_plugin_rt;
|
||||
}
|
||||
@@ -220,9 +220,9 @@ void fqdn_plugin_runtime_free(void *fqdn_plugin_runtime)
|
||||
fqdn_plugin_rt->ex_data_rt = NULL;
|
||||
}
|
||||
|
||||
if (fqdn_plugin_rt->scan_cnt != NULL) {
|
||||
alignment_int64_array_free(fqdn_plugin_rt->scan_cnt);
|
||||
fqdn_plugin_rt->scan_cnt = NULL;
|
||||
if (fqdn_plugin_rt->scan_times != NULL) {
|
||||
alignment_int64_array_free(fqdn_plugin_rt->scan_times);
|
||||
fqdn_plugin_rt->scan_times = NULL;
|
||||
}
|
||||
|
||||
FREE(fqdn_plugin_rt);
|
||||
@@ -596,26 +596,27 @@ long long fqdn_plugin_runtime_update_err_count(void *fqdn_plugin_runtime)
|
||||
return fqdn_plugin_rt->update_err_cnt;
|
||||
}
|
||||
|
||||
void fqdn_plugin_runtime_scan_inc(void *fqdn_plugin_runtime, int thread_id)
|
||||
void fqdn_plugin_runtime_scan_times_inc(void *fqdn_plugin_runtime, int thread_id)
|
||||
{
|
||||
if (NULL == fqdn_plugin_runtime || thread_id < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct fqdn_plugin_runtime *fqdn_plugin_rt = (struct fqdn_plugin_runtime *)fqdn_plugin_runtime;
|
||||
alignment_int64_array_add(fqdn_plugin_rt->scan_cnt, thread_id, 1);
|
||||
alignment_int64_array_add(fqdn_plugin_rt->scan_times, thread_id, 1);
|
||||
}
|
||||
|
||||
long long fqdn_plugin_runtime_scan_count(void *fqdn_plugin_runtime)
|
||||
long long fqdn_plugin_runtime_scan_times(void *fqdn_plugin_runtime)
|
||||
{
|
||||
if (NULL == fqdn_plugin_runtime) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct fqdn_plugin_runtime *fqdn_plugin_rt = (struct fqdn_plugin_runtime *)fqdn_plugin_runtime;
|
||||
long long sum = alignment_int64_array_sum(fqdn_plugin_rt->scan_cnt,
|
||||
long long sum = alignment_int64_array_sum(fqdn_plugin_rt->scan_times,
|
||||
fqdn_plugin_rt->n_worker_thread);
|
||||
alignment_int64_array_reset(fqdn_plugin_rt->scan_cnt, fqdn_plugin_rt->n_worker_thread);
|
||||
alignment_int64_array_reset(fqdn_plugin_rt->scan_times,
|
||||
fqdn_plugin_rt->n_worker_thread);
|
||||
|
||||
return sum;
|
||||
}
|
||||
@@ -53,10 +53,13 @@ struct interval_runtime {
|
||||
struct maat_kv_store *district_map;
|
||||
struct maat_kv_store *tmp_district_map;
|
||||
|
||||
long long update_err_cnt;
|
||||
long long *scan_cnt;
|
||||
long long *scan_times;
|
||||
long long *scan_cpu_time;
|
||||
long long *hit_cnt;
|
||||
|
||||
long long *hit_times;
|
||||
long long *hit_item_num;
|
||||
|
||||
long long update_err_cnt;
|
||||
};
|
||||
|
||||
void *interval_schema_new(cJSON *json, struct table_manager *tbl_mgr,
|
||||
@@ -188,9 +191,10 @@ void *interval_runtime_new(void *interval_schema, size_t max_thread_num,
|
||||
interval_rt->logger = logger;
|
||||
interval_rt->district_map = maat_kv_store_new();
|
||||
|
||||
interval_rt->hit_cnt = alignment_int64_array_alloc(max_thread_num);
|
||||
interval_rt->scan_cnt = alignment_int64_array_alloc(max_thread_num);
|
||||
interval_rt->hit_times = alignment_int64_array_alloc(max_thread_num);
|
||||
interval_rt->scan_times = alignment_int64_array_alloc(max_thread_num);
|
||||
interval_rt->scan_cpu_time = alignment_int64_array_alloc(max_thread_num);
|
||||
interval_rt->hit_item_num = alignment_int64_array_alloc(max_thread_num);
|
||||
|
||||
return interval_rt;
|
||||
}
|
||||
@@ -219,14 +223,14 @@ void interval_runtime_free(void *interval_runtime)
|
||||
interval_rt->district_map = NULL;
|
||||
}
|
||||
|
||||
if (interval_rt->hit_cnt != NULL) {
|
||||
alignment_int64_array_free(interval_rt->hit_cnt);
|
||||
interval_rt->hit_cnt = NULL;
|
||||
if (interval_rt->hit_times != NULL) {
|
||||
alignment_int64_array_free(interval_rt->hit_times);
|
||||
interval_rt->hit_times = NULL;
|
||||
}
|
||||
|
||||
if (interval_rt->scan_cnt != NULL) {
|
||||
alignment_int64_array_free(interval_rt->scan_cnt);
|
||||
interval_rt->scan_cnt = NULL;
|
||||
if (interval_rt->scan_times != NULL) {
|
||||
alignment_int64_array_free(interval_rt->scan_times);
|
||||
interval_rt->scan_times = NULL;
|
||||
}
|
||||
|
||||
if (interval_rt->scan_cpu_time != NULL) {
|
||||
@@ -234,6 +238,11 @@ void interval_runtime_free(void *interval_runtime)
|
||||
interval_rt->scan_cpu_time = NULL;
|
||||
}
|
||||
|
||||
if (interval_rt->hit_item_num != NULL) {
|
||||
alignment_int64_array_free(interval_rt->hit_item_num);
|
||||
interval_rt->hit_item_num = NULL;
|
||||
}
|
||||
|
||||
FREE(interval_rt);
|
||||
}
|
||||
|
||||
@@ -563,6 +572,11 @@ int interval_runtime_scan(struct interval_runtime *interval_rt, int thread_id,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (n_hit_item > 0) {
|
||||
alignment_int64_array_add(interval_rt->hit_item_num, state->thread_id,
|
||||
n_hit_item);
|
||||
}
|
||||
|
||||
struct maat_item hit_maat_items[n_hit_item];
|
||||
size_t real_hit_item_cnt = 0;
|
||||
|
||||
@@ -596,19 +610,10 @@ next:
|
||||
}
|
||||
|
||||
return compile_state_update(state->compile_state, state->maat_inst, vtable_id,
|
||||
state->compile_table_id, state->scan_cnt,
|
||||
state->compile_table_id, state->Nth_scan,
|
||||
hit_maat_items, real_hit_item_cnt);
|
||||
}
|
||||
|
||||
void interval_runtime_hit_inc(struct interval_runtime *interval_rt, int thread_id)
|
||||
{
|
||||
if (NULL == interval_rt || thread_id < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
alignment_int64_array_add(interval_rt->hit_cnt, thread_id, 1);
|
||||
}
|
||||
|
||||
void interval_runtime_perf_stat(struct interval_runtime *interval_rt,
|
||||
struct timespec *start, struct timespec *end,
|
||||
int thread_id)
|
||||
@@ -617,7 +622,7 @@ void interval_runtime_perf_stat(struct interval_runtime *interval_rt,
|
||||
return;
|
||||
}
|
||||
|
||||
alignment_int64_array_add(interval_rt->scan_cnt, thread_id, 1);
|
||||
alignment_int64_array_add(interval_rt->scan_times, thread_id, 1);
|
||||
|
||||
if (start != NULL && end != NULL) {
|
||||
long long consume_time = (end->tv_sec - start->tv_sec) * 1000000000 +
|
||||
@@ -626,16 +631,41 @@ void interval_runtime_perf_stat(struct interval_runtime *interval_rt,
|
||||
}
|
||||
}
|
||||
|
||||
long long interval_runtime_scan_count(void *interval_runtime)
|
||||
long long interval_runtime_hit_times(void *interval_runtime)
|
||||
{
|
||||
if (NULL == interval_runtime) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct interval_runtime *interval_rt = (struct interval_runtime *)interval_runtime;
|
||||
long long sum = alignment_int64_array_sum(interval_rt->scan_cnt,
|
||||
long long sum = alignment_int64_array_sum(interval_rt->hit_times,
|
||||
interval_rt->n_worker_thread);
|
||||
alignment_int64_array_reset(interval_rt->scan_cnt, interval_rt->n_worker_thread);
|
||||
alignment_int64_array_reset(interval_rt->hit_times,
|
||||
interval_rt->n_worker_thread);
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
void interval_runtime_hit_times_inc(struct interval_runtime *interval_rt, int thread_id)
|
||||
{
|
||||
if (NULL == interval_rt || thread_id < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
alignment_int64_array_add(interval_rt->hit_times, thread_id, 1);
|
||||
}
|
||||
|
||||
long long interval_runtime_scan_times(void *interval_runtime)
|
||||
{
|
||||
if (NULL == interval_runtime) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct interval_runtime *interval_rt = (struct interval_runtime *)interval_runtime;
|
||||
long long sum = alignment_int64_array_sum(interval_rt->scan_times,
|
||||
interval_rt->n_worker_thread);
|
||||
alignment_int64_array_reset(interval_rt->scan_times,
|
||||
interval_rt->n_worker_thread);
|
||||
|
||||
return sum;
|
||||
}
|
||||
@@ -649,21 +679,23 @@ long long interval_runtime_scan_cpu_time(void *interval_runtime)
|
||||
struct interval_runtime *interval_rt = (struct interval_runtime *)interval_runtime;
|
||||
long long sum = alignment_int64_array_sum(interval_rt->scan_cpu_time,
|
||||
interval_rt->n_worker_thread);
|
||||
alignment_int64_array_reset(interval_rt->scan_cpu_time, interval_rt->n_worker_thread);
|
||||
alignment_int64_array_reset(interval_rt->scan_cpu_time,
|
||||
interval_rt->n_worker_thread);
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
long long interval_runtime_hit_count(void *interval_runtime)
|
||||
long long interval_runtime_hit_item_num(void *interval_runtime)
|
||||
{
|
||||
if (NULL == interval_runtime) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct interval_runtime *interval_rt = (struct interval_runtime *)interval_runtime;
|
||||
long long sum = alignment_int64_array_sum(interval_rt->hit_cnt,
|
||||
long long sum = alignment_int64_array_sum(interval_rt->hit_item_num,
|
||||
interval_rt->n_worker_thread);
|
||||
alignment_int64_array_reset(interval_rt->hit_cnt, interval_rt->n_worker_thread);
|
||||
alignment_int64_array_reset(interval_rt->hit_item_num,
|
||||
interval_rt->n_worker_thread);
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
@@ -79,10 +79,13 @@ struct ip_runtime {
|
||||
struct log_handle *logger;
|
||||
struct maat_garbage_bin *ref_garbage_bin;
|
||||
|
||||
long long update_err_cnt;
|
||||
long long *scan_cnt;
|
||||
long long *scan_times;
|
||||
long long *scan_cpu_time;
|
||||
long long *hit_cnt;
|
||||
|
||||
long long *hit_times;
|
||||
long long *hit_item_num;
|
||||
|
||||
long long update_err_cnt;
|
||||
};
|
||||
|
||||
void *ip_schema_new(cJSON *json, struct table_manager *tbl_mgr,
|
||||
@@ -429,10 +432,12 @@ void *ip_runtime_new(void *ip_schema, size_t max_thread_num,
|
||||
ip_rt->ref_garbage_bin = garbage_bin;
|
||||
ip_rt->logger = logger;
|
||||
|
||||
ip_rt->hit_cnt = alignment_int64_array_alloc(max_thread_num);
|
||||
ip_rt->scan_cnt = alignment_int64_array_alloc(max_thread_num);
|
||||
ip_rt->scan_times = alignment_int64_array_alloc(max_thread_num);
|
||||
ip_rt->scan_cpu_time = alignment_int64_array_alloc(max_thread_num);
|
||||
|
||||
ip_rt->hit_times = alignment_int64_array_alloc(max_thread_num);
|
||||
ip_rt->hit_item_num = alignment_int64_array_alloc(max_thread_num);
|
||||
|
||||
return ip_rt;
|
||||
}
|
||||
|
||||
@@ -453,14 +458,9 @@ void ip_runtime_free(void *ip_runtime)
|
||||
ip_rt->item_hash = NULL;
|
||||
}
|
||||
|
||||
if (ip_rt->hit_cnt != NULL) {
|
||||
alignment_int64_array_free(ip_rt->hit_cnt);
|
||||
ip_rt->hit_cnt = NULL;
|
||||
}
|
||||
|
||||
if (ip_rt->scan_cnt != NULL) {
|
||||
alignment_int64_array_free(ip_rt->scan_cnt);
|
||||
ip_rt->scan_cnt = NULL;
|
||||
if (ip_rt->scan_times != NULL) {
|
||||
alignment_int64_array_free(ip_rt->scan_times);
|
||||
ip_rt->scan_times = NULL;
|
||||
}
|
||||
|
||||
if (ip_rt->scan_cpu_time != NULL) {
|
||||
@@ -468,6 +468,16 @@ void ip_runtime_free(void *ip_runtime)
|
||||
ip_rt->scan_cpu_time = NULL;
|
||||
}
|
||||
|
||||
if (ip_rt->hit_times != NULL) {
|
||||
alignment_int64_array_free(ip_rt->hit_times);
|
||||
ip_rt->hit_times = NULL;
|
||||
}
|
||||
|
||||
if (ip_rt->hit_item_num != NULL) {
|
||||
alignment_int64_array_free(ip_rt->hit_item_num);
|
||||
ip_rt->hit_item_num = NULL;
|
||||
}
|
||||
|
||||
FREE(ip_rt);
|
||||
}
|
||||
|
||||
@@ -760,6 +770,10 @@ int ip_runtime_scan(struct ip_runtime *ip_rt, int thread_id, int ip_type,
|
||||
real_hit_item_cnt++;
|
||||
}
|
||||
|
||||
if (real_hit_item_cnt > 0) {
|
||||
alignment_int64_array_add(ip_rt->hit_item_num, state->thread_id,
|
||||
real_hit_item_cnt);
|
||||
}
|
||||
next:
|
||||
if (NULL == state->compile_state) {
|
||||
state->compile_state = compile_state_new();
|
||||
@@ -768,19 +782,10 @@ next:
|
||||
}
|
||||
|
||||
return compile_state_update(state->compile_state, state->maat_inst, vtable_id,
|
||||
state->compile_table_id, state->scan_cnt,
|
||||
state->compile_table_id, state->Nth_scan,
|
||||
hit_maat_items, real_hit_item_cnt);
|
||||
}
|
||||
|
||||
void ip_runtime_hit_inc(struct ip_runtime *ip_rt, int thread_id)
|
||||
{
|
||||
if (NULL == ip_rt || thread_id < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
alignment_int64_array_add(ip_rt->hit_cnt, thread_id, 1);
|
||||
}
|
||||
|
||||
void ip_runtime_perf_stat(struct ip_runtime *ip_rt, struct timespec *start,
|
||||
struct timespec *end, int thread_id)
|
||||
{
|
||||
@@ -788,7 +793,7 @@ void ip_runtime_perf_stat(struct ip_runtime *ip_rt, struct timespec *start,
|
||||
return;
|
||||
}
|
||||
|
||||
alignment_int64_array_add(ip_rt->scan_cnt, thread_id, 1);
|
||||
alignment_int64_array_add(ip_rt->scan_times, thread_id, 1);
|
||||
|
||||
if (start != NULL && end != NULL) {
|
||||
long long consume_time = (end->tv_sec - start->tv_sec) * 1000000000 +
|
||||
@@ -797,15 +802,17 @@ void ip_runtime_perf_stat(struct ip_runtime *ip_rt, struct timespec *start,
|
||||
}
|
||||
}
|
||||
|
||||
long long ip_runtime_scan_count(void *ip_runtime)
|
||||
long long ip_runtime_scan_times(void *ip_runtime)
|
||||
{
|
||||
if (NULL == ip_runtime) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct ip_runtime *ip_rt = (struct ip_runtime *)ip_runtime;
|
||||
long long sum = alignment_int64_array_sum(ip_rt->scan_cnt, ip_rt->n_worker_thread);
|
||||
alignment_int64_array_reset(ip_rt->scan_cnt, ip_rt->n_worker_thread);
|
||||
long long sum = alignment_int64_array_sum(ip_rt->scan_times,
|
||||
ip_rt->n_worker_thread);
|
||||
alignment_int64_array_reset(ip_rt->scan_times,
|
||||
ip_rt->n_worker_thread);
|
||||
|
||||
return sum;
|
||||
}
|
||||
@@ -824,16 +831,41 @@ long long ip_runtime_scan_cpu_time(void *ip_runtime)
|
||||
return sum;
|
||||
}
|
||||
|
||||
long long ip_runtime_hit_count(void *ip_runtime)
|
||||
long long ip_runtime_hit_times(void *ip_runtime)
|
||||
{
|
||||
if (NULL == ip_runtime) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct ip_runtime *ip_rt = (struct ip_runtime *)ip_runtime;
|
||||
long long sum = alignment_int64_array_sum(ip_rt->hit_cnt,
|
||||
long long sum = alignment_int64_array_sum(ip_rt->hit_times,
|
||||
ip_rt->n_worker_thread);
|
||||
alignment_int64_array_reset(ip_rt->hit_cnt, ip_rt->n_worker_thread);
|
||||
alignment_int64_array_reset(ip_rt->hit_times,
|
||||
ip_rt->n_worker_thread);
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
void ip_runtime_hit_times_inc(struct ip_runtime *ip_rt, int thread_id)
|
||||
{
|
||||
if (NULL == ip_rt || thread_id < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
alignment_int64_array_add(ip_rt->hit_times, thread_id, 1);
|
||||
}
|
||||
|
||||
long long ip_runtime_hit_item_num(void *ip_runtime)
|
||||
{
|
||||
if (NULL == ip_runtime) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct ip_runtime *ip_rt = (struct ip_runtime *)ip_runtime;
|
||||
long long sum = alignment_int64_array_sum(ip_rt->hit_item_num,
|
||||
ip_rt->n_worker_thread);
|
||||
alignment_int64_array_reset(ip_rt->hit_item_num,
|
||||
ip_rt->n_worker_thread);
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ struct ip_plugin_runtime {
|
||||
|
||||
long long rule_num;
|
||||
long long update_err_cnt;
|
||||
long long *scan_cnt;
|
||||
long long *scan_times;
|
||||
};
|
||||
|
||||
void *ip_plugin_schema_new(cJSON *json, struct table_manager *tbl_mgr,
|
||||
@@ -362,7 +362,7 @@ void *ip_plugin_runtime_new(void *ip_plugin_schema, size_t max_thread_num,
|
||||
ip_plugin_rt->n_worker_thread = max_thread_num;
|
||||
ip_plugin_rt->ref_garbage_bin = garbage_bin;
|
||||
ip_plugin_rt->logger = logger;
|
||||
ip_plugin_rt->scan_cnt = alignment_int64_array_alloc(max_thread_num);
|
||||
ip_plugin_rt->scan_times = alignment_int64_array_alloc(max_thread_num);
|
||||
|
||||
return ip_plugin_rt;
|
||||
}
|
||||
@@ -384,9 +384,9 @@ void ip_plugin_runtime_free(void *ip_plugin_runtime)
|
||||
ip_plugin_rt->ex_data_rt = NULL;
|
||||
}
|
||||
|
||||
if (ip_plugin_rt->scan_cnt != NULL) {
|
||||
alignment_int64_array_free(ip_plugin_rt->scan_cnt);
|
||||
ip_plugin_rt->scan_cnt = NULL;
|
||||
if (ip_plugin_rt->scan_times != NULL) {
|
||||
alignment_int64_array_free(ip_plugin_rt->scan_times);
|
||||
ip_plugin_rt->scan_times = NULL;
|
||||
}
|
||||
|
||||
FREE(ip_plugin_rt);
|
||||
@@ -596,26 +596,27 @@ long long ip_plugin_runtime_update_err_count(void *ip_plugin_runtime)
|
||||
return ip_plugin_rt->update_err_cnt;
|
||||
}
|
||||
|
||||
void ip_plugin_runtime_scan_inc(void *ip_plugin_runtime, int thread_id)
|
||||
void ip_plugin_runtime_scan_times_inc(void *ip_plugin_runtime, int thread_id)
|
||||
{
|
||||
if (NULL == ip_plugin_runtime || thread_id < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct ip_plugin_runtime *ip_plugin_rt = (struct ip_plugin_runtime *)ip_plugin_runtime;
|
||||
alignment_int64_array_add(ip_plugin_rt->scan_cnt, thread_id, 1);
|
||||
alignment_int64_array_add(ip_plugin_rt->scan_times, thread_id, 1);
|
||||
}
|
||||
|
||||
long long ip_plugin_runtime_scan_count(void *ip_plugin_runtime)
|
||||
long long ip_plugin_runtime_scan_times(void *ip_plugin_runtime)
|
||||
{
|
||||
if (NULL == ip_plugin_runtime) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct ip_plugin_runtime *ip_plugin_rt = (struct ip_plugin_runtime *)ip_plugin_runtime;
|
||||
long long sum = alignment_int64_array_sum(ip_plugin_rt->scan_cnt,
|
||||
long long sum = alignment_int64_array_sum(ip_plugin_rt->scan_times,
|
||||
ip_plugin_rt->n_worker_thread);
|
||||
alignment_int64_array_reset(ip_plugin_rt->scan_cnt, ip_plugin_rt->n_worker_thread);
|
||||
alignment_int64_array_reset(ip_plugin_rt->scan_times,
|
||||
ip_plugin_rt->n_worker_thread);
|
||||
|
||||
return sum;
|
||||
}
|
||||
@@ -65,7 +65,7 @@ struct ipport_plugin_runtime {
|
||||
|
||||
long long rule_num;
|
||||
long long update_err_cnt;
|
||||
long long *scan_cnt;
|
||||
long long *scan_times;
|
||||
};
|
||||
|
||||
void *ipport_plugin_schema_new(cJSON *json, struct table_manager *tbl_mgr,
|
||||
@@ -223,7 +223,7 @@ void *ipport_plugin_runtime_new(void *ipport_plugin_schema, size_t max_thread_nu
|
||||
ipport_plugin_rt->n_worker_thread = max_thread_num;
|
||||
ipport_plugin_rt->ref_garbage_bin = garbage_bin;
|
||||
ipport_plugin_rt->logger = logger;
|
||||
ipport_plugin_rt->scan_cnt = alignment_int64_array_alloc(max_thread_num);
|
||||
ipport_plugin_rt->scan_times = alignment_int64_array_alloc(max_thread_num);
|
||||
|
||||
return ipport_plugin_rt;
|
||||
}
|
||||
@@ -245,9 +245,9 @@ void ipport_plugin_runtime_free(void *ipport_plugin_runtime)
|
||||
ipport_plugin_rt->ex_data_rt = NULL;
|
||||
}
|
||||
|
||||
if (ipport_plugin_rt->scan_cnt != NULL) {
|
||||
alignment_int64_array_free(ipport_plugin_rt->scan_cnt);
|
||||
ipport_plugin_rt->scan_cnt = NULL;
|
||||
if (ipport_plugin_rt->scan_times != NULL) {
|
||||
alignment_int64_array_free(ipport_plugin_rt->scan_times);
|
||||
ipport_plugin_rt->scan_times = NULL;
|
||||
}
|
||||
|
||||
FREE(ipport_plugin_rt);
|
||||
@@ -634,26 +634,27 @@ long long ipport_plugin_runtime_update_err_count(void *ipport_plugin_runtime)
|
||||
return ipport_plugin_rt->update_err_cnt;
|
||||
}
|
||||
|
||||
void ipport_plugin_runtime_scan_inc(void *ipport_plugin_runtime, int thread_id)
|
||||
void ipport_plugin_runtime_scan_times_inc(void *ipport_plugin_runtime, int thread_id)
|
||||
{
|
||||
if (NULL == ipport_plugin_runtime || thread_id < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct ipport_plugin_runtime *ipport_plugin_rt = (struct ipport_plugin_runtime *)ipport_plugin_runtime;
|
||||
alignment_int64_array_add(ipport_plugin_rt->scan_cnt, thread_id, 1);
|
||||
alignment_int64_array_add(ipport_plugin_rt->scan_times, thread_id, 1);
|
||||
}
|
||||
|
||||
long long ipport_plugin_runtime_scan_count(void *ipport_plugin_runtime)
|
||||
long long ipport_plugin_runtime_scan_times(void *ipport_plugin_runtime)
|
||||
{
|
||||
if (NULL == ipport_plugin_runtime) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct ipport_plugin_runtime *ipport_plugin_rt = (struct ipport_plugin_runtime *)ipport_plugin_runtime;
|
||||
long long sum = alignment_int64_array_sum(ipport_plugin_rt->scan_cnt,
|
||||
long long sum = alignment_int64_array_sum(ipport_plugin_rt->scan_times,
|
||||
ipport_plugin_rt->n_worker_thread);
|
||||
alignment_int64_array_reset(ipport_plugin_rt->scan_cnt, ipport_plugin_rt->n_worker_thread);
|
||||
alignment_int64_array_reset(ipport_plugin_rt->scan_times,
|
||||
ipport_plugin_rt->n_worker_thread);
|
||||
|
||||
return sum;
|
||||
}
|
||||
@@ -41,7 +41,7 @@ struct plugin_runtime {
|
||||
long long rule_num;
|
||||
long long acc_line_num;
|
||||
long long update_err_cnt;
|
||||
long long *scan_cnt;
|
||||
long long *scan_times;
|
||||
};
|
||||
|
||||
enum plugin_key_type {
|
||||
@@ -320,7 +320,7 @@ void *plugin_runtime_new(void *plugin_schema, size_t max_thread_num,
|
||||
plugin_rt->n_worker_thread = max_thread_num;
|
||||
plugin_rt->ref_garbage_bin = garbage_bin;
|
||||
plugin_rt->logger = logger;
|
||||
plugin_rt->scan_cnt = alignment_int64_array_alloc(max_thread_num);
|
||||
plugin_rt->scan_times = alignment_int64_array_alloc(max_thread_num);
|
||||
|
||||
return plugin_rt;
|
||||
}
|
||||
@@ -337,9 +337,9 @@ void plugin_runtime_free(void *plugin_runtime)
|
||||
plugin_rt->ex_data_rt = NULL;
|
||||
}
|
||||
|
||||
if (plugin_rt->scan_cnt != NULL) {
|
||||
alignment_int64_array_free(plugin_rt->scan_cnt);
|
||||
plugin_rt->scan_cnt = NULL;
|
||||
if (plugin_rt->scan_times != NULL) {
|
||||
alignment_int64_array_free(plugin_rt->scan_times);
|
||||
plugin_rt->scan_times = NULL;
|
||||
}
|
||||
|
||||
FREE(plugin_rt);
|
||||
@@ -720,26 +720,27 @@ void *plugin_runtime_get_ex_data(void *plugin_runtime, void *plugin_schema,
|
||||
return ex_data_runtime_get_ex_data_by_key(plugin_rt->ex_data_rt, key, key_len);
|
||||
}
|
||||
|
||||
void plugin_runtime_scan_inc(void *plugin_runtime, int thread_id)
|
||||
void plugin_runtime_scan_times_inc(void *plugin_runtime, int thread_id)
|
||||
{
|
||||
if (NULL == plugin_runtime || thread_id < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct plugin_runtime *plugin_rt = (struct plugin_runtime *)plugin_runtime;
|
||||
alignment_int64_array_add(plugin_rt->scan_cnt, thread_id, 1);
|
||||
alignment_int64_array_add(plugin_rt->scan_times, thread_id, 1);
|
||||
}
|
||||
|
||||
long long plugin_runtime_scan_count(void *plugin_runtime)
|
||||
long long plugin_runtime_scan_times(void *plugin_runtime)
|
||||
{
|
||||
if (NULL == plugin_runtime) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct plugin_runtime *plugin_rt = (struct plugin_runtime *)plugin_runtime;
|
||||
long long sum = alignment_int64_array_sum(plugin_rt->scan_cnt,
|
||||
long long sum = alignment_int64_array_sum(plugin_rt->scan_times,
|
||||
plugin_rt->n_worker_thread);
|
||||
alignment_int64_array_reset(plugin_rt->scan_cnt, plugin_rt->n_worker_thread);
|
||||
alignment_int64_array_reset(plugin_rt->scan_times,
|
||||
plugin_rt->n_worker_thread);
|
||||
|
||||
return sum;
|
||||
}
|
||||
125
src/maat_stat.c
125
src/maat_stat.c
@@ -30,6 +30,7 @@ enum MAAT_FS_STATUS {
|
||||
STATUS_PLUGIN_ACC_NUM,
|
||||
STATUS_CLAUSE_REF_NOT_NUM,
|
||||
STATUS_GROUP_REF_EXCL_NUM, //group reference exclude group num
|
||||
STATUS_HIT_COMPILE_NUM,
|
||||
STATUS_MAAT_STATE_NUM,
|
||||
STATUS_MAAT_PER_STATE_MEM,
|
||||
STATUS_COMPILE_STATE_NUM,
|
||||
@@ -44,17 +45,19 @@ enum MAAT_FS_STATUS {
|
||||
enum MAAT_FS_COLUMN {
|
||||
COLUMN_RULE_NUM = 0,
|
||||
COLUMN_REGEX_NUM,
|
||||
COLUMN_SCAN_CNT,
|
||||
COLUMN_SCAN_TIMES, //the times of scan
|
||||
COLUMN_HIT_TIMES, //the times of hit compile
|
||||
COLUMN_SCAN_BYTES,
|
||||
COLUMN_CPU_TIME, //microseconds
|
||||
COLUMN_HIT_CNT,
|
||||
COLUMN_SCAN_BPS, //scan bytes per second
|
||||
COLUMN_SCAN_TPS, //scan times per second
|
||||
COLUMN_HIT_RATE //scan hit rate(hit_cnt/scan_cnt)
|
||||
COLUMN_SCAN_CPU_TIME, //microseconds
|
||||
COLUMN_HIT_ITEM_NUM,
|
||||
COLUMN_HIT_PAT_NUM, //hit pattern num(only valid for expr/expr_plus table)
|
||||
COLUMN_SCAN_BPS, //scan bytes per second
|
||||
COLUMN_SCAN_TPS, //scan times per second
|
||||
COLUMN_HIT_RATE //scan hit rate(hit_times/scan_times)
|
||||
};
|
||||
|
||||
const char *common_column_name[] = {"rule", "reg/v6", "scan_cnt", "scan_bytes", "scan_cpu_time",
|
||||
"hit_cnt", "IN_Bps", "IN_Tps", "hit_rate"};
|
||||
const char *common_column_name[] = {"rule", "reg/v6", "scan_times", "hit_times", "scan_bytes", "scan_cpu_time",
|
||||
"hit_item_num", "hit_pat_num", "IN_Bps", "IN_Tps", "hit_rate"};
|
||||
|
||||
enum field_type common_column_type[] = {
|
||||
FIELD_TYPE_GAUGE,
|
||||
@@ -66,6 +69,8 @@ enum field_type common_column_type[] = {
|
||||
FIELD_TYPE_GAUGE,
|
||||
FIELD_TYPE_GAUGE,
|
||||
FIELD_TYPE_GAUGE,
|
||||
FIELD_TYPE_GAUGE,
|
||||
FIELD_TYPE_GAUGE,
|
||||
FIELD_TYPE_GAUGE
|
||||
};
|
||||
|
||||
@@ -88,6 +93,8 @@ static void maat_fieldstat_register(struct maat_stat *stat)
|
||||
"excl_grp", NULL, 0);
|
||||
stat->fs_status_id[STATUS_GARBAGE_QSIZE] = fieldstat_register(stat->fs_handle, FIELD_TYPE_GAUGE,
|
||||
"garbage_num", NULL, 0);
|
||||
stat->fs_status_id[STATUS_HIT_COMPILE_NUM] = fieldstat_register(stat->fs_handle, FIELD_TYPE_GAUGE,
|
||||
"hit_compile_num", NULL, 0);
|
||||
stat->fs_status_id[STATUS_MAAT_STATE_NUM] = fieldstat_register(stat->fs_handle, FIELD_TYPE_GAUGE,
|
||||
"state_num", NULL, 0);
|
||||
stat->fs_status_id[STATUS_MAAT_PER_STATE_MEM] = fieldstat_register(stat->fs_handle, FIELD_TYPE_GAUGE,
|
||||
@@ -120,23 +127,23 @@ static int maat_fieldstat_table_row_register(struct maat_stat *stat,
|
||||
|
||||
ret = fieldstat_set_metric_ratio_para(stat->fs_handle, stat->total_stat_id[COLUMN_SCAN_BPS],
|
||||
stat->total_stat_id[COLUMN_SCAN_BYTES],
|
||||
stat->total_stat_id[COLUMN_CPU_TIME], 1000000000);
|
||||
stat->total_stat_id[COLUMN_SCAN_CPU_TIME], 1000000000);
|
||||
if (ret < 0) {
|
||||
log_fatal(stat->logger, MODULE_MAAT_STAT, "fieldstat set IN_Bps for Sum failed.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = fieldstat_set_metric_ratio_para(stat->fs_handle, stat->total_stat_id[COLUMN_SCAN_TPS],
|
||||
stat->total_stat_id[COLUMN_SCAN_CNT],
|
||||
stat->total_stat_id[COLUMN_CPU_TIME], 1000000000);
|
||||
stat->total_stat_id[COLUMN_SCAN_TIMES],
|
||||
stat->total_stat_id[COLUMN_SCAN_CPU_TIME], 1000000000);
|
||||
if (ret < 0) {
|
||||
log_fatal(stat->logger, MODULE_MAAT_STAT, "fieldstat set IN_Tps for Sum failed.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = fieldstat_set_metric_ratio_para(stat->fs_handle, stat->total_stat_id[COLUMN_HIT_RATE],
|
||||
stat->total_stat_id[COLUMN_HIT_CNT],
|
||||
stat->total_stat_id[COLUMN_SCAN_CNT], 1);
|
||||
stat->total_stat_id[COLUMN_HIT_TIMES],
|
||||
stat->total_stat_id[COLUMN_SCAN_TIMES], 1);
|
||||
if (ret < 0) {
|
||||
log_fatal(stat->logger, MODULE_MAAT_STAT, "fieldstat set hit_rate for Sum failed.");
|
||||
return -1;
|
||||
@@ -166,7 +173,7 @@ static int maat_fieldstat_table_row_register(struct maat_stat *stat,
|
||||
|
||||
ret = fieldstat_set_metric_ratio_para(stat->fs_handle, stat->fs_column_id[i][COLUMN_SCAN_BPS],
|
||||
stat->fs_column_id[i][COLUMN_SCAN_BYTES],
|
||||
stat->fs_column_id[i][COLUMN_CPU_TIME], 1000000000);
|
||||
stat->fs_column_id[i][COLUMN_SCAN_CPU_TIME], 1000000000);
|
||||
if (ret < 0) {
|
||||
log_fatal(stat->logger, MODULE_MAAT_STAT,
|
||||
"fieldstat set IN_Bps for %s failed.", table_name);
|
||||
@@ -174,8 +181,8 @@ static int maat_fieldstat_table_row_register(struct maat_stat *stat,
|
||||
}
|
||||
|
||||
ret = fieldstat_set_metric_ratio_para(stat->fs_handle, stat->fs_column_id[i][COLUMN_SCAN_TPS],
|
||||
stat->fs_column_id[i][COLUMN_SCAN_CNT],
|
||||
stat->fs_column_id[i][COLUMN_CPU_TIME], 1000000000);
|
||||
stat->fs_column_id[i][COLUMN_SCAN_TIMES],
|
||||
stat->fs_column_id[i][COLUMN_SCAN_CPU_TIME], 1000000000);
|
||||
if (ret < 0) {
|
||||
log_fatal(stat->logger, MODULE_MAAT_STAT,
|
||||
"fieldstat set IN_Tps for %s failed.", table_name);
|
||||
@@ -183,8 +190,8 @@ static int maat_fieldstat_table_row_register(struct maat_stat *stat,
|
||||
}
|
||||
|
||||
ret = fieldstat_set_metric_ratio_para(stat->fs_handle, stat->fs_column_id[i][COLUMN_HIT_RATE],
|
||||
stat->fs_column_id[i][COLUMN_HIT_CNT],
|
||||
stat->fs_column_id[i][COLUMN_SCAN_CNT], 1);
|
||||
stat->fs_column_id[i][COLUMN_HIT_TIMES],
|
||||
stat->fs_column_id[i][COLUMN_SCAN_TIMES], 1);
|
||||
if (ret < 0) {
|
||||
log_fatal(stat->logger, MODULE_MAAT_STAT,
|
||||
"fieldstat set hit_rate for %s failed.", table_name);
|
||||
@@ -205,9 +212,9 @@ struct maat_stat *maat_stat_new(const char *stat_file, size_t max_thread_num,
|
||||
|
||||
stat->nr_worker_thread = max_thread_num;
|
||||
stat->logger = logger;
|
||||
stat->stream_num = alignment_int64_array_alloc(max_thread_num);
|
||||
stat->stream_cnt = alignment_int64_array_alloc(max_thread_num);
|
||||
stat->thread_call_cnt = alignment_int64_array_alloc(max_thread_num);
|
||||
stat->hit_cnt = alignment_int64_array_alloc(max_thread_num);
|
||||
stat->hit_compile_cnt = alignment_int64_array_alloc(max_thread_num);
|
||||
stat->maat_state_cnt = alignment_int64_array_alloc(max_thread_num);
|
||||
stat->compile_state_cnt = alignment_int64_array_alloc(max_thread_num);
|
||||
stat->maat_state_free_cnt = alignment_int64_array_alloc(max_thread_num);
|
||||
@@ -222,9 +229,9 @@ void maat_stat_free(struct maat_stat *stat)
|
||||
return;
|
||||
}
|
||||
|
||||
if (stat->stream_num != NULL) {
|
||||
alignment_int64_array_free(stat->stream_num);
|
||||
stat->stream_num = NULL;
|
||||
if (stat->stream_cnt != NULL) {
|
||||
alignment_int64_array_free(stat->stream_cnt);
|
||||
stat->stream_cnt = NULL;
|
||||
}
|
||||
|
||||
if (stat->thread_call_cnt != NULL) {
|
||||
@@ -232,9 +239,9 @@ void maat_stat_free(struct maat_stat *stat)
|
||||
stat->thread_call_cnt = NULL;
|
||||
}
|
||||
|
||||
if (stat->hit_cnt != NULL) {
|
||||
alignment_int64_array_free(stat->hit_cnt);
|
||||
stat->hit_cnt = NULL;
|
||||
if (stat->hit_compile_cnt != NULL) {
|
||||
alignment_int64_array_free(stat->hit_compile_cnt);
|
||||
stat->hit_compile_cnt = NULL;
|
||||
}
|
||||
|
||||
if (stat->maat_state_cnt != NULL) {
|
||||
@@ -318,9 +325,9 @@ int maat_stat_init(struct maat_stat *stat, struct table_manager *tbl_mgr,
|
||||
static void maat_fieldstat_table_row_output(struct maat_stat *stat, int perf_on)
|
||||
{
|
||||
long long plugin_cache_num = 0, plugin_rule_num = 0;
|
||||
long long total_rule_num = 0, total_input_bytes = 0;
|
||||
long long total_scan_cnt = 0, total_scan_cpu_time = 0, total_regex_num = 0;
|
||||
long long total_ipv6_num = 0, total_hit_cnt = 0, total_update_err = 0;
|
||||
long long total_rule_num = 0, total_input_bytes = 0, total_update_err = 0;
|
||||
long long total_scan_times = 0, total_scan_cpu_time = 0, total_regex_num = 0;
|
||||
long long total_ipv6_num = 0, total_hit_item_num = 0, total_hit_pattern_num = 0;
|
||||
long long g2c_not_clause_num = 0, g2g_excl_rule_num = 0;
|
||||
size_t max_table_count = table_manager_table_size(stat->ref_tbl_mgr);
|
||||
|
||||
@@ -370,9 +377,9 @@ static void maat_fieldstat_table_row_output(struct maat_stat *stat, int perf_on)
|
||||
fieldstat_value_set(stat->fs_handle, stat->fs_column_id[i][COLUMN_RULE_NUM], rule_num);
|
||||
total_rule_num += rule_num;
|
||||
|
||||
long long scan_cnt = table_manager_runtime_scan_count(stat->ref_tbl_mgr, i);
|
||||
fieldstat_value_set(stat->fs_handle, stat->fs_column_id[i][COLUMN_SCAN_CNT], scan_cnt);
|
||||
total_scan_cnt += scan_cnt;
|
||||
long long scan_times = table_manager_runtime_scan_times(stat->ref_tbl_mgr, i);
|
||||
fieldstat_value_set(stat->fs_handle, stat->fs_column_id[i][COLUMN_SCAN_TIMES], scan_times);
|
||||
total_scan_times += scan_times;
|
||||
|
||||
if (table_type == TABLE_TYPE_PLUGIN || table_type == TABLE_TYPE_IP_PLUGIN ||
|
||||
table_type == TABLE_TYPE_IPPORT_PLUGIN || table_type == TABLE_TYPE_BOOL_PLUGIN ||
|
||||
@@ -387,6 +394,11 @@ static void maat_fieldstat_table_row_output(struct maat_stat *stat, int perf_on)
|
||||
fieldstat_value_set(stat->fs_handle, stat->fs_column_id[i][COLUMN_SCAN_BYTES],
|
||||
input_bytes);
|
||||
total_input_bytes += input_bytes;
|
||||
|
||||
long long hit_pattern_num = expr_runtime_hit_pattern_num(runtime);
|
||||
fieldstat_value_set(stat->fs_handle, stat->fs_column_id[i][COLUMN_HIT_PAT_NUM],
|
||||
hit_pattern_num);
|
||||
total_hit_pattern_num += hit_pattern_num;
|
||||
}
|
||||
|
||||
if (table_type == TABLE_TYPE_IP_PLUS) {
|
||||
@@ -396,14 +408,14 @@ static void maat_fieldstat_table_row_output(struct maat_stat *stat, int perf_on)
|
||||
|
||||
if (1 == perf_on) {
|
||||
long long scan_cpu_time = table_manager_runtime_scan_cpu_time(stat->ref_tbl_mgr, i);
|
||||
fieldstat_value_set(stat->fs_handle, stat->fs_column_id[i][COLUMN_CPU_TIME],
|
||||
fieldstat_value_set(stat->fs_handle, stat->fs_column_id[i][COLUMN_SCAN_CPU_TIME],
|
||||
scan_cpu_time);
|
||||
total_scan_cpu_time += scan_cpu_time;
|
||||
}
|
||||
|
||||
long long hit_cnt = table_manager_runtime_hit_count(stat->ref_tbl_mgr, i);
|
||||
fieldstat_value_set(stat->fs_handle, stat->fs_column_id[i][COLUMN_HIT_CNT], hit_cnt);
|
||||
total_hit_cnt += hit_cnt;
|
||||
long long hit_item_num = table_manager_runtime_hit_item_num(stat->ref_tbl_mgr, i);
|
||||
fieldstat_value_set(stat->fs_handle, stat->fs_column_id[i][COLUMN_HIT_ITEM_NUM], hit_item_num);
|
||||
total_hit_item_num += hit_item_num;
|
||||
|
||||
total_update_err += table_manager_runtime_update_err_count(stat->ref_tbl_mgr, i);
|
||||
}
|
||||
@@ -412,15 +424,17 @@ static void maat_fieldstat_table_row_output(struct maat_stat *stat, int perf_on)
|
||||
total_rule_num);
|
||||
fieldstat_value_set(stat->fs_handle, stat->total_stat_id[COLUMN_REGEX_NUM],
|
||||
total_regex_num);
|
||||
fieldstat_value_set(stat->fs_handle, stat->total_stat_id[COLUMN_SCAN_CNT],
|
||||
total_scan_cnt);
|
||||
fieldstat_value_set(stat->fs_handle, stat->total_stat_id[COLUMN_HIT_CNT],
|
||||
total_hit_cnt);
|
||||
fieldstat_value_set(stat->fs_handle, stat->total_stat_id[COLUMN_SCAN_TIMES],
|
||||
total_scan_times);
|
||||
fieldstat_value_set(stat->fs_handle, stat->total_stat_id[COLUMN_HIT_ITEM_NUM],
|
||||
total_hit_item_num);
|
||||
fieldstat_value_set(stat->fs_handle, stat->total_stat_id[COLUMN_HIT_PAT_NUM],
|
||||
total_hit_pattern_num);
|
||||
fieldstat_value_set(stat->fs_handle, stat->total_stat_id[COLUMN_SCAN_BYTES],
|
||||
total_input_bytes);
|
||||
|
||||
if (1 == perf_on) {
|
||||
fieldstat_value_set(stat->fs_handle, stat->total_stat_id[COLUMN_CPU_TIME],
|
||||
fieldstat_value_set(stat->fs_handle, stat->total_stat_id[COLUMN_SCAN_CPU_TIME],
|
||||
total_scan_cpu_time);
|
||||
}
|
||||
|
||||
@@ -446,22 +460,25 @@ void maat_stat_output(struct maat_stat *stat, long long maat_version, int perf_o
|
||||
|
||||
long long active_thread_num = alignment_int64_array_cnt(stat->thread_call_cnt,
|
||||
stat->nr_worker_thread);
|
||||
long long stream_num = alignment_int64_array_sum(stat->stream_num,
|
||||
stat->nr_worker_thread);
|
||||
long long maat_state_cnt = alignment_int64_array_sum(stat->maat_state_cnt,
|
||||
long long stream_num = alignment_int64_array_sum(stat->stream_cnt,
|
||||
stat->nr_worker_thread);
|
||||
long long hit_compile_num = alignment_int64_array_sum(stat->hit_compile_cnt,
|
||||
stat->nr_worker_thread);
|
||||
long long maat_state_num = alignment_int64_array_sum(stat->maat_state_cnt,
|
||||
stat->nr_worker_thread);
|
||||
long long maat_state_free_cnt = alignment_int64_array_sum(stat->maat_state_free_cnt,
|
||||
long long compile_state_num = alignment_int64_array_sum(stat->compile_state_cnt,
|
||||
stat->nr_worker_thread);
|
||||
long long maat_state_free_num = alignment_int64_array_sum(stat->maat_state_free_cnt,
|
||||
stat->nr_worker_thread);
|
||||
long long maat_state_free_bytes = alignment_int64_array_sum(stat->maat_state_free_bytes,
|
||||
stat->nr_worker_thread);
|
||||
long long compile_state_cnt = alignment_int64_array_sum(stat->compile_state_cnt,
|
||||
stat->nr_worker_thread);
|
||||
size_t table_cnt = table_manager_table_count(stat->ref_tbl_mgr);
|
||||
|
||||
size_t table_num = table_manager_table_num(stat->ref_tbl_mgr);
|
||||
size_t garbage_q_len = maat_garbage_bin_get_size(stat->ref_garbage_bin);
|
||||
|
||||
long long per_state_mem = 0;
|
||||
if (maat_state_free_cnt != 0) {
|
||||
per_state_mem = maat_state_free_bytes / maat_state_free_cnt;
|
||||
if (maat_state_free_num != 0) {
|
||||
per_state_mem = maat_state_free_bytes / maat_state_free_num;
|
||||
}
|
||||
|
||||
fieldstat_value_set(stat->fs_handle, stat->fs_status_id[STATUS_VERSION],
|
||||
@@ -469,13 +486,15 @@ void maat_stat_output(struct maat_stat *stat, long long maat_version, int perf_o
|
||||
fieldstat_value_set(stat->fs_handle, stat->fs_status_id[STATUS_THRED_NUM],
|
||||
active_thread_num);
|
||||
fieldstat_value_set(stat->fs_handle, stat->fs_status_id[STATUS_TABLE_NUM],
|
||||
table_cnt);
|
||||
table_num);
|
||||
fieldstat_value_set(stat->fs_handle, stat->fs_status_id[STATUS_HIT_COMPILE_NUM],
|
||||
hit_compile_num);
|
||||
fieldstat_value_set(stat->fs_handle, stat->fs_status_id[STATUS_MAAT_STATE_NUM],
|
||||
maat_state_cnt);
|
||||
maat_state_num);
|
||||
fieldstat_value_set(stat->fs_handle, stat->fs_status_id[STATUS_MAAT_PER_STATE_MEM],
|
||||
per_state_mem);
|
||||
fieldstat_value_set(stat->fs_handle, stat->fs_status_id[STATUS_COMPILE_STATE_NUM],
|
||||
compile_state_cnt);
|
||||
compile_state_num);
|
||||
fieldstat_value_set(stat->fs_handle, stat->fs_status_id[STATUS_CMD_LINE_NUM],
|
||||
stat->line_cmd_acc_num);
|
||||
fieldstat_value_set(stat->fs_handle, stat->fs_status_id[STATUS_GARBAGE_QSIZE],
|
||||
|
||||
@@ -82,11 +82,13 @@ struct table_operations {
|
||||
|
||||
long long (*rule_count)(void *runtime);
|
||||
|
||||
long long (*scan_count)(void *runtime);
|
||||
long long (*scan_times)(void *runtime);
|
||||
|
||||
long long (*scan_cpu_time)(void *runtime);
|
||||
|
||||
long long (*hit_count)(void *runtime);
|
||||
long long (*hit_times)(void *runtime);
|
||||
|
||||
long long (*hit_item_num)(void *runtime);
|
||||
|
||||
long long (*update_err_count)(void *runtime);
|
||||
};
|
||||
@@ -101,9 +103,10 @@ struct table_operations table_ops[TABLE_TYPE_MAX] = {
|
||||
.update_runtime = flag_runtime_update,
|
||||
.commit_runtime = flag_runtime_commit,
|
||||
.rule_count = flag_runtime_rule_count,
|
||||
.scan_count = flag_runtime_scan_count,
|
||||
.scan_times = flag_runtime_scan_times,
|
||||
.scan_cpu_time = flag_runtime_scan_cpu_time,
|
||||
.hit_count = flag_runtime_hit_count,
|
||||
.hit_times = flag_runtime_hit_times,
|
||||
.hit_item_num = flag_runtime_hit_item_num,
|
||||
.update_err_count = flag_runtime_update_err_count
|
||||
},
|
||||
{
|
||||
@@ -115,9 +118,10 @@ struct table_operations table_ops[TABLE_TYPE_MAX] = {
|
||||
.update_runtime = flag_runtime_update,
|
||||
.commit_runtime = flag_runtime_commit,
|
||||
.rule_count = flag_runtime_rule_count,
|
||||
.scan_count = flag_runtime_scan_count,
|
||||
.scan_times = flag_runtime_scan_times,
|
||||
.scan_cpu_time = flag_runtime_scan_cpu_time,
|
||||
.hit_count = flag_runtime_hit_count,
|
||||
.hit_times = flag_runtime_hit_times,
|
||||
.hit_item_num = flag_runtime_hit_item_num,
|
||||
.update_err_count = flag_runtime_update_err_count
|
||||
},
|
||||
{
|
||||
@@ -129,9 +133,10 @@ struct table_operations table_ops[TABLE_TYPE_MAX] = {
|
||||
.update_runtime = expr_runtime_update,
|
||||
.commit_runtime = expr_runtime_commit,
|
||||
.rule_count = expr_runtime_rule_count,
|
||||
.scan_count = expr_runtime_scan_count,
|
||||
.scan_times = expr_runtime_scan_times,
|
||||
.scan_cpu_time = expr_runtime_scan_cpu_time,
|
||||
.hit_count = expr_runtime_hit_count,
|
||||
.hit_times = expr_runtime_hit_times,
|
||||
.hit_item_num = expr_runtime_hit_item_num,
|
||||
.update_err_count = expr_runtime_update_err_count
|
||||
},
|
||||
{
|
||||
@@ -143,9 +148,10 @@ struct table_operations table_ops[TABLE_TYPE_MAX] = {
|
||||
.update_runtime = expr_runtime_update,
|
||||
.commit_runtime = expr_runtime_commit,
|
||||
.rule_count = expr_runtime_rule_count,
|
||||
.scan_count = expr_runtime_scan_count,
|
||||
.scan_times = expr_runtime_scan_times,
|
||||
.scan_cpu_time = expr_runtime_scan_cpu_time,
|
||||
.hit_count = expr_runtime_hit_count,
|
||||
.hit_times = expr_runtime_hit_times,
|
||||
.hit_item_num = expr_runtime_hit_item_num,
|
||||
.update_err_count = expr_runtime_update_err_count
|
||||
},
|
||||
{
|
||||
@@ -157,9 +163,10 @@ struct table_operations table_ops[TABLE_TYPE_MAX] = {
|
||||
.update_runtime = ip_runtime_update,
|
||||
.commit_runtime = ip_runtime_commit,
|
||||
.rule_count = ip_runtime_rule_count,
|
||||
.scan_count = ip_runtime_scan_count,
|
||||
.scan_times = ip_runtime_scan_times,
|
||||
.scan_cpu_time = ip_runtime_scan_cpu_time,
|
||||
.hit_count = ip_runtime_hit_count,
|
||||
.hit_times = ip_runtime_hit_times,
|
||||
.hit_item_num = ip_runtime_hit_item_num,
|
||||
.update_err_count = ip_runtime_update_err_count
|
||||
},
|
||||
{
|
||||
@@ -171,9 +178,10 @@ struct table_operations table_ops[TABLE_TYPE_MAX] = {
|
||||
.update_runtime = interval_runtime_update,
|
||||
.commit_runtime = interval_runtime_commit,
|
||||
.rule_count = interval_runtime_rule_count,
|
||||
.scan_count = interval_runtime_scan_count,
|
||||
.scan_times = interval_runtime_scan_times,
|
||||
.scan_cpu_time = interval_runtime_scan_cpu_time,
|
||||
.hit_count = interval_runtime_hit_count,
|
||||
.hit_times = interval_runtime_hit_times,
|
||||
.hit_item_num = interval_runtime_hit_item_num,
|
||||
.update_err_count = interval_runtime_update_err_cnt
|
||||
},
|
||||
{
|
||||
@@ -185,9 +193,10 @@ struct table_operations table_ops[TABLE_TYPE_MAX] = {
|
||||
.update_runtime = interval_runtime_update,
|
||||
.commit_runtime = interval_runtime_commit,
|
||||
.rule_count = interval_runtime_rule_count,
|
||||
.scan_count = interval_runtime_scan_count,
|
||||
.scan_times = interval_runtime_scan_times,
|
||||
.scan_cpu_time = interval_runtime_scan_cpu_time,
|
||||
.hit_count = interval_runtime_hit_count,
|
||||
.hit_times = interval_runtime_hit_times,
|
||||
.hit_item_num = interval_runtime_hit_item_num,
|
||||
.update_err_count = interval_runtime_update_err_cnt
|
||||
},
|
||||
{
|
||||
@@ -198,7 +207,7 @@ struct table_operations table_ops[TABLE_TYPE_MAX] = {
|
||||
.free_runtime = plugin_runtime_free,
|
||||
.update_runtime = plugin_runtime_update,
|
||||
.commit_runtime = plugin_runtime_commit,
|
||||
.scan_count = plugin_runtime_scan_count,
|
||||
.scan_times = plugin_runtime_scan_times,
|
||||
.rule_count = plugin_runtime_rule_count,
|
||||
.update_err_count = plugin_runtime_update_err_count
|
||||
},
|
||||
@@ -210,7 +219,7 @@ struct table_operations table_ops[TABLE_TYPE_MAX] = {
|
||||
.free_runtime = ip_plugin_runtime_free,
|
||||
.update_runtime = ip_plugin_runtime_update,
|
||||
.commit_runtime = ip_plugin_runtime_commit,
|
||||
.scan_count = ip_plugin_runtime_scan_count,
|
||||
.scan_times = ip_plugin_runtime_scan_times,
|
||||
.rule_count = ip_plugin_runtime_rule_count,
|
||||
.update_err_count = ip_plugin_runtime_update_err_count
|
||||
},
|
||||
@@ -222,8 +231,8 @@ struct table_operations table_ops[TABLE_TYPE_MAX] = {
|
||||
.free_runtime = ipport_plugin_runtime_free,
|
||||
.update_runtime = ipport_plugin_runtime_update,
|
||||
.commit_runtime = ipport_plugin_runtime_commit,
|
||||
.scan_times = ipport_plugin_runtime_scan_times,
|
||||
.rule_count = ipport_plugin_runtime_rule_count,
|
||||
.scan_count = ipport_plugin_runtime_scan_count,
|
||||
.update_err_count = ipport_plugin_runtime_update_err_count
|
||||
},
|
||||
{
|
||||
@@ -234,7 +243,7 @@ struct table_operations table_ops[TABLE_TYPE_MAX] = {
|
||||
.free_runtime = fqdn_plugin_runtime_free,
|
||||
.update_runtime = fqdn_plugin_runtime_update,
|
||||
.commit_runtime = fqdn_plugin_runtime_commit,
|
||||
.scan_count = fqdn_plugin_runtime_scan_count,
|
||||
.scan_times = fqdn_plugin_runtime_scan_times,
|
||||
.rule_count = fqdn_plugin_runtime_rule_count,
|
||||
.update_err_count = fqdn_plugin_runtime_update_err_count
|
||||
},
|
||||
@@ -246,7 +255,7 @@ struct table_operations table_ops[TABLE_TYPE_MAX] = {
|
||||
.free_runtime = bool_plugin_runtime_free,
|
||||
.update_runtime = bool_plugin_runtime_update,
|
||||
.commit_runtime = bool_plugin_runtime_commit,
|
||||
.scan_count = bool_plugin_runtime_scan_count,
|
||||
.scan_times = bool_plugin_runtime_scan_times,
|
||||
.rule_count = bool_plugin_runtime_rule_count,
|
||||
.update_err_count = bool_plugin_runtime_update_err_count
|
||||
},
|
||||
@@ -1062,7 +1071,7 @@ size_t table_manager_table_size(struct table_manager *tbl_mgr)
|
||||
return MAX_TABLE_NUM;
|
||||
}
|
||||
|
||||
size_t table_manager_table_count(struct table_manager *tbl_mgr)
|
||||
size_t table_manager_table_num(struct table_manager *tbl_mgr)
|
||||
{
|
||||
if (NULL == tbl_mgr) {
|
||||
return 0;
|
||||
@@ -1371,7 +1380,7 @@ long long table_manager_runtime_rule_count(struct table_manager *tbl_mgr, int ta
|
||||
return table_ops[table_type].rule_count(runtime);
|
||||
}
|
||||
|
||||
long long table_manager_runtime_scan_count(struct table_manager *tbl_mgr, int table_id)
|
||||
long long table_manager_runtime_scan_times(struct table_manager *tbl_mgr, int table_id)
|
||||
{
|
||||
void *runtime = table_manager_get_runtime(tbl_mgr, table_id);
|
||||
if (NULL == runtime) {
|
||||
@@ -1386,11 +1395,11 @@ long long table_manager_runtime_scan_count(struct table_manager *tbl_mgr, int ta
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (NULL == table_ops[table_type].scan_count) {
|
||||
if (NULL == table_ops[table_type].scan_times) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return table_ops[table_type].scan_count(runtime);
|
||||
return table_ops[table_type].scan_times(runtime);
|
||||
}
|
||||
|
||||
long long table_manager_runtime_scan_cpu_time(struct table_manager *tbl_mgr, int table_id)
|
||||
@@ -1415,7 +1424,7 @@ long long table_manager_runtime_scan_cpu_time(struct table_manager *tbl_mgr, int
|
||||
return table_ops[table_type].scan_cpu_time(runtime);
|
||||
}
|
||||
|
||||
long long table_manager_runtime_hit_count(struct table_manager *tbl_mgr, int table_id)
|
||||
long long table_manager_runtime_hit_item_num(struct table_manager *tbl_mgr, int table_id)
|
||||
{
|
||||
void *runtime = table_manager_get_runtime(tbl_mgr, table_id);
|
||||
if (NULL == runtime) {
|
||||
@@ -1430,11 +1439,11 @@ long long table_manager_runtime_hit_count(struct table_manager *tbl_mgr, int tab
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (NULL == table_ops[table_type].hit_count) {
|
||||
if (NULL == table_ops[table_type].hit_item_num) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return table_ops[table_type].hit_count(runtime);
|
||||
return table_ops[table_type].hit_item_num(runtime);
|
||||
}
|
||||
|
||||
long long table_manager_runtime_update_err_count(struct table_manager *tbl_mgr, int table_id)
|
||||
|
||||
@@ -266,7 +266,7 @@ int system_cmd_gzip(const char *src_file, const char *dst_file)
|
||||
int system_cmd_encrypt(const char *src_file, const char *dst_file, const char *password)
|
||||
{
|
||||
char cmd[MAX_SYSTEM_CMD_LEN] = { 0 };
|
||||
snprintf(cmd, sizeof(cmd), "openssl enc -e -aes-256-cbc -k %s -p -nosalt -in %s -out %s -md md5",
|
||||
snprintf(cmd, sizeof(cmd), "openssl enc -e -aes-256-cbc -k %s -nosalt -in %s -out %s -md md5",
|
||||
password, src_file, dst_file);
|
||||
return system(cmd);
|
||||
}
|
||||
|
||||
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
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user