2 // Copyright (c) 2010-2017 Intel Corporation
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include "display_rings.h"
21 #include "stats_ring.h"
22 #include "prox_port_cfg.h"
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;
32 static void display_rings_draw_frame(struct screen_state *state)
34 const uint32_t n_rings = stats_get_n_rings();
37 display_page_init(&display_page_rings);
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);
42 display_table_init(ring_table, "Name");
44 display_table_init(stats_table, "Sampled statistics");
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);
59 display_page_draw_frame(&display_page_rings, n_rings);
61 for (uint16_t i = 0; i < n_rings; ++i) {
62 struct ring_stats *rs = stats_get_ring_stats(i);
64 if (rs->nb_ports == 0) {
65 display_column_print(ring_col, i, "%s", rs->ring->name);
70 for (uint32_t j = 0; j < rs->nb_ports; j++)
71 offset += sprintf(name + offset, "%s", rs->port[j]->name);
74 sc_val = (rs->ring->flags & RING_F_SC_DEQ) ? 'y' : 'n';
75 sp_val = (rs->ring->flags & RING_F_SP_ENQ) ? 'y' : 'n';
77 display_column_print(sc_col, i, " %c", sc_val);
78 display_column_print(sp_col, i, " %c", sp_val);
82 static void display_rings_draw_stats(struct screen_state *state)
84 const uint32_t n_rings = stats_get_n_rings();
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;
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);
96 static int display_rings_get_height(void)
98 return stats_get_n_rings();
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,
108 struct display_screen *display_rings(void)
110 return &display_screen_rings;