2 // Copyright (c) 2019 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 "handle_lat.h"
19 #include "display_latency_distr.h"
20 #include "stats_latency.h"
24 static struct display_page display_page_latency_distr;
25 static struct display_column *stats_latency_distr[LAT_BUCKET_COUNT];
26 static struct display_column *stats_max;
27 static struct display_column *core_col;
28 static struct display_column *name_col;
29 static uint32_t global_min_bucket_id = 0, global_max_bucket_id = LAT_BUCKET_COUNT - 1;
30 static const uint16_t global_nb_buckets_displayed = 15;
31 static uint32_t group_size = 9; //LAT_BUCKET_COUNT / global_nb_buckets_displayed;
33 #define UNIT_INT(i) (((i) * bucket_unit_nsec)/1000)
34 #define UNIT_FRACT(i) ((((i) * bucket_unit_nsec) % 1000) / 100)
36 static void display_latency_distr_draw_frame(struct screen_state *state)
38 uint32_t n_tasks = stats_get_n_latency();
39 struct lcore_cfg *lconf = NULL;
40 struct task_args *targ;
44 display_page_init(&display_page_latency_distr);
46 struct display_table *core_name = display_page_add_table(&display_page_latency_distr);
48 display_table_init(core_name, "Core/task");
49 core_col = display_table_add_col(core_name);
50 name_col = display_table_add_col(core_name);
51 display_column_init(core_col, "Nb", 4);
52 display_column_init(name_col, "Name", 5);
54 uint32_t bucket_size = stats_get_latency_bucket_size();
55 struct display_table *stats = display_page_add_table(&display_page_latency_distr);
56 uint32_t bucket_unit_nsec = 1000000000 / (rte_get_tsc_hz() >> bucket_size);
57 if (state->toggle == 0) {
58 display_table_init(stats, "Statistics per second");
60 display_table_init(stats, "Total statistics");
63 stats_max = display_table_add_col(stats);
64 snprintf(title, sizeof(title), " MAXIMUM(mic)");
65 display_column_init(stats_max, title, 11);
66 plog_info("Bucket unit is %d nsec, bucket size is %d, freq is %ld\n", bucket_unit_nsec, bucket_size, rte_get_tsc_hz());
68 uint32_t i = global_min_bucket_id, first = i, k = 0;
69 while ((i < LAT_BUCKET_COUNT) && (i <= global_max_bucket_id)) {
70 stats_latency_distr[k] = display_table_add_col(stats);
71 if (i < LAT_BUCKET_COUNT - group_size) {
72 snprintf(title, sizeof(title), "%d.%01d-%d.%01d", UNIT_INT(i), UNIT_FRACT(i), UNIT_INT(i + group_size), UNIT_FRACT(i + group_size));
74 snprintf(title, sizeof(title), "> %d.%01d", UNIT_INT(i), UNIT_FRACT(i));
76 display_column_init(stats_latency_distr[k++], title, 9);
79 display_page_draw_frame(&display_page_latency_distr, n_tasks);
83 while (core_targ_next(&lconf, &targ, 0) == 0) {
84 if (strcmp(targ->task_init->mode_str, "lat") == 0) {
85 display_column_print_core_task(core_col, count, lconf, targ);
87 display_column_print(name_col, count, "%s", lconf->name);
93 static void display_latency_distr_draw_stats(struct screen_state *state)
95 const uint32_t n_latency = stats_get_n_latency();
97 uint32_t bucket_id = 0, min_bucket_id = LAT_BUCKET_COUNT - 1, max_bucket_id = 0;
100 for (uint32_t count = 0; count < n_latency; ++count) {
101 if (state->toggle == 0)
102 tu = stats_latency_get(count)->max.time;
104 tu = stats_latency_tot_get(count)->max.time;
105 display_column_print(stats_max, count, "%9lu.%03lu", tu.sec * 1000000 + tu.nsec / 1000, tu.nsec % 1000);
108 // Calculate min_bucket_id: id of 1st bucket with data for any tasks
109 // Calculate max_bucket_id: id of last bucket with data for any tasks
110 for (uint i = 0; i < LAT_BUCKET_COUNT; ++i) {
111 for (uint32_t count = 0; count < n_latency; ++count) {
112 if (state->toggle == 0)
113 bucket = stats_latency_get_bucket(count);
115 bucket = stats_latency_get_tot_bucket(count);
116 if (bucket[i] != 0) {
121 if (min_bucket_id != LAT_BUCKET_COUNT - 1)
125 for (uint i = LAT_BUCKET_COUNT; i > 0; i--) {
126 for (uint32_t count = 0; count < n_latency; ++count) {
127 if (state->toggle == 0)
128 bucket = stats_latency_get_bucket(count);
130 bucket = stats_latency_get_tot_bucket(count);
131 if (bucket[i - 1] != 0) {
132 max_bucket_id = i - 1;
140 if (max_bucket_id - min_bucket_id + 1 < global_nb_buckets_displayed) {
141 max_bucket_id = global_nb_buckets_displayed + min_bucket_id - 1;
144 if ((global_min_bucket_id != min_bucket_id) || (global_max_bucket_id != max_bucket_id)) {
145 global_min_bucket_id = min_bucket_id;
146 global_max_bucket_id = max_bucket_id;
147 // Calculate how many buckets must be grouped together
148 if (max_bucket_id - min_bucket_id + 1 > global_nb_buckets_displayed)
149 group_size = ceil(1.0 * (max_bucket_id - min_bucket_id + 1) / global_nb_buckets_displayed);
152 display_latency_distr_draw_frame(state);
154 plog_info("min_bucket_id = %d, max_bucket_id = %d\n", min_bucket_id, max_bucket_id);
157 for (uint32_t count = 0; count < n_latency; ++count) {
158 if (state->toggle == 0)
159 bucket = stats_latency_get_bucket(count);
161 bucket = stats_latency_get_tot_bucket(count);
162 uint32_t i = min_bucket_id, k = 0;
164 while ((i < LAT_BUCKET_COUNT) && (i <= global_max_bucket_id)){
165 for (uint32_t j = 0; j <= group_size; j++)
166 if (i + j < LAT_BUCKET_COUNT)
168 display_column_print(stats_latency_distr[k++], count, "%9lu", nb);
175 static int display_latency_distr_get_height(void)
177 return stats_get_n_latency();
180 static struct display_screen display_screen_latency_distr = {
181 .draw_frame = display_latency_distr_draw_frame,
182 .draw_stats = display_latency_distr_draw_stats,
183 .get_height = display_latency_distr_get_height,
184 .title = "latency_distr",
187 struct display_screen *display_latency_distr(void)
189 return &display_screen_latency_distr;