1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
|
#include "field_stat2.h"
#include "fieldstat.h"
#include "sapp_declaration.h"
static int sapp_fs2_init(sapp_global_t *global_parameters);
static int sapp_fs3_init(sapp_global_t *global_parameters);
void sapp_fs2_update_count(int field_index, unsigned long long value)
{
if(sapp_global_val->individual_fixed.fs2_runtime.fs_metric_handle != NULL){
FS_operate(sapp_global_val->individual_fixed.fs2_runtime.fs_metric_handle,
sapp_global_val->individual_fixed.fs2_runtime.fs_id_count_array[field_index],
0, FS_OP_SET, (long long)value);
}
}
void sapp_fs2_update_length(int field_index, unsigned long long value)
{
if(sapp_global_val->individual_fixed.fs2_runtime.fs_metric_handle != NULL){
FS_operate(sapp_global_val->individual_fixed.fs2_runtime.fs_metric_handle,
sapp_global_val->individual_fixed.fs2_runtime.fs_id_length_array[field_index],
0, FS_OP_SET, (long long)value);
}
}
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,
sapp_global_val->individual_fixed.fs2_runtime.fs_latency_id_array[thead_seq],
0, FS_OP_SET, time_cost);
}
}
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,
sapp_global_val->individual_fixed.fs2_runtime.fs_latency_plug_entrg_id_array[entry_id],
0, FS_OP_SET, time_cost);
}
}
/*
ģ�������������ʱ, ����ÿ����������һ��FS_operate(),
��sapp timer�߳�ÿ��һ��ʱ�����sapp_fuzzy_latency_update(), ����filed_stat2����.
*/
extern "C" void sapp_fs2_fuzzy_latency_update_per_thread(int thead_seq, long long time_cost)
{
sapp_fuzzy_latency_stat_t *this_thread_stat = &sapp_global_val->mthread_volatile[thead_seq]->fuzzy_pkt_latency_stat_per_thread;
if(time_cost < this_thread_stat->min_time_cost){
this_thread_stat->min_time_cost = time_cost;
}
if(time_cost > this_thread_stat->max_time_cost){
this_thread_stat->max_time_cost = time_cost;
}
this_thread_stat->time_cost_sum += time_cost;
this_thread_stat->stat_count++;
}
extern "C" void sapp_fs2_fuzzy_latency_update_per_entry(int thead_seq, int entry_id, long long time_cost)
{
sapp_fuzzy_latency_stat_t *this_thread_stat;
if(unlikely(entry_id < 0 || entry_id >= SAPP_MAX_PLUG_ENTRY_NUM)){
return;
}
this_thread_stat = &sapp_global_val->mthread_volatile[thead_seq]->fuzzy_pkt_latency_stat_per_entry_per_thread[entry_id];
if(time_cost < this_thread_stat->min_time_cost){
this_thread_stat->min_time_cost = time_cost;
}
if(time_cost > this_thread_stat->max_time_cost){
this_thread_stat->max_time_cost = time_cost;
}
this_thread_stat->time_cost_sum += time_cost;
this_thread_stat->stat_count++;
}
/*
��sapp timer�����̵߳���, ÿ��һ��ʱ��, �����۵İ�������ʱ����ˢ�¸�field_stat2.
*/
void sapp_fuzzy_latency_update(void)
{
int tid, entry_id, this_stat_count;
long long min_latency, max_latency;
double avg_latency;
sapp_fuzzy_latency_stat_t *this_thread_stat, *this_entry_stat;
for(tid = 0; tid < g_packet_io_thread_num; tid++){
this_thread_stat = &sapp_global_val->mthread_volatile[tid]->fuzzy_pkt_latency_stat_per_thread;
avg_latency = (double)this_thread_stat->time_cost_sum/(double)this_thread_stat->stat_count;
min_latency = this_thread_stat->min_time_cost;
max_latency = this_thread_stat->max_time_cost;
this_stat_count = this_thread_stat->stat_count;
if(this_stat_count > 0){
memset(this_thread_stat, 0, sizeof(sapp_fuzzy_latency_stat_t));
this_thread_stat->min_time_cost = 999999999; /* Ҫ��¼��Сֵ, ��ʼ��Ҫ������ֵ */
/* ÿ�θ�������ֵ, ���,��С��ƽ��ֵ */
sapp_fs2_set_latency(tid, min_latency);
sapp_fs2_set_latency(tid, max_latency);
sapp_fs2_set_latency(tid, (long long)avg_latency);
}
for(entry_id = 1; entry_id < g_plug_global_entry_index; entry_id++){
this_entry_stat = &sapp_global_val->mthread_volatile[tid]->fuzzy_pkt_latency_stat_per_entry_per_thread[entry_id];
avg_latency = (double)this_entry_stat->time_cost_sum/(double)this_entry_stat->stat_count;
min_latency = this_entry_stat->min_time_cost;
max_latency = this_entry_stat->max_time_cost;
this_stat_count = this_entry_stat->stat_count;
if(this_stat_count > 0){
memset(this_entry_stat, 0, sizeof(sapp_fuzzy_latency_stat_t));
this_entry_stat->min_time_cost = 999999999; /* Ҫ��¼��Сֵ, ��ʼ��Ҫ������ֵ */
sapp_fs2_set_latency(tid, min_latency);
sapp_fs2_set_latency(tid, max_latency);
sapp_fs2_set_plug_entry_latency(entry_id, (long long)avg_latency);
}
}
}
}
int sapp_metric_init(void)
{
int ret = 0;
if( sapp_global_val->config.profiling.fs2.enabled == 1)
{
sapp_fs2_init(sapp_global_val);
}
if( sapp_global_val->config.profiling.fs3.enabled == 1)
{
sapp_fs3_init(sapp_global_val);
}
return ret;
}
static int fs2_plug_entry_historgram_init(sapp_gval_individual_fixed_fs_t *fs_rt)
{
int i;
/* 0������sapp���ò��, index��1��ʼ */
for(i = 1; i < g_plug_global_entry_index; i++){
fs_rt->fs_latency_plug_entrg_id_array[i] = FS_register_histogram(fs_rt->fs_metric_handle, //Field Stat���
FS_CALC_SPEED, //����ۼ�ֵ��˲ʱֵ
g_plug_global_entry[i].plug_entry_name, //ͳ�������ƣ��ַ���
1, //���ٵ���Сֵ
1000000, //���ٵ����ֵ
2); //���ȣ���С�����λ����Χ1~4
if(fs_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;
}
}
return 0;
}
void sapp_fs2_set_tcp_unorder_historgram(int thead_seq, long long unorder_num)
{
if(sapp_global_val->individual_fixed.fs2_runtime.fs_metric_handle != NULL){
FS_operate(sapp_global_val->individual_fixed.fs2_runtime.fs_metric_handle,
sapp_global_val->individual_fixed.fs2_runtime.fs_tcp_unorder_id_array[thead_seq],
0, FS_OP_SET, unorder_num);
}
}
static int fs2_tcp_unorder_historgram_init(sapp_gval_individual_fixed_fs_t *fs_rt)
{
int i;
char histogram_name[16];
/* 0������sapp���ò��, index��1��ʼ */
for (i = 1; i < g_packet_io_thread_num; i++)
{
sprintf(histogram_name, "OoO_num(tid_%d)", i);
fs_rt->fs_tcp_unorder_id_array[i] =
FS_register_histogram(fs_rt->fs_metric_handle, // Field Stat���
FS_CALC_SPEED, //����ۼ�ֵ��˲ʱֵ
histogram_name, //ͳ�������ƣ��ַ���
1, //���ٵ���Сֵ
65536, //���ٵ����ֵ
2); //���ȣ���С�����λ����Χ1~4
if (fs_rt->fs_tcp_unorder_id_array[i] < 0)
{
sapp_runtime_log(RLOG_LV_FATAL, "FS_fs2_tcp_unorder_historgram_init() error, name:%s",
histogram_name);
return -1;
}
}
return 0;
}
/************************ C++ compiler **************************************/
static int sapp_fs2_init(sapp_global_t *global_paramters)
{
void *fs2_handle=NULL;
int fs2_opt;
sapp_gval_individual_fixed_fs_t *p_fs2_rt = &global_paramters->individual_fixed.fs2_runtime;
sapp_config_profiling_metric_t *p_fs2_para = &global_paramters->config.profiling.fs2;
int fs2_local_enabled = 0;
int fs2_prometheus_enabled = 0;
if(strlen(p_fs2_para->local_file) > 0)
{
fs2_local_enabled = 1;
}
if(strlen(p_fs2_para->prometheus_service_uri) > 0 && p_fs2_para->prometheus_service_port > 0)
{
fs2_prometheus_enabled = 1;
}
p_fs2_rt->fs_metric_handle = FS_create_handle();
if(NULL == p_fs2_rt->fs_metric_handle){
sapp_log(RLOG_LV_FATAL, 30, 30, "FS_create_handle() error: %s!\n", strerror(errno));
return -1;
}
fs2_handle = p_fs2_rt->fs_metric_handle;
if(fs2_prometheus_enabled){
FS_library_set_prometheus_port((unsigned short)p_fs2_para->prometheus_service_port);
FS_library_set_prometheus_url_path(p_fs2_para->prometheus_service_uri);
if(FS_library_init() < 0){
sapp_log(RLOG_LV_FATAL, 30, 30, "FS_library_init() error, port:%d, url:%s\n",
p_fs2_para->prometheus_service_port,
p_fs2_para->prometheus_service_uri);
return -1;
}
fs2_opt = 1;
FS_set_para(fs2_handle, OUTPUT_PROMETHEUS, &fs2_opt, sizeof(int));
}
FS_set_para(fs2_handle, STAT_CYCLE, &p_fs2_para->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));
if(fs2_local_enabled){
FS_set_para(fs2_handle, OUTPUT_DEVICE, ABBR_FS2_LOG_DATA_FILE, strlen(ABBR_FS2_LOG_DATA_FILE)+1);
}else{
sapp_log(RLOG_LV_INFO, 10, 10, "profiling.log.local.enabled is 0, not save local stat log file.\n");
FS_set_para(fs2_handle, OUTPUT_DEVICE, "/dev/null", strlen("/dev/null") + 1);
}
FS_set_para(fs2_handle, APP_NAME, sapp_global_val->config.system.instance_name, strlen(sapp_global_val->config.system.instance_name)+1);
p_fs2_rt->fs_id_count_array[SAPP_STAT_RCV_LINE] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Line_Pkt");
p_fs2_rt->fs_id_length_array[SAPP_STAT_RCV_LINE] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Line_Bit");
p_fs2_rt->fs_id_count_array[SAPP_STAT_RCV_ETHERNET] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Eth_Pkt");
p_fs2_rt->fs_id_length_array[SAPP_STAT_RCV_ETHERNET] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Eth_Bit");
if((DEPOLYMENT_MODE_INLINE == sapp_global_val->config.packet_io.depolyment_mode_bin)
|| (DEPOLYMENT_MODE_TRANSPARENT == sapp_global_val->config.packet_io.depolyment_mode_bin)){
p_fs2_rt->fs_id_count_array[SAPP_STAT_ETH_INBOUND] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Pkt_Inbound");
p_fs2_rt->fs_id_length_array[SAPP_STAT_ETH_INBOUND] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Bit_Inbound");
p_fs2_rt->fs_id_count_array[SAPP_STAT_ETH_OUTBOUND] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Pkt_Outbound");
p_fs2_rt->fs_id_length_array[SAPP_STAT_ETH_OUTBOUND] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Bit_Outbound");
}
p_fs2_rt->fs_id_count_array[SAPP_STAT_RCV_UNKNOWN] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Unknown_Pkt");
p_fs2_rt->fs_id_length_array[SAPP_STAT_RCV_UNKNOWN] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Unknown_Bit");
p_fs2_rt->fs_id_count_array[SAPP_STAT_SND_ERROR] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Snd_Err_Pkt");
//pfs_para->fs_id_length_array[SAPP_STAT_SND_ERROR] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Snd_Err_Bit");
p_fs2_rt->fs_id_count_array[SAPP_STAT_RCV_IPV4] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Ipv4_Pkt");
p_fs2_rt->fs_id_length_array[SAPP_STAT_RCV_IPV4] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Ipv4_Bit");
p_fs2_rt->fs_id_count_array[SAPP_STAT_RCV_IPV6] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Ipv6_Pkt");
p_fs2_rt->fs_id_length_array[SAPP_STAT_RCV_IPV6] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Ipv6_Bit");
p_fs2_rt->fs_id_count_array[SAPP_STAT_RCV_TCP] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Pkt");
p_fs2_rt->fs_id_length_array[SAPP_STAT_RCV_TCP] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Bit");
p_fs2_rt->fs_id_count_array[SAPP_STAT_RCV_DUP_TCP] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Dup_Tcp_Pkt");
p_fs2_rt->fs_id_length_array[SAPP_STAT_RCV_DUP_TCP] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Dup_Tcp_Bit");
p_fs2_rt->fs_id_length_array[SAPP_STAT_TCP_LOST_PKT] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Lost_Bit");
p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_LOST_PKT_STREAM_NUM] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Lost_STM");
p_fs2_rt->fs_id_count_array[SAPP_STAT_DUP_IDENTIFY_ERR] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Dup_Key_Err"); /* dup�ظ���ʶ������key������� */
p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_CLOSE_BY_TIMEOUT] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Close_byT");
p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_CLOSE_BY_KICKOUT] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Close_byK");
p_fs2_rt->fs_id_count_array[SAPP_STAT_RCV_UDP] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Pkt");
p_fs2_rt->fs_id_length_array[SAPP_STAT_RCV_UDP] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Bit");
p_fs2_rt->fs_id_count_array[SAPP_STAT_RCV_DUP_UDP] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Dup_Udp_Pkt");
p_fs2_rt->fs_id_length_array[SAPP_STAT_RCV_DUP_UDP] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Dup_Udp_Bit");
p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_CLOSE_BY_TIMEOUT] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Close_byT");
p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_CLOSE_BY_KICKOUT] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Close_byK");
p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_STREAM_NEW] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Link_New");
p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_STREAM_DEL] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Link_Del");
p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_STREAM_DATA] = FS_register(fs2_handle, FS_STYLE_STATUS, FS_CALC_CURRENT, "Tcp_Concurrent");
p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_STREAM_NEW] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Link_New");
p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_STREAM_DEL] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Link_Del");
p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_STREAM_MORE] = FS_register(fs2_handle, FS_STYLE_STATUS, FS_CALC_CURRENT, "Udp_Concurrent");
p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_STREAM_DOUBLE] = FS_register(fs2_handle, FS_STYLE_STATUS,FS_CALC_CURRENT, "Tcp_Link_Double");
p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_STREAM_C2S] = FS_register(fs2_handle,FS_STYLE_STATUS, FS_CALC_CURRENT, "Tcp_Link_C2S");
p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_STREAM_S2C] = FS_register(fs2_handle,FS_STYLE_STATUS, FS_CALC_CURRENT, "Tcp_Link_S2C");
p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_STREAM_TOTAL_DOUBLE] = FS_register(fs2_handle, FS_STYLE_STATUS,FS_CALC_CURRENT, "Tcp_Link_Double_ALL");
p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_STREAM_TOTAL_C2S] = FS_register(fs2_handle,FS_STYLE_STATUS, FS_CALC_CURRENT, "Tcp_Link_C2S_ALL");
p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_STREAM_TOTAL_S2C] = FS_register(fs2_handle,FS_STYLE_STATUS, FS_CALC_CURRENT, "Tcp_Link_S2C_ALL");
p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_STREAM_DOUBLE] = FS_register(fs2_handle, FS_STYLE_STATUS,FS_CALC_CURRENT, "Udp_Link_Double");
p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_STREAM_C2S] = FS_register(fs2_handle,FS_STYLE_STATUS, FS_CALC_CURRENT, "Udp_Link_C2S");
p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_STREAM_S2C] = FS_register(fs2_handle,FS_STYLE_STATUS, FS_CALC_CURRENT, "Udp_Link_S2C");
p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_STREAM_TOTAL_DOUBLE] = FS_register(fs2_handle, FS_STYLE_STATUS,FS_CALC_CURRENT, "Udp_Link_Double_ALL");
p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_STREAM_TOTAL_C2S] = FS_register(fs2_handle,FS_STYLE_STATUS, FS_CALC_CURRENT, "Udp_Link_C2S_ALL");
p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_STREAM_TOTAL_S2C] = FS_register(fs2_handle,FS_STYLE_STATUS, FS_CALC_CURRENT, "Udp_Link_S2C_ALL");
p_fs2_rt->fs_id_count_array[SAPP_STAT_SND_TCP_RST] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Send_Tcp_Rst");
p_fs2_rt->fs_id_count_array[SAPP_STAT_SND_TCP_SYNACK] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Send_Tcp_S/A");
p_fs2_rt->fs_id_count_array[SAPP_STAT_SND_UDP] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Send_Udp");
p_fs2_rt->fs_id_count_array[SAPP_STAT_GLOBAL_BYPASS] = FS_register(fs2_handle,FS_STYLE_STATUS, FS_CALC_CURRENT, "DDOS_Bypass");
p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_BYPASS_STREAM] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Bypass_STM");
p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_BYPASS_PKTS] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Bypass_Pkt");
p_fs2_rt->fs_id_length_array[SAPP_STAT_TCP_BYPASS_BYTES] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Bypass_Bit");
p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_BYPASS_STREAM] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Bypass_STM");
p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_BYPASS_PKTS] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Bypass_Pkt");
p_fs2_rt->fs_id_length_array[SAPP_STAT_UDP_BYPASS_BYTES] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Bypass_Bit");
p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_OFFLOAD_STREAM] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Offload_STM");
p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_OFFLOAD_PKTS] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Offload_Pkt");
p_fs2_rt->fs_id_length_array[SAPP_STAT_TCP_OFFLOAD_BYTES] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Offload_Bit");
p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_OFFLOAD_STREAM] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Offload_STM");
p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_OFFLOAD_PKTS] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Offload_Pkt");
p_fs2_rt->fs_id_length_array[SAPP_STAT_UDP_OFFLOAD_BYTES] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Offload_Bit");
if (unlikely(g_timestamp_record_sw))
{
if (fs2_tcp_unorder_historgram_init(p_fs2_rt) < 0)
{
return -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));
}
if (fs2_plug_entry_historgram_init(p_fs2_rt) < 0)
{
return -1;
}
}
FS_start(fs2_handle);
return 0;
}
static void sapp_fs2_destroy(sapp_global_t *global_paramters)
{
sapp_config_profiling_metric_t *p_fs2_para = &global_paramters->config.profiling.fs2;
sapp_gval_individual_fixed_fs_t *p_fs2_rt = &global_paramters->individual_fixed.fs2_runtime;
if (strlen(p_fs2_para->prometheus_service_uri) > 0 && p_fs2_para->prometheus_service_port > 0)
{
FS_library_destroy();
}
if (p_fs2_rt->fs_metric_handle)
{
FS_stop(&p_fs2_rt->fs_metric_handle);
}
}
static int sapp_fs3_init(sapp_global_t *global_paramters)
{
sapp_config_profiling_metric_t *p_fs3_para = &global_paramters->config.profiling.fs3;
sapp_gval_individual_fixed_fs_t *p_fs3_rt = &global_paramters->individual_fixed.fs3_runtime;
return 0;
}
static void sapp_fs3_destroy(sapp_global_t *global_paramters)
{
return;
}
void sapp_metric_destroy(void)
{
if( sapp_global_val->config.profiling.fs2.enabled == 1)
{
sapp_fs2_destroy(sapp_global_val);
}
if( sapp_global_val->config.profiling.fs3.enabled == 1)
{
sapp_fs3_destroy(sapp_global_val);
}
}
|