aboutsummaryrefslogtreecommitdiffstats
path: root/src/timestamp.c
blob: 57fa734cf3e791b018cc84aab1388258dd1e68cb (plain) (blame)
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
81
82
83
#include <stdio.h>
#include <string.h>

#include "timestamp.h"

struct event_name {
	const char* 	name;
	cmd_t	 	id;
};

#define EVENT(name)					\
	{#name "_START", TS_ ## name ## _START},	\
	{#name "_END", TS_ ## name ## _END}

static struct event_name event_table[] =
{
	EVENT(SCHED),
	EVENT(SCHED2),
	EVENT(TICK),
	EVENT(RELEASE),
	EVENT(PLUGIN_SCHED),
	EVENT(PLUGIN_TICK),
	EVENT(CXS),
	EVENT(SEND_RESCHED),
	EVENT(LVLA_RELEASE),
	EVENT(LVLA_SCHED),
	EVENT(LVLB_RELEASE),
	EVENT(LVLB_SCHED),
	EVENT(LVLC_RELEASE),
	EVENT(LVLC_SCHED),
	EVENT(CQ_ENQUEUE_READ),
	EVENT(CQ_ENQUEUE_FLUSH),
	EVENT(CQ_SUBMIT_WORK),
	EVENT(CQ_LOOP_WORK_CHECK),
	EVENT(CQ_LOOP_PEACE_OUT),
	EVENT(CQ_LOOP_BRANCH),
	EVENT(CQ_WORK_DO_WORK),
	EVENT(CQ_WORK_NOTIFY),
	EVENT(CQ_PHASE_WAIT),
	{"RELEASE_LATENCY", TS_RELEASE_LATENCY},

	EVENT(SYSCALL_IN),
	EVENT(SYSCALL_OUT),
	EVENT(LOCK),
	EVENT(UNLOCK),
	{"LOCK_SUSPEND", TS_LOCK_SUSPEND},
	{"LOCK_RESUME", TS_LOCK_RESUME},
};

int  str2event(const char* str, cmd_t *id)
{
	int i;

	for (i = 0; i < sizeof(event_table) / sizeof(event_table[0]); i++) {
		if (!strcmp(str, event_table[i].name)) {
			*id = event_table[i].id;
			return 1;
		}
	}
	/* try to parse it as a number */
	return sscanf(str, "%u", id);
}

const char* event2str(cmd_t id)
{
	int i;

	for (i = 0; i < sizeof(event_table) / sizeof(event_table[0]); i++)
		if (event_table[i].id == id)
			return event_table[i].name;

	return NULL;
}

const char* task_type2str(int task_type)
{
	if (task_type == TSK_RT)
		return "RT";
	else if (task_type == TSK_BE)
		return "BE";
	else
		return "UNKNOWN";
}