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 "display_priority.h"
18 #include "stats_prio_task.h"
22 #define PRIORITY_COUNT 8
24 static struct display_page display_page_priority;
25 static struct display_column *stats_tx[PRIORITY_COUNT];
26 static struct display_column *stats_drop[PRIORITY_COUNT];
27 static struct display_column *core_col;
28 static struct display_column *name_col;
30 static void display_priority_draw_frame(struct screen_state *state)
32 uint32_t n_tasks = stats_get_n_prio_tasks_tot();
33 struct lcore_cfg *lconf = NULL;
34 struct task_args *targ;
38 display_page_init(&display_page_priority);
40 struct display_table *core_name = display_page_add_table(&display_page_priority);
42 display_table_init(core_name, "Core/task");
43 core_col = display_table_add_col(core_name);
44 name_col = display_table_add_col(core_name);
45 display_column_init(core_col, "Nb", 4);
46 display_column_init(name_col, "Name", 5);
48 struct display_table *stats = display_page_add_table(&display_page_priority);
49 if (state->toggle == 0) {
50 display_table_init(stats, "Statistics per second");
53 for (int i = 0; i < PRIORITY_COUNT; ++i) {
54 stats_tx[i] = display_table_add_col(stats);
55 snprintf(title, sizeof(title), "TX %d (K)", i);
56 display_column_init(stats_tx[i], title, 9);
58 stats_drop[i] = display_table_add_col(stats);
59 snprintf(title, sizeof(title), "DRP %d (K)", i);
60 display_column_init(stats_drop[i], title, 9);
63 display_table_init(stats, "Total statistics");
66 for (int i = 0; i < PRIORITY_COUNT; ++i) {
67 stats_tx[i] = display_table_add_col(stats);
68 snprintf(title, sizeof(title), "TX %d (#)", i);
69 display_column_init(stats_tx[i], title, 9);
71 stats_drop[i] = display_table_add_col(stats);
72 snprintf(title, sizeof(title), "DRP %d (#)", i);
73 display_column_init(stats_drop[i], title, 9);
77 display_page_draw_frame(&display_page_priority, n_tasks);
81 while (core_targ_next(&lconf, &targ, 0) == 0) {
82 if (strcmp(targ->task_init->mode_str, "aggreg") == 0) {
83 display_column_print_core_task(core_col, count, lconf, targ);
85 display_column_print(name_col, count, "%s", lconf->name);
91 static void display_priority_draw_stats(struct screen_state *state)
94 uint64_t drop_tx_fail_prio;
95 struct lcore_cfg *lconf = NULL;
96 struct task_args *targ;
97 const uint32_t n_stats_prio = stats_get_n_prio_tasks_tot();
99 if (state->toggle == 0) {
100 for (uint32_t count = 0; count < n_stats_prio; ++count) {
101 struct prio_task_stats_sample *last = stats_get_prio_task_stats_sample(count, 1);
102 struct prio_task_stats_sample *prev = stats_get_prio_task_stats_sample(count, 0);
104 uint64_t delta_t = (last->tsc - prev->tsc) * 1000;
105 if (delta_t == 0) // This could happen if we just reset the screen => stats will be updated later
108 for (uint8_t i = 0; i < PRIORITY_COUNT; i++) {
109 rx_prio = last->rx_prio[i] - prev->rx_prio[i];
110 drop_tx_fail_prio = last->drop_tx_fail_prio[i] - prev->drop_tx_fail_prio[i];
112 display_column_print(stats_tx[i], count, "%9lu", val_to_rate(rx_prio, delta_t));
113 display_column_print(stats_drop[i], count, "%9lu", val_to_rate(drop_tx_fail_prio, delta_t));
117 for (uint32_t count = 0; count < n_stats_prio; ++count) {
118 for (uint8_t i = 0; i < PRIORITY_COUNT; i++) {
119 rx_prio = stats_core_task_tot_rx_prio(count, i);
120 drop_tx_fail_prio = stats_core_task_tot_drop_tx_fail_prio(count, i);
122 display_column_print(stats_tx[i], count, "%9lu", rx_prio);
123 display_column_print(stats_drop[i], count, "%9lu", drop_tx_fail_prio);
129 static int display_priority_get_height(void)
131 return stats_get_n_prio_tasks_tot();
134 static struct display_screen display_screen_priority = {
135 .draw_frame = display_priority_draw_frame,
136 .draw_stats = display_priority_draw_stats,
137 .get_height = display_priority_get_height,
141 struct display_screen *display_priority(void)
143 return &display_screen_priority;