diff options
| author | yangwei <[email protected]> | 2023-08-06 08:34:46 +0800 |
|---|---|---|
| committer | yangwei <[email protected]> | 2023-08-06 18:11:03 +0800 |
| commit | 8f2fb6cd223320e6acd925e68d541e3cfcca015e (patch) | |
| tree | 75230bcf44eb806b87b78e5af85218add92e98af /src/extensions/sapp_metrics.cpp | |
| parent | bb36af1595a53ea74a19a18ac1b48856b8abd8d2 (diff) | |
✨ feat(clock_gettime): 使用CLOCK_MONOTONIC_COARSE
Diffstat (limited to 'src/extensions/sapp_metrics.cpp')
| -rw-r--r-- | src/extensions/sapp_metrics.cpp | 145 |
1 files changed, 96 insertions, 49 deletions
diff --git a/src/extensions/sapp_metrics.cpp b/src/extensions/sapp_metrics.cpp index d2432e4..e6beb5c 100644 --- a/src/extensions/sapp_metrics.cpp +++ b/src/extensions/sapp_metrics.cpp @@ -24,8 +24,8 @@ void sapp_fs2_update_length(int field_index, unsigned long long value) void sapp_fs2_set_work_percent(int thead_seq, long long work_percent) { - if(sapp_global_val->individual_fixed.fs2_runtime.fs_metric_handle != NULL){ - FS_operate(sapp_global_val->individual_fixed.fs2_runtime.fs_metric_handle, + if(sapp_global_val->individual_fixed.fs2_runtime.fs_process_lantency_handle != NULL){ + FS_operate(sapp_global_val->individual_fixed.fs2_runtime.fs_process_lantency_handle, sapp_global_val->individual_fixed.fs2_runtime.fs_work_percent_id_array[thead_seq], 0, FS_OP_SET, work_percent); } @@ -33,8 +33,8 @@ void sapp_fs2_set_work_percent(int thead_seq, long long work_percent) void sapp_fs2_set_latency(int thead_seq, long long time_cost) { - if(sapp_global_val->individual_fixed.fs2_runtime.fs_metric_handle != NULL){ - FS_operate(sapp_global_val->individual_fixed.fs2_runtime.fs_metric_handle, + if(sapp_global_val->individual_fixed.fs2_runtime.fs_process_lantency_handle != NULL){ + FS_operate(sapp_global_val->individual_fixed.fs2_runtime.fs_process_lantency_handle, sapp_global_val->individual_fixed.fs2_runtime.fs_latency_id_array[thead_seq], 0, FS_OP_SET, time_cost); } @@ -47,8 +47,8 @@ void sapp_fs2_set_plug_entry_latency(int entry_id, long long time_cost) if(unlikely(entry_id < 0 || entry_id >= SAPP_MAX_PLUG_ENTRY_NUM)){ return; } - if(sapp_global_val->individual_fixed.fs2_runtime.fs_metric_handle != NULL){ - FS_operate(sapp_global_val->individual_fixed.fs2_runtime.fs_metric_handle, + if(sapp_global_val->individual_fixed.fs2_runtime.fs_process_lantency_handle != NULL){ + FS_operate(sapp_global_val->individual_fixed.fs2_runtime.fs_process_lantency_handle, sapp_global_val->individual_fixed.fs2_runtime.fs_latency_plug_entrg_id_array[entry_id], 0, FS_OP_SET, time_cost); } @@ -142,6 +142,78 @@ void sapp_fuzzy_latency_update(void) } } +static int sapp_process_latency_metric_init(sapp_global_t *global_paramters) +{ + void *fs2_handle=NULL; + int fs2_opt; + sapp_gval_individual_fixed_fs2_t *p_fs2_rt = &global_paramters->individual_fixed.fs2_runtime; + if(strlen(global_paramters->config.profiling.process_latency_local_file) == 0) + { + return -1; + } + p_fs2_rt->fs_process_lantency_handle = FS_create_handle(); + if (NULL == p_fs2_rt->fs_process_lantency_handle) + { + sapp_log(RLOG_LV_FATAL, 30, 30, "FS_create_handle() error: %s!\n", strerror(errno)); + return -1; + } + fs2_handle = p_fs2_rt->fs_process_lantency_handle; + FS_set_para(fs2_handle, STAT_CYCLE, &global_paramters->config.profiling.process_latency_refresh_interval_s, sizeof(int)); + + fs2_opt = 1; /* 1:Rewrite ,2: Append. */ + FS_set_para(fs2_handle, PRINT_MODE, &fs2_opt, sizeof(int)); + + fs2_opt = 1; + FS_set_para(fs2_handle, PRINT_TRIGGER, &fs2_opt, sizeof(int)); + + fs2_opt = 1; + FS_set_para(fs2_handle, NOT_SEND_METRIC_TO_SERVER, &fs2_opt, sizeof(int)); + FS_set_para(fs2_handle, OUTPUT_DEVICE, ABBR_PROCESS_LATENTCY_DATA_FILE, strlen(ABBR_PROCESS_LATENTCY_DATA_FILE) + 1); + + for (int i = 0; i < g_packet_io_thread_num; i++) + { + char histogram_name[16]; + sprintf(histogram_name, "TD_ns(tid_%d)", i); + p_fs2_rt->fs_latency_id_array[i] = FS_register_histogram(fs2_handle, // Field Stat��� + FS_CALC_SPEED, // ����ۼ�ֵ��˲ʱֵ + histogram_name, // ͳ�������ƣ��ַ��� + 1, // ���ٵ���Сֵ + 1000000, // ���ٵ����ֵ + 2); // ���ȣ���С�����λ����Χ1~4 + FS_set_para(fs2_handle, NOT_SEND_METRIC_TO_SERVER, &p_fs2_rt->fs_latency_id_array[i], sizeof(int)); + } + + /* 0������sapp���ò��, index��1��ʼ */ + for (int i = 1; i < g_plug_global_entry_index; i++) + { + p_fs2_rt->fs_latency_plug_entrg_id_array[i] = FS_register_histogram(p_fs2_rt->fs_metric_handle, // Field Stat��� + FS_CALC_SPEED, // ����ۼ�ֵ��˲ʱֵ + g_plug_global_entry[i].plug_entry_name, // ͳ�������ƣ��ַ��� + 1, // ���ٵ���Сֵ + 1000000, // ���ٵ����ֵ + 2); // ���ȣ���С�����λ����Χ1~4 + if (p_fs2_rt->fs_latency_plug_entrg_id_array[i] < 0) + { + sapp_runtime_log(RLOG_LV_FATAL, "FS_register_histogram() error, plug name:%s", g_plug_global_entry[i].plug_entry_name); + return -1; + } + } + + for (int i = 0; i < g_packet_io_thread_num; i++) + { + char histogram_name[16]; + sprintf(histogram_name, "Work(tid_%d)", i); + p_fs2_rt->fs_work_percent_id_array[i] = FS_register_histogram(fs2_handle, // Field Stat��� + FS_CALC_SPEED, // ����ۼ�ֵ��˲ʱֵ + histogram_name, // ͳ�������ƣ��ַ��� + 1, // ���ٵ���Сֵ + 100, // ���ٵ����ֵ + 1); // ���ȣ���С�����λ����Χ1~4 + FS_set_para(fs2_handle, NOT_SEND_METRIC_TO_SERVER, &p_fs2_rt->fs_work_percent_id_array[i], sizeof(int)); + } + return 0; +} + /************************ C++ compiler **************************************/ static int sapp_fs2_init(sapp_global_t *global_paramters) { @@ -321,49 +393,6 @@ static int sapp_fs2_start(sapp_global_t *global_paramters) { sapp_gval_individual_fixed_fs2_t *p_fs2_rt = &global_paramters->individual_fixed.fs2_runtime; void *fs2_handle = p_fs2_rt->fs_metric_handle; - if (unlikely(sapp_global_val->config.profiling.histogram_enabled)) - { - for (int i = 0; i < g_packet_io_thread_num; i++) - { - char histogram_name[16]; - sprintf(histogram_name, "TD_ns(tid_%d)", i); - p_fs2_rt->fs_latency_id_array[i] = FS_register_histogram(fs2_handle, // Field Stat��� - FS_CALC_SPEED, // ����ۼ�ֵ��˲ʱֵ - histogram_name, // ͳ�������ƣ��ַ��� - 1, // ���ٵ���Сֵ - 1000000, // ���ٵ����ֵ - 2); // ���ȣ���С�����λ����Χ1~4 - FS_set_para(fs2_handle, NOT_SEND_METRIC_TO_SERVER, &p_fs2_rt->fs_latency_id_array[i], sizeof(int)); - } - - /* 0������sapp���ò��, index��1��ʼ */ - for (int i = 1; i < g_plug_global_entry_index; i++) - { - p_fs2_rt->fs_latency_plug_entrg_id_array[i] = FS_register_histogram(p_fs2_rt->fs_metric_handle, // Field Stat��� - FS_CALC_SPEED, // ����ۼ�ֵ��˲ʱֵ - g_plug_global_entry[i].plug_entry_name, // ͳ�������ƣ��ַ��� - 1, // ���ٵ���Сֵ - 1000000, // ���ٵ����ֵ - 2); // ���ȣ���С�����λ����Χ1~4 - if (p_fs2_rt->fs_latency_plug_entrg_id_array[i] < 0) - { - sapp_runtime_log(RLOG_LV_FATAL, "FS_register_histogram() error, plug name:%s", g_plug_global_entry[i].plug_entry_name); - return -1; - } - } - } - for (int i = 0; i < g_packet_io_thread_num; i++) - { - char histogram_name[16]; - sprintf(histogram_name, "Work(tid_%d)", i); - p_fs2_rt->fs_work_percent_id_array[i] = FS_register_histogram(fs2_handle, // Field Stat��� - FS_CALC_SPEED, // ����ۼ�ֵ��˲ʱֵ - histogram_name, // ͳ�������ƣ��ַ��� - 1, // ���ٵ���Сֵ - 100, // ���ٵ����ֵ - 1); // ���ȣ���С�����λ����Χ1~4 - FS_set_para(fs2_handle, NOT_SEND_METRIC_TO_SERVER, &p_fs2_rt->fs_work_percent_id_array[i], sizeof(int)); - } FS_start(fs2_handle); return 0; } @@ -616,6 +645,10 @@ int sapp_metric_init(void) { sapp_fs3_init(sapp_global_val); } + if( sapp_global_val->config.profiling.histogram_enabled == 1) + { + sapp_process_latency_metric_init(sapp_global_val); + } return ret; } @@ -631,6 +664,13 @@ int sapp_metric_start(void) { sapp_fs3_start(sapp_global_val); } + if( sapp_global_val->config.profiling.histogram_enabled == 1) + { + if(sapp_global_val->individual_fixed.fs2_runtime.fs_process_lantency_handle) + { + FS_start(sapp_global_val->individual_fixed.fs2_runtime.fs_process_lantency_handle); + } + } return ret; } @@ -645,4 +685,11 @@ void sapp_metric_destroy(void) { sapp_fs3_destroy(sapp_global_val); } + if( sapp_global_val->config.profiling.histogram_enabled == 1) + { + if (sapp_global_val->individual_fixed.fs2_runtime.fs_process_lantency_handle) + { + FS_stop(&sapp_global_val->individual_fixed.fs2_runtime.fs_process_lantency_handle); + } + } } |
