Пример #1
0
struct barectf_platform_linux_fs_ctx *barectf_platform_linux_fs_init(
	unsigned int buf_size, const char *trace_dir, int simulate_full_backend,
	unsigned int full_backend_rand_lt, unsigned int full_backend_rand_max)
{
	char stream_path[256];
	uint8_t *buf;
	struct barectf_platform_linux_fs_ctx *ctx;
	struct barectf_platform_callbacks cbs = {
		.default_clock_get_value = get_clock,
		.is_backend_full = is_backend_full,
		.open_packet = open_packet,
		.close_packet = close_packet,
	};

	ctx = malloc(sizeof(*ctx));

	if (!ctx) {
		return NULL;
	}

	buf = malloc(buf_size);

	if (!buf) {
		free(ctx);
		return NULL;
	}

	memset(buf, 0, buf_size);

	sprintf(stream_path, "%s/stream", trace_dir);
	ctx->fh = fopen(stream_path, "wb");

	if (!ctx->fh) {
		free(ctx);
		free(buf);
		return NULL;
	}

	ctx->simulate_full_backend = simulate_full_backend;
	ctx->full_backend_rand_lt = full_backend_rand_lt;
	ctx->full_backend_rand_max = full_backend_rand_max;

	barectf_init(&ctx->ctx, buf, buf_size, cbs, ctx);
	open_packet(ctx);

	return ctx;
}
Пример #2
0
static void simple(uint8_t* buf, size_t sz)
{
	/* initialize barectf context */
	struct barectf_ctx ctx;
	struct barectf_ctx* pctx = &ctx;

	barectf_init(pctx, buf, sz, get_clock, NULL);

	/* open packet */
	barectf_open_packet(pctx);

	/* record events */
	barectf_trace_simple_uint32(pctx, 20150101);
	barectf_trace_simple_int16(pctx, -2999);
	barectf_trace_simple_float(pctx, 23.57);
	barectf_trace_simple_string(pctx, "Hello, World!");
	barectf_trace_simple_enum(pctx, RUNNING);
	barectf_trace_a_few_fields(pctx, -1, 301, -3.14159, "Hello again!", NEW);
	barectf_trace_bit_packed_integers(pctx, 1, -1, 3, -2, 2, 7, 23, -55, 232);

	/* close packet */
	barectf_close_packet(pctx);
}