File: linux-fs-simple.c

package info (click to toggle)
barectf 3.1.2-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,840 kB
  • sloc: python: 3,781; ansic: 1,585; makefile: 45; sh: 11
file content (95 lines) | stat: -rw-r--r-- 2,796 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
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
84
85
86
87
88
89
90
91
92
93
94
95
/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2016-2020 Philippe Proulx <pproulx@efficios.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <time.h>

#include "barectf-platform-linux-fs.h"
#include "barectf.h"

enum state_t {
	NEW,
	TERMINATED,
	READY,
	RUNNING,
	WAITING,
};

static void trace_stuff(struct barectf_default_ctx * const ctx, const int argc,
	const char * const argv[])
{
	int i;
	const char *str;

	/* Record 40,000 events */
	for (i = 0; i < 5000; ++i) {
		barectf_trace_simple_uint32(ctx, i * 1500);
		barectf_trace_simple_int16(ctx, -i * 2);
		barectf_trace_simple_float(ctx, (float) i / 1.23);

		if (argc > 0) {
			str = argv[i % argc];
		} else {
			str = "hello there!";
		}

		barectf_trace_simple_string(ctx, str);
		barectf_trace_context_no_payload(ctx, i, "ctx");
		barectf_trace_simple_enum(ctx, RUNNING);
		barectf_trace_a_few_fields(ctx, -1, 301, -3.14159, str, NEW);
		barectf_trace_bit_packed_integers(ctx, 1, -1, 3, -2, 2, 7, 23,
			-55, 232);
		barectf_trace_no_context_no_payload(ctx);
		barectf_trace_simple_enum(ctx, TERMINATED);
	}
}

int main(const int argc, const char * const argv[])
{
	struct barectf_platform_linux_fs_ctx *platform_ctx;
	int exit_status = 0;

	/* Initialize platform */
	platform_ctx = barectf_platform_linux_fs_init(512, "trace/stream",
		1, 2, 7);

	if (!platform_ctx) {
		fprintf(stderr,
			"Error: failed to initialize Linux FS platform.\n");
		exit_status = 1;
		goto end;
	}

	/* Trace stuff (will create/write packets as it executes) */
	trace_stuff(barectf_platform_linux_fs_get_barectf_ctx(platform_ctx),
		argc, argv);

	/* Finalize platform */
	barectf_platform_linux_fs_fini(platform_ctx);

end:
	return exit_status;
}