618350e2e893815d60ad41a289230fbcb40ced0b
[samplevnf.git] / VNFs / DPPD-PROX / display_rings.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 <rte_ring.h>
18
19 #include "display.h"
20 #include "display_rings.h"
21 #include "stats_ring.h"
22 #include "prox_port_cfg.h"
23
24 static struct display_page display_page_rings;
25 static struct display_column *ring_col;
26 static struct display_column *occup_col;
27 static struct display_column *free_col;
28 static struct display_column *size_col;
29 static struct display_column *sc_col;
30 static struct display_column *sp_col;
31
32 static void display_rings_draw_frame(struct screen_state *state)
33 {
34         const uint32_t n_rings = stats_get_n_rings();
35         char sc_val, sp_val;
36
37         display_page_init(&display_page_rings);
38
39         struct display_table *ring_table = display_page_add_table(&display_page_rings);
40         struct display_table *stats_table = display_page_add_table(&display_page_rings);
41
42         display_table_init(ring_table, "Name");
43
44         display_table_init(stats_table, "Sampled statistics");
45
46         ring_col = display_table_add_col(ring_table);
47         display_column_init(ring_col, "Ring/Port", 11);
48         occup_col = display_table_add_col(stats_table);
49         display_column_init(occup_col, "Occup (%)", 11);
50         free_col = display_table_add_col(stats_table);
51         display_column_init(free_col, "Free", 11);
52         size_col = display_table_add_col(stats_table);
53         display_column_init(size_col, "Size", 11);
54         sc_col = display_table_add_col(stats_table);
55         display_column_init(sc_col, "SC", 2);
56         sp_col = display_table_add_col(stats_table);
57         display_column_init(sp_col, "SP", 2);
58
59         display_page_draw_frame(&display_page_rings, n_rings);
60
61         for (uint16_t i = 0; i < n_rings; ++i) {
62                 struct ring_stats *rs = stats_get_ring_stats(i);
63
64                 if (rs->nb_ports == 0) {
65                         display_column_print(ring_col, i, "%s", rs->ring->name);
66                 } else {
67                         char name[64] = {0};
68                         int offset = 0;
69
70                         for (uint32_t j = 0; j < rs->nb_ports; j++)
71                                 offset += sprintf(name + offset, "%s", rs->port[j]->name);
72                 }
73
74                 sc_val = (rs->ring->flags & RING_F_SC_DEQ) ? 'y' : 'n';
75                 sp_val = (rs->ring->flags & RING_F_SP_ENQ) ? 'y' : 'n';
76
77                 display_column_print(sc_col, i, " %c", sc_val);
78                 display_column_print(sp_col, i, " %c", sp_val);
79         }
80 }
81
82 static void display_rings_draw_stats(struct screen_state *state)
83 {
84         const uint32_t n_rings = stats_get_n_rings();
85
86         for (uint32_t i = 0; i < n_rings; ++i) {
87                 struct ring_stats *rs = stats_get_ring_stats(i);
88                 uint32_t used = ((rs->size - rs->free)*10000)/rs->size;
89
90                 display_column_print(occup_col, i, "%8u.%02u", used/100, used%100);
91                 display_column_print(free_col, i, "%11u", rs->free);
92                 display_column_print(size_col, i, "%11u", rs->size);
93         }
94 }
95
96 static int display_rings_get_height(void)
97 {
98         return stats_get_n_rings();
99 }
100
101 static struct display_screen display_screen_rings = {
102         .draw_frame = display_rings_draw_frame,
103         .draw_stats = display_rings_draw_stats,
104         .get_height = display_rings_get_height,
105         .title = "rings",
106 };
107
108 struct display_screen *display_rings(void)
109 {
110         return &display_screen_rings;
111 }