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.
18 #include "display_l4gen.h"
19 #include "stats_l4gen.h"
21 static struct display_page display_page_l4gen;
23 static struct display_column *core_col;
24 static struct display_column *tcp_setup_col;
25 static struct display_column *udp_setup_col;
26 static struct display_column *all_setup_col;
27 static struct display_column *bundles_setup_col;
28 static struct display_column *tcp_teardown_col;
29 static struct display_column *tcp_teardown_retx_col;
30 static struct display_column *udp_teardown_col;
31 static struct display_column *tcp_expire_col;
32 static struct display_column *udp_expire_col;
33 static struct display_column *active_col;
34 static struct display_column *retx_col;
36 static void display_l4gen_draw_frame(struct screen_state *state)
38 const uint32_t n_l4gen = stats_get_n_l4gen();
40 display_page_init(&display_page_l4gen);
42 struct display_table *core = display_page_add_table(&display_page_l4gen);
43 struct display_table *setup_rate = display_page_add_table(&display_page_l4gen);
44 struct display_table *teardown_rate = display_page_add_table(&display_page_l4gen);
45 struct display_table *expire_rate = display_page_add_table(&display_page_l4gen);
46 struct display_table *other = display_page_add_table(&display_page_l4gen);
48 display_table_init(core, "Core");
49 display_table_init(setup_rate, "Setup rate (flows/s)");
50 display_table_init(teardown_rate, "Teardown rate (flows/s)");
51 display_table_init(expire_rate, "Expire rate (flows/s)");
52 display_table_init(other, "Other");
54 core_col = display_table_add_col(core);
55 display_column_init(core_col, "Nb", 4);
57 tcp_setup_col = display_table_add_col(setup_rate);
58 display_column_init(tcp_setup_col, "TCP", 10);
59 udp_setup_col = display_table_add_col(setup_rate);
60 display_column_init(udp_setup_col, "UDP", 10);
61 all_setup_col = display_table_add_col(setup_rate);
62 display_column_init(all_setup_col, "TCP + UDP", 9);
63 bundles_setup_col = display_table_add_col(setup_rate);
64 display_column_init(bundles_setup_col, "Bundles", 9);
66 tcp_teardown_col = display_table_add_col(teardown_rate);
67 display_column_init(tcp_teardown_col, "TCP w/o reTX", 12);
68 tcp_teardown_retx_col = display_table_add_col(teardown_rate);
69 display_column_init(tcp_teardown_retx_col, "TCP w/ reTX", 12);
70 udp_teardown_col = display_table_add_col(teardown_rate);
71 display_column_init(udp_teardown_col, "UDP", 12);
73 tcp_expire_col = display_table_add_col(expire_rate);
74 display_column_init(tcp_expire_col, "TCP", 10);
75 udp_expire_col = display_table_add_col(expire_rate);
76 display_column_init(udp_expire_col, "TCP", 10);
78 active_col = display_table_add_col(other);
79 display_column_init(active_col, "Active (#)", 10);
80 retx_col = display_table_add_col(other);
81 display_column_init(retx_col, "reTX (/s)", 10);
83 display_page_draw_frame(&display_page_l4gen, n_l4gen);
85 for (uint16_t i = 0; i < n_l4gen; ++i) {
86 struct task_l4_stats *tls = stats_get_l4_stats(i);
88 display_column_print(core_col, i, "%2u/%1u", tls->lcore_id, tls->task_id);
92 static void display_l4gen_draw_stats_line(int row, struct l4_stats_sample *clast, struct l4_stats_sample *cprev)
94 struct l4_stats *last = &clast->stats;
95 struct l4_stats *prev = &cprev->stats;
97 uint64_t delta_t = clast->tsc - cprev->tsc;
99 uint64_t tcp_created = last->tcp_created - prev->tcp_created;
100 uint64_t udp_created = last->udp_created - prev->udp_created;
102 uint64_t tcp_finished_no_retransmit = last->tcp_finished_no_retransmit - prev->tcp_finished_no_retransmit;
103 uint64_t tcp_finished_retransmit = last->tcp_finished_retransmit - prev->tcp_finished_retransmit;
104 uint64_t tcp_expired = last->tcp_expired - prev->tcp_expired;
105 uint64_t tcp_retransmits = last->tcp_retransmits - prev->tcp_retransmits;
106 uint64_t udp_finished = last->udp_finished - prev->udp_finished;
107 uint64_t udp_expired = last->udp_expired - prev->udp_expired;
108 uint64_t bundles_created = last->bundles_created - prev->bundles_created;
110 uint64_t tcp_setup_rate = val_to_rate(tcp_created, delta_t);
111 uint64_t udp_setup_rate = val_to_rate(udp_created, delta_t);
112 uint64_t all_setup_rate = val_to_rate(tcp_created + udp_created, delta_t);
113 uint64_t bundle_setup_rate = val_to_rate(bundles_created, delta_t);
115 uint64_t tcp_teardown_rate = val_to_rate(tcp_finished_no_retransmit, delta_t);
116 uint64_t tcp_teardown_retx_rate = val_to_rate(tcp_finished_retransmit, delta_t);
117 uint64_t udp_teardown_rate = val_to_rate(udp_finished, delta_t);
119 uint64_t tcp_expire_rate = val_to_rate(tcp_expired, delta_t);
120 uint64_t udp_expire_rate = val_to_rate(udp_expired, delta_t);
122 display_column_print(tcp_setup_col, row, "%"PRIu64"", tcp_setup_rate);
123 display_column_print(udp_setup_col, row, "%"PRIu64"", udp_setup_rate);
124 display_column_print(all_setup_col, row, "%"PRIu64"", all_setup_rate);
125 display_column_print(bundles_setup_col, row, "%"PRIu64"", bundle_setup_rate);
127 display_column_print(tcp_teardown_col, row, "%"PRIu64"", tcp_teardown_rate);
128 display_column_print(tcp_teardown_retx_col, row, "%"PRIu64"", tcp_teardown_retx_rate);
129 display_column_print(udp_teardown_col, row, "%"PRIu64"", udp_teardown_rate);
131 display_column_print(tcp_expire_col, row, "%"PRIu64"", tcp_expire_rate);
132 display_column_print(udp_expire_col, row, "%"PRIu64"", udp_expire_rate);
134 uint64_t tot_created = last->tcp_created + last->udp_created;
135 uint64_t tot_finished = last->tcp_finished_retransmit + last->tcp_finished_no_retransmit +
136 last->udp_finished + last->udp_expired + last->tcp_expired;
138 uint64_t active = tot_created - tot_finished;
139 uint64_t retx = tcp_retransmits;
141 display_column_print(active_col, row, "%10"PRIu64"", active);
142 display_column_print(retx_col, row, "%10"PRIu64"", retx);
145 static void display_l4gen_draw_stats(struct screen_state *state)
147 const uint32_t n_l4gen = stats_get_n_l4gen();
149 for (uint16_t i = 0; i < n_l4gen; ++i) {
150 struct l4_stats_sample *clast = stats_get_l4_stats_sample(i, 1);
151 struct l4_stats_sample *cprev = stats_get_l4_stats_sample(i, 0);
153 display_l4gen_draw_stats_line(i, clast, cprev);
157 static int display_l4gen_get_height(void)
159 return stats_get_n_l4gen();
162 static struct display_screen display_screen_l4gen = {
163 .draw_frame = display_l4gen_draw_frame,
164 .draw_stats = display_l4gen_draw_stats,
165 .get_height = display_l4gen_get_height,
169 struct display_screen *display_l4gen(void)
171 return &display_screen_l4gen;