xlap.c 955 Bytes
Newer Older
Andreas Schmidt's avatar
Andreas Schmidt committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "xlap.h"


void XlapTimestampTableDumpHeader(FILE *out)
{
	fprintf(out, "SeqNo,Kind" );
#	define OUT(id) fprintf(out, ",%s_T,%s_C", #id, #id);
	PP_foreach(PP_join_space, OUT, TIMESTAMP_ID_LIST)
#	undef OUT
	fprintf(out, "\n");
}

static inline unsigned long long timestampByTime(struct timespec *ts)
{
	// convert timespec to microseconds
	unsigned long long x = ts->tv_sec;
	x *= 1000000ULL;
	x += ts->tv_nsec / 1000;
	return x;
}

void XlapTimestampTableDump(FILE *out, XlapTimestampPacketKind kind, XlapTimestampTable *table)
{
#	define OUT(id) fprintf(out, ",%llu,%llu", timestampByTime(&table->rows[row].time[ts_##id].actual.t), (unsigned long long) table->rows[row].time[ts_##id].actual.c);
25
26
    // Start at 1 to remove the scratch row 0 from output.
	for (unsigned int row = 1; row < TS_ROWS; row++) {
Andreas Schmidt's avatar
Andreas Schmidt committed
27
28
29
30
31
32
		fprintf(out, "%u,%u", row, (unsigned) kind);
		PP_foreach(PP_join_space, OUT, TIMESTAMP_ID_LIST)
		fprintf(out, "\n");
	}
#	undef OUT
}