forked from igaw/jitterdebugger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjd_samples_csv.c
47 lines (36 loc) · 926 Bytes
/
jd_samples_csv.c
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);