[PATCH] add plugin table rule statistics

This commit is contained in:
liuwentan
2023-07-12 18:14:28 +08:00
parent 6911420ebf
commit b1dcf0d5b0
10 changed files with 9 additions and 152 deletions

View File

@@ -55,10 +55,6 @@ struct ex_data_runtime *bool_plugin_runtime_get_ex_data_rt(void *bool_plugin_run
int bool_plugin_runtime_get_ex_data(void *bool_plugin_runtime, unsigned long long *item_ids,
size_t n_item, void **ex_data_array, size_t n_ex_data);
long long bool_plugin_runtime_scan_count(void *bool_plugin_runtime);
long long bool_plugin_runtime_scan_cpu_time(void *bool_plugin_runtime);
long long bool_plugin_runtime_update_err_count(void *bool_plugin_runtime);
#ifdef __cplusplus

View File

@@ -59,10 +59,6 @@ int fqdn_plugin_runtime_get_ex_data(void *fqdn_plugin_runtime, const char *fqdn,
void fqdn_rule_free(struct FQDN_rule *fqdn_rule);
long long fqdn_plugin_runtime_scan_count(void *fqdn_plugin_runtime);
long long fqdn_plugin_runtime_scan_cpu_time(void *fqdn_plugin_runtime);
long long fqdn_plugin_runtime_update_err_count(void *fqdn_plugin_runtime);
#ifdef __cplusplus

View File

@@ -55,10 +55,6 @@ struct ex_data_runtime *ip_plugin_runtime_get_ex_data_rt(void *ip_plugin_runtime
int ip_plugin_runtime_get_ex_data(void *ip_plugin_runtime, const struct ip_addr *ip_addr,
void **ex_data_array, size_t n_ex_data_array);
long long ip_plugin_runtime_scan_count(void *ip_plugin_runtime);
long long ip_plugin_runtime_scan_cpu_time(void *ip_plugin_runtime);
long long ip_plugin_runtime_update_err_count(void *ip_plugin_runtime);
#ifdef __cplusplus

View File

@@ -817,8 +817,6 @@ void *maat_plugin_table_get_ex_data(struct maat *maat_inst, int table_id,
ret = compile_runtime_get_ex_data(runtime, schema, *(long long *)key);
} else if (TABLE_TYPE_PLUGIN == table_type) {
ret = plugin_runtime_get_ex_data(runtime, schema, key, key_len);
} else {
return NULL;
}
return ret;

View File

@@ -39,8 +39,6 @@ struct bool_plugin_runtime {
struct log_handle *logger;
long long update_err_cnt;
long long *scan_cnt;
long long *scan_cpu_time;
};
/* bool plugin schema API */
@@ -200,8 +198,6 @@ 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_cpu_time = alignment_int64_array_alloc(max_thread_num);
return bool_plugin_rt;
}
@@ -223,16 +219,6 @@ 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_cpu_time != NULL) {
alignment_int64_array_free(bool_plugin_rt->scan_cpu_time);
bool_plugin_rt->scan_cpu_time = NULL;
}
FREE(bool_plugin_rt);
}
@@ -567,34 +553,6 @@ int bool_plugin_runtime_get_ex_data(void *bool_plugin_runtime, unsigned long lon
return n_result;
}
long long bool_plugin_runtime_scan_count(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,
bool_plugin_rt->n_worker_thread);
alignment_int64_array_reset(bool_plugin_rt->scan_cnt, bool_plugin_rt->n_worker_thread);
return sum;
}
long long bool_plugin_runtime_scan_cpu_time(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_cpu_time,
bool_plugin_rt->n_worker_thread);
alignment_int64_array_reset(bool_plugin_rt->scan_cpu_time, bool_plugin_rt->n_worker_thread);
return sum;
}
long long bool_plugin_runtime_update_err_count(void *bool_plugin_runtime)
{
if (NULL == bool_plugin_runtime) {

View File

@@ -39,9 +39,6 @@ struct fqdn_plugin_runtime {
size_t n_worker_thread;
struct maat_garbage_bin *ref_garbage_bin;
struct log_handle *logger;
long long *scan_cnt;
long long *scan_cpu_time;
};
void *fqdn_plugin_schema_new(cJSON *json, struct table_manager *tbl_mgr,
@@ -199,8 +196,6 @@ 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_cpu_time = alignment_int64_array_alloc(max_thread_num);
return fqdn_plugin_rt;
}
@@ -222,16 +217,6 @@ 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_cpu_time != NULL) {
alignment_int64_array_free(fqdn_plugin_rt->scan_cpu_time);
fqdn_plugin_rt->scan_cpu_time = NULL;
}
FREE(fqdn_plugin_rt);
}
@@ -573,34 +558,6 @@ int fqdn_plugin_runtime_get_ex_data(void *fqdn_plugin_runtime, const char *query
return n_result;
}
long long fqdn_plugin_runtime_scan_count(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,
fqdn_plugin_rt->n_worker_thread);
alignment_int64_array_reset(fqdn_plugin_rt->scan_cnt, fqdn_plugin_rt->n_worker_thread);
return sum;
}
long long fqdn_plugin_runtime_scan_cpu_time(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_cpu_time,
fqdn_plugin_rt->n_worker_thread);
alignment_int64_array_reset(fqdn_plugin_rt->scan_cpu_time, fqdn_plugin_rt->n_worker_thread);
return sum;
}
long long fqdn_plugin_runtime_update_err_count(void *fqdn_plugin_runtime)
{
if (NULL == fqdn_plugin_runtime) {

View File

@@ -43,9 +43,6 @@ struct ip_plugin_runtime {
size_t n_worker_thread;
struct maat_garbage_bin *ref_garbage_bin;
struct log_handle *logger;
long long *scan_cnt;
long long *scan_cpu_time;
};
void *ip_plugin_schema_new(cJSON *json, struct table_manager *tbl_mgr,
@@ -398,9 +395,6 @@ void *ip_plugin_runtime_new(void *ip_plugin_schema, size_t 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_cpu_time = alignment_int64_array_alloc(max_thread_num);
return ip_plugin_rt;
}
@@ -421,16 +415,6 @@ 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_cpu_time != NULL) {
alignment_int64_array_free(ip_plugin_rt->scan_cpu_time);
ip_plugin_rt->scan_cpu_time = NULL;
}
FREE(ip_plugin_rt);
}
@@ -617,34 +601,6 @@ int ip_plugin_runtime_get_ex_data(void *ip_plugin_runtime, const struct ip_addr
return n_result;
}
long long ip_plugin_runtime_scan_count(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,
ip_plugin_rt->n_worker_thread);
alignment_int64_array_reset(ip_plugin_rt->scan_cnt, ip_plugin_rt->n_worker_thread);
return sum;
}
long long ip_plugin_runtime_scan_cpu_time(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_cpu_time,
ip_plugin_rt->n_worker_thread);
alignment_int64_array_reset(ip_plugin_rt->scan_cpu_time, ip_plugin_rt->n_worker_thread);
return sum;
}
long long ip_plugin_runtime_update_err_count(void *ip_plugin_runtime)
{
if (NULL == ip_plugin_runtime) {

View File

@@ -373,8 +373,9 @@ static int plugin_runtime_update_row(struct plugin_runtime *plugin_rt,
}
}
if ((0 == container_schema->set_flag) && (0 == cb_count)) {
if (0 == container_schema->set_flag) {
ex_data_runtime_cache_row_put(plugin_rt->ex_data_rt, row);
plugin_rt->rule_num = ex_data_runtime_cached_row_count(plugin_rt->ex_data_rt);
}
return 0;

View File

@@ -382,7 +382,7 @@ static void maat_fieldstat_table_row_output(struct maat_stat *stat, int perf_on)
break;
}
if (table_type == TABLE_TYPE_PLUGIN || table_type == TABLE_TYPE_VIRTUAL) {
if (table_type == TABLE_TYPE_VIRTUAL) {
continue;
}
@@ -393,6 +393,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_RULE_NUM], rule_num);
total_rule_num += rule_num;
if (table_type == TABLE_TYPE_PLUGIN || table_type == TABLE_TYPE_IP_PLUGIN ||
table_type == TABLE_TYPE_BOOL_PLUGIN || table_type == TABLE_TYPE_FQDN_PLUGIN) {
continue;
}
if (table_type == TABLE_TYPE_EXPR || table_type == TABLE_TYPE_EXPR_PLUS) {
fieldstat_value_set(stat->fs_handle, stat->fs_column_id[i][COLUMN_REGEX_NUM],
regex_rule_num);

View File

@@ -204,8 +204,6 @@ struct table_operations table_ops[TABLE_TYPE_MAX] = {
.update_runtime = ip_plugin_runtime_update,
.commit_runtime = ip_plugin_runtime_commit,
.rule_count = ip_plugin_runtime_rule_count,
.scan_count = ip_plugin_runtime_scan_count,
.scan_cpu_time = ip_plugin_runtime_scan_cpu_time,
.update_err_count = ip_plugin_runtime_update_err_count
},
{
@@ -217,8 +215,6 @@ struct table_operations table_ops[TABLE_TYPE_MAX] = {
.update_runtime = fqdn_plugin_runtime_update,
.commit_runtime = fqdn_plugin_runtime_commit,
.rule_count = fqdn_plugin_runtime_rule_count,
.scan_count = fqdn_plugin_runtime_scan_count,
.scan_cpu_time = fqdn_plugin_runtime_scan_cpu_time,
.update_err_count = fqdn_plugin_runtime_update_err_count
},
{
@@ -230,8 +226,6 @@ struct table_operations table_ops[TABLE_TYPE_MAX] = {
.update_runtime = bool_plugin_runtime_update,
.commit_runtime = bool_plugin_runtime_commit,
.rule_count = bool_plugin_runtime_rule_count,
.scan_count = bool_plugin_runtime_scan_count,
.scan_cpu_time = bool_plugin_runtime_scan_cpu_time,
.update_err_count = bool_plugin_runtime_update_err_count
},
{