summaryrefslogtreecommitdiffstats
path: root/VNFs/DPPD-PROX/display_priority.c
blob: c997d85d1025014af8302227f3bd04d3e8335f9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107

@media only all and (prefers-color-scheme: dark) {
.highlight .hll { background-color: #49483e }
.highlight .c { color: #75715e } /* Comment */
.highlight .err { color: #960050; background-color: #1e0010 } /* Error */
.highlight .k { color: #66d9ef } /* Keyword */
.highlight .l { color: #ae81ff } /* Literal */
.highlight .n { color: #f8f8f2 } /* Name */
.highlight .o { color: #f92672 } /* Operator */
.highlight .p { color: #f8f8f2 } /* Punctuation */
.highlight .ch { color: #75715e } /* Comment.Hashbang */
.highlight .cm { color: #75715e } /* Comment.Multiline */
.highlight .cp { color: #75715e } /* Comment.Preproc */
.highlight .cpf { color: #75715e } /* Comment.PreprocFile */
.highlight .c1 { color: #75715e } /* Comment.Single */
.highlight .cs { color: #75715e } /* Comment.Special */
.highlight .gd { color: #f92672 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gi { color: #a6e22e } /* Generic.Inserted */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #75715e } /* Generic.Subheading */
.highlight .kc { color: #66d9ef } /* Keyword.Constant */
.highlight .kd { color: #66d9ef } /* Keyword.Declaration */
.highlight .kn { color: #f92672 } /* Keyword.Namespace */
.highlight .kp
/*
// Copyright (c) 2010-2017 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
*/

#include "display_priority.h"
#include "stats_prio_task.h"
#include "display.h"
#include "lconf.h"

#define PRIORITY_COUNT 8

static struct display_page display_page_priority;
static struct display_column *stats_tx[PRIORITY_COUNT];
static struct display_column *stats_drop[PRIORITY_COUNT];
static struct display_column *core_col;
static struct display_column *name_col;

static void display_priority_draw_frame(struct screen_state *state)
{
  	uint32_t n_tasks = stats_get_n_prio_tasks_tot();
	struct lcore_cfg *lconf = NULL;
	struct task_args *targ;
	char name[32];
	char *ptr;

	display_page_init(&display_page_priority);

	struct display_table *core_name = display_page_add_table(&display_page_priority);

	display_table_init(core_name, "Core/task");
	core_col = display_table_add_col(core_name);
	name_col = display_table_add_col(core_name);
	display_column_init(core_col, "Nb", 4);
	display_column_init(name_col, "Name", 5);

	struct display_table *stats = display_page_add_table(&display_page_priority);
	if (state->toggle == 0) {
		display_table_init(stats, "Statistics per second");

		char title[64];
		for (int i = 0; i < PRIORITY_COUNT; ++i) {
			stats_tx[i] = display_table_add_col(stats);
			snprintf(title, sizeof(title), "TX %d (K)", i);
			display_column_init(stats_tx[i], title, 9);

			stats_drop[i] = display_table_add_col(stats);
			snprintf(title, sizeof(title), "DRP %d (K)", i);
			display_column_init(stats_drop[i], title, 9);
		}
	} else {
		display_table_init(stats, "Total statistics");

		char title[64];
		for (int i = 0; i < PRIORITY_COUNT; ++i) {
			stats_tx[i] = display_table_add_col(stats);
			snprintf(title, sizeof(title), "TX %d (#)", i);
			display_column_init(stats_tx[i], title, 9);

			stats_drop[i] = display_table_add_col(stats);
			snprintf(title, sizeof(title), "DRP %d (#)", i);
			display_column_init(stats_drop[i], title, 9);
		}
	}

	display_page_draw_frame(&display_page_priority, n_tasks);

	uint32_t count = 0;
	lconf = NULL;
	while (core_targ_next(&lconf, &targ, 0) == 0) {
		if (strcmp(targ->task_init->mode_str, "aggreg") == 0) {
			display_column_print_core_task(core_col, count, lconf, targ);
			if (targ->id == 0)
				display_column_print(name_col, count, "%s", lconf->name);
			count++;
		}
	}
}

static void display_priority_draw_stats(struct screen_state *state)
{
	uint64_t rx_prio;
	uint64_t drop_tx_fail_prio;
	struct lcore_cfg *lconf = NULL;
	struct task_args *targ;
	const uint32_t n_stats_prio = stats_get_n_prio_tasks_tot();

	if (state->toggle == 0) {
		for (uint32_t count = 0; count < n_stats_prio; ++count) {
			struct prio_task_stats_sample *last = stats_get_prio_task_stats_sample(count, 1);
			struct prio_task_stats_sample *prev = stats_get_prio_task_stats_sample(count, 0);

			uint64_t delta_t = (last->tsc - prev->tsc) * 1000;
			if (delta_t == 0) // This could happen if we just reset the screen => stats will be updated later
				continue;

			for (uint8_t i = 0; i < PRIORITY_COUNT; i++) {
				rx_prio = last->rx_prio[i] - prev->rx_prio[i];
				drop_tx_fail_prio = last->drop_tx_fail_prio[i] - prev->drop_tx_fail_prio[i];

				display_column_print(stats_tx[i], count, "%9lu", val_to_rate(rx_prio, delta_t));
				display_column_print(stats_drop[i], count, "%9lu", val_to_rate(drop_tx_fail_prio, delta_t));
			}
		}
	} else {
		for (uint32_t count = 0; count < n_stats_prio; ++count) {
			for (uint8_t i = 0; i < PRIORITY_COUNT; i++) {
				rx_prio = stats_core_task_tot_rx_prio(count, i);
				drop_tx_fail_prio = stats_core_task_tot_drop_tx_fail_prio(count, i);

				display_column_print(stats_tx[i], count, "%9lu", rx_prio);
				display_column_print(stats_drop[i], count, "%9lu", drop_tx_fail_prio);
			}
		}
	}
}

static int display_priority_get_height(void)
{
	return stats_get_n_prio_tasks_tot();
}

static struct display_screen display_screen_priority = {
	.draw_frame = display_priority_draw_frame,
	.draw_stats = display_priority_draw_stats,
	.get_height = display_priority_get_height,
	.title = "priority",
};

struct display_screen *display_priority(void)
{
	return &display_screen_priority;
}