forked from sdnfv/openNetVM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathonvm_stats.c
656 lines (564 loc) · 26.6 KB
/
onvm_stats.c
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
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
/*********************************************************************
* openNetVM
* https://sdnfv.github.io
*
* BSD LICENSE
*
* Copyright(c)
* 2015-2019 George Washington University
* 2015-2019 University of California Riverside
* 2010-2019 Intel Corporation. All rights reserved.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
********************************************************************/
/******************************************************************************
onvm_stats.c
This file contain the implementation of all functions related to
statistics display in the manager.
******************************************************************************/
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include "onvm_mgr.h"
#include "onvm_nf.h"
#include "onvm_stats.h"
/************************Internal Functions Prototypes************************/
/*
* Function to send json events to web view
*
*/
static void
onvm_stats_add_event(struct onvm_event *event_info);
/*
* Function displaying statistics for all ports
*
* Input : time passed since last display (to compute packet rate)
*
*/
static void
onvm_stats_display_ports(unsigned difftime, uint8_t verbosity_level);
/*
* Function displaying statistics for all NFs
*
*/
static void
onvm_stats_display_nfs(unsigned difftime, uint8_t verbosity_level);
/*
* Function clearing the terminal and moving back the cursor to the top left.
*
*/
static void
onvm_stats_clear_terminal(void);
/*
* Function giving the MAC address of a port in string format.
*
* Input : port
* Output : its MAC address
*
*/
static const char *
onvm_stats_print_MAC(uint8_t port);
/*
* Flush the file streams we're writing stats to
*/
static void
onvm_stats_flush(void);
/*
* Truncate the files back to being empty, so each iteration we reset the data
*/
static void
onvm_stats_truncate(void);
/*
* Free and reset the cJSON variables to build new json string with
*/
static void
onvm_json_reset_objects(void);
/*********************Stats Output Streams************************************/
static FILE *stats_out;
static FILE *json_stats_out;
static FILE *json_events_out;
/****************************Global variables***************************************/
/* Holds current timestamp, might want to make this not global */
char buffer[20];
/****************************Interfaces***************************************/
void
onvm_stats_init(uint8_t verbosity_level) {
if (verbosity_level == ONVM_RAW_STATS_DUMP) {
printf("%s", ONVM_STATS_RAW_DUMP_PORT_MSG);
printf("%s", ONVM_STATS_RAW_DUMP_NF_MSG);
}
}
void
onvm_stats_set_output(ONVM_STATS_OUTPUT output) {
if (output != ONVM_STATS_NONE) {
switch (output) {
case ONVM_STATS_STDOUT:
stats_out = stdout;
break;
case ONVM_STATS_STDERR:
stats_out = stderr;
break;
case ONVM_STATS_WEB:
stats_out = fopen(ONVM_STATS_FILE, ONVM_STATS_FOPEN_ARGS);
json_stats_out = fopen(ONVM_JSON_STATS_FILE, ONVM_STATS_FOPEN_ARGS);
json_events_out = fopen(ONVM_JSON_EVENTS_FILE, ONVM_STATS_FOPEN_ARGS);
if (stats_out == NULL || json_stats_out == NULL) {
rte_exit(-1, "Error opening stats files\n");
}
onvm_json_root = NULL;
onvm_json_port_stats_obj = NULL;
onvm_json_nf_stats_obj = NULL;
onvm_json_events_arr = cJSON_CreateArray();
break;
default:
rte_exit(-1, "Error handling stats output file\n");
break;
}
}
}
void
onvm_stats_cleanup(void) {
if (stats_destination == ONVM_STATS_WEB) {
fclose(stats_out);
fclose(json_stats_out);
fclose(json_events_out);
/* Delete all JSON objects to free memory */
cJSON_Delete(onvm_json_root);
cJSON_Delete(onvm_json_events_arr);
}
}
void
onvm_stats_display_all(unsigned difftime, uint8_t verbosity_level) {
time_t time_raw_format;
struct tm *ptr_time;
time(&time_raw_format);
ptr_time = localtime(&time_raw_format);
if (strftime(buffer, 20, "%F %T", ptr_time) == 0) {
perror("Couldn't prepare formatted string");
}
if (stats_out == stdout) {
if (verbosity_level != ONVM_RAW_STATS_DUMP)
onvm_stats_clear_terminal();
} else {
onvm_stats_truncate();
onvm_json_reset_objects();
}
onvm_stats_display_ports(difftime, verbosity_level);
onvm_stats_display_nfs(difftime, verbosity_level);
if (stats_destination == ONVM_STATS_WEB) {
fprintf(json_stats_out, "%s\n", cJSON_Print(onvm_json_root));
fprintf(json_events_out, "%s\n", cJSON_Print(onvm_json_events_arr));
}
onvm_stats_flush();
}
void
onvm_stats_clear_all_nfs(void) {
unsigned i;
for (i = 0; i < MAX_NFS; i++) {
onvm_stats_clear_nf(i);
}
}
void
onvm_stats_clear_nf(uint16_t id) {
nfs[id].stats.rx = nfs[id].stats.rx_drop = 0;
nfs[id].stats.tx = nfs[id].stats.tx_drop = 0;
nfs[id].stats.act_drop = nfs[id].stats.act_tonf = 0;
nfs[id].stats.act_next = nfs[id].stats.act_out = 0;
nfs[id].stats.tx_returned = nfs[id].stats.tx_buffer = 0;
}
void
onvm_stats_gen_event_info(const char *msg, uint8_t type, void *data) {
struct onvm_event *event;
event = (struct onvm_event *)rte_malloc("onvm stats gen event info", sizeof(struct onvm_event), 0);
if (event == NULL) {
perror("Couldn't allocate event");
return;
}
event->type = type;
event->msg = msg;
event->data = data;
onvm_stats_add_event(event);
}
void
onvm_stats_gen_event_nf_info(const char *msg, struct onvm_nf *nf) {
struct onvm_event *event;
event = (struct onvm_event *)rte_malloc("onvm stats gen event nf info", sizeof(struct onvm_event), 0);
if (event == NULL) {
perror("Couldn't allocate event");
return;
}
event->type = ONVM_EVENT_NF_INFO;
event->msg = msg;
event->data = nf;
onvm_stats_add_event(event);
}
/****************************Internal functions*******************************/
static void
onvm_stats_add_event(struct onvm_event *event_info) {
if (event_info == NULL || stats_destination != ONVM_STATS_WEB) {
rte_free(event_info);
return;
}
char event_time_buf[20];
uint8_t type;
struct tm *ptr_time;
struct onvm_nf *nf;
time_t time_raw_format;
time(&time_raw_format);
type = event_info->type;
ptr_time = localtime(&time_raw_format);
if (strftime(event_time_buf, 20, "%F %T", ptr_time) == 0) {
perror("Couldn't prepare formatted string");
}
cJSON *source = cJSON_CreateObject();
cJSON *new_event = cJSON_CreateObject();
cJSON_AddStringToObject(new_event, "timestamp", event_time_buf);
cJSON_AddStringToObject(new_event, "message", event_info->msg);
if (type == ONVM_EVENT_WITH_CORE) {
cJSON_AddNumberToObject(source, "core", *(int *)(event_info->data));
} else if (type == ONVM_EVENT_PORT_INFO) {
cJSON_AddStringToObject(source, "type", "MGR");
} else if (type == ONVM_EVENT_NF_INFO) {
nf = (struct onvm_nf *)event_info->data;
if (nf->tag)
cJSON_AddStringToObject(source, "type", (char *)nf->tag);
else
cJSON_AddStringToObject(source, "type", "NF");
cJSON_AddNumberToObject(source, "instance_id", (int16_t)nf->instance_id);
cJSON_AddNumberToObject(source, "service_id", (int16_t)nf->service_id);
cJSON_AddNumberToObject(source, "core", (int16_t)nf->thread_info.core);
} else if (type == ONVM_EVENT_NF_STOP) {
cJSON_AddStringToObject(source, "type", "NF");
cJSON_AddNumberToObject(source, "instance_id", *(int16_t *)(event_info->data));
} else
rte_exit(-1, "Invalid stats event type\n");
cJSON_AddItemToObject(new_event, "source", source);
cJSON_AddItemToArray(onvm_json_events_arr, new_event);
rte_free(event_info);
}
static void
onvm_stats_display_ports(unsigned difftime, uint8_t verbosity_level) {
unsigned i = 0;
uint64_t nic_rx_pkts = 0;
uint64_t nic_tx_pkts = 0;
uint64_t nic_rx_pps = 0;
uint64_t nic_tx_pps = 0;
uint64_t nic_received_pkts = 0;
uint64_t nic_dropped_pkts = 0;
char *port_label = NULL;
/* Arrays to store last TX/RX count to calculate rate */
static uint64_t tx_last[RTE_MAX_ETHPORTS];
static uint64_t rx_last[RTE_MAX_ETHPORTS];
static const char *PORT_MSG[3];
PORT_MSG[0] = PORT_MSG[1] = "PORTS\n-----\n";
PORT_MSG[2] = "";
fprintf(stats_out, "%s", PORT_MSG[verbosity_level - 1]);
if (verbosity_level != ONVM_RAW_STATS_DUMP) {
for (i = 0; i < ports->num_ports; i++)
fprintf(stats_out, "Port %u: '%s'\t", (unsigned)ports->id[i],
onvm_stats_print_MAC(ports->id[i]));
fprintf(stats_out, "\n\n");
}
for (i = 0; i < ports->num_ports; i++) {
nic_rx_pkts = ports->rx_stats.rx[ports->id[i]];
nic_tx_pkts = ports->tx_stats.tx[ports->id[i]];
nic_rx_pps = (nic_rx_pkts - rx_last[i]) / difftime;
nic_tx_pps = (nic_tx_pkts - tx_last[i]) / difftime;
nic_dropped_pkts = ports->nic_drop[ports->id[i]];
nic_received_pkts = ports->nic_receive[ports->id[i]];
if (verbosity_level == ONVM_RAW_STATS_DUMP) {
fprintf(stats_out, ONVM_STATS_RAW_DUMP_PORTS_CONTENT, buffer,
(unsigned)ports->id[i], nic_rx_pkts, nic_rx_pps, nic_tx_pkts, nic_tx_pps);
} else {
fprintf(stats_out, ONVM_STATS_REG_PORTS,
(unsigned)ports->id[i],
nic_received_pkts, nic_dropped_pkts,
nic_rx_pkts, nic_rx_pps, nic_tx_pkts, nic_tx_pps);
}
/* Only print this information out if we haven't already printed it to the console above */
if (stats_out != stdout && stats_out != stderr) {
ONVM_SNPRINTF(port_label, 8, "Port %d", i);
cJSON_AddItemToObject(onvm_json_port_stats_obj, port_label,
onvm_json_port_stats[i] = cJSON_CreateObject());
cJSON_AddStringToObject(onvm_json_port_stats[i], "Label", port_label);
cJSON_AddNumberToObject(onvm_json_port_stats[i], "RX", nic_rx_pps);
cJSON_AddNumberToObject(onvm_json_port_stats[i], "TX", nic_tx_pps);
free(port_label);
port_label = NULL;
}
rx_last[i] = nic_rx_pkts;
tx_last[i] = nic_tx_pkts;
}
}
static void
onvm_stats_display_client_wakeup_thread_context(int difftime) {
uint64_t num_wakeups = 0;
uint64_t prev_num_wakeups = 0;
uint64_t wakeup_rate;
unsigned i = 0;
for (i = 0; i < MAX_NFS; i++) {
if (!onvm_nf_is_valid(&nfs[i]))
continue;
num_wakeups += nf_wakeup_infos[i].num_wakeups;
prev_num_wakeups += nf_wakeup_infos[i].prev_num_wakeups;
nf_wakeup_infos[i].prev_num_wakeups = nf_wakeup_infos[i].num_wakeups;
}
wakeup_rate = (num_wakeups - prev_num_wakeups) / difftime;
fprintf(stats_out, "Total wakeups = %"PRIu64", Wakeup rate = %"PRIu64"\n", num_wakeups, wakeup_rate);
}
static void
onvm_stats_display_nfs(unsigned difftime, uint8_t verbosity_level) {
char *nf_label = NULL;
unsigned i = 0;
/* Arrays to store last TX/RX count for NFs to calculate rate */
static uint64_t nf_tx_last[MAX_NFS];
static uint64_t nf_rx_last[MAX_NFS];
/* Arrays to store last TX/RX pkts dropped for NFs to calculate drop rate */
static uint64_t nf_tx_drop_last[MAX_NFS];
static uint64_t nf_rx_drop_last[MAX_NFS];
static const char *NF_MSG[3];
NF_MSG[0] = ONVM_STATS_MSG;
if (ONVM_NF_SHARE_CORES) {
NF_MSG[1] = ONVM_STATS_SHARED_CORE_MSG;
} else {
NF_MSG[1] = ONVM_STATS_ADV_MSG;
}
NF_MSG[2] = "";
/* For same service id TX/RX stats */
uint8_t print_total_stats = 0;
uint64_t rx_for_service[MAX_SERVICES];
uint64_t tx_for_service[MAX_SERVICES];
uint64_t rx_drop_for_service[MAX_SERVICES];
uint64_t tx_drop_for_service[MAX_SERVICES];
uint64_t rx_pps_for_service[MAX_SERVICES];
uint64_t tx_pps_for_service[MAX_SERVICES];
uint64_t rx_drop_rate_for_service[MAX_SERVICES];
uint64_t tx_drop_rate_for_service[MAX_SERVICES];
uint64_t act_out_for_service[MAX_SERVICES];
uint64_t act_tonf_for_service[MAX_SERVICES];
uint64_t act_drop_for_service[MAX_SERVICES];
uint64_t act_next_for_service[MAX_SERVICES];
uint64_t act_buffer_for_service[MAX_SERVICES];
uint64_t act_returned_for_service[MAX_SERVICES];
for (i = 0; i < MAX_SERVICES; i++) {
if (nf_per_service_count[i] > 1)
print_total_stats = 1;
rx_for_service[i] = 0;
tx_for_service[i] = 0;
rx_drop_for_service[i] = 0;
tx_drop_for_service[i] = 0;
rx_pps_for_service[i] = 0;
tx_pps_for_service[i] = 0;
rx_drop_rate_for_service[i] = 0;
tx_drop_rate_for_service[i] = 0;
act_out_for_service[i] = 0;
act_tonf_for_service[i] = 0;
act_drop_for_service[i] = 0;
act_next_for_service[i] = 0;
act_buffer_for_service[i] = 0;
act_returned_for_service[i] = 0;
}
fprintf(stats_out, "%s", NF_MSG[verbosity_level - 1]);
for (i = 0; i < MAX_NFS; i++) {
if (!onvm_nf_is_valid(&nfs[i]))
continue;
const uint64_t rx = nfs[i].stats.rx;
const uint64_t rx_drop = nfs[i].stats.rx_drop;
const uint64_t tx = nfs[i].stats.tx;
const uint64_t tx_drop = nfs[i].stats.tx_drop;
const uint64_t act_out = nfs[i].stats.act_out;
const uint64_t act_tonf = nfs[i].stats.act_tonf;
const uint64_t act_drop = nfs[i].stats.act_drop;
const uint64_t act_next = nfs[i].stats.act_next;
const uint64_t act_buffer = nfs[i].stats.tx_buffer;
const uint64_t act_returned = nfs[i].stats.tx_returned;
const uint64_t rx_pps = (rx - nf_rx_last[i]) / difftime;
const uint64_t tx_pps = (tx - nf_tx_last[i]) / difftime;
const uint64_t tx_drop_rate = (tx_drop - nf_tx_drop_last[i]) / difftime;
const uint64_t rx_drop_rate = (rx_drop - nf_rx_drop_last[i]) / difftime;
const uint64_t num_wakeups = nf_wakeup_infos[i].num_wakeups;
const uint64_t prev_num_wakeups = nf_wakeup_infos[i].prev_num_wakeups;
const uint64_t wakeup_rate = (num_wakeups - prev_num_wakeups) / difftime;
char state;
uint8_t active = 0;
if (ONVM_NF_SHARE_CORES)
active = rte_atomic16_read(nf_wakeup_infos[i].shm_server);
if (!active) {
state = 'W';
} else {
state = 'S';
}
/* Save stats for NFs with same service id */
if (print_total_stats) {
rx_for_service[nfs[i].service_id] += rx;
tx_for_service[nfs[i].service_id] += tx;
rx_drop_for_service[nfs[i].service_id] += rx_drop;
tx_drop_for_service[nfs[i].service_id] += tx_drop;
rx_pps_for_service[nfs[i].service_id] += rx_pps;
tx_pps_for_service[nfs[i].service_id] += tx_pps;
rx_drop_rate_for_service[nfs[i].service_id] += rx_drop_rate;
tx_drop_rate_for_service[nfs[i].service_id] += tx_drop_rate;
act_out_for_service[nfs[i].service_id] += act_out;
act_tonf_for_service[nfs[i].service_id] += act_tonf;
act_drop_for_service[nfs[i].service_id] += act_drop;
act_next_for_service[nfs[i].service_id] += act_next;
act_buffer_for_service[nfs[i].service_id] += act_buffer;
act_returned_for_service[nfs[i].service_id] += act_returned;
}
if (verbosity_level == ONVM_RAW_STATS_DUMP) {
fprintf(stats_out, ONVM_STATS_RAW_DUMP_CONTENT,
buffer, nfs[i].tag, nfs[i].instance_id, nfs[i].service_id, nfs[i].thread_info.core,
nfs[i].thread_info.parent, state, rte_atomic16_read(&nfs[i].thread_info.children_cnt),
rx, tx, rx_pps, tx_pps, rx_drop, tx_drop, rx_drop_rate, tx_drop_rate,
act_out, act_tonf, act_drop, act_next, act_buffer, act_returned,
num_wakeups, wakeup_rate);
} else if (verbosity_level == 2) {
fprintf(stats_out, ONVM_STATS_ADV_CONTENT,
nfs[i].tag, nfs[i].instance_id, nfs[i].service_id, nfs[i].thread_info.core,
rx_pps, tx_pps, rx, tx, act_out, act_tonf, act_drop,
nfs[i].thread_info.parent, state, rte_atomic16_read(&nfs[i].thread_info.children_cnt),
rx_drop_rate, tx_drop_rate, rx_drop, tx_drop, act_next, act_buffer, act_returned);
if (ONVM_NF_SHARE_CORES)
fprintf(stats_out, ONVM_STATS_SHARED_CORE_CONTENT, num_wakeups, wakeup_rate);
fprintf(stats_out, "\n");
} else {
fprintf(stats_out, ONVM_STATS_REG_CONTENT,
nfs[i].tag, nfs[i].instance_id, nfs[i].service_id, nfs[i].thread_info.core,
rx_pps, tx_pps, rx_drop, tx_drop, act_out, act_tonf, act_drop);
}
/* Only print this information out if we haven't already printed it to the console above */
if (stats_out != stdout && stats_out != stderr) {
ONVM_SNPRINTF(nf_label, 6, "NF %d", i);
cJSON_AddItemToObject(onvm_json_nf_stats_obj, nf_label,
onvm_json_nf_stats[i] = cJSON_CreateObject());
cJSON_AddStringToObject(onvm_json_nf_stats[i], "Label", nf_label);
cJSON_AddNumberToObject(onvm_json_nf_stats[i], "RX", rx_pps);
cJSON_AddNumberToObject(onvm_json_nf_stats[i], "TX", tx_pps);
cJSON_AddNumberToObject(onvm_json_nf_stats[i], "TX_Drop_Rate", tx_drop_rate);
cJSON_AddNumberToObject(onvm_json_nf_stats[i], "RX_Drop_Rate", rx_drop_rate);
cJSON_AddNumberToObject(onvm_json_nf_stats[i], "service_id", (int16_t)nfs[i].service_id);
cJSON_AddNumberToObject(onvm_json_nf_stats[i], "instance_id",
(int16_t)nfs[i].instance_id);
cJSON_AddNumberToObject(onvm_json_nf_stats[i], "core", (int16_t)nfs[i].thread_info.core);
free(nf_label);
nf_label = NULL;
}
nf_rx_last[i] = nfs[i].stats.rx;
nf_tx_last[i] = nfs[i].stats.tx;
nf_rx_drop_last[i] = rx_drop;
nf_tx_drop_last[i] = tx_drop;
}
if (verbosity_level == ONVM_RAW_STATS_DUMP)
return;
if (print_total_stats) {
fprintf(stats_out, "\nService id totals\n");
fprintf(stats_out, "-----------------\n");
for (i = 0; i < MAX_SERVICES; i++) {
uint16_t nfs_for_service = nf_per_service_count[i];
const char *nf_count = nfs_for_service == 1 ? "NF " : "NFs";
if (nfs_for_service == 0)
continue;
if (verbosity_level == 2) {
fprintf(stats_out, ONVM_STATS_ADV_TOTALS,
i, nfs_for_service, nf_count, rx_pps_for_service[i], tx_pps_for_service[i],
rx_for_service[i], tx_for_service[i], act_out_for_service[i],
act_tonf_for_service[i], act_drop_for_service[i], rx_drop_rate_for_service[i],
tx_drop_rate_for_service[i], rx_drop_for_service[i], tx_drop_for_service[i],
act_next_for_service[i], act_buffer_for_service[i], act_returned_for_service[i]);
} else {
fprintf(stats_out, ONVM_STATS_REG_TOTALS,
i, nfs_for_service, nf_count, rx_pps_for_service[i], tx_pps_for_service[i],
rx_drop_for_service[i], tx_drop_for_service[i], act_out_for_service[i],
act_tonf_for_service[i], act_drop_for_service[i]);
}
}
}
if (ONVM_NF_SHARE_CORES) {
fprintf(stats_out, "\n\nShared core stats\n");
fprintf(stats_out, "-----------------\n");
onvm_stats_display_client_wakeup_thread_context(difftime);
}
}
/***************************Helper functions**********************************/
static void
onvm_stats_clear_terminal(void) {
const char clr[] = {27, '[', '2', 'J', '\0'};
const char topLeft[] = {27, '[', '1', ';', '1', 'H', '\0'};
fprintf(stats_out, "%s%s", clr, topLeft);
}
static const char *
onvm_stats_print_MAC(uint8_t port) {
static const char err_address[] = "00:00:00:00:00:00";
static char addresses[RTE_MAX_ETHPORTS][sizeof(err_address)];
if (unlikely(port >= RTE_MAX_ETHPORTS))
return err_address;
if (unlikely(addresses[port][0] == '\0')) {
struct rte_ether_addr mac;
rte_eth_macaddr_get(port, &mac);
snprintf(addresses[port], sizeof(addresses[port]), "%02x:%02x:%02x:%02x:%02x:%02x\n", mac.addr_bytes[0],
mac.addr_bytes[1], mac.addr_bytes[2], mac.addr_bytes[3], mac.addr_bytes[4], mac.addr_bytes[5]);
}
return addresses[port];
}
static void
onvm_stats_flush(void) {
if (stats_out == stdout || stats_out == stderr) {
return;
}
fflush(stats_out);
fflush(json_stats_out);
fflush(json_events_out);
}
static void
onvm_stats_truncate(void) {
if (stats_out == stdout || stats_out == stderr) {
return;
}
stats_out = freopen(NULL, ONVM_STATS_FOPEN_ARGS, stats_out);
json_stats_out = freopen(NULL, ONVM_STATS_FOPEN_ARGS, json_stats_out);
json_events_out = freopen(NULL, ONVM_STATS_FOPEN_ARGS, json_events_out);
/* Ensure we're able to open all the files we need */
if (stats_out == NULL) {
rte_exit(-1, "Error truncating stats files\n");
}
}
static void
onvm_json_reset_objects(void) {
time_t current_time;
if (onvm_json_root) {
cJSON_Delete(onvm_json_root);
onvm_json_root = NULL;
}
onvm_json_root = cJSON_CreateObject();
current_time = time(0);
cJSON_AddStringToObject(onvm_json_root, ONVM_JSON_TIMESTAMP_KEY, ctime(¤t_time));
cJSON_AddItemToObject(onvm_json_root, ONVM_JSON_PORT_STATS_KEY,
onvm_json_port_stats_obj = cJSON_CreateObject());
cJSON_AddItemToObject(onvm_json_root, ONVM_JSON_NF_STATS_KEY, onvm_json_nf_stats_obj = cJSON_CreateObject());
}