Commit 3bc3b28a authored by Alessandro Rubini's avatar Alessandro Rubini

cmd_stat: run stat printing as a background process

"stat" enables statistics, without interrupting shell interaction.
Thus, there is no "esc to terminate" any more.

Another "stat" command with turn stats off. As an alternative, "stat on"
and "stat off" is supported.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent d5054a33
......@@ -3,9 +3,9 @@
#define UI_SHELL_MODE 0
#define UI_GUI_MODE 1
#define UI_STAT_MODE 2
extern int wrc_ui_mode;
extern int wrc_stat_running;
const char *fromhex(const char *hex, int *v);
const char *fromdec(const char *dec, int *v);
......
......@@ -2,15 +2,29 @@
#include "endpoint.h"
#include <string.h>
#include <wrc.h>
#include <errno.h>
int wrc_stat_running;
static int cmd_stat(const char *args[])
{
/* no arguments: invert */
if (!args[0]) {
wrc_stat_running = !wrc_stat_running;
return 0;
}
/* arguments: bts, on, off */
if (!strcasecmp(args[0], "bts"))
mprintf("%d ps\n", ep_get_bitslide());
else if (!strcasecmp(args[0], "on"))
wrc_stat_running = 1;
else if (!strcasecmp(args[0], "off"))
wrc_stat_running = 0;
else
wrc_ui_mode = UI_STAT_MODE;
return -EINVAL;
return 0;
}
DEFINE_WRC_COMMAND(stat) = {
......
......@@ -148,15 +148,12 @@ static void ui_update(void)
shell_init();
wrc_ui_mode = UI_SHELL_MODE;
}
} else if (wrc_ui_mode == UI_STAT_MODE) {
wrc_log_stats();
if (uart_read_byte() == 27 || wrc_ui_refperiod == 0) {
shell_init();
wrc_ui_mode = UI_SHELL_MODE;
}
} else
} else {
shell_interactive();
}
/* Stats is asynchronous now. It's not a different mode, but a flag */
if (wrc_stat_running)
wrc_log_stats();
}
/* initialize functions to be called after reset in check_reset function */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment