Merge "Fix latency accuracy and dumping latencies to file"
[samplevnf.git] / VNFs / DPPD-PROX / display_latency.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.h"
18 #include "display_latency.h"
19 #include "stats_latency.h"
20 #include "lconf.h"
21
22 static struct display_column *min_col;
23 static struct display_column *max_col;
24 static struct display_column *avg_col;
25 static struct display_column *stddev_col;
26 static struct display_column *accuracy_limit_col;
27 static struct display_column *used_col;
28 static struct display_column *lost_col;
29 static struct display_page display_page_latency;
30
31 static void display_latency_draw_frame(struct screen_state *screen_state)
32 {
33         const uint32_t n_latency = stats_get_n_latency();
34         struct display_column *core_col;
35         struct display_column *port_col;
36
37         display_page_init(&display_page_latency);
38
39         struct display_table *core = display_page_add_table(&display_page_latency);
40         struct display_table *port = display_page_add_table(&display_page_latency);
41         struct display_table *lat = display_page_add_table(&display_page_latency);
42         struct display_table *acc = display_page_add_table(&display_page_latency);
43         struct display_table *other = display_page_add_table(&display_page_latency);
44
45         display_table_init(core, "Core");
46         core_col = display_table_add_col(core);
47         display_column_init(core_col, "Nb", 4);
48
49         display_table_init(port, "Port Nb");
50         port_col = display_table_add_col(port);
51         display_column_init(port_col, "RX", 8);
52
53         if (screen_state->toggle == 0)
54                 display_table_init(lat, "Measured Latency per interval");
55         else
56                 display_table_init(lat, "Measured Latency since reset");
57
58         min_col = display_table_add_col(lat);
59         display_column_init(min_col, "Min (us)", 20);
60         max_col = display_table_add_col(lat);
61         display_column_init(max_col, "Max (us)", 20);
62         avg_col = display_table_add_col(lat);
63         display_column_init(avg_col, "Avg (us)", 20);
64         stddev_col = display_table_add_col(lat);
65         display_column_init(stddev_col, "Stddev (us)", 20);
66
67         display_table_init(acc, "Accuracy ");
68         used_col = display_table_add_col(acc);
69         display_column_init(used_col, "Used Packets (%)", 16);
70         accuracy_limit_col = display_table_add_col(acc);
71         display_column_init(accuracy_limit_col, "limit (us)", 16);
72
73         display_table_init(other, "Other");
74
75         lost_col = display_table_add_col(other);
76         display_column_init(lost_col, "Lost Packets", 16);
77
78         display_page_draw_frame(&display_page_latency, n_latency);
79
80         for (uint16_t i = 0; i < n_latency; ++i) {
81                 uint32_t lcore_id = stats_latency_get_core_id(i);
82                 uint32_t task_id = stats_latency_get_task_id(i);
83                 struct task_args *targ = &lcore_cfg[lcore_id].targs[task_id];
84
85                 display_column_print(core_col, i, "%2u/%1u", lcore_id, task_id);
86                 display_column_port_ring(port_col, i, targ->rx_port_queue, targ->nb_rxports, targ->rx_rings, targ->nb_rxrings);
87         }
88 }
89
90 #define AFTER_POINT 1000000
91
92 static void display_stats_latency_entry(int row, struct stats_latency *stats_latency)
93 {
94         struct time_unit_err avg = stats_latency->avg;
95         struct time_unit_err min = stats_latency->min;
96         struct time_unit_err max = stats_latency->max;
97         struct time_unit_err stddev = stats_latency->stddev;
98         struct time_unit accuracy_limit = stats_latency->accuracy_limit;
99
100         uint32_t used = 0;
101
102         if (stats_latency->tot_all_packets)
103                 used = stats_latency->tot_packets * (100 * AFTER_POINT) / stats_latency->tot_all_packets;
104
105         char dst[32];
106
107         if (stats_latency->tot_packets) {
108                 display_column_print(min_col, row, "%s", print_time_unit_err_usec(dst, &min));
109                 display_column_print(max_col, row, "%s", print_time_unit_err_usec(dst, &max));
110                 display_column_print(avg_col, row, "%s", print_time_unit_err_usec(dst, &avg));
111                 display_column_print(stddev_col, row, "%s", print_time_unit_err_usec(dst, &stddev));
112         } else {
113                 display_column_print(min_col, row, "%s", "N/A");
114                 display_column_print(max_col, row, "%s", "N/A");
115                 display_column_print(avg_col, row, "%s", "N/A");
116                 display_column_print(stddev_col, row, "%s", "N/A");
117         }
118
119         display_column_print(accuracy_limit_col, row, "%s", print_time_unit_usec(dst, &accuracy_limit));
120         display_column_print(lost_col, row, "%16"PRIu64"", stats_latency->lost_packets);
121         display_column_print(used_col, row, "%3u.%06u", used / AFTER_POINT, used % AFTER_POINT);
122 }
123
124 static void display_latency_draw_stats(struct screen_state *screen_state)
125 {
126         const uint32_t n_latency = stats_get_n_latency();
127         struct stats_latency *stats_latency;
128
129         for (uint16_t i = 0; i < n_latency; ++i) {
130                 if (screen_state->toggle == 0)
131                         stats_latency = stats_latency_get(i);
132                 else
133                         stats_latency = stats_latency_tot_get(i);
134
135                 display_stats_latency_entry(i, stats_latency);
136         }
137 }
138
139 static int display_latency_get_height(void)
140 {
141         return stats_get_n_latency();
142 }
143
144 static struct display_screen display_screen_latency = {
145         .draw_frame = display_latency_draw_frame,
146         .draw_stats = display_latency_draw_stats,
147         .get_height = display_latency_get_height,
148         .title = "latency",
149 };
150
151 struct display_screen *display_latency(void)
152 {
153         return &display_screen_latency;
154 }