2016-02-10 10:01:18 +08:00
|
|
|
#include "Maat_rule_internal.h"
|
2016-02-18 14:53:06 +08:00
|
|
|
#include "aligment_int64.h"
|
|
|
|
|
#include <time.h>
|
2016-02-18 09:58:01 +08:00
|
|
|
#include <MESA/field_stat.h>
|
2016-02-10 10:01:18 +08:00
|
|
|
enum MAAT_FS_STATUS{
|
|
|
|
|
STATUS_VERSION=0,
|
2016-02-18 14:53:06 +08:00
|
|
|
STATUS_THRED_NUM,
|
2016-02-10 10:01:18 +08:00
|
|
|
STATUS_TABLE_NUM,
|
2016-02-11 13:57:39 +08:00
|
|
|
STATUS_OUTER_MID_NUM,
|
|
|
|
|
STATUS_INNER_MID_NUM,
|
2016-02-10 10:01:18 +08:00
|
|
|
STATUS_GARBAGE_QSIZE,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum MAAT_FS_COLUMN
|
|
|
|
|
{
|
|
|
|
|
COLUMN_TABLE_RULE_NUM=0,
|
|
|
|
|
COLUMN_TABLE_REGEX_NUM,
|
|
|
|
|
COLUMN_TABLE_STREAM_NUM,
|
|
|
|
|
COLUMN_TABLE_SCAN_CNT,
|
|
|
|
|
COLUMN_TABLE_SCAN_BYTES,
|
|
|
|
|
COLUMN_TABLE_CPU_TIME,//microseconds
|
|
|
|
|
COLUMN_TABLE_HIT_CNT
|
|
|
|
|
};
|
|
|
|
|
void maat_stat_init(struct _Maat_feather_t* feather)
|
|
|
|
|
{
|
|
|
|
|
int value=0;
|
|
|
|
|
int i=0;
|
|
|
|
|
struct _Maat_table_info_t* p_table=NULL;
|
|
|
|
|
|
|
|
|
|
feather->stat_handle=FS_create_handle();
|
|
|
|
|
FS_set_para(feather->stat_handle, OUTPUT_DEVICE, feather->stat_file, strlen(feather->stat_file)+1);
|
|
|
|
|
value=1;
|
|
|
|
|
FS_set_para(feather->stat_handle, PRINT_MODE, &value, sizeof(value));
|
|
|
|
|
value=0;
|
|
|
|
|
FS_set_para(feather->stat_handle, CREATE_THREAD, &value, sizeof(value));
|
|
|
|
|
|
|
|
|
|
feather->fs_status_id[STATUS_VERSION]=FS_register(feather->stat_handle, FS_STYLE_STATUS, FS_CALC_CURRENT,"version");
|
2016-02-18 14:53:06 +08:00
|
|
|
feather->fs_status_id[STATUS_THRED_NUM]=FS_register(feather->stat_handle, FS_STYLE_STATUS, FS_CALC_CURRENT,"active_thread");
|
2016-02-10 10:01:18 +08:00
|
|
|
feather->fs_status_id[STATUS_TABLE_NUM]=FS_register(feather->stat_handle, FS_STYLE_STATUS, FS_CALC_CURRENT,"table_num");
|
2016-02-11 13:57:39 +08:00
|
|
|
feather->fs_status_id[STATUS_OUTER_MID_NUM]=FS_register(feather->stat_handle, FS_STYLE_STATUS, FS_CALC_CURRENT,"outer_mid");
|
|
|
|
|
feather->fs_status_id[STATUS_INNER_MID_NUM]=FS_register(feather->stat_handle, FS_STYLE_STATUS, FS_CALC_CURRENT,"inner_mid");
|
2016-02-10 10:01:18 +08:00
|
|
|
feather->fs_status_id[STATUS_GARBAGE_QSIZE]=FS_register(feather->stat_handle, FS_STYLE_STATUS, FS_CALC_CURRENT,"garbage_num");
|
|
|
|
|
|
|
|
|
|
feather->fs_column_id[COLUMN_TABLE_RULE_NUM]=FS_register(feather->stat_handle, FS_STYLE_COLUMN, FS_CALC_CURRENT,"rule");
|
|
|
|
|
feather->fs_column_id[COLUMN_TABLE_REGEX_NUM]=FS_register(feather->stat_handle, FS_STYLE_COLUMN, FS_CALC_CURRENT,"regex");
|
|
|
|
|
feather->fs_column_id[COLUMN_TABLE_STREAM_NUM]=FS_register(feather->stat_handle, FS_STYLE_COLUMN, FS_CALC_CURRENT,"stream");
|
|
|
|
|
feather->fs_column_id[COLUMN_TABLE_SCAN_BYTES]=FS_register(feather->stat_handle, FS_STYLE_COLUMN, FS_CALC_SPEED,"IN_Bps");
|
|
|
|
|
if(feather->perf_on==1)
|
|
|
|
|
{
|
|
|
|
|
feather->fs_column_id[COLUMN_TABLE_CPU_TIME]=FS_register(feather->stat_handle, FS_STYLE_COLUMN, FS_CALC_SPEED,"cpu_us");
|
|
|
|
|
value=feather->fs_column_id[COLUMN_TABLE_CPU_TIME];
|
|
|
|
|
FS_set_para(feather->stat_handle, ID_INVISBLE, &value, sizeof(value));
|
|
|
|
|
FS_register_ratio(feather->stat_handle,
|
|
|
|
|
feather->fs_column_id[COLUMN_TABLE_SCAN_BYTES],
|
|
|
|
|
feather->fs_column_id[COLUMN_TABLE_CPU_TIME],
|
2016-02-18 09:58:01 +08:00
|
|
|
1000000, //microsecond to second
|
2016-02-10 10:01:18 +08:00
|
|
|
FS_STYLE_COLUMN,
|
|
|
|
|
FS_CALC_SPEED,
|
|
|
|
|
"PROC_Bps");
|
2016-02-18 14:53:06 +08:00
|
|
|
}
|
|
|
|
|
feather->fs_column_id[COLUMN_TABLE_SCAN_CNT]=FS_register(feather->stat_handle, FS_STYLE_COLUMN, FS_CALC_SPEED,"IN_Tps");
|
|
|
|
|
if(feather->perf_on==1)
|
|
|
|
|
{
|
2016-02-18 09:58:01 +08:00
|
|
|
FS_register_ratio(feather->stat_handle,
|
|
|
|
|
feather->fs_column_id[COLUMN_TABLE_SCAN_CNT],
|
|
|
|
|
feather->fs_column_id[COLUMN_TABLE_CPU_TIME],
|
|
|
|
|
1000000, //microsecond to second
|
|
|
|
|
FS_STYLE_COLUMN,
|
|
|
|
|
FS_CALC_SPEED,
|
|
|
|
|
"PROC_Tps");
|
2016-02-10 10:01:18 +08:00
|
|
|
}
|
|
|
|
|
feather->fs_column_id[COLUMN_TABLE_HIT_CNT]=FS_register(feather->stat_handle, FS_STYLE_COLUMN, FS_CALC_SPEED,"hit_cnt");
|
|
|
|
|
value=feather->fs_column_id[COLUMN_TABLE_HIT_CNT];
|
|
|
|
|
FS_set_para(feather->stat_handle, ID_INVISBLE, &value, sizeof(value));
|
|
|
|
|
FS_register_ratio(feather->stat_handle,
|
|
|
|
|
feather->fs_column_id[COLUMN_TABLE_HIT_CNT],
|
|
|
|
|
feather->fs_column_id[COLUMN_TABLE_SCAN_CNT],
|
2016-02-18 09:58:01 +08:00
|
|
|
1,
|
2016-02-10 10:01:18 +08:00
|
|
|
FS_STYLE_COLUMN,
|
|
|
|
|
FS_CALC_SPEED,
|
|
|
|
|
"hit_rate");
|
|
|
|
|
feather->total_stat_id=FS_register(feather->stat_handle, FS_STYLE_LINE, FS_CALC_CURRENT,"Sum");
|
|
|
|
|
for(i=0;i<MAX_TABLE_NUM;i++)
|
|
|
|
|
{
|
|
|
|
|
p_table=feather->p_table_info[i];
|
|
|
|
|
if(p_table==NULL||p_table->table_type==TABLE_TYPE_PLUGIN
|
|
|
|
|
||p_table->table_type==TABLE_TYPE_GROUP
|
|
|
|
|
||p_table->table_type==TABLE_TYPE_COMPILE)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
p_table->stat_line_id=FS_register(feather->stat_handle, FS_STYLE_LINE, FS_CALC_CURRENT,p_table->table_name);
|
|
|
|
|
}
|
|
|
|
|
FS_start(feather->stat_handle);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-02-18 14:53:06 +08:00
|
|
|
void maat_stat_table(struct _Maat_table_info_t* p_table,int scan_len,struct timespec* start, struct timespec* end)
|
2016-02-10 10:01:18 +08:00
|
|
|
{
|
|
|
|
|
p_table->scan_cnt++;
|
|
|
|
|
p_table->input_bytes+=scan_len;
|
2016-02-18 14:53:06 +08:00
|
|
|
if(start!=NULL&&end!=NULL)
|
|
|
|
|
{
|
|
|
|
|
p_table->scan_cpu_time+=(end->tv_sec-start->tv_sec)*1000000000+end->tv_nsec-start->tv_nsec;
|
|
|
|
|
}
|
2016-02-10 10:01:18 +08:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
void maat_stat_output(struct _Maat_feather_t* feather)
|
|
|
|
|
{
|
|
|
|
|
long value=0;
|
|
|
|
|
long long total_cfg_num=0, total_input_bytes=0, total_regex_num=0;
|
2016-02-18 14:53:06 +08:00
|
|
|
long long total_scan_cnt=0, total_cpu_time=0,total_stream_cnt=0,active_thread_num=0;
|
2016-02-10 10:01:18 +08:00
|
|
|
int i=0;
|
2016-02-18 14:53:06 +08:00
|
|
|
time_t now;
|
2016-02-10 10:01:18 +08:00
|
|
|
struct _Maat_table_info_t* p_table=NULL;
|
2016-02-18 14:53:06 +08:00
|
|
|
time(&now);
|
|
|
|
|
active_thread_num=aligment_int64_array_cnt(feather->thread_call_cnt, feather->scan_thread_num);
|
2016-02-10 10:01:18 +08:00
|
|
|
FS_operate(feather->stat_handle, feather->fs_status_id[STATUS_VERSION], 0,FS_OP_SET,feather->maat_version);
|
2016-02-18 14:53:06 +08:00
|
|
|
FS_operate(feather->stat_handle, feather->fs_status_id[STATUS_THRED_NUM], 0,FS_OP_SET,active_thread_num);
|
2016-02-10 10:01:18 +08:00
|
|
|
FS_operate(feather->stat_handle, feather->fs_status_id[STATUS_TABLE_NUM], 0,FS_OP_SET,feather->table_cnt);
|
2016-02-11 13:57:39 +08:00
|
|
|
FS_operate(feather->stat_handle, feather->fs_status_id[STATUS_OUTER_MID_NUM], 0,FS_OP_SET,feather->outer_mid_cnt);
|
|
|
|
|
FS_operate(feather->stat_handle, feather->fs_status_id[STATUS_INNER_MID_NUM], 0,FS_OP_SET,feather->inner_mid_cnt);
|
2016-02-10 10:01:18 +08:00
|
|
|
|
|
|
|
|
value=MESA_lqueue_get_count(feather->garbage_q);
|
|
|
|
|
FS_operate(feather->stat_handle, feather->fs_status_id[STATUS_GARBAGE_QSIZE], 0,FS_OP_SET,value);
|
|
|
|
|
|
|
|
|
|
for(i=0;i<MAX_TABLE_NUM;i++)
|
|
|
|
|
{
|
|
|
|
|
p_table=feather->p_table_info[i];
|
|
|
|
|
if(p_table==NULL||p_table->table_type==TABLE_TYPE_PLUGIN
|
|
|
|
|
||p_table->table_type==TABLE_TYPE_GROUP
|
|
|
|
|
||p_table->table_type==TABLE_TYPE_COMPILE)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
FS_operate(feather->stat_handle,
|
|
|
|
|
p_table->stat_line_id,
|
|
|
|
|
feather->fs_column_id[COLUMN_TABLE_RULE_NUM],
|
|
|
|
|
FS_OP_SET,
|
|
|
|
|
p_table->cfg_num);
|
|
|
|
|
total_cfg_num+=p_table->cfg_num;
|
|
|
|
|
|
|
|
|
|
FS_operate(feather->stat_handle,
|
|
|
|
|
p_table->stat_line_id,
|
|
|
|
|
feather->fs_column_id[COLUMN_TABLE_REGEX_NUM],
|
|
|
|
|
FS_OP_SET,
|
|
|
|
|
p_table->regex_rule_cnt);
|
|
|
|
|
total_regex_num+= p_table->regex_rule_cnt;
|
|
|
|
|
|
|
|
|
|
FS_operate(feather->stat_handle,
|
|
|
|
|
p_table->stat_line_id,
|
|
|
|
|
feather->fs_column_id[COLUMN_TABLE_STREAM_NUM],
|
|
|
|
|
FS_OP_SET,
|
|
|
|
|
p_table->stream_num);
|
|
|
|
|
total_stream_cnt+= p_table->stream_num;
|
|
|
|
|
|
|
|
|
|
FS_operate(feather->stat_handle,
|
|
|
|
|
p_table->stat_line_id,
|
|
|
|
|
feather->fs_column_id[COLUMN_TABLE_SCAN_CNT],
|
|
|
|
|
FS_OP_ADD,
|
|
|
|
|
p_table->scan_cnt);
|
|
|
|
|
total_scan_cnt+=p_table->scan_cnt;
|
|
|
|
|
p_table->scan_cnt=0;
|
|
|
|
|
|
|
|
|
|
FS_operate(feather->stat_handle,
|
|
|
|
|
p_table->stat_line_id,
|
|
|
|
|
feather->fs_column_id[COLUMN_TABLE_SCAN_BYTES],
|
|
|
|
|
FS_OP_ADD,
|
|
|
|
|
p_table->input_bytes);
|
|
|
|
|
total_input_bytes+=p_table->input_bytes;
|
|
|
|
|
p_table->input_bytes=0;
|
|
|
|
|
if(feather->perf_on==1)
|
|
|
|
|
{
|
|
|
|
|
FS_operate(feather->stat_handle,
|
|
|
|
|
p_table->stat_line_id,
|
|
|
|
|
feather->fs_column_id[COLUMN_TABLE_CPU_TIME],
|
|
|
|
|
FS_OP_ADD,
|
2016-02-18 14:53:06 +08:00
|
|
|
p_table->scan_cpu_time/1000);
|
2016-02-10 10:01:18 +08:00
|
|
|
total_cpu_time+=p_table->scan_cpu_time;
|
|
|
|
|
p_table->scan_cpu_time=0;
|
|
|
|
|
}
|
|
|
|
|
FS_operate(feather->stat_handle,
|
|
|
|
|
p_table->stat_line_id,
|
|
|
|
|
feather->fs_column_id[COLUMN_TABLE_HIT_CNT],
|
|
|
|
|
FS_OP_ADD,
|
|
|
|
|
p_table->hit_cnt);
|
|
|
|
|
//total hit count stat in region_compile
|
|
|
|
|
p_table->hit_cnt=0;
|
|
|
|
|
}
|
|
|
|
|
FS_operate(feather->stat_handle,
|
|
|
|
|
feather->total_stat_id,
|
|
|
|
|
feather->fs_column_id[COLUMN_TABLE_RULE_NUM],
|
|
|
|
|
FS_OP_SET,
|
|
|
|
|
total_cfg_num);
|
|
|
|
|
FS_operate(feather->stat_handle,
|
|
|
|
|
feather->total_stat_id,
|
|
|
|
|
feather->fs_column_id[COLUMN_TABLE_REGEX_NUM],
|
|
|
|
|
FS_OP_SET,
|
|
|
|
|
total_regex_num);
|
|
|
|
|
FS_operate(feather->stat_handle,
|
|
|
|
|
feather->total_stat_id,
|
|
|
|
|
feather->fs_column_id[COLUMN_TABLE_STREAM_NUM],
|
|
|
|
|
FS_OP_SET,
|
|
|
|
|
total_stream_cnt);
|
|
|
|
|
FS_operate(feather->stat_handle,
|
|
|
|
|
feather->total_stat_id,
|
|
|
|
|
feather->fs_column_id[COLUMN_TABLE_SCAN_CNT],
|
|
|
|
|
FS_OP_ADD,
|
|
|
|
|
total_scan_cnt);
|
|
|
|
|
FS_operate(feather->stat_handle,
|
|
|
|
|
feather->total_stat_id,
|
|
|
|
|
feather->fs_column_id[COLUMN_TABLE_SCAN_BYTES],
|
|
|
|
|
FS_OP_ADD,
|
|
|
|
|
total_input_bytes);
|
|
|
|
|
if(feather->perf_on==1)
|
|
|
|
|
{
|
|
|
|
|
FS_operate(feather->stat_handle,
|
|
|
|
|
feather->total_stat_id,
|
|
|
|
|
feather->fs_column_id[COLUMN_TABLE_CPU_TIME],
|
|
|
|
|
FS_OP_ADD,
|
2016-02-18 14:53:06 +08:00
|
|
|
total_cpu_time/1000);
|
2016-02-10 10:01:18 +08:00
|
|
|
}
|
|
|
|
|
FS_operate(feather->stat_handle,
|
|
|
|
|
feather->total_stat_id,
|
|
|
|
|
feather->fs_column_id[COLUMN_TABLE_HIT_CNT],
|
|
|
|
|
FS_OP_ADD,
|
|
|
|
|
feather->hit_cnt);
|
|
|
|
|
feather->hit_cnt=0;
|
|
|
|
|
FS_passive_output(feather->stat_handle);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|