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.
17 #include "prox_globals.h"
18 #include "display_pkt_len.h"
19 #include "stats_port.h"
22 #include "prox_port_cfg.h"
25 static struct display_page display_page_pkt_len;
26 static struct display_column *port_col;
27 static struct display_column *name_col;
28 static struct display_column *type_col;
29 static struct display_column *stats_col[PKT_SIZE_COUNT];
31 const char *titles[] = {
41 static int port_disp[PROX_MAX_PORTS];
42 static int n_port_disp;
44 static void display_pkt_len_draw_frame(struct screen_state *screen_state)
47 for (uint8_t i = 0; i < PROX_MAX_PORTS; ++i) {
48 if (prox_port_cfg[i].active) {
49 port_disp[n_port_disp++] = i;
53 display_page_init(&display_page_pkt_len);
55 struct display_table *port_name = display_page_add_table(&display_page_pkt_len);
57 display_table_init(port_name, "Port");
58 port_col = display_table_add_col(port_name);
59 name_col = display_table_add_col(port_name);
60 type_col = display_table_add_col(port_name);
62 display_column_init(port_col, "ID", 4);
63 display_column_init(name_col, "Name", 8);
64 display_column_init(type_col, "Type", 7);
66 struct display_table *stats = display_page_add_table(&display_page_pkt_len);
68 if (screen_state->toggle == 0)
69 display_table_init(stats, "Statistics per second");
71 display_table_init(stats, "Total Statistics");
73 for (int i = 0; i < PKT_SIZE_COUNT; ++i) {
74 stats_col[i] = display_table_add_col(stats);
75 display_column_init(stats_col[i], titles[i], 13);
78 display_page_draw_frame(&display_page_pkt_len, n_port_disp);
80 for (uint8_t i = 0; i < n_port_disp; ++i) {
81 const uint32_t port_id = port_disp[i];
83 display_column_print(port_col, i, "%4u", port_id);
84 display_column_print(name_col, i, "%8s", prox_port_cfg[port_id].name);
85 display_column_print(type_col, i, "%7s", prox_port_cfg[port_id].short_name);
89 static void display_pkt_len_draw_stats(struct screen_state *state)
91 for (uint8_t i = 0; i < n_port_disp; ++i) {
92 const uint32_t port_id = port_disp[i];
93 struct port_stats_sample *last = stats_get_port_stats_sample(port_id, 1);
94 struct port_stats_sample *prev = stats_get_port_stats_sample(port_id, 0);
96 uint64_t delta_t = last->tsc - prev->tsc;
97 if (delta_t == 0) // This could happen if we just reset the screen => stats will be updated later
100 if (state->toggle == 0) {
103 for (int j = 0; j < PKT_SIZE_COUNT; ++j) {
104 if (last->tx_pkt_size[j] == (uint64_t)-1) {
105 display_column_print(stats_col[j], i, " --- ");
107 diff = last->tx_pkt_size[j] - prev->tx_pkt_size[j];
108 display_column_print(stats_col[j], i, "%13lu", val_to_rate(diff, delta_t));
112 for (int j = 0; j < PKT_SIZE_COUNT; ++j) {
113 if (last->tx_pkt_size[j] == (uint64_t)-1) {
114 display_column_print(stats_col[j], i, " --- ");
116 display_column_print(stats_col[j], i, "%13lu", last->tx_pkt_size[j]);
123 static int display_pkt_len_get_height(void)
125 return stats_get_n_ports();
128 static struct display_screen display_screen_pkt_len = {
129 .draw_frame = display_pkt_len_draw_frame,
130 .draw_stats = display_pkt_len_draw_stats,
131 .get_height = display_pkt_len_get_height,
135 struct display_screen *display_pkt_len(void)
137 return &display_screen_pkt_len;