diff options
| author | luwenpeng <[email protected]> | 2024-11-13 14:09:03 +0800 |
|---|---|---|
| committer | luwenpeng <[email protected]> | 2024-11-13 17:17:13 +0800 |
| commit | 3d99178958d99a2ee6a7c94c58ae8f7479ea1e2a (patch) | |
| tree | ea880387c3d13d34a7e0e73f9a7ff48521a42b0e /platform/src/proxy.cpp | |
| parent | aa98cf915e965203479dec7ab7d231edd8301384 (diff) | |
TSG-23378 TFE移除平台层的FieldStat2,为适配AArch64做准备
Diffstat (limited to 'platform/src/proxy.cpp')
| -rw-r--r-- | platform/src/proxy.cpp | 80 |
1 files changed, 18 insertions, 62 deletions
diff --git a/platform/src/proxy.cpp b/platform/src/proxy.cpp index 07b6bd4..b8d89c9 100644 --- a/platform/src/proxy.cpp +++ b/platform/src/proxy.cpp @@ -30,7 +30,7 @@ #include <MESA/MESA_handle_logger.h> #include <MESA/MESA_prof_load.h> -#include <MESA/field_stat2.h> +#include <fieldstat/fieldstat_easy.h> #include <tfe_utils.h> #include <tfe_future.h> @@ -299,17 +299,16 @@ static void __signal_handler_cb(evutil_socket_t fd, short what, void * arg) static void __gc_handler_cb(evutil_socket_t fd, short what, void * arg) { - tfe_proxy * ctx = (tfe_proxy *) arg; - int i = 0; - for (i = 0; i < TFE_STAT_MAX; i++) + tfe_proxy *ctx = (tfe_proxy *)arg; + for (int i = 0; i < TFE_STAT_MAX; i++) { - FS_operate(ctx->fs_handle, ctx->fs_id[i], 0, FS_OP_SET, ATOMIC_READ(&(ctx->stat_val[i]))); + long long delta = ATOMIC_EXCHANGE(&(ctx->stat_val[i]), 0); + fieldstat_easy_counter_incrby(ctx->fs_handle, 0, ctx->fs_id[i], NULL, 0, delta); } if (ctx->kni_v4_acceptor != NULL) packet_io_fs_dump(ctx->kni_v4_acceptor->packet_io_fs); - FS_passive_output(ctx->fs_handle); timestamp_update(); return; } @@ -498,54 +497,21 @@ static const char * __str_stat_spec_map[] = [TFE_STAT_MAX] = NULL }; -int tfe_stat_init(struct tfe_proxy * proxy, const char * profile) -{ - static const char * fieldstat_output = "log/tfe.fs2"; - static const char * app_name = "tfe3a"; - - int value = 0, i = 0; - screen_stat_handle_t fs_handle = NULL; - char statsd_server_ip[TFE_SYMBOL_MAX]={0}; - char histogram_bins[TFE_SYMBOL_MAX]={0}; - int statsd_format=0; - int statsd_server_port=0; - MESA_load_profile_string_def(profile, "STAT", "statsd_server", statsd_server_ip, - sizeof(statsd_server_ip), ""); - MESA_load_profile_int_def(profile, "STAT", "statsd_port", &(statsd_server_port), 0); - // FS_OUTPUT_STATSD=1, FS_OUTPUT_INFLUX_LINE=2 - MESA_load_profile_int_def(profile, "STAT", "statsd_format", &(statsd_format), 1); - MESA_load_profile_string_def(profile, "STAT", "histogram_bins", - histogram_bins, sizeof(histogram_bins), "0.5,0.8,0.9,0.95"); - - if (statsd_format != 1 && statsd_format != 2) - { - statsd_format = 1; - } +int tfe_stat_init(struct tfe_proxy *proxy, const char *profile) +{ + int output_cycle = 0; + char output_file[TFE_STRING_MAX] = {0}; + MESA_load_profile_string_def(profile, "STAT", "output_file", output_file, sizeof(output_file), "log/tfe.fs4"); + MESA_load_profile_int_def(profile, "STAT", "output_cycle", &(output_cycle), 5); - fs_handle = FS_create_handle(); - FS_set_para(fs_handle, OUTPUT_DEVICE, fieldstat_output, (int)strlen(fieldstat_output) + 1); - FS_set_para(fs_handle, APP_NAME, app_name, (int)strlen(app_name) + 1); - value = 1; - FS_set_para(fs_handle, OUTPUT_PROMETHEUS, &value, sizeof(value)); - value = 1; - FS_set_para(fs_handle, PRINT_MODE, &value, sizeof(value)); - value = 0; - FS_set_para(fs_handle, CREATE_THREAD, &value, sizeof(value)); - if(strlen(statsd_server_ip)>0 && statsd_server_port!=0) - { - FS_set_para(fs_handle, STATS_SERVER_IP, statsd_server_ip, strlen(statsd_server_ip)+1); - FS_set_para(fs_handle, STATS_SERVER_PORT, &(statsd_server_port), sizeof(statsd_server_port)); - FS_set_para(fs_handle, STATS_FORMAT, &statsd_format, sizeof(statsd_format)); - } - FS_set_para(fs_handle, HISTOGRAM_GLOBAL_BINS, histogram_bins, strlen(histogram_bins)+1); + proxy->fs_handle = fieldstat_easy_new(1, "tfe", NULL, 0); + fieldstat_easy_enable_auto_output(proxy->fs_handle, output_file, output_cycle); - for (i = 0; i < TFE_STAT_MAX; i++) + for (int i = 0; i < TFE_STAT_MAX; i++) { - proxy->fs_id[i] = FS_register(fs_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, __str_stat_spec_map[i]); + proxy->fs_id[i] = fieldstat_easy_register_counter(proxy->fs_handle, __str_stat_spec_map[i]); } - FS_start(fs_handle); - proxy->fs_handle = fs_handle; return 0; } @@ -651,7 +617,7 @@ int main(int argc, char * argv[]) /* PROXY INSTANCE */ g_default_proxy = ALLOC(struct tfe_proxy, 1); assert(g_default_proxy); - strcpy(g_default_proxy->name, "tfe3a"); + strcpy(g_default_proxy->name, "tfe"); g_default_proxy->breakpad = breakpad_init(main_profile, "system", g_default_logger, tfe_version()); CHECK_OR_EXIT(g_default_proxy->breakpad, "Failed at starting breakpad. Exit."); @@ -661,14 +627,6 @@ int main(int argc, char * argv[]) breakpad_segv_generate(); } - int prometheus_port = 9001; - char prometheus_url_path[1024] = {0}; - MESA_load_profile_int_def(main_profile, "STAT", "statsd_set_prometheus_port", &(prometheus_port), 9001); - MESA_load_profile_string_def(main_profile, "STAT", "statsd_set_prometheus_url_path", prometheus_url_path, sizeof(prometheus_url_path), "/tfe_prometheus"); - FS_library_set_prometheus_port(prometheus_port); - FS_library_set_prometheus_url_path(prometheus_url_path); - FS_library_init(); - future_promise_library_init(future_profile); /* CONFIG */ ret = tfe_proxy_config(g_default_proxy, main_profile); @@ -706,9 +664,7 @@ int main(int argc, char * argv[]) CHECK_OR_EXIT(g_default_proxy->sev[i], "Failed at create signal event. Exit."); evsignal_add(g_default_proxy->sev[i], NULL); } - int statsd_cycle = 0; - MESA_load_profile_int_def(main_profile, "STAT", "statsd_cycle", &(statsd_cycle), 2); - struct timeval gc_delay = {statsd_cycle, 0}; + struct timeval gc_delay = {0, 500 * 1000}; // Microseconds, we set 500 miliseconds here. evtimer_add(g_default_proxy->gcev, &gc_delay); timestamp_update(); @@ -809,7 +765,7 @@ struct event_base * tfe_proxy_get_gc_evbase(void) return g_default_proxy->evbase; } -screen_stat_handle_t tfe_proxy_get_fs_handle(void) +struct fieldstat_easy *tfe_proxy_get_fs_handle(void) { return g_default_proxy->fs_handle; } |
