File: jd_samples_csv.c

package info (click to toggle)
jitterdebugger 0.3.1%2Bgit20200117.b90ff3a-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 180 kB
  • sloc: ansic: 1,581; python: 77; sh: 44; makefile: 42
file content (47 lines) | stat: -rw-r--r-- 926 bytes parent folder | download | duplicates (3)
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
// SPDX-License-Identifier: MIT

#include <inttypes.h>
#include <errno.h>

#include "jitterdebugger.h"

static int output_csv(struct jd_samples_info *info, FILE *input)
{
	struct latency_sample sample;
	FILE *output;

	output = jd_fopen(info->dir, "samples.csv", "w");
	if (!output)
		err_handler(errno, "Could not open '%s/samples.csv' for writing",
			info->dir);

	while(fread(&sample, sizeof(struct latency_sample), 1, input)) {
		fprintf(output, "%d;%lld.%.9ld;%" PRIu64 "\n",
			sample.cpuid,
			(long long)sample.ts.tv_sec,
			sample.ts.tv_nsec,
			sample.val);
	}

	fclose(output);

	return 0;
}

struct jd_samples_ops csv_ops = {
	.name = "comma separate values",
	.format = "csv",
	.output = output_csv,
};

static int csv_plugin_init(void)
{
	return jd_samples_register(&csv_ops);
}

static void csv_plugin_cleanup(void)
{
	jd_samples_unregister(&csv_ops);
}

JD_PLUGIN_DEFINE(csv_plugin_init, csv_plugin_cleanup);