Added initial support for NDP (IPv6)
[samplevnf.git] / VNFs / DPPD-PROX / display_priority.c
1 /*
2 // Copyright (c) 2010-2017 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16
17 #include "display_priority.h"
18 #include "stats_prio_task.h"
19 #include "display.h"
20 #include "lconf.h"
21
22 #define PRIORITY_COUNT 8
23
24 static struct display_page display_page_priority;
25 static struct display_column *stats_tx[PRIORITY_COUNT];
26 static struct display_column *stats_drop[PRIORITY_COUNT];
27 static struct display_column *core_col;
28 static struct display_column *name_col;
29
30 static void display_priority_draw_frame(struct screen_state *state)
31 {
32         uint32_t n_tasks = stats_get_n_prio_tasks_tot();
33         struct lcore_cfg *lconf = NULL;
34         struct task_args *targ;
35         char name[32];
36         char *ptr;
37
38         display_page_init(&display_page_priority);
39
40         struct display_table *core_name = display_page_add_table(&display_page_priority);
41
42         display_table_init(core_name, "Core/task");
43         core_col = display_table_add_col(core_name);
44         name_col = display_table_add_col(core_name);
45         display_column_init(core_col, "Nb", 4);
46         display_column_init(name_col, "Name", 5);
47
48         struct display_table *stats = display_page_add_table(&display_page_priority);
49         if (state->toggle == 0) {
50                 display_table_init(stats, "Statistics per second");
51
52                 char title[64];
53                 for (int i = 0; i < PRIORITY_COUNT; ++i) {
54                         stats_tx[i] = display_table_add_col(stats);
55                         snprintf(title, sizeof(title), "TX %d (K)", i);
56                         display_column_init(stats_tx[i], title, 9);
57
58                         stats_drop[i] = display_table_add_col(stats);
59                         snprintf(title, sizeof(title), "DRP %d (K)", i);
60                         display_column_init(stats_drop[i], title, 9);
61                 }
62         } else {
63                 display_table_init(stats, "Total statistics");
64
65                 char title[64];
66                 for (int i = 0; i < PRIORITY_COUNT; ++i) {
67                         stats_tx[i] = display_table_add_col(stats);
68                         snprintf(title, sizeof(title), "TX %d (#)", i);
69                         display_column_init(stats_tx[i], title, 9);
70
71                         stats_drop[i] = display_table_add_col(stats);
72                         snprintf(title, sizeof(title), "DRP %d (#)", i);
73                         display_column_init(stats_drop[i], title, 9);
74                 }
75         }
76
77         display_page_draw_frame(&display_page_priority, n_tasks);
78
79         uint32_t count = 0;
80         lconf = NULL;
81         while (core_targ_next(&lconf, &targ, 0) == 0) {
82                 if (strcmp(targ->task_init->mode_str, "aggreg") == 0) {
83                         display_column_print_core_task(core_col, count, lconf, targ);
84                         if (targ->id == 0)
85                                 display_column_print(name_col, count, "%s", lconf->name);
86                         count++;
87                 }
88         }
89 }
90
91 static void display_priority_draw_stats(struct screen_state *state)
92 {
93         uint64_t rx_prio;
94         uint64_t drop_tx_fail_prio;
95         struct lcore_cfg *lconf = NULL;
96         struct task_args *targ;
97         const uint32_t n_stats_prio = stats_get_n_prio_tasks_tot();
98
99         if (state->toggle == 0) {
100                 for (uint32_t count = 0; count < n_stats_prio; ++count) {
101                         struct prio_task_stats_sample *last = stats_get_prio_task_stats_sample(count, 1);
102                         struct prio_task_stats_sample *prev = stats_get_prio_task_stats_sample(count, 0);
103
104                         uint64_t delta_t = (last->tsc - prev->tsc) * 1000;
105                         if (delta_t == 0) // This could happen if we just reset the screen => stats will be updated later
106                                 continue;
107
108                         for (uint8_t i = 0; i < PRIORITY_COUNT; i++) {
109                                 rx_prio = last->rx_prio[i] - prev->rx_prio[i];
110                                 drop_tx_fail_prio = last->drop_tx_fail_prio[i] - prev->drop_tx_fail_prio[i];
111
112                                 display_column_print(stats_tx[i], count, "%9lu", val_to_rate(rx_prio, delta_t));
113                                 display_column_print(stats_drop[i], count, "%9lu", val_to_rate(drop_tx_fail_prio, delta_t));
114                         }
115                 }
116         } else {
117                 for (uint32_t count = 0; count < n_stats_prio; ++count) {
118                         for (uint8_t i = 0; i < PRIORITY_COUNT; i++) {
119                                 rx_prio = stats_core_task_tot_rx_prio(count, i);
120                                 drop_tx_fail_prio = stats_core_task_tot_drop_tx_fail_prio(count, i);
121
122                                 display_column_print(stats_tx[i], count, "%9lu", rx_prio);
123                                 display_column_print(stats_drop[i], count, "%9lu", drop_tx_fail_prio);
124                         }
125                 }
126         }
127 }
128
129 static int display_priority_get_height(void)
130 {
131         return stats_get_n_prio_tasks_tot();
132 }
133
134 static struct display_screen display_screen_priority = {
135         .draw_frame = display_priority_draw_frame,
136         .draw_stats = display_priority_draw_stats,
137         .get_height = display_priority_get_height,
138         .title = "priority",
139 };
140
141 struct display_screen *display_priority(void)
142 {
143         return &display_screen_priority;
144 }