| 1 | /*
|
|---|
| 2 | * Copyright (c) 2010 Stanislav Kozina
|
|---|
| 3 | * Copyright (c) 2010 Martin Decky
|
|---|
| 4 | * All rights reserved.
|
|---|
| 5 | *
|
|---|
| 6 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 7 | * modification, are permitted provided that the following conditions
|
|---|
| 8 | * are met:
|
|---|
| 9 | *
|
|---|
| 10 | * - Redistributions of source code must retain the above copyright
|
|---|
| 11 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 12 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 13 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 14 | * documentation and/or other materials provided with the distribution.
|
|---|
| 15 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 16 | * derived from this software without specific prior written permission.
|
|---|
| 17 | *
|
|---|
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 28 | */
|
|---|
| 29 |
|
|---|
| 30 | /** @addtogroup top
|
|---|
| 31 | * @brief Top utility.
|
|---|
| 32 | * @{
|
|---|
| 33 | */
|
|---|
| 34 | /**
|
|---|
| 35 | * @file
|
|---|
| 36 | */
|
|---|
| 37 |
|
|---|
| 38 | #include <stdio.h>
|
|---|
| 39 | #include <stdlib.h>
|
|---|
| 40 | #include <io/console.h>
|
|---|
| 41 | #include <io/style.h>
|
|---|
| 42 | #include <vfs/vfs.h>
|
|---|
| 43 | #include <stdarg.h>
|
|---|
| 44 | #include <stats.h>
|
|---|
| 45 | #include <inttypes.h>
|
|---|
| 46 | #include <macros.h>
|
|---|
| 47 | #include <str.h>
|
|---|
| 48 | #include "screen.h"
|
|---|
| 49 | #include "top.h"
|
|---|
| 50 |
|
|---|
| 51 | static usec_t timeleft = 0;
|
|---|
| 52 |
|
|---|
| 53 | console_ctrl_t *console;
|
|---|
| 54 |
|
|---|
| 55 | static sysarg_t warning_col = 0;
|
|---|
| 56 | static sysarg_t warning_row = 0;
|
|---|
| 57 | static usec_t warning_timeleft = 0;
|
|---|
| 58 | static char *warning_text = NULL;
|
|---|
| 59 |
|
|---|
| 60 | static void screen_style_normal(void)
|
|---|
| 61 | {
|
|---|
| 62 | console_flush(console);
|
|---|
| 63 | console_set_style(console, STYLE_NORMAL);
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 | static void screen_style_inverted(void)
|
|---|
| 67 | {
|
|---|
| 68 | console_flush(console);
|
|---|
| 69 | console_set_style(console, STYLE_INVERTED);
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | static void screen_style_emphasis(void)
|
|---|
| 73 | {
|
|---|
| 74 | console_flush(console);
|
|---|
| 75 | console_set_style(console, STYLE_EMPHASIS);
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | static void screen_moveto(sysarg_t col, sysarg_t row)
|
|---|
| 79 | {
|
|---|
| 80 | console_flush(console);
|
|---|
| 81 | console_set_pos(console, col, row);
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 | static void screen_get_pos(sysarg_t *col, sysarg_t *row)
|
|---|
| 85 | {
|
|---|
| 86 | console_flush(console);
|
|---|
| 87 | console_get_pos(console, col, row);
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | static void screen_get_size(sysarg_t *col, sysarg_t *row)
|
|---|
| 91 | {
|
|---|
| 92 | console_flush(console);
|
|---|
| 93 | console_get_size(console, col, row);
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | static void screen_restart(bool clear)
|
|---|
| 97 | {
|
|---|
| 98 | screen_style_normal();
|
|---|
| 99 |
|
|---|
| 100 | if (clear) {
|
|---|
| 101 | console_flush(console);
|
|---|
| 102 | console_clear(console);
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | screen_moveto(0, 0);
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | static void screen_newline(void)
|
|---|
| 109 | {
|
|---|
| 110 | sysarg_t cols;
|
|---|
| 111 | sysarg_t rows;
|
|---|
| 112 | screen_get_size(&cols, &rows);
|
|---|
| 113 |
|
|---|
| 114 | sysarg_t c;
|
|---|
| 115 | sysarg_t r;
|
|---|
| 116 | screen_get_pos(&c, &r);
|
|---|
| 117 |
|
|---|
| 118 | sysarg_t i;
|
|---|
| 119 | for (i = c + 1; i < cols; i++)
|
|---|
| 120 | fputs(" ", stdout);
|
|---|
| 121 |
|
|---|
| 122 | if (r + 1 < rows)
|
|---|
| 123 | puts("");
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | void screen_init(void)
|
|---|
| 127 | {
|
|---|
| 128 | console = console_init(stdin, stdout);
|
|---|
| 129 |
|
|---|
| 130 | console_flush(console);
|
|---|
| 131 | console_cursor_visibility(console, false);
|
|---|
| 132 |
|
|---|
| 133 | screen_restart(true);
|
|---|
| 134 | }
|
|---|
| 135 |
|
|---|
| 136 | void screen_done(void)
|
|---|
| 137 | {
|
|---|
| 138 | free(warning_text);
|
|---|
| 139 | warning_text = NULL;
|
|---|
| 140 |
|
|---|
| 141 | screen_restart(true);
|
|---|
| 142 |
|
|---|
| 143 | console_flush(console);
|
|---|
| 144 | console_cursor_visibility(console, true);
|
|---|
| 145 | }
|
|---|
| 146 |
|
|---|
| 147 | static void print_percent(fixed_float ffloat, unsigned int precision)
|
|---|
| 148 | {
|
|---|
| 149 | printf("%3" PRIu64 ".", ffloat.upper / ffloat.lower);
|
|---|
| 150 |
|
|---|
| 151 | unsigned int i;
|
|---|
| 152 | uint64_t rest = (ffloat.upper % ffloat.lower) * 10;
|
|---|
| 153 | for (i = 0; i < precision; i++) {
|
|---|
| 154 | printf("%" PRIu64, rest / ffloat.lower);
|
|---|
| 155 | rest = (rest % ffloat.lower) * 10;
|
|---|
| 156 | }
|
|---|
| 157 |
|
|---|
| 158 | printf("%%");
|
|---|
| 159 | }
|
|---|
| 160 |
|
|---|
| 161 | static void print_string(const char *str)
|
|---|
| 162 | {
|
|---|
| 163 | sysarg_t cols;
|
|---|
| 164 | sysarg_t rows;
|
|---|
| 165 | screen_get_size(&cols, &rows);
|
|---|
| 166 |
|
|---|
| 167 | sysarg_t c;
|
|---|
| 168 | sysarg_t r;
|
|---|
| 169 | screen_get_pos(&c, &r);
|
|---|
| 170 |
|
|---|
| 171 | if (c < cols) {
|
|---|
| 172 | int pos = cols - c - 1;
|
|---|
| 173 | printf("%.*s", pos, str);
|
|---|
| 174 | }
|
|---|
| 175 | }
|
|---|
| 176 |
|
|---|
| 177 | static inline void print_global_head(data_t *data)
|
|---|
| 178 | {
|
|---|
| 179 | printf("top - %02lld:%02lld:%02lld up "
|
|---|
| 180 | "%" PRIun " days, %02" PRIun ":%02" PRIun ":%02" PRIun ", "
|
|---|
| 181 | "load average:",
|
|---|
| 182 | data->hours, data->minutes, data->seconds,
|
|---|
| 183 | data->udays, data->uhours, data->uminutes, data->useconds);
|
|---|
| 184 |
|
|---|
| 185 | size_t i;
|
|---|
| 186 | for (i = 0; i < data->load_count; i++) {
|
|---|
| 187 | fputs(" ", stdout);
|
|---|
| 188 | stats_print_load_fragment(data->load[i], 2);
|
|---|
| 189 | }
|
|---|
| 190 |
|
|---|
| 191 | screen_newline();
|
|---|
| 192 | }
|
|---|
| 193 |
|
|---|
| 194 | static inline void print_task_summary(data_t *data)
|
|---|
| 195 | {
|
|---|
| 196 | printf("tasks: %zu total", data->tasks_count);
|
|---|
| 197 | screen_newline();
|
|---|
| 198 | }
|
|---|
| 199 |
|
|---|
| 200 | static inline void print_thread_summary(data_t *data)
|
|---|
| 201 | {
|
|---|
| 202 | size_t total = 0;
|
|---|
| 203 | size_t running = 0;
|
|---|
| 204 | size_t ready = 0;
|
|---|
| 205 | size_t sleeping = 0;
|
|---|
| 206 | size_t lingering = 0;
|
|---|
| 207 | size_t other = 0;
|
|---|
| 208 | size_t invalid = 0;
|
|---|
| 209 |
|
|---|
| 210 | size_t i;
|
|---|
| 211 | for (i = 0; i < data->threads_count; i++) {
|
|---|
| 212 | total++;
|
|---|
| 213 |
|
|---|
| 214 | switch (data->threads[i].state) {
|
|---|
| 215 | case Running:
|
|---|
| 216 | running++;
|
|---|
| 217 | break;
|
|---|
| 218 | case Ready:
|
|---|
| 219 | ready++;
|
|---|
| 220 | break;
|
|---|
| 221 | case Sleeping:
|
|---|
| 222 | sleeping++;
|
|---|
| 223 | break;
|
|---|
| 224 | case Lingering:
|
|---|
| 225 | lingering++;
|
|---|
| 226 | break;
|
|---|
| 227 | case Entering:
|
|---|
| 228 | case Exiting:
|
|---|
| 229 | other++;
|
|---|
| 230 | break;
|
|---|
| 231 | default:
|
|---|
| 232 | invalid++;
|
|---|
| 233 | }
|
|---|
| 234 | }
|
|---|
| 235 |
|
|---|
| 236 | printf("threads: %zu total, %zu running, %zu ready, "
|
|---|
| 237 | "%zu sleeping, %zu lingering, %zu other, %zu invalid",
|
|---|
| 238 | total, running, ready, sleeping, lingering, other, invalid);
|
|---|
| 239 | screen_newline();
|
|---|
| 240 | }
|
|---|
| 241 |
|
|---|
| 242 | static inline void print_cpu_info(data_t *data)
|
|---|
| 243 | {
|
|---|
| 244 | size_t i;
|
|---|
| 245 | for (i = 0; i < data->cpus_count; i++) {
|
|---|
| 246 | if (data->cpus[i].active) {
|
|---|
| 247 | uint64_t busy;
|
|---|
| 248 | uint64_t idle;
|
|---|
| 249 | char busy_suffix;
|
|---|
| 250 | char idle_suffix;
|
|---|
| 251 |
|
|---|
| 252 | order_suffix(data->cpus[i].busy_cycles, &busy, &busy_suffix);
|
|---|
| 253 | order_suffix(data->cpus[i].idle_cycles, &idle, &idle_suffix);
|
|---|
| 254 |
|
|---|
| 255 | printf("cpu%u (%4" PRIu16 " MHz): busy cycles: "
|
|---|
| 256 | "%" PRIu64 "%c, idle cycles: %" PRIu64 "%c",
|
|---|
| 257 | data->cpus[i].id, data->cpus[i].frequency_mhz,
|
|---|
| 258 | busy, busy_suffix, idle, idle_suffix);
|
|---|
| 259 | fputs(", idle: ", stdout);
|
|---|
| 260 | print_percent(data->cpus_perc[i].idle, 2);
|
|---|
| 261 | fputs(", busy: ", stdout);
|
|---|
| 262 | print_percent(data->cpus_perc[i].busy, 2);
|
|---|
| 263 | } else
|
|---|
| 264 | printf("cpu%u inactive", data->cpus[i].id);
|
|---|
| 265 |
|
|---|
| 266 | screen_newline();
|
|---|
| 267 | }
|
|---|
| 268 | }
|
|---|
| 269 |
|
|---|
| 270 | static inline void print_physmem_info(data_t *data)
|
|---|
| 271 | {
|
|---|
| 272 | uint64_t total;
|
|---|
| 273 | uint64_t unavail;
|
|---|
| 274 | uint64_t used;
|
|---|
| 275 | uint64_t free;
|
|---|
| 276 | const char *total_suffix;
|
|---|
| 277 | const char *unavail_suffix;
|
|---|
| 278 | const char *used_suffix;
|
|---|
| 279 | const char *free_suffix;
|
|---|
| 280 |
|
|---|
| 281 | bin_order_suffix(data->physmem->total, &total, &total_suffix, false);
|
|---|
| 282 | bin_order_suffix(data->physmem->unavail, &unavail, &unavail_suffix, false);
|
|---|
| 283 | bin_order_suffix(data->physmem->used, &used, &used_suffix, false);
|
|---|
| 284 | bin_order_suffix(data->physmem->free, &free, &free_suffix, false);
|
|---|
| 285 |
|
|---|
| 286 | printf("memory: %" PRIu64 "%s total, %" PRIu64 "%s unavail, %"
|
|---|
| 287 | PRIu64 "%s used, %" PRIu64 "%s free", total, total_suffix,
|
|---|
| 288 | unavail, unavail_suffix, used, used_suffix, free, free_suffix);
|
|---|
| 289 | screen_newline();
|
|---|
| 290 | }
|
|---|
| 291 |
|
|---|
| 292 | static inline void print_help_head(void)
|
|---|
| 293 | {
|
|---|
| 294 | screen_style_inverted();
|
|---|
| 295 | printf("Help");
|
|---|
| 296 | screen_newline();
|
|---|
| 297 | screen_style_normal();
|
|---|
| 298 | }
|
|---|
| 299 |
|
|---|
| 300 | static inline void print_help(void)
|
|---|
| 301 | {
|
|---|
| 302 | sysarg_t cols;
|
|---|
| 303 | sysarg_t rows;
|
|---|
| 304 | screen_get_size(&cols, &rows);
|
|---|
| 305 |
|
|---|
| 306 | screen_newline();
|
|---|
| 307 |
|
|---|
| 308 | printf("Operation modes:");
|
|---|
| 309 | screen_newline();
|
|---|
| 310 |
|
|---|
| 311 | printf(" t .. tasks statistics");
|
|---|
| 312 | screen_newline();
|
|---|
| 313 |
|
|---|
| 314 | printf(" i .. IPC statistics");
|
|---|
| 315 | screen_newline();
|
|---|
| 316 |
|
|---|
| 317 | printf(" e .. exceptions statistics");
|
|---|
| 318 | screen_newline();
|
|---|
| 319 |
|
|---|
| 320 | printf(" a .. toggle display of all/hot exceptions");
|
|---|
| 321 | screen_newline();
|
|---|
| 322 |
|
|---|
| 323 | printf(" h .. toggle this help screen");
|
|---|
| 324 | screen_newline();
|
|---|
| 325 |
|
|---|
| 326 | screen_newline();
|
|---|
| 327 |
|
|---|
| 328 | printf("Other keys:");
|
|---|
| 329 | screen_newline();
|
|---|
| 330 |
|
|---|
| 331 | printf(" s .. choose column to sort by");
|
|---|
| 332 | screen_newline();
|
|---|
| 333 |
|
|---|
| 334 | printf(" r .. toggle reversed sorting");
|
|---|
| 335 | screen_newline();
|
|---|
| 336 |
|
|---|
| 337 | printf(" q .. quit");
|
|---|
| 338 | screen_newline();
|
|---|
| 339 |
|
|---|
| 340 | sysarg_t col;
|
|---|
| 341 | sysarg_t row;
|
|---|
| 342 | screen_get_pos(&col, &row);
|
|---|
| 343 |
|
|---|
| 344 | while (row < rows) {
|
|---|
| 345 | screen_newline();
|
|---|
| 346 | row++;
|
|---|
| 347 | }
|
|---|
| 348 | }
|
|---|
| 349 |
|
|---|
| 350 | static inline void print_table_head(const table_t *table)
|
|---|
| 351 | {
|
|---|
| 352 | sysarg_t cols;
|
|---|
| 353 | sysarg_t rows;
|
|---|
| 354 | screen_get_size(&cols, &rows);
|
|---|
| 355 |
|
|---|
| 356 | screen_style_inverted();
|
|---|
| 357 | for (size_t i = 0; i < table->num_columns; i++) {
|
|---|
| 358 | const char *name = table->columns[i].name;
|
|---|
| 359 | int width = table->columns[i].width;
|
|---|
| 360 | if (i != 0) {
|
|---|
| 361 | fputs(" ", stdout);
|
|---|
| 362 | }
|
|---|
| 363 | if (width == 0) {
|
|---|
| 364 | sysarg_t col;
|
|---|
| 365 | sysarg_t row;
|
|---|
| 366 | screen_get_pos(&col, &row);
|
|---|
| 367 | width = cols - col - 1;
|
|---|
| 368 | }
|
|---|
| 369 | printf("[%-*.*s]", width - 2, width - 2, name);
|
|---|
| 370 | }
|
|---|
| 371 | screen_newline();
|
|---|
| 372 | screen_style_normal();
|
|---|
| 373 | }
|
|---|
| 374 |
|
|---|
| 375 | static inline void print_table(const table_t *table)
|
|---|
| 376 | {
|
|---|
| 377 | sysarg_t cols;
|
|---|
| 378 | sysarg_t rows;
|
|---|
| 379 | screen_get_size(&cols, &rows);
|
|---|
| 380 |
|
|---|
| 381 | sysarg_t col;
|
|---|
| 382 | sysarg_t row;
|
|---|
| 383 | screen_get_pos(&col, &row);
|
|---|
| 384 |
|
|---|
| 385 | size_t i;
|
|---|
| 386 | for (i = 0; (i < table->num_fields) && (row < rows); i++) {
|
|---|
| 387 | size_t column_index = i % table->num_columns;
|
|---|
| 388 | int width = table->columns[column_index].width;
|
|---|
| 389 | field_t *field = &table->fields[i];
|
|---|
| 390 | uint64_t val;
|
|---|
| 391 | const char *psuffix;
|
|---|
| 392 | char suffix;
|
|---|
| 393 |
|
|---|
| 394 | if (column_index != 0) {
|
|---|
| 395 | fputs(" ", stdout);
|
|---|
| 396 | }
|
|---|
| 397 |
|
|---|
| 398 | if (width == 0) {
|
|---|
| 399 | screen_get_pos(&col, &row);
|
|---|
| 400 | width = cols - col - 1;
|
|---|
| 401 | }
|
|---|
| 402 |
|
|---|
| 403 | switch (field->type) {
|
|---|
| 404 | case FIELD_EMPTY:
|
|---|
| 405 | printf("%*s", width, "");
|
|---|
| 406 | break;
|
|---|
| 407 | case FIELD_UINT:
|
|---|
| 408 | printf("%*" PRIu64, width, field->uint);
|
|---|
| 409 | break;
|
|---|
| 410 | case FIELD_UINT_SUFFIX_BIN:
|
|---|
| 411 | val = field->uint;
|
|---|
| 412 | width -= 3;
|
|---|
| 413 | bin_order_suffix(val, &val, &psuffix, true);
|
|---|
| 414 | printf("%*" PRIu64 "%s", width, val, psuffix);
|
|---|
| 415 | break;
|
|---|
| 416 | case FIELD_UINT_SUFFIX_DEC:
|
|---|
| 417 | val = field->uint;
|
|---|
| 418 | width -= 1;
|
|---|
| 419 | order_suffix(val, &val, &suffix);
|
|---|
| 420 | printf("%*" PRIu64 "%c", width, val, suffix);
|
|---|
| 421 | break;
|
|---|
| 422 | case FIELD_PERCENT:
|
|---|
| 423 | width -= 5; /* nnn.% */
|
|---|
| 424 | if (width > 2) {
|
|---|
| 425 | printf("%*s", width - 2, "");
|
|---|
| 426 | width = 2;
|
|---|
| 427 | }
|
|---|
| 428 | print_percent(field->fixed, width);
|
|---|
| 429 | break;
|
|---|
| 430 | case FIELD_STRING:
|
|---|
| 431 | printf("%-*.*s", width, width, field->string);
|
|---|
| 432 | break;
|
|---|
| 433 | }
|
|---|
| 434 |
|
|---|
| 435 | if (column_index == table->num_columns - 1) {
|
|---|
| 436 | screen_newline();
|
|---|
| 437 | row++;
|
|---|
| 438 | }
|
|---|
| 439 | }
|
|---|
| 440 |
|
|---|
| 441 | while (row < rows) {
|
|---|
| 442 | screen_newline();
|
|---|
| 443 | row++;
|
|---|
| 444 | }
|
|---|
| 445 | }
|
|---|
| 446 |
|
|---|
| 447 | static inline void print_sort(table_t *table)
|
|---|
| 448 | {
|
|---|
| 449 | sysarg_t cols;
|
|---|
| 450 | sysarg_t rows;
|
|---|
| 451 | screen_get_size(&cols, &rows);
|
|---|
| 452 |
|
|---|
| 453 | sysarg_t col;
|
|---|
| 454 | sysarg_t row;
|
|---|
| 455 | screen_get_pos(&col, &row);
|
|---|
| 456 |
|
|---|
| 457 | size_t num = min(table->num_columns, rows - row);
|
|---|
| 458 | for (size_t i = 0; i < num; i++) {
|
|---|
| 459 | printf("%c - %s", table->columns[i].key, table->columns[i].name);
|
|---|
| 460 | screen_newline();
|
|---|
| 461 | row++;
|
|---|
| 462 | }
|
|---|
| 463 |
|
|---|
| 464 | while (row < rows) {
|
|---|
| 465 | screen_newline();
|
|---|
| 466 | row++;
|
|---|
| 467 | }
|
|---|
| 468 | }
|
|---|
| 469 |
|
|---|
| 470 | static inline void print_warning(void)
|
|---|
| 471 | {
|
|---|
| 472 | screen_get_pos(&warning_col, &warning_row);
|
|---|
| 473 | if (warning_timeleft > 0) {
|
|---|
| 474 | screen_style_emphasis();
|
|---|
| 475 | print_string(warning_text);
|
|---|
| 476 | screen_style_normal();
|
|---|
| 477 | } else {
|
|---|
| 478 | free(warning_text);
|
|---|
| 479 | warning_text = NULL;
|
|---|
| 480 | }
|
|---|
| 481 | screen_newline();
|
|---|
| 482 | }
|
|---|
| 483 |
|
|---|
| 484 | void print_data(data_t *data)
|
|---|
| 485 | {
|
|---|
| 486 | screen_restart(false);
|
|---|
| 487 | print_global_head(data);
|
|---|
| 488 | print_task_summary(data);
|
|---|
| 489 | print_thread_summary(data);
|
|---|
| 490 | print_cpu_info(data);
|
|---|
| 491 | print_physmem_info(data);
|
|---|
| 492 | print_warning();
|
|---|
| 493 |
|
|---|
| 494 | switch (screen_mode) {
|
|---|
| 495 | case SCREEN_TABLE:
|
|---|
| 496 | print_table_head(&data->table);
|
|---|
| 497 | print_table(&data->table);
|
|---|
| 498 | break;
|
|---|
| 499 | case SCREEN_SORT:
|
|---|
| 500 | print_sort(&data->table);
|
|---|
| 501 | break;
|
|---|
| 502 | case SCREEN_HELP:
|
|---|
| 503 | print_help_head();
|
|---|
| 504 | print_help();
|
|---|
| 505 | }
|
|---|
| 506 |
|
|---|
| 507 | console_flush(console);
|
|---|
| 508 | }
|
|---|
| 509 |
|
|---|
| 510 | void show_warning(const char *fmt, ...)
|
|---|
| 511 | {
|
|---|
| 512 | sysarg_t cols;
|
|---|
| 513 | sysarg_t rows;
|
|---|
| 514 | screen_get_size(&cols, &rows);
|
|---|
| 515 |
|
|---|
| 516 | size_t warning_text_size = 1 + cols * sizeof(*warning_text);
|
|---|
| 517 | free(warning_text);
|
|---|
| 518 | warning_text = malloc(warning_text_size);
|
|---|
| 519 | if (!warning_text)
|
|---|
| 520 | return;
|
|---|
| 521 |
|
|---|
| 522 | va_list args;
|
|---|
| 523 | va_start(args, fmt);
|
|---|
| 524 | vsnprintf(warning_text, warning_text_size, fmt, args);
|
|---|
| 525 | va_end(args);
|
|---|
| 526 |
|
|---|
| 527 | warning_timeleft = SEC2USEC(2);
|
|---|
| 528 |
|
|---|
| 529 | screen_moveto(warning_col, warning_row);
|
|---|
| 530 | print_warning();
|
|---|
| 531 | console_flush(console);
|
|---|
| 532 | }
|
|---|
| 533 |
|
|---|
| 534 | /** Get char with timeout
|
|---|
| 535 | *
|
|---|
| 536 | */
|
|---|
| 537 | int tgetchar(sec_t sec)
|
|---|
| 538 | {
|
|---|
| 539 | /*
|
|---|
| 540 | * Reset timeleft whenever it is not positive.
|
|---|
| 541 | */
|
|---|
| 542 |
|
|---|
| 543 | if (timeleft <= 0)
|
|---|
| 544 | timeleft = SEC2USEC(sec);
|
|---|
| 545 |
|
|---|
| 546 | /*
|
|---|
| 547 | * Wait to see if there is any input. If so, take it and
|
|---|
| 548 | * update timeleft so that the next call to tgetchar()
|
|---|
| 549 | * will not wait as long. If there is no input,
|
|---|
| 550 | * make timeleft zero and return -1.
|
|---|
| 551 | */
|
|---|
| 552 |
|
|---|
| 553 | wchar_t c = 0;
|
|---|
| 554 |
|
|---|
| 555 | while (c == 0) {
|
|---|
| 556 | cons_event_t event;
|
|---|
| 557 |
|
|---|
| 558 | warning_timeleft -= timeleft;
|
|---|
| 559 | if (!console_get_event_timeout(console, &event, &timeleft)) {
|
|---|
| 560 | timeleft = 0;
|
|---|
| 561 | return -1;
|
|---|
| 562 | }
|
|---|
| 563 | warning_timeleft += timeleft;
|
|---|
| 564 |
|
|---|
| 565 | if (event.type == CEV_KEY && event.ev.key.type == KEY_PRESS)
|
|---|
| 566 | c = event.ev.key.c;
|
|---|
| 567 | }
|
|---|
| 568 |
|
|---|
| 569 | return (int) c;
|
|---|
| 570 | }
|
|---|
| 571 |
|
|---|
| 572 | /** @}
|
|---|
| 573 | */
|
|---|