[FEATURE]fieldstat3 -> fieldstat4

This commit is contained in:
liuwentan
2024-03-15 18:17:36 +08:00
parent b1c629811d
commit d2422fe7e1
12 changed files with 353 additions and 284 deletions

View File

@@ -3,7 +3,7 @@ variables:
BUILD_IMAGE_CENTOS7: "git.mesalab.cn:7443/mesa_platform/build-env:master" BUILD_IMAGE_CENTOS7: "git.mesalab.cn:7443/mesa_platform/build-env:master"
BUILD_IMAGE_CENTOS8: "git.mesalab.cn:7443/mesa_platform/build-env:rockylinux" BUILD_IMAGE_CENTOS8: "git.mesalab.cn:7443/mesa_platform/build-env:rockylinux"
BUILD_PADDING_PREFIX: /tmp/padding_for_CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX_PREFIX_PREFIX_PREFIX_PREFIX_PREFIX/ BUILD_PADDING_PREFIX: /tmp/padding_for_CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX_PREFIX_PREFIX_PREFIX_PREFIX_PREFIX/
INSTALL_DEPENDENCY_LIBRARY: framework_env openssl-devel libasan libfieldstat3-devel INSTALL_DEPENDENCY_LIBRARY: framework_env openssl-devel libasan libfieldstat4-devel
stages: stages:
- build - build

View File

@@ -15,7 +15,7 @@ include_directories(/opt/MESA/include/)
set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD 11)
set(CMAKE_C_FLAGS "-fPIC -Wall") set(CMAKE_C_FLAGS "-fPIC -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall")
set(MAAT_DEPEND_DYN_LIB pthread m crypto z fieldstat3) set(MAAT_DEPEND_DYN_LIB pthread m crypto z fieldstat4)
include_directories(include) include_directories(include)
#for ASAN #for ASAN

View File

@@ -25,7 +25,7 @@ extern "C"
#include <openssl/md5.h> #include <openssl/md5.h>
#include "log/log.h" #include "log/log.h"
#include "fieldstat.h" #include "fieldstat/fieldstat_easy.h"
#include "maat_command.h" #include "maat_command.h"
#include "maat_limits.h" #include "maat_limits.h"
#include "maat.h" #include "maat.h"
@@ -140,17 +140,17 @@ struct maat_options {
struct maat_stat { struct maat_stat {
char stat_file[PATH_MAX]; char stat_file[PATH_MAX];
struct fieldstat_instance *fs_handle; struct fieldstat_easy *fs_handle;
int total_stat_id[MAX_MAAT_STAT_NUM]; int g_metric_id[MAX_MAAT_STAT_NUM];
int fs_status_id[MAX_MAAT_STAT_NUM]; int fs_column_id[MAX_MAAT_STAT_NUM];
int fs_column_id[MAX_TABLE_NUM][MAX_MAAT_STAT_NUM]; char tag_value[MAX_TABLE_NUM][MAX_NAME_STR_LEN];
char sum_tag[MAX_NAME_STR_LEN];
struct log_handle *logger; struct log_handle *logger;
struct table_manager *ref_tbl_mgr; struct table_manager *ref_tbl_mgr;
struct maat_garbage_bin *ref_garbage_bin; struct maat_garbage_bin *ref_garbage_bin;
size_t nr_worker_thread; size_t nr_worker_thread;
int cmd_q_cnt; int cmd_q_cnt;
long long *thread_call_cnt; long long *thread_call_cnt;
long long *stream_cnt; long long *stream_cnt;
long long *hit_compile_cnt; long long *hit_compile_cnt;

View File

@@ -26,7 +26,8 @@ void maat_stat_free(struct maat_stat *stat);
int maat_stat_init(struct maat_stat *stat, struct table_manager *tbl_mgr, int maat_stat_init(struct maat_stat *stat, struct table_manager *tbl_mgr,
struct maat_garbage_bin *garbage_bin); struct maat_garbage_bin *garbage_bin);
void maat_stat_output(struct maat_stat *stat, long long maat_version, int perf_on); void maat_stat_output(struct maat_stat *stat, struct table_manager *tbl_mgr,
long long maat_version, int perf_on);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@@ -107,6 +107,8 @@ long long table_manager_runtime_rule_count(struct table_manager *tbl_mgr, int ta
long long table_manager_runtime_scan_times(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_hit_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_scan_cpu_time(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_hit_item_num(struct table_manager *tbl_mgr, int table_id);

View File

@@ -378,7 +378,7 @@ struct maat *maat_new(struct maat_options *opts, const char *table_info_path)
system_cmd_mkdir(maat_inst->opts.foreign_cont_dir); system_cmd_mkdir(maat_inst->opts.foreign_cont_dir);
if (0 == strlen(maat_inst->opts.stat_file)) { if (0 == strlen(maat_inst->opts.stat_file)) {
snprintf(maat_inst->opts.stat_file, sizeof(maat_inst->opts.stat_file), "maat.fs3"); snprintf(maat_inst->opts.stat_file, sizeof(maat_inst->opts.stat_file), "maat_stat.fs");
} }
snprintf(maat_inst->opts.decrypt_algo, sizeof(maat_inst->opts.decrypt_algo), "aes-256-cbc"); snprintf(maat_inst->opts.decrypt_algo, sizeof(maat_inst->opts.decrypt_algo), "aes-256-cbc");

View File

@@ -582,7 +582,6 @@ int ip_runtime_scan(struct ip_runtime *ip_rt, int thread_id, int ip_type,
ipv6_ntoh(scan_data.ipv6); ipv6_ntoh(scan_data.ipv6);
} }
int ret = 0;
size_t real_hit_item_cnt = 0; size_t real_hit_item_cnt = 0;
struct maat_item hit_maat_items[MAX_HIT_ITEM_NUM]; struct maat_item hit_maat_items[MAX_HIT_ITEM_NUM];

View File

@@ -545,8 +545,8 @@ void *rule_monitor_loop(void *arg)
maat_plugin_table_garbage_collect_routine(maat_inst->tbl_mgr); maat_plugin_table_garbage_collect_routine(maat_inst->tbl_mgr);
if ((1 == maat_inst->opts.stat_on) && (time(NULL) % 2 == 0)) { if ((1 == maat_inst->opts.stat_on) && (time(NULL) % 2 == 0)) {
maat_stat_output(maat_inst->stat, maat_inst->maat_version, maat_stat_output(maat_inst->stat, maat_inst->tbl_mgr,
maat_inst->opts.perf_on); maat_inst->maat_version, maat_inst->opts.perf_on);
} }
} }

View File

@@ -9,10 +9,11 @@
*/ */
#include <assert.h> #include <assert.h>
#include <math.h>
#include "maat_utils.h" #include "maat_utils.h"
#include "maat_stat.h" #include "maat_stat.h"
#include "fieldstat.h" #include "fieldstat/fieldstat_easy.h"
#include "alignment.h" #include "alignment.h"
#include "maat_ip.h" #include "maat_ip.h"
#include "maat_compile.h" #include "maat_compile.h"
@@ -24,7 +25,7 @@
enum MAAT_FS_STATUS { enum MAAT_FS_STATUS {
STATUS_VERSION = 0, STATUS_VERSION = 0,
STATUS_THRED_NUM, STATUS_THREAD_NUM,
STATUS_TABLE_NUM, STATUS_TABLE_NUM,
STATUS_PLUGIN_CACHE_NUM, STATUS_PLUGIN_CACHE_NUM,
STATUS_PLUGIN_ACC_NUM, STATUS_PLUGIN_ACC_NUM,
@@ -34,7 +35,7 @@ enum MAAT_FS_STATUS {
STATUS_MAAT_STATE_NUM, STATUS_MAAT_STATE_NUM,
STATUS_MAAT_PER_STATE_MEM, STATUS_MAAT_PER_STATE_MEM,
STATUS_COMPILE_STATE_NUM, STATUS_COMPILE_STATE_NUM,
STATUS_GARBAGE_QSIZE, STATUS_GARBAGE_QUEUE_LEN,
STATUS_UPDATE_ERR_CNT, STATUS_UPDATE_ERR_CNT,
STATUS_SCAN_ERR_CNT, STATUS_SCAN_ERR_CNT,
STATUS_STREAM_NUM, STATUS_STREAM_NUM,
@@ -46,160 +47,100 @@ enum MAAT_FS_COLUMN {
COLUMN_RULE_NUM = 0, COLUMN_RULE_NUM = 0,
COLUMN_REGEX_NUM, COLUMN_REGEX_NUM,
COLUMN_SCAN_TIMES, //the times of scan COLUMN_SCAN_TIMES, //the times of scan
COLUMN_HIT_TIMES, //the times of hit compile COLUMN_HIT_TIMES, //the times of hit item
COLUMN_SCAN_BYTES, COLUMN_SCAN_BYTES,
COLUMN_SCAN_CPU_TIME, //microseconds COLUMN_SCAN_CPU_TIME, //microseconds
COLUMN_HIT_ITEM_NUM, COLUMN_HIT_ITEM_NUM,
COLUMN_HIT_PAT_NUM, //hit pattern num(only valid for expr/expr_plus table) COLUMN_HIT_PAT_NUM //the number of hit pattern(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_times", "hit_times", "scan_bytes", "scan_cpu_time", const char *column_name[] = {
"hit_item_num", "hit_pat_num", "IN_Bps", "IN_Tps", "hit_rate"}; "rule", "reg/v6", "scan_times", "hit_times",
"scan_bytes", "scan_cpu_time(ns)", "hit_item_num", "hit_pat_num"};
enum field_type common_column_type[] = { static void fs_global_metric_register(struct maat_stat *stat)
FIELD_TYPE_GAUGE,
FIELD_TYPE_GAUGE,
FIELD_TYPE_GAUGE,
FIELD_TYPE_GAUGE,
FIELD_TYPE_GAUGE,
FIELD_TYPE_GAUGE,
FIELD_TYPE_GAUGE,
FIELD_TYPE_GAUGE,
FIELD_TYPE_GAUGE,
FIELD_TYPE_GAUGE,
FIELD_TYPE_GAUGE,
FIELD_TYPE_GAUGE
};
#define MAX_CONJ_NAME_LEN 22
static void maat_fieldstat_register(struct maat_stat *stat)
{ {
stat->fs_status_id[STATUS_VERSION] = fieldstat_register(stat->fs_handle, FIELD_TYPE_GAUGE, stat->g_metric_id[STATUS_VERSION] =
"version", NULL, 0); fieldstat_easy_register_counter(stat->fs_handle, "version");
stat->fs_status_id[STATUS_THRED_NUM] = fieldstat_register(stat->fs_handle, FIELD_TYPE_GAUGE,
"threads", NULL, 0); stat->g_metric_id[STATUS_THREAD_NUM] =
stat->fs_status_id[STATUS_TABLE_NUM] = fieldstat_register(stat->fs_handle, FIELD_TYPE_GAUGE, fieldstat_easy_register_counter(stat->fs_handle, "thread_num");
"tables", NULL, 0);
stat->fs_status_id[STATUS_PLUGIN_CACHE_NUM] = fieldstat_register(stat->fs_handle, FIELD_TYPE_GAUGE, stat->g_metric_id[STATUS_TABLE_NUM] =
"plug_cached", NULL, 0); fieldstat_easy_register_counter(stat->fs_handle, "table_num");
stat->fs_status_id[STATUS_PLUGIN_ACC_NUM] = fieldstat_register(stat->fs_handle, FIELD_TYPE_GAUGE,
"plug_acc", NULL, 0); stat->g_metric_id[STATUS_PLUGIN_CACHE_NUM] =
stat->fs_status_id[STATUS_CLAUSE_REF_NOT_NUM] = fieldstat_register(stat->fs_handle, FIELD_TYPE_GAUGE, fieldstat_easy_register_counter(stat->fs_handle, "plug_cached_num");
"not_clause", NULL, 0);
stat->fs_status_id[STATUS_GROUP_REF_EXCL_NUM] = fieldstat_register(stat->fs_handle, FIELD_TYPE_GAUGE, stat->g_metric_id[STATUS_PLUGIN_ACC_NUM] =
"excl_grp", NULL, 0); fieldstat_easy_register_counter(stat->fs_handle, "plug_acc_num");
stat->fs_status_id[STATUS_GARBAGE_QSIZE] = fieldstat_register(stat->fs_handle, FIELD_TYPE_GAUGE,
"garbage_num", NULL, 0); stat->g_metric_id[STATUS_CLAUSE_REF_NOT_NUM] =
stat->fs_status_id[STATUS_HIT_COMPILE_NUM] = fieldstat_register(stat->fs_handle, FIELD_TYPE_GAUGE, fieldstat_easy_register_counter(stat->fs_handle, "NOT_clause_num");
"hit_compile_num", NULL, 0);
stat->fs_status_id[STATUS_MAAT_STATE_NUM] = fieldstat_register(stat->fs_handle, FIELD_TYPE_GAUGE, stat->g_metric_id[STATUS_GROUP_REF_EXCL_NUM] =
"state_num", NULL, 0); fieldstat_easy_register_counter(stat->fs_handle, "excl_grp");
stat->fs_status_id[STATUS_MAAT_PER_STATE_MEM] = fieldstat_register(stat->fs_handle, FIELD_TYPE_GAUGE,
"per_state_mem(B)", NULL, 0); stat->g_metric_id[STATUS_GARBAGE_QUEUE_LEN] =
stat->fs_status_id[STATUS_COMPILE_STATE_NUM] = fieldstat_register(stat->fs_handle, FIELD_TYPE_GAUGE, fieldstat_easy_register_counter(stat->fs_handle, "garbage_queue_len");
"compile_state_num", NULL, 0);
stat->fs_status_id[STATUS_STREAM_NUM] = fieldstat_register(stat->fs_handle, FIELD_TYPE_GAUGE, stat->g_metric_id[STATUS_HIT_COMPILE_NUM] =
"stream_num", NULL, 0); fieldstat_easy_register_counter(stat->fs_handle, "hit_compile_num");
stat->fs_status_id[STATUS_ZOMBIE_STREAM_NUM] = fieldstat_register(stat->fs_handle, FIELD_TYPE_GAUGE,
"z_stream_num", NULL, 0); stat->g_metric_id[STATUS_MAAT_STATE_NUM] =
stat->fs_status_id[STATUS_UPDATE_ERR_CNT] = fieldstat_register(stat->fs_handle, FIELD_TYPE_GAUGE, fieldstat_easy_register_counter(stat->fs_handle, "state_num");
"update_error", NULL, 0);
stat->fs_status_id[STATUS_SCAN_ERR_CNT] = fieldstat_register(stat->fs_handle, FIELD_TYPE_GAUGE, stat->g_metric_id[STATUS_MAAT_PER_STATE_MEM] =
"scan_error", NULL, 0); fieldstat_easy_register_counter(stat->fs_handle, "per_state_mem(B)");
stat->fs_status_id[STATUS_CMD_LINE_NUM] = fieldstat_register(stat->fs_handle, FIELD_TYPE_GAUGE,
"line_cmd/s", NULL, 0); stat->g_metric_id[STATUS_COMPILE_STATE_NUM] =
fieldstat_easy_register_counter(stat->fs_handle, "compile_state_num");
stat->g_metric_id[STATUS_STREAM_NUM] =
fieldstat_easy_register_counter(stat->fs_handle, "stream_num");
stat->g_metric_id[STATUS_ZOMBIE_STREAM_NUM] =
fieldstat_easy_register_counter(stat->fs_handle, "z_stream_num");
stat->g_metric_id[STATUS_UPDATE_ERR_CNT] =
fieldstat_easy_register_counter(stat->fs_handle, "update_error");
stat->g_metric_id[STATUS_SCAN_ERR_CNT] =
fieldstat_easy_register_counter(stat->fs_handle, "scan_error");
stat->g_metric_id[STATUS_CMD_LINE_NUM] =
fieldstat_easy_register_counter(stat->fs_handle, "line_cmd/s");
} }
static int maat_fieldstat_table_row_register(struct maat_stat *stat, static void fs_table_column_register(struct maat_stat *stat)
struct table_manager *tbl_mgr,
int table_id)
{ {
size_t max_table_cnt = table_manager_table_size(tbl_mgr); size_t column_num = sizeof(column_name) / sizeof(column_name[0]);
int ret = fieldstat_register_table_row(stat->fs_handle, table_id, "Sum", NULL, 0,
stat->total_stat_id);
if (ret < 0) {
log_fatal(stat->logger, MODULE_MAAT_STAT, "fieldstat_register_table_row Sum failed.");
return -1;
}
ret = fieldstat_set_metric_ratio_para(stat->fs_handle, stat->total_stat_id[COLUMN_SCAN_BPS], assert(column_num <= MAX_MAAT_STAT_NUM);
stat->total_stat_id[COLUMN_SCAN_BYTES],
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], for (size_t i = 0; i < column_num; i++) {
stat->total_stat_id[COLUMN_SCAN_TIMES], stat->fs_column_id[i] =
stat->total_stat_id[COLUMN_SCAN_CPU_TIME], 1000000000); fieldstat_easy_register_counter(stat->fs_handle, column_name[i]);
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], static void fs_table_row_register(struct maat_stat *stat)
stat->total_stat_id[COLUMN_HIT_TIMES], {
stat->total_stat_id[COLUMN_SCAN_TIMES], 1); //In fieldstat4, row is the tag
if (ret < 0) { size_t max_table_cnt = table_manager_table_size(stat->ref_tbl_mgr);
log_fatal(stat->logger, MODULE_MAAT_STAT, "fieldstat set hit_rate for Sum failed."); memcpy(stat->sum_tag, "Sum", strlen("Sum"));
return -1;
}
size_t counter = 0;
for (size_t i = 0; i < max_table_cnt; i++) { for (size_t i = 0; i < max_table_cnt; i++) {
void *schema = table_manager_get_schema(tbl_mgr, i); const char *table_name =
if (NULL == schema) { table_manager_get_table_name(stat->ref_tbl_mgr, i);
if (NULL == table_name) {
continue; continue;
} }
memcpy(stat->tag_value[counter], table_name,
enum table_type table_type = table_manager_get_table_type(tbl_mgr, i); MIN(strlen(table_name), sizeof(stat->tag_value[counter])));
if (table_type == TABLE_TYPE_VIRTUAL) { counter++;
continue;
} }
const char *table_name = table_manager_get_table_name(tbl_mgr, i);
assert(table_name != NULL);
ret = fieldstat_register_table_row(stat->fs_handle, table_id, table_name, NULL, 0,
stat->fs_column_id[i]);
if (ret < 0) {
log_fatal(stat->logger, MODULE_MAAT_STAT,
"fieldstat_register_table_row %s failed.", table_name);
return -1;
}
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_SCAN_CPU_TIME], 1000000000);
if (ret < 0) {
log_fatal(stat->logger, MODULE_MAAT_STAT,
"fieldstat set IN_Bps for %s failed.", table_name);
return -1;
}
ret = fieldstat_set_metric_ratio_para(stat->fs_handle, stat->fs_column_id[i][COLUMN_SCAN_TPS],
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);
return -1;
}
ret = fieldstat_set_metric_ratio_para(stat->fs_handle, stat->fs_column_id[i][COLUMN_HIT_RATE],
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);
return -1;
}
}
return 0;
} }
struct maat_stat *maat_stat_new(const char *stat_file, size_t max_thread_num, struct maat_stat *maat_stat_new(const char *stat_file, size_t max_thread_num,
@@ -265,7 +206,7 @@ void maat_stat_free(struct maat_stat *stat)
} }
if (stat->fs_handle != NULL) { if (stat->fs_handle != NULL) {
fieldstat_instance_free(stat->fs_handle); fieldstat_easy_free(stat->fs_handle);
stat->fs_handle = NULL; stat->fs_handle = NULL;
} }
@@ -275,71 +216,54 @@ void maat_stat_free(struct maat_stat *stat)
int maat_stat_init(struct maat_stat *stat, struct table_manager *tbl_mgr, int maat_stat_init(struct maat_stat *stat, struct table_manager *tbl_mgr,
struct maat_garbage_bin *garbage_bin) struct maat_garbage_bin *garbage_bin)
{ {
if (NULL == stat || NULL == tbl_mgr || NULL == garbage_bin) { if (NULL == stat || NULL == tbl_mgr) {
return -1; return -1;
} }
const char *instance_name = "maat_stat"; const char *instance_name = "maat_stat";
stat->fs_handle = fieldstat_instance_new(instance_name); stat->fs_handle = fieldstat_easy_new(1, instance_name, NULL, 0);
if (NULL == stat->fs_handle) { if (NULL == stat->fs_handle) {
log_fatal(stat->logger, MODULE_MAAT_STAT, "fieldstat_instance_new failed.");
return -1;
}
int ret = fieldstat_set_local_output(stat->fs_handle, stat->stat_file, "default");
if (ret < 0) {
log_fatal(stat->logger, MODULE_MAAT_STAT, "fieldstat_set_local_output failed.");
return -1;
}
ret = fieldstat_disable_background_thread(stat->fs_handle);
if (ret < 0) {
log_fatal(stat->logger, MODULE_MAAT_STAT, log_fatal(stat->logger, MODULE_MAAT_STAT,
"fieldstat_disable_background_thread failed."); "fieldstat_easy_new failed.");
return -1; return -1;
} }
maat_fieldstat_register(stat);
stat->ref_tbl_mgr = tbl_mgr; stat->ref_tbl_mgr = tbl_mgr;
stat->ref_garbage_bin = garbage_bin; stat->ref_garbage_bin = garbage_bin;
size_t n_column = sizeof(common_column_name) / sizeof(common_column_name[0]);
int fs_table_id = fieldstat_register_table(stat->fs_handle, instance_name,
common_column_name, common_column_type,
n_column);
if (fs_table_id < 0) {
log_fatal(stat->logger, MODULE_MAAT_STAT, "fieldstat_register_table failed.");
return -1;
}
ret = maat_fieldstat_table_row_register(stat, tbl_mgr, fs_table_id); fs_global_metric_register(stat);
if (ret < 0) { fs_table_column_register(stat);
return -1; fs_table_row_register(stat);
}
fieldstat_instance_start(stat->fs_handle);
return 0; return 0;
} }
static void maat_fieldstat_table_row_output(struct maat_stat *stat, int perf_on) static void fs_table_row_output(FILE *fp, struct maat_stat *stat, int perf_on)
{ {
long long plugin_cache_num = 0, plugin_rule_num = 0; long long plugin_cache_num = 0, plugin_rule_num = 0;
long long total_rule_num = 0, total_input_bytes = 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_scan_times = 0, total_hit_times = 0, total_scan_cpu_time = 0;
long long total_ipv6_num = 0, total_hit_item_num = 0, total_hit_pattern_num = 0; long long total_regex_num = 0, total_ipv6_num = 0;
long long total_hit_item_num = 0, total_hit_pattern_num = 0;
long long g2c_not_clause_num = 0, g2g_excl_rule_num = 0; long long g2c_not_clause_num = 0, g2g_excl_rule_num = 0;
struct fieldstat_tag cell_tag = {
.key = "TBL",
.type = TAG_CSTRING
};
size_t max_table_count = table_manager_table_size(stat->ref_tbl_mgr); size_t max_table_count = table_manager_table_size(stat->ref_tbl_mgr);
for (size_t i = 0; i < max_table_count; i++) { for (size_t i = 0; i < max_table_count; i++) {
long long regex_rule_num = 0; long long regex_rule_num = 0;
long long ipv6_rule_num = 0; long long ipv6_rule_num = 0;
void *schema = table_manager_get_schema(stat->ref_tbl_mgr, i); void *schema = table_manager_get_schema(stat->ref_tbl_mgr, i);
if (NULL == schema) { if (NULL == schema) {
continue; continue;
} }
enum table_type table_type = table_manager_get_table_type(stat->ref_tbl_mgr, i); enum table_type table_type =
table_manager_get_table_type(stat->ref_tbl_mgr, i);
assert(table_type != TABLE_TYPE_INVALID); assert(table_type != TABLE_TYPE_INVALID);
void *runtime = table_manager_get_runtime(stat->ref_tbl_mgr, i); void *runtime = table_manager_get_runtime(stat->ref_tbl_mgr, i);
@@ -373,105 +297,182 @@ static void maat_fieldstat_table_row_output(struct maat_stat *stat, int perf_on)
total_regex_num += regex_rule_num; total_regex_num += regex_rule_num;
total_ipv6_num += ipv6_rule_num; total_ipv6_num += ipv6_rule_num;
long long rule_num = table_manager_runtime_rule_count(stat->ref_tbl_mgr, i); long long rule_num =
fieldstat_value_set(stat->fs_handle, stat->fs_column_id[i][COLUMN_RULE_NUM], rule_num); table_manager_runtime_rule_count(stat->ref_tbl_mgr, i);
cell_tag.value_str = stat->tag_value[i];
fieldstat_easy_counter_set(stat->fs_handle, 0,
stat->fs_column_id[COLUMN_RULE_NUM],
&cell_tag, 1, rule_num);
total_rule_num += rule_num; total_rule_num += rule_num;
long long scan_times = table_manager_runtime_scan_times(stat->ref_tbl_mgr, i); long long scan_times =
fieldstat_value_set(stat->fs_handle, stat->fs_column_id[i][COLUMN_SCAN_TIMES], scan_times); table_manager_runtime_scan_times(stat->ref_tbl_mgr, i);
fieldstat_easy_counter_set(stat->fs_handle, 0,
stat->fs_column_id[COLUMN_SCAN_TIMES],
&cell_tag, 1, scan_times);
total_scan_times += scan_times; total_scan_times += scan_times;
if (table_type == TABLE_TYPE_PLUGIN || table_type == TABLE_TYPE_IP_PLUGIN || long long hit_times =
table_type == TABLE_TYPE_IPPORT_PLUGIN || table_type == TABLE_TYPE_BOOL_PLUGIN || table_manager_runtime_hit_times(stat->ref_tbl_mgr, i);
fieldstat_easy_counter_set(stat->fs_handle, 0,
stat->fs_column_id[COLUMN_HIT_TIMES],
&cell_tag, 1, hit_times);
total_hit_times += hit_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 ||
table_type == TABLE_TYPE_FQDN_PLUGIN) { table_type == TABLE_TYPE_FQDN_PLUGIN) {
continue; continue;
} }
if (table_type == TABLE_TYPE_EXPR || table_type == TABLE_TYPE_EXPR_PLUS) { long long input_bytes = 0;
fieldstat_value_set(stat->fs_handle, stat->fs_column_id[i][COLUMN_REGEX_NUM], if (table_type == TABLE_TYPE_EXPR ||
regex_rule_num); table_type == TABLE_TYPE_EXPR_PLUS) {
long long input_bytes = expr_runtime_scan_bytes(runtime); fieldstat_easy_counter_set(stat->fs_handle, 0,
fieldstat_value_set(stat->fs_handle, stat->fs_column_id[i][COLUMN_SCAN_BYTES], stat->fs_column_id[COLUMN_REGEX_NUM],
input_bytes); &cell_tag, 1, regex_rule_num);
input_bytes = expr_runtime_scan_bytes(runtime);
fieldstat_easy_counter_set(stat->fs_handle, 0,
stat->fs_column_id[COLUMN_SCAN_BYTES],
&cell_tag, 1, input_bytes);
total_input_bytes += input_bytes; total_input_bytes += input_bytes;
long long hit_pattern_num = expr_runtime_hit_pattern_num(runtime); 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], fieldstat_easy_counter_set(stat->fs_handle, 0,
hit_pattern_num); stat->fs_column_id[COLUMN_HIT_PAT_NUM],
&cell_tag, 1, hit_pattern_num);
total_hit_pattern_num += hit_pattern_num; total_hit_pattern_num += hit_pattern_num;
} }
if (table_type == TABLE_TYPE_IP_PLUS) { if (table_type == TABLE_TYPE_IP_PLUS) {
fieldstat_value_set(stat->fs_handle, stat->fs_column_id[i][COLUMN_REGEX_NUM], fieldstat_easy_counter_set(stat->fs_handle, 0,
ipv6_rule_num); stat->fs_column_id[COLUMN_REGEX_NUM],
&cell_tag, 1, ipv6_rule_num);
} }
if (1 == perf_on) { if (1 == perf_on) {
long long scan_cpu_time = table_manager_runtime_scan_cpu_time(stat->ref_tbl_mgr, i); long long scan_cpu_time =
fieldstat_value_set(stat->fs_handle, stat->fs_column_id[i][COLUMN_SCAN_CPU_TIME], table_manager_runtime_scan_cpu_time(stat->ref_tbl_mgr, i);
scan_cpu_time);
total_scan_cpu_time += scan_cpu_time; fieldstat_easy_counter_set(stat->fs_handle, 0,
stat->fs_column_id[COLUMN_SCAN_CPU_TIME],
&cell_tag, 1, scan_cpu_time);
} }
long long hit_item_num = table_manager_runtime_hit_item_num(stat->ref_tbl_mgr, i); long long hit_item_num =
fieldstat_value_set(stat->fs_handle, stat->fs_column_id[i][COLUMN_HIT_ITEM_NUM], hit_item_num); table_manager_runtime_hit_item_num(stat->ref_tbl_mgr, i);
fieldstat_easy_counter_set(stat->fs_handle, 0,
stat->fs_column_id[COLUMN_HIT_ITEM_NUM],
&cell_tag, 1, hit_item_num);
total_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); total_update_err +=
table_manager_runtime_update_err_count(stat->ref_tbl_mgr, i);
} }
fieldstat_value_set(stat->fs_handle, stat->total_stat_id[COLUMN_RULE_NUM], cell_tag.value_str = stat->sum_tag;
total_rule_num); fieldstat_easy_counter_set(stat->fs_handle, 0,
fieldstat_value_set(stat->fs_handle, stat->total_stat_id[COLUMN_REGEX_NUM], stat->fs_column_id[COLUMN_RULE_NUM],
total_regex_num); &cell_tag, 1, total_rule_num);
fieldstat_value_set(stat->fs_handle, stat->total_stat_id[COLUMN_SCAN_TIMES], fieldstat_easy_counter_set(stat->fs_handle, 0,
total_scan_times); stat->fs_column_id[COLUMN_REGEX_NUM],
fieldstat_value_set(stat->fs_handle, stat->total_stat_id[COLUMN_HIT_ITEM_NUM], &cell_tag, 1, total_regex_num);
total_hit_item_num); fieldstat_easy_counter_set(stat->fs_handle, 0,
fieldstat_value_set(stat->fs_handle, stat->total_stat_id[COLUMN_HIT_PAT_NUM], stat->fs_column_id[COLUMN_SCAN_TIMES],
total_hit_pattern_num); &cell_tag, 1, total_scan_times);
fieldstat_value_set(stat->fs_handle, stat->total_stat_id[COLUMN_SCAN_BYTES], fieldstat_easy_counter_set(stat->fs_handle, 0,
total_input_bytes); stat->fs_column_id[COLUMN_HIT_TIMES],
&cell_tag, 1, total_hit_times);
fieldstat_easy_counter_set(stat->fs_handle, 0,
stat->fs_column_id[COLUMN_HIT_ITEM_NUM],
&cell_tag, 1, total_hit_item_num);
fieldstat_easy_counter_set(stat->fs_handle, 0,
stat->fs_column_id[COLUMN_HIT_PAT_NUM],
&cell_tag, 1, total_hit_pattern_num);
fieldstat_easy_counter_set(stat->fs_handle, 0,
stat->fs_column_id[COLUMN_SCAN_BYTES],
&cell_tag, 1, total_input_bytes);
if (1 == perf_on) { if (1 == perf_on) {
fieldstat_value_set(stat->fs_handle, stat->total_stat_id[COLUMN_SCAN_CPU_TIME], fieldstat_easy_counter_set(stat->fs_handle, 0,
total_scan_cpu_time); stat->fs_column_id[COLUMN_SCAN_CPU_TIME],
&cell_tag, 1, total_scan_cpu_time);
} }
fieldstat_value_set(stat->fs_handle, stat->fs_status_id[STATUS_UPDATE_ERR_CNT], fieldstat_easy_counter_set(stat->fs_handle, 0,
total_update_err); stat->g_metric_id[STATUS_UPDATE_ERR_CNT],
fieldstat_value_set(stat->fs_handle, stat->fs_status_id[STATUS_SCAN_ERR_CNT], NULL, 0, total_update_err);
stat->scan_err_cnt);
fieldstat_value_set(stat->fs_handle, stat->fs_status_id[STATUS_PLUGIN_CACHE_NUM], fieldstat_easy_counter_set(stat->fs_handle, 0,
plugin_cache_num); stat->g_metric_id[STATUS_SCAN_ERR_CNT],
fieldstat_value_set(stat->fs_handle, stat->fs_status_id[STATUS_PLUGIN_ACC_NUM], NULL, 0, stat->scan_err_cnt);
plugin_rule_num);
fieldstat_value_set(stat->fs_handle, stat->fs_status_id[STATUS_CLAUSE_REF_NOT_NUM], fieldstat_easy_counter_set(stat->fs_handle, 0,
g2c_not_clause_num); stat->g_metric_id[STATUS_PLUGIN_CACHE_NUM],
fieldstat_value_set(stat->fs_handle, stat->fs_status_id[STATUS_GROUP_REF_EXCL_NUM], NULL, 0, plugin_cache_num);
g2g_excl_rule_num);
fieldstat_easy_counter_set(stat->fs_handle, 0,
stat->g_metric_id[STATUS_PLUGIN_ACC_NUM],
NULL, 0, plugin_rule_num);
fieldstat_easy_counter_set(stat->fs_handle, 0,
stat->g_metric_id[STATUS_CLAUSE_REF_NOT_NUM],
NULL, 0, g2c_not_clause_num);
fieldstat_easy_counter_set(stat->fs_handle, 0,
stat->g_metric_id[STATUS_GROUP_REF_EXCL_NUM],
NULL, 0, g2g_excl_rule_num);
char *buff = NULL;
size_t buff_len = 0;
fieldstat_easy_output(stat->fs_handle, &buff, &buff_len);
fwrite(buff, buff_len, 1, fp);
fflush(fp);
FREE(buff);
} }
void maat_stat_output(struct maat_stat *stat, long long maat_version, int perf_on) void maat_stat_output(struct maat_stat *stat, struct table_manager *tbl_mgr,
long long maat_version, int perf_on)
{ {
if (NULL == stat) { if (NULL == stat) {
return; return;
} }
long long active_thread_num = alignment_int64_array_cnt(stat->thread_call_cnt, FILE *fp = fopen(stat->stat_file, "w+");
stat->nr_worker_thread); if (NULL == fp) {
long long stream_num = alignment_int64_array_sum(stat->stream_cnt, log_fatal(stat->logger, MODULE_MAAT_STAT, "open stat_file:%s failed.",
stat->nr_worker_thread); stat->stat_file);
long long hit_compile_num = alignment_int64_array_sum(stat->hit_compile_cnt, return;
stat->nr_worker_thread); }
long long maat_state_num = alignment_int64_array_sum(stat->maat_state_cnt,
stat->nr_worker_thread); long long active_thread_num =
long long compile_state_num = alignment_int64_array_sum(stat->compile_state_cnt, alignment_int64_array_cnt(stat->thread_call_cnt, stat->nr_worker_thread);
stat->nr_worker_thread);
long long maat_state_free_num = alignment_int64_array_sum(stat->maat_state_free_cnt, long long stream_num =
stat->nr_worker_thread); alignment_int64_array_sum(stat->stream_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 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 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);
size_t table_num = table_manager_table_num(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); size_t garbage_q_len = maat_garbage_bin_get_size(stat->ref_garbage_bin);
@@ -481,29 +482,41 @@ void maat_stat_output(struct maat_stat *stat, long long maat_version, int perf_o
per_state_mem = maat_state_free_bytes / maat_state_free_num; per_state_mem = maat_state_free_bytes / maat_state_free_num;
} }
fieldstat_value_set(stat->fs_handle, stat->fs_status_id[STATUS_VERSION], fieldstat_easy_counter_set(stat->fs_handle, 0,
maat_version); stat->g_metric_id[STATUS_VERSION],
fieldstat_value_set(stat->fs_handle, stat->fs_status_id[STATUS_THRED_NUM], NULL, 0, maat_version);
active_thread_num); fieldstat_easy_counter_set(stat->fs_handle, 0,
fieldstat_value_set(stat->fs_handle, stat->fs_status_id[STATUS_TABLE_NUM], stat->g_metric_id[STATUS_THREAD_NUM],
table_num); NULL, 0, active_thread_num);
fieldstat_value_set(stat->fs_handle, stat->fs_status_id[STATUS_HIT_COMPILE_NUM], fieldstat_easy_counter_set(stat->fs_handle, 0,
hit_compile_num); stat->g_metric_id[STATUS_TABLE_NUM],
fieldstat_value_set(stat->fs_handle, stat->fs_status_id[STATUS_MAAT_STATE_NUM], NULL, 0, table_num);
maat_state_num); fieldstat_easy_counter_set(stat->fs_handle, 0,
fieldstat_value_set(stat->fs_handle, stat->fs_status_id[STATUS_MAAT_PER_STATE_MEM], stat->g_metric_id[STATUS_HIT_COMPILE_NUM],
per_state_mem); NULL, 0, hit_compile_num);
fieldstat_value_set(stat->fs_handle, stat->fs_status_id[STATUS_COMPILE_STATE_NUM], fieldstat_easy_counter_set(stat->fs_handle, 0,
compile_state_num); stat->g_metric_id[STATUS_MAAT_STATE_NUM],
fieldstat_value_set(stat->fs_handle, stat->fs_status_id[STATUS_CMD_LINE_NUM], NULL, 0, maat_state_num);
stat->line_cmd_acc_num); fieldstat_easy_counter_set(stat->fs_handle, 0,
fieldstat_value_set(stat->fs_handle, stat->fs_status_id[STATUS_GARBAGE_QSIZE], stat->g_metric_id[STATUS_MAAT_PER_STATE_MEM],
garbage_q_len); NULL, 0, per_state_mem);
fieldstat_value_set(stat->fs_handle, stat->fs_status_id[STATUS_STREAM_NUM], fieldstat_easy_counter_set(stat->fs_handle, 0,
stream_num); stat->g_metric_id[STATUS_COMPILE_STATE_NUM],
fieldstat_value_set(stat->fs_handle, stat->fs_status_id[STATUS_ZOMBIE_STREAM_NUM], NULL, 0, compile_state_num);
stat->zombie_rs_stream); fieldstat_easy_counter_set(stat->fs_handle, 0,
maat_fieldstat_table_row_output(stat, perf_on); stat->g_metric_id[STATUS_CMD_LINE_NUM],
NULL, 0, stat->line_cmd_acc_num);
fieldstat_easy_counter_set(stat->fs_handle, 0,
stat->g_metric_id[STATUS_GARBAGE_QUEUE_LEN],
NULL, 0, garbage_q_len);
fieldstat_easy_counter_set(stat->fs_handle, 0,
stat->g_metric_id[STATUS_STREAM_NUM],
NULL, 0, stream_num);
fieldstat_easy_counter_set(stat->fs_handle, 0,
stat->g_metric_id[STATUS_ZOMBIE_STREAM_NUM],
NULL, 0, stat->zombie_rs_stream);
fieldstat_passive_output(stat->fs_handle); fs_table_row_output(fp, stat, perf_on);
fclose(fp);
} }

View File

@@ -1402,6 +1402,28 @@ long long table_manager_runtime_scan_times(struct table_manager *tbl_mgr, int ta
return table_ops[table_type].scan_times(runtime); return table_ops[table_type].scan_times(runtime);
} }
long long table_manager_runtime_hit_times(struct table_manager *tbl_mgr, int table_id)
{
void *runtime = table_manager_get_runtime(tbl_mgr, table_id);
if (NULL == runtime) {
return 0;
}
enum table_type table_type = table_manager_get_table_type(tbl_mgr, table_id);
if (table_type == TABLE_TYPE_INVALID) {
log_fatal(tbl_mgr->logger, MODULE_TABLE,
"[%s:%d] table(table_id:%d) table_type is invalid, can't get scan count",
__FUNCTION__, __LINE__, table_id);
return 0;
}
if (NULL == table_ops[table_type].hit_times) {
return 0;
}
return table_ops[table_type].hit_times(runtime);
}
long long table_manager_runtime_scan_cpu_time(struct table_manager *tbl_mgr, int table_id) long long table_manager_runtime_scan_cpu_time(struct table_manager *tbl_mgr, int table_id)
{ {
void *runtime = table_manager_get_runtime(tbl_mgr, table_id); void *runtime = table_manager_get_runtime(tbl_mgr, table_id);

View File

@@ -363,6 +363,7 @@ protected:
struct maat_options *opts = maat_options_new(); struct maat_options *opts = maat_options_new();
maat_options_set_instance_name(opts, "firewall"); maat_options_set_instance_name(opts, "firewall");
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO); maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
maat_options_set_perf_on(opts);
maat_options_set_json_file(opts, watched_json); maat_options_set_json_file(opts, watched_json);
maat_options_set_json_file_gzip_flag(opts, 1); maat_options_set_json_file_gzip_flag(opts, 1);
maat_options_set_json_file_decrypt_key(opts, json_decrypt_key); maat_options_set_json_file_decrypt_key(opts, json_decrypt_key);
@@ -475,6 +476,7 @@ protected:
struct maat_options *opts = maat_options_new(); struct maat_options *opts = maat_options_new();
maat_options_set_redis(opts, redis_ip, redis_port, redis_db); maat_options_set_redis(opts, redis_ip, redis_port, redis_db);
maat_options_set_stat_file(opts, "./stat.log"); maat_options_set_stat_file(opts, "./stat.log");
maat_options_set_perf_on(opts);
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO); maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
maat_options_set_accept_tags(opts, accept_tags); maat_options_set_accept_tags(opts, accept_tags);
maat_options_set_hit_path_enabled(opts); maat_options_set_hit_path_enabled(opts);
@@ -781,6 +783,7 @@ protected:
struct maat_options *opts = maat_options_new(); struct maat_options *opts = maat_options_new();
maat_options_set_redis(opts, redis_ip, redis_port, redis_db); maat_options_set_redis(opts, redis_ip, redis_port, redis_db);
maat_options_set_stat_file(opts, "./stat.log"); maat_options_set_stat_file(opts, "./stat.log");
maat_options_set_perf_on(opts);
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO); maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
maat_options_set_accept_tags(opts, accept_tags); maat_options_set_accept_tags(opts, accept_tags);
maat_options_set_hit_path_enabled(opts); maat_options_set_hit_path_enabled(opts);
@@ -1668,6 +1671,7 @@ protected:
struct maat_options *opts = maat_options_new(); struct maat_options *opts = maat_options_new();
maat_options_set_redis(opts, redis_ip, redis_port, redis_db); maat_options_set_redis(opts, redis_ip, redis_port, redis_db);
maat_options_set_stat_file(opts, "./stat.log"); maat_options_set_stat_file(opts, "./stat.log");
maat_options_set_perf_on(opts);
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO); maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
maat_options_set_accept_tags(opts, accept_tags); maat_options_set_accept_tags(opts, accept_tags);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
@@ -2565,6 +2569,7 @@ protected:
maat_options_set_rule_effect_interval_ms(opts, 0); maat_options_set_rule_effect_interval_ms(opts, 0);
maat_options_set_gc_timeout_ms(opts, 0); // start GC immediately maat_options_set_gc_timeout_ms(opts, 0); // start GC immediately
maat_options_set_stat_file(opts, "./stat.log"); maat_options_set_stat_file(opts, "./stat.log");
maat_options_set_perf_on(opts);
_shared_maat_inst = maat_new(opts, table_info_path); _shared_maat_inst = maat_new(opts, table_info_path);
maat_options_free(opts); maat_options_free(opts);
} }
@@ -2678,6 +2683,7 @@ protected:
maat_options_set_rule_effect_interval_ms(opts, 0); maat_options_set_rule_effect_interval_ms(opts, 0);
maat_options_set_gc_timeout_ms(opts, 0); // start GC immediately maat_options_set_gc_timeout_ms(opts, 0); // start GC immediately
maat_options_set_stat_file(opts, "./stat.log"); maat_options_set_stat_file(opts, "./stat.log");
maat_options_set_perf_on(opts);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
_shared_maat_inst = maat_new(opts, table_info_path); _shared_maat_inst = maat_new(opts, table_info_path);
maat_options_free(opts); maat_options_free(opts);
@@ -2795,6 +2801,7 @@ protected:
struct maat_options *opts = maat_options_new(); struct maat_options *opts = maat_options_new();
maat_options_set_redis(opts, redis_ip, redis_port, redis_db); maat_options_set_redis(opts, redis_ip, redis_port, redis_db);
maat_options_set_stat_file(opts, "./stat.log"); maat_options_set_stat_file(opts, "./stat.log");
maat_options_set_perf_on(opts);
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO); maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
maat_options_set_accept_tags(opts, accept_tags); maat_options_set_accept_tags(opts, accept_tags);
@@ -3190,6 +3197,7 @@ protected:
struct maat_options *opts = maat_options_new(); struct maat_options *opts = maat_options_new();
maat_options_set_redis(opts, redis_ip, redis_port, redis_db); maat_options_set_redis(opts, redis_ip, redis_port, redis_db);
maat_options_set_stat_file(opts, "./stat.log"); maat_options_set_stat_file(opts, "./stat.log");
maat_options_set_perf_on(opts);
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO); maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
maat_options_set_accept_tags(opts, accept_tags); maat_options_set_accept_tags(opts, accept_tags);
@@ -3325,6 +3333,7 @@ protected:
struct maat_options *opts = maat_options_new(); struct maat_options *opts = maat_options_new();
maat_options_set_redis(opts, redis_ip, redis_port, redis_db); maat_options_set_redis(opts, redis_ip, redis_port, redis_db);
maat_options_set_stat_file(opts, "./stat.log"); maat_options_set_stat_file(opts, "./stat.log");
maat_options_set_perf_on(opts);
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO); maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
maat_options_set_accept_tags(opts, accept_tags); maat_options_set_accept_tags(opts, accept_tags);
@@ -3424,6 +3433,7 @@ protected:
struct maat_options *opts = maat_options_new(); struct maat_options *opts = maat_options_new();
maat_options_set_redis(opts, redis_ip, redis_port, redis_db); maat_options_set_redis(opts, redis_ip, redis_port, redis_db);
maat_options_set_stat_file(opts, "./stat.log"); maat_options_set_stat_file(opts, "./stat.log");
maat_options_set_perf_on(opts);
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO); maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
maat_options_set_accept_tags(opts, accept_tags); maat_options_set_accept_tags(opts, accept_tags);
@@ -4682,6 +4692,7 @@ protected:
struct maat_options *opts = maat_options_new(); struct maat_options *opts = maat_options_new();
maat_options_set_redis(opts, redis_ip, redis_port, redis_db); maat_options_set_redis(opts, redis_ip, redis_port, redis_db);
maat_options_set_stat_file(opts, "./stat.log"); maat_options_set_stat_file(opts, "./stat.log");
maat_options_set_perf_on(opts);
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO); maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
maat_options_set_accept_tags(opts, accept_tags); maat_options_set_accept_tags(opts, accept_tags);
@@ -5068,6 +5079,7 @@ protected:
struct maat_options *opts = maat_options_new(); struct maat_options *opts = maat_options_new();
maat_options_set_redis(opts, redis_ip, redis_port, redis_db); maat_options_set_redis(opts, redis_ip, redis_port, redis_db);
maat_options_set_stat_file(opts, "./stat.log"); maat_options_set_stat_file(opts, "./stat.log");
maat_options_set_perf_on(opts);
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_DEBUG); maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_DEBUG);
maat_options_set_accept_tags(opts, accept_tags); maat_options_set_accept_tags(opts, accept_tags);
@@ -5331,6 +5343,7 @@ protected:
struct maat_options *opts = maat_options_new(); struct maat_options *opts = maat_options_new();
maat_options_set_redis(opts, redis_ip, redis_port, redis_db); maat_options_set_redis(opts, redis_ip, redis_port, redis_db);
maat_options_set_stat_file(opts, "./stat.log"); maat_options_set_stat_file(opts, "./stat.log");
maat_options_set_perf_on(opts);
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO); maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
maat_options_set_accept_tags(opts, accept_tags); maat_options_set_accept_tags(opts, accept_tags);
@@ -5470,6 +5483,7 @@ protected:
struct maat_options *opts = maat_options_new(); struct maat_options *opts = maat_options_new();
maat_options_set_redis(opts, redis_ip, redis_port, redis_db); maat_options_set_redis(opts, redis_ip, redis_port, redis_db);
maat_options_set_stat_file(opts, "./stat.log"); maat_options_set_stat_file(opts, "./stat.log");
maat_options_set_perf_on(opts);
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO); maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
maat_options_set_accept_tags(opts, accept_tags); maat_options_set_accept_tags(opts, accept_tags);
@@ -5609,6 +5623,7 @@ protected:
struct maat_options *opts = maat_options_new(); struct maat_options *opts = maat_options_new();
maat_options_set_redis(opts, redis_ip, redis_port, redis_db); maat_options_set_redis(opts, redis_ip, redis_port, redis_db);
maat_options_set_stat_file(opts, "./stat.log"); maat_options_set_stat_file(opts, "./stat.log");
maat_options_set_perf_on(opts);
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO); maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
maat_options_set_accept_tags(opts, accept_tags); maat_options_set_accept_tags(opts, accept_tags);
@@ -5779,6 +5794,7 @@ protected:
struct maat_options *opts = maat_options_new(); struct maat_options *opts = maat_options_new();
maat_options_set_redis(opts, redis_ip, redis_port, redis_db); maat_options_set_redis(opts, redis_ip, redis_port, redis_db);
maat_options_set_stat_file(opts, "./stat.log"); maat_options_set_stat_file(opts, "./stat.log");
maat_options_set_perf_on(opts);
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO); maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
maat_options_set_accept_tags(opts, accept_tags); maat_options_set_accept_tags(opts, accept_tags);
@@ -5865,6 +5881,7 @@ protected:
struct maat_options *opts = maat_options_new(); struct maat_options *opts = maat_options_new();
maat_options_set_redis(opts, redis_ip, redis_port, redis_db); maat_options_set_redis(opts, redis_ip, redis_port, redis_db);
maat_options_set_stat_file(opts, "./stat.log"); maat_options_set_stat_file(opts, "./stat.log");
maat_options_set_perf_on(opts);
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO); maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
maat_options_set_accept_tags(opts, accept_tags); maat_options_set_accept_tags(opts, accept_tags);
@@ -5930,6 +5947,7 @@ protected:
struct maat_options *opts = maat_options_new(); struct maat_options *opts = maat_options_new();
maat_options_set_redis(opts, redis_ip, redis_port, redis_db); maat_options_set_redis(opts, redis_ip, redis_port, redis_db);
maat_options_set_stat_file(opts, "./stat.log"); maat_options_set_stat_file(opts, "./stat.log");
maat_options_set_perf_on(opts);
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO); maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
maat_options_set_accept_tags(opts, accept_tags); maat_options_set_accept_tags(opts, accept_tags);
maat_options_set_hit_path_enabled(opts); maat_options_set_hit_path_enabled(opts);
@@ -6082,6 +6100,7 @@ protected:
struct maat_options *opts = maat_options_new(); struct maat_options *opts = maat_options_new();
maat_options_set_redis(opts, redis_ip, redis_port, redis_db); maat_options_set_redis(opts, redis_ip, redis_port, redis_db);
maat_options_set_stat_file(opts, "./stat.log"); maat_options_set_stat_file(opts, "./stat.log");
maat_options_set_perf_on(opts);
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO); maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
maat_options_set_accept_tags(opts, accept_tags); maat_options_set_accept_tags(opts, accept_tags);
maat_options_set_hit_path_enabled(opts); maat_options_set_hit_path_enabled(opts);
@@ -6263,6 +6282,7 @@ protected:
struct maat_options *opts = maat_options_new(); struct maat_options *opts = maat_options_new();
maat_options_set_redis(opts, redis_ip, redis_port, redis_db); maat_options_set_redis(opts, redis_ip, redis_port, redis_db);
maat_options_set_stat_file(opts, "./stat.log"); maat_options_set_stat_file(opts, "./stat.log");
maat_options_set_perf_on(opts);
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO); maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
maat_options_set_accept_tags(opts, accept_tags); maat_options_set_accept_tags(opts, accept_tags);
maat_options_set_hit_path_enabled(opts); maat_options_set_hit_path_enabled(opts);
@@ -6673,6 +6693,7 @@ protected:
struct maat_options *opts = maat_options_new(); struct maat_options *opts = maat_options_new();
maat_options_set_stat_file(opts, "./stat.log"); maat_options_set_stat_file(opts, "./stat.log");
maat_options_set_perf_on(opts);
maat_options_set_redis(opts, redis_ip, redis_port, redis_db); maat_options_set_redis(opts, redis_ip, redis_port, redis_db);
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO); maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
maat_options_set_accept_tags(opts, accept_tags); maat_options_set_accept_tags(opts, accept_tags);
@@ -6744,6 +6765,7 @@ protected:
maat_options_set_caller_thread_number(opts, g_thread_num); maat_options_set_caller_thread_number(opts, g_thread_num);
maat_options_set_instance_name(opts, "files"); maat_options_set_instance_name(opts, "files");
maat_options_set_stat_file(opts, "./stat.log"); maat_options_set_stat_file(opts, "./stat.log");
maat_options_set_perf_on(opts);
maat_options_set_iris(opts, rule_folder, rule_folder); maat_options_set_iris(opts, rule_folder, rule_folder);
maat_options_set_rule_update_checking_interval_ms(opts, scan_interval_ms); maat_options_set_rule_update_checking_interval_ms(opts, scan_interval_ms);
maat_options_set_rule_effect_interval_ms(opts, effective_interval_ms); maat_options_set_rule_effect_interval_ms(opts, effective_interval_ms);
@@ -6849,6 +6871,7 @@ protected:
struct maat_options *opts = maat_options_new(); struct maat_options *opts = maat_options_new();
maat_options_set_redis(opts, redis_ip, redis_port, redis_db); maat_options_set_redis(opts, redis_ip, redis_port, redis_db);
maat_options_set_stat_file(opts, "./stat.log"); maat_options_set_stat_file(opts, "./stat.log");
maat_options_set_perf_on(opts);
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO); maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
maat_options_set_accept_tags(opts, accept_tags); maat_options_set_accept_tags(opts, accept_tags);
@@ -7206,6 +7229,7 @@ protected:
struct maat_options *opts = maat_options_new(); struct maat_options *opts = maat_options_new();
maat_options_set_redis(opts, redis_ip, redis_port, redis_db); maat_options_set_redis(opts, redis_ip, redis_port, redis_db);
maat_options_set_stat_file(opts, "./stat.log"); maat_options_set_stat_file(opts, "./stat.log");
maat_options_set_perf_on(opts);
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_FATAL); maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_FATAL);
maat_options_set_hit_path_enabled(opts); maat_options_set_hit_path_enabled(opts);
maat_options_set_hit_group_enabled(opts); maat_options_set_hit_group_enabled(opts);
@@ -11143,6 +11167,8 @@ protected:
struct maat_options *opts = maat_options_new(); struct maat_options *opts = maat_options_new();
maat_options_set_redis(opts, redis_ip, redis_port, redis_db); maat_options_set_redis(opts, redis_ip, redis_port, redis_db);
maat_options_set_stat_file(opts, "./stat.log");
maat_options_set_perf_on(opts);
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO); maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
maat_options_set_accept_tags(opts, accept_tags); maat_options_set_accept_tags(opts, accept_tags);

View File

@@ -39,6 +39,8 @@ TEST(json_mode, maat_scan_string) {
char json_path[PATH_MAX] = {0}; char json_path[PATH_MAX] = {0};
snprintf(json_path, sizeof(json_path), "./%s", json_filename); snprintf(json_path, sizeof(json_path), "./%s", json_filename);
maat_options_set_json_file(opts, json_path); maat_options_set_json_file(opts, json_path);
maat_options_set_stat_on(opts);
maat_options_set_perf_on(opts);
maat_options_set_logger(opts, "./maat_input_mode_gtest.log", LOG_LEVEL_INFO); maat_options_set_logger(opts, "./maat_input_mode_gtest.log", LOG_LEVEL_INFO);
struct maat *maat_inst = maat_new(opts, table_info_path); struct maat *maat_inst = maat_new(opts, table_info_path);
@@ -93,6 +95,8 @@ TEST(iris_mode, maat_scan_string) {
"%s/index", json_iris_path); "%s/index", json_iris_path);
struct maat_options *opts = maat_options_new(); struct maat_options *opts = maat_options_new();
maat_options_set_stat_on(opts);
maat_options_set_perf_on(opts);
maat_options_set_iris(opts, tmp_iris_full_idx_path, tmp_iris_inc_idx_path); maat_options_set_iris(opts, tmp_iris_full_idx_path, tmp_iris_inc_idx_path);
maat_options_set_logger(opts, "./maat_input_mode_gtest.log", LOG_LEVEL_INFO); maat_options_set_logger(opts, "./maat_input_mode_gtest.log", LOG_LEVEL_INFO);
@@ -225,6 +229,8 @@ TEST(redis_mode, maat_scan_string) {
redisFree(c); redisFree(c);
struct maat_options *opts = maat_options_new(); struct maat_options *opts = maat_options_new();
maat_options_set_stat_on(opts);
maat_options_set_perf_on(opts);
maat_options_set_redis(opts, redis_ip, redis_port, redis_db); maat_options_set_redis(opts, redis_ip, redis_port, redis_db);
maat_options_set_logger(opts, "./maat_input_mode_gtest.log", maat_options_set_logger(opts, "./maat_input_mode_gtest.log",
LOG_LEVEL_INFO); LOG_LEVEL_INFO);