Added support for VLAN in IPv6
[samplevnf.git] / VNFs / DPPD-PROX / display_mempools.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_mempools.h"
18 #include "stats_mempool.h"
19 #include "display.h"
20 #include "defaults.h"
21
22 static struct display_page display_page_mempools;
23 static struct display_column *nb_col;
24 static struct display_column *queue_col;
25 static struct display_column *occup_col;
26 static struct display_column *used_col;
27 static struct display_column *free_col;
28 static struct display_column *total_col;
29 static struct display_column *mem_used_col;
30 static struct display_column *mem_free_col;
31 static struct display_column *mem_tot_col;
32
33 static void display_mempools_draw_frame(struct screen_state *screen_state)
34 {
35         const uint32_t n_mempools = stats_get_n_mempools();
36
37         display_page_init(&display_page_mempools);
38
39         struct display_table *port = display_page_add_table(&display_page_mempools);
40         struct display_table *stats = display_page_add_table(&display_page_mempools);
41
42         display_table_init(port, "Port");
43         display_table_init(stats, "Sampled statistics");
44
45         nb_col = display_table_add_col(port);
46         queue_col = display_table_add_col(port);
47         display_column_init(nb_col, "Nb", 4);
48         display_column_init(queue_col, "Queue", 5);
49
50         occup_col = display_table_add_col(stats);
51         display_column_init(occup_col, "Occup (%)", 9);
52         used_col = display_table_add_col(stats);
53         display_column_init(used_col, "Used (#)", 12);
54         free_col = display_table_add_col(stats);
55         display_column_init(free_col, "Free (#)", 12);
56         total_col = display_table_add_col(stats);
57         display_column_init(total_col, "Total (#)", 13);
58
59         mem_used_col = display_table_add_col(stats);
60         display_column_init(mem_used_col, "Mem Used (KB)", 13);
61         mem_free_col = display_table_add_col(stats);
62         display_column_init(mem_free_col, "Mem Free (KB)", 13);
63         mem_tot_col = display_table_add_col(stats);
64         display_column_init(mem_tot_col, "Mem Tot (KB)", 12);
65
66         display_page_draw_frame(&display_page_mempools, n_mempools);
67
68         for (uint16_t i = 0; i < n_mempools; ++i) {
69                 struct mempool_stats *ms = stats_get_mempool_stats(i);
70
71                 display_column_print(nb_col, i, "%4u", ms->port);
72                 display_column_print(queue_col, i, "%5u", ms->queue);
73                 display_column_print(total_col, i, "%13zu", ms->size);
74                 display_column_print(mem_tot_col, i, "%12zu", ms->size * MBUF_SIZE/1024);
75         }
76 }
77
78 static void display_mempools_draw_stats(struct screen_state *state)
79 {
80         const uint32_t n_mempools = stats_get_n_mempools();
81
82         for (uint16_t i = 0; i < n_mempools; ++i) {
83                 struct mempool_stats *ms = stats_get_mempool_stats(i);
84                 const size_t used = ms->size - ms->free;
85                 const uint32_t used_frac = used*10000/ms->size;
86
87                 display_column_print(occup_col, i, "%6u.%02u", used_frac/100, used_frac % 100);
88                 display_column_print(used_col, i, "%12zu", used);
89                 display_column_print(free_col, i, "%12zu", ms->free);
90
91                 display_column_print(mem_free_col, i, "%13zu", used * MBUF_SIZE/1024);
92                 display_column_print(mem_used_col, i, "%13zu", ms->free * MBUF_SIZE/1024);
93         }
94 }
95
96 static int display_mempools_get_height(void)
97 {
98         return stats_get_n_mempools();
99 }
100
101 static struct display_screen display_screen_mempools = {
102         .draw_frame = display_mempools_draw_frame,
103         .draw_stats = display_mempools_draw_stats,
104         .get_height = display_mempools_get_height,
105         .title = "mempools",
106 };
107
108 struct display_screen *display_mempools(void)
109 {
110         return &display_screen_mempools;
111 }