cmd_stat.c 1.06 KB
Newer Older
1 2 3 4 5 6 7 8
/*
 * This work is part of the White Rabbit project
 *
 * Copyright (C) 2012 - 2015 CERN (www.cern.ch)
 * Author: Grzegorz Daniluk <grzegorz.daniluk@cern.ch>
 *
 * Released according to the GNU GPL, version 2 or any later version.
 */
9
#include "shell.h"
10
#include "endpoint.h"
11 12
#include <string.h>
#include <wrc.h>
13 14 15
#include <errno.h>

int wrc_stat_running;
16
extern uint32_t wrc_stats_last;
17

18
static int cmd_stat(const char *args[])
19
{
20 21 22
	/* no arguments: invert */
	if (!args[0]) {
		wrc_stat_running = !wrc_stat_running;
23
		wrc_stats_last--; /* force a line to be printed */
24 25
		if (!wrc_stat_running)
			pp_printf("statistics now off\n");
26 27 28 29
		return 0;
	}

	/* arguments: bts, on, off */
30
	if (!strcasecmp(args[0], "bts")) {
31
		pp_printf("%d ps\n", ep_get_bitslide());
32
	} else if (!strcasecmp(args[0], "on")) {
33
		wrc_stat_running = 1;
34 35
		wrc_stats_last--; /* force a line to be printed */
	} else if (!strcasecmp(args[0], "off")) {
36
		wrc_stat_running = 0;
37 38
		pp_printf("statistics now off\n");
	} else
39
		return -EINVAL;
40
	return 0;
41

42
}
43 44 45 46 47

DEFINE_WRC_COMMAND(stat) = {
	.name = "stat",
	.exec = cmd_stat,
};