Adjust benchmark directory,enable HTTP test,rename variables,format codes
This commit is contained in:
@@ -2,41 +2,44 @@
|
||||
#include <stdio.h>
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
#include "http_decoder_inc.h"
|
||||
#include "http_decoder_private.h"
|
||||
|
||||
static const struct hd_stat_config_tuple g_httpd_stat_tuple[HTTPD_STAT_MAX] =
|
||||
{
|
||||
{HTTPD_STAT_BYTES_C2S, "bytes_c2s"},
|
||||
{HTTPD_STAT_BYTES_S2C, "bytes_s2c"},
|
||||
{HTTPD_STAT_TCP_SEG_C2S, "tcp_seg_c2s"},
|
||||
{HTTPD_STAT_TCP_SEG_S2C, "tcp_seg_s2c"},
|
||||
{HTTPD_STAT_HEADERS_C2S, "headers_c2s"},
|
||||
{HTTPD_STAT_HEADERS_S2C, "headers_s2c"},
|
||||
{HTTPD_STAT_ZIP_BYTES, "zip_bytes"},
|
||||
{HTTPD_STAT_UNZIP_BYTES, "unzip_bytes"},
|
||||
{HTTPD_STAT_URL_BYTES, "url_bytes"},
|
||||
{HTTPD_STAT_SESSION_NEW, "session_new"},
|
||||
{HTTPD_STAT_SESSION_FREE, "session_free"},
|
||||
{HTTPD_STAT_SESSION_EXCEPTION, "sess_exception"},
|
||||
{HTTPD_STAT_TUNNEL, "tunnel"},
|
||||
{HTTPD_STAT_TRANSACTION_NEW, "trans_new"},
|
||||
{HTTPD_STAT_TRANSACTION_FREE, "trans_free"},
|
||||
{HTTPD_STAT_ASYMMETRY_SESSION_C2S, "asymmetry_sess_c2s"},
|
||||
{HTTPD_STAT_ASYMMETRY_SESSION_S2C, "asymmetry_sess_s2c"},
|
||||
{HTTPD_STAT_ASYMMETRY_TRANSACTION_C2S, "asymmetry_trans_c2s"},
|
||||
{HTTPD_STAT_ASYMMETRY_TRANSACTION_S2C, "asymmetry_trans_s2c"},
|
||||
{HTTPD_STAT_PARSE_ERR, "parse_err"},
|
||||
};
|
||||
static const struct hd_stat_config_tuple g_httpd_stat_tuple[HTTP_STAT_MAX] =
|
||||
{
|
||||
{HTTP_C2S_BYTES, "http_c2s_bytes"},
|
||||
{HTTP_S2C_BYTES, "http_s2c_bytes"},
|
||||
{HTTP_C2S_TCP_SEG, "http_c2s_tcp_seg"},
|
||||
{HTTP_S2C_TCP_SEG, "http_s2c_tcp_seg"},
|
||||
{HTTP_C2S_HEADERS, "http_c2s_headers"},
|
||||
{HTTP_S2C_HEADERS, "http_s2c_headers"},
|
||||
{HTTP_C2S_ZIP_BYTES, "http_c2s_zip_bytes"},
|
||||
{HTTP_S2C_ZIP_BYTES, "http_s2c_zip_bytes"},
|
||||
{HTTP_C2S_UNZIP_BYTES, "http_c2s_unzip_bytes"},
|
||||
{HTTP_S2C_UNZIP_BYTES, "http_s2c_unzip_bytes"},
|
||||
{HTTP_URL_BYTES, "http_url_bytes"},
|
||||
{HTTP_SESSION_NEW, "http_session_new"},
|
||||
{HTTP_SESSION_FREE, "http_session_free"},
|
||||
{HTTP_TRANSACTION_NEW, "http_transaction_new"},
|
||||
{HTTP_TRANSACTION_FREE, "http_transaction_free"},
|
||||
{HTTP_C2S_ASYMMETRY_SESSION, "http_c2s_asymmetry_sess"},
|
||||
{HTTP_S2C_ASYMMETRY_SESSION, "http_s2c_asymmetry_sess"},
|
||||
{HTTP_C2S_ASYMMETRY_TRANSACTION, "http_c2s_asymmetry_trans"},
|
||||
{HTTP_S2C_ASYMMETRY_TRANSACTION, "http_s2c_asymmetry_trans"},
|
||||
{HTTP_STAT_PARSE_ERR, "http_parse_error"},
|
||||
};
|
||||
|
||||
void http_decoder_stat_free(struct http_decoder_stat *hd_stat)
|
||||
{
|
||||
if(hd_stat->timer_pid != 0){
|
||||
if (hd_stat->timer_pid != 0)
|
||||
{
|
||||
pthread_cancel(hd_stat->timer_pid);
|
||||
}
|
||||
if(hd_stat->stats != NULL){
|
||||
if (hd_stat->stats != NULL)
|
||||
{
|
||||
free(hd_stat->stats);
|
||||
}
|
||||
if(hd_stat->fse != NULL){
|
||||
if (hd_stat->fse != NULL)
|
||||
{
|
||||
fieldstat_easy_free(hd_stat->fse);
|
||||
}
|
||||
}
|
||||
@@ -46,7 +49,8 @@ static void *httpd_stat_timer_thread(void *arg)
|
||||
pthread_setname_np(pthread_self(), "http_decoder_timer_thread");
|
||||
struct http_decoder_stat *hd_stat = (struct http_decoder_stat *)arg;
|
||||
struct timespec res;
|
||||
while(1){
|
||||
while (1)
|
||||
{
|
||||
clock_gettime(CLOCK_MONOTONIC, &res);
|
||||
hd_stat->current_time_ms = (res.tv_sec * 1000) + (res.tv_nsec / 1000000);
|
||||
usleep(800);
|
||||
@@ -56,8 +60,9 @@ static void *httpd_stat_timer_thread(void *arg)
|
||||
|
||||
int http_decoder_stat_init(struct http_decoder_stat *hd_stat, int thread_max, int stat_interval_pkts, int stat_interval_time)
|
||||
{
|
||||
assert(sizeof(g_httpd_stat_tuple)/sizeof(struct hd_stat_config_tuple) == HTTPD_STAT_MAX);
|
||||
if(sizeof(g_httpd_stat_tuple)/sizeof(struct hd_stat_config_tuple) != HTTPD_STAT_MAX){
|
||||
assert(sizeof(g_httpd_stat_tuple) / sizeof(struct hd_stat_config_tuple) == HTTP_STAT_MAX);
|
||||
if (sizeof(g_httpd_stat_tuple) / sizeof(struct hd_stat_config_tuple) != HTTP_STAT_MAX)
|
||||
{
|
||||
fprintf(stderr, "enum http_decoder_stat_type number not match with g_httpd_stat_tuple!");
|
||||
return -1;
|
||||
}
|
||||
@@ -68,7 +73,7 @@ int http_decoder_stat_init(struct http_decoder_stat *hd_stat, int thread_max, in
|
||||
return -1;
|
||||
}
|
||||
|
||||
for(int i = 0; i < HTTPD_STAT_MAX; i++)
|
||||
for (int i = 0; i < HTTP_STAT_MAX; i++)
|
||||
{
|
||||
hd_stat->field_stat_id[i] = fieldstat_easy_register_counter(hd_stat->fse, g_httpd_stat_tuple[i].name);
|
||||
if (hd_stat->field_stat_id[i] < 0)
|
||||
@@ -79,13 +84,13 @@ int http_decoder_stat_init(struct http_decoder_stat *hd_stat, int thread_max, in
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int ret = fieldstat_easy_enable_auto_output(hd_stat->fse, FILEDSTAT_OUTPUT_FILE, stat_interval_time);
|
||||
if (ret < 0)
|
||||
{
|
||||
fprintf(stderr, "fieldstat_easy_enable_auto_output failed.");
|
||||
fieldstat_easy_free(hd_stat->fse);
|
||||
hd_stat->fse = NULL;
|
||||
hd_stat->fse = NULL;
|
||||
return -1;
|
||||
}
|
||||
hd_stat->stats = (struct hd_statistics *)calloc(thread_max, sizeof(struct hd_statistics));
|
||||
@@ -100,9 +105,10 @@ void http_decoder_stat_update(struct http_decoder_stat *hd_stat, int thread_id,
|
||||
{
|
||||
assert(hd_stat);
|
||||
assert(thread_id >= 0);
|
||||
assert(type < HTTPD_STAT_MAX);
|
||||
assert(type < HTTP_STAT_MAX);
|
||||
|
||||
if(unlikely(hd_stat->stats == NULL)){
|
||||
if (unlikely(hd_stat->stats == NULL))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -111,11 +117,11 @@ void http_decoder_stat_update(struct http_decoder_stat *hd_stat, int thread_id,
|
||||
cur_hds->counter[type] += value;
|
||||
cur_hds->batch[type]++;
|
||||
|
||||
if(cur_hds->batch[type] >= hd_stat->stat_interval_pkts
|
||||
|| cur_hds->time_ms[type] + 1000 < hd_stat->current_time_ms){
|
||||
fieldstat_easy_counter_incrby(hd_stat->fse, thread_id, hd_stat->field_stat_id[type], NULL, 0, cur_hds->counter[type]);
|
||||
cur_hds->counter[type] = 0;
|
||||
cur_hds->batch[type] = 0;
|
||||
cur_hds->time_ms[type] = hd_stat->current_time_ms;
|
||||
if (cur_hds->batch[type] >= hd_stat->stat_interval_pkts || cur_hds->time_ms[type] + 1000 < hd_stat->current_time_ms)
|
||||
{
|
||||
fieldstat_easy_counter_incrby(hd_stat->fse, thread_id, hd_stat->field_stat_id[type], NULL, 0, cur_hds->counter[type]);
|
||||
cur_hds->counter[type] = 0;
|
||||
cur_hds->batch[type] = 0;
|
||||
cur_hds->time_ms[type] = hd_stat->current_time_ms;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user