summaryrefslogtreecommitdiff
path: root/tools/stat/event_stat.c
blob: 1521b543f8bbb945358c7b4bebc92c675da820a3 (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
#include <mr_stat.h>

#include "libstat.h"

static void write_timeinfo(FILE * stream)
{
	time_t currect;
	time(&currect);

	char str_localtime[MR_STRING_MAX];
	libstat_strtime(str_localtime, sizeof(str_localtime), currect);
	fprintf(stream, "Time: %12s\n", str_localtime);
	return;
}

#define EVENT_NAME_WIDTH		25
#define EVENT_COUNT_WIDTH		25

static void write_table_header(FILE * stream)
{
	char linebuf[MR_STRING_MAX];
	unsigned int linecur = 0;

	__WRITE_TABLE_ITEM("EventSymbol", "c", EVENT_NAME_WIDTH);
	__WRITE_TABLE_ITEM("Count", "c", EVENT_COUNT_WIDTH);
	fprintf(stream, "%s\n", linebuf);

	linecur = 0;
	__WRITE_TABLE_CLINE('-', "c", EVENT_NAME_WIDTH);
	__WRITE_TABLE_CLINE('-', "c", EVENT_COUNT_WIDTH);
	fprintf(stream, "%s\n", linebuf);
}

static void write_event_item(FILE * stream, const char * ev_symbol, uint64_t value)
{
	char linebuf[MR_STRING_MAX];
	char numbuf[MR_STRING_MAX];
	unsigned int linecur = 0;

	__WRITE_TABLE_ITEM(ev_symbol, "r", EVENT_NAME_WIDTH);
	__TRANS_DATA(value, numbuf);
	__WRITE_TABLE_ITEM(numbuf, "r", EVENT_COUNT_WIDTH);
	fprintf(stream, "%s\n", linebuf);
}

static void event_stat_loop(FILE * stream)
{
	struct mr_event_stat * stat_handle;
	stat_handle = mr_event_stat_get();
	if(stat_handle == NULL)
	{
		fprintf(stderr, "Master(serivce) is not run or event stat "
			"function is disable(handle is null).\n");
		exit(EXIT_FAILURE);
	}

	uint64_t total_ev_rx_dup_failed = 0;
	uint64_t total_ev_rx_entunnel_failed = 0;

	for(int i = 0; i < RTE_DIM(stat_handle->_per_thread); i++)
	{
		total_ev_rx_dup_failed += stat_handle->_per_thread[i].ev_rx_dup_failed;
		total_ev_rx_entunnel_failed += stat_handle->_per_thread[i].ev_rx_entunnel_failed;
	}

	fprintf(stream, "\n");
	write_timeinfo(stream);
	fprintf(stream, "\n");
	write_table_header(stdout);
	write_event_item(stream, "ev_rx_dup_failed", total_ev_rx_dup_failed);
	write_event_item(stream, "ev_rx_entunnel_failed", total_ev_rx_entunnel_failed);
	fprintf(stream, "\n");
	return;
}

int main(int argc, char * argv[])
{
	libstat_init();
	event_stat_loop(stdout);
}