Exemplo n.º 1
0
static
void write_packet_context(struct ctf_stream_pos *pos)
{
	struct ctf_stream_pos dummy;

	/* content_size */
	ctf_dummy_pos(pos, &dummy);
	ctf_align_pos(&dummy, sizeof(uint64_t) * CHAR_BIT);
	ctf_move_pos(&dummy, sizeof(uint64_t) * CHAR_BIT);
	assert(!ctf_pos_packet(&dummy));

	ctf_align_pos(pos, sizeof(uint64_t) * CHAR_BIT);
	*(uint64_t *) ctf_get_pos_addr(pos) = ~0ULL;	/* Not known yet */
	pos->content_size_loc = (uint64_t *) ctf_get_pos_addr(pos);
	ctf_move_pos(pos, sizeof(uint64_t) * CHAR_BIT);

	/* packet_size */
	ctf_dummy_pos(pos, &dummy);
	ctf_align_pos(&dummy, sizeof(uint64_t) * CHAR_BIT);
	ctf_move_pos(&dummy, sizeof(uint64_t) * CHAR_BIT);
	assert(!ctf_pos_packet(&dummy));

	ctf_align_pos(pos, sizeof(uint64_t) * CHAR_BIT);
	*(uint64_t *) ctf_get_pos_addr(pos) = pos->packet_size;
	ctf_move_pos(pos, sizeof(uint64_t) * CHAR_BIT);
}
Exemplo n.º 2
0
static
void write_packet_header(struct ctf_stream_pos *pos, unsigned char *uuid)
{
	struct ctf_stream_pos dummy;

	/* magic */
	ctf_dummy_pos(pos, &dummy);
	ctf_align_pos(&dummy, sizeof(uint32_t) * CHAR_BIT);
	ctf_move_pos(&dummy, sizeof(uint32_t) * CHAR_BIT);
	assert(!ctf_pos_packet(&dummy));

	ctf_align_pos(pos, sizeof(uint32_t) * CHAR_BIT);
	*(uint32_t *) ctf_get_pos_addr(pos) = 0xC1FC1FC1;
	ctf_move_pos(pos, sizeof(uint32_t) * CHAR_BIT);

	/* uuid */
	ctf_dummy_pos(pos, &dummy);
	ctf_align_pos(&dummy, sizeof(uint8_t) * CHAR_BIT);
	ctf_move_pos(&dummy, 16 * CHAR_BIT);
	assert(!ctf_pos_packet(&dummy));

	ctf_align_pos(pos, sizeof(uint8_t) * CHAR_BIT);
	memcpy(ctf_get_pos_addr(pos), uuid, BABELTRACE_UUID_LEN);
	ctf_move_pos(pos, BABELTRACE_UUID_LEN * CHAR_BIT);
}
Exemplo n.º 3
0
static
void write_packet_context(struct ctf_stream_pos *pos)
{
	struct ctf_stream_pos dummy;

	/* content_size */
	ctf_dummy_pos(pos, &dummy);
	if (!ctf_align_pos(&dummy, sizeof(uint64_t) * CHAR_BIT))
		goto error;
	if (!ctf_move_pos(&dummy, sizeof(uint64_t) * CHAR_BIT))
		goto error;
	assert(!ctf_pos_packet(&dummy));

	if (!ctf_align_pos(pos, sizeof(uint64_t) * CHAR_BIT))
		goto error;
	*(uint64_t *) ctf_get_pos_addr(pos) = ~0ULL;	/* Not known yet */
	pos->content_size_loc = (uint64_t *) ctf_get_pos_addr(pos);
	if (!ctf_move_pos(pos, sizeof(uint64_t) * CHAR_BIT))
		goto error;

	/* packet_size */
	ctf_dummy_pos(pos, &dummy);
	if (!ctf_align_pos(&dummy, sizeof(uint64_t) * CHAR_BIT))
		goto error;
	if (!ctf_move_pos(&dummy, sizeof(uint64_t) * CHAR_BIT))
		goto error;
	assert(!ctf_pos_packet(&dummy));

	if (!ctf_align_pos(pos, sizeof(uint64_t) * CHAR_BIT))
		goto error;
	*(uint64_t *) ctf_get_pos_addr(pos) = pos->packet_size;
	if (!ctf_move_pos(pos, sizeof(uint64_t) * CHAR_BIT))
		goto error;
	return;

error:
	fprintf(stderr, "[error] Out of packet bounds when writing packet context\n");
	abort();
}
Exemplo n.º 4
0
static
void write_packet_header(struct ctf_stream_pos *pos, unsigned char *uuid)
{
	struct ctf_stream_pos dummy;

	/* magic */
	ctf_dummy_pos(pos, &dummy);
	if (!ctf_align_pos(&dummy, sizeof(uint32_t) * CHAR_BIT))
		goto error;
	if (!ctf_move_pos(&dummy, sizeof(uint32_t) * CHAR_BIT))
		goto error;
	assert(!ctf_pos_packet(&dummy));

	if (!ctf_align_pos(pos, sizeof(uint32_t) * CHAR_BIT))
		goto error;
	*(uint32_t *) ctf_get_pos_addr(pos) = 0xC1FC1FC1;
	if (!ctf_move_pos(pos, sizeof(uint32_t) * CHAR_BIT))
		goto error;

	/* uuid */
	ctf_dummy_pos(pos, &dummy);
	if (!ctf_align_pos(&dummy, sizeof(uint8_t) * CHAR_BIT))
		goto error;
	if (!ctf_move_pos(&dummy, 16 * CHAR_BIT))
		goto error;
	assert(!ctf_pos_packet(&dummy));

	if (!ctf_align_pos(pos, sizeof(uint8_t) * CHAR_BIT))
		goto error;
	memcpy(ctf_get_pos_addr(pos), uuid, BABELTRACE_UUID_LEN);
	if (!ctf_move_pos(pos, BABELTRACE_UUID_LEN * CHAR_BIT))
		goto error;
	return;

error:
	fprintf(stderr, "[error] Out of packet bounds when writing packet header\n");
	abort();
}
Exemplo n.º 5
0
static
void trace_string(char *line, struct ctf_stream_pos *pos, size_t len)
{
	struct ctf_stream_pos dummy;
	int attempt = 0;
	char *tline = line;	/* tline is start of text, after timestamp */
	size_t tlen = len;
	uint64_t ts = 0;

	printf_debug("read: %s\n", line);

	for (;;) {
		int packet_filled = 0;

		ctf_dummy_pos(pos, &dummy);
		write_event_header(&dummy, line, &tline, len, &tlen, &ts);
		if (!ctf_align_pos(&dummy, sizeof(uint8_t) * CHAR_BIT))
			packet_filled = 1;
		if (!ctf_move_pos(&dummy, tlen * CHAR_BIT))
			packet_filled = 1;
		if (packet_filled || ctf_pos_packet(&dummy)) {
			ctf_pos_pad_packet(pos);
			write_packet_header(pos, s_uuid);
			write_packet_context(pos);
			if (attempt++ == 1) {
				fprintf(stderr, "[Error] Line too large for packet size (%" PRIu64 "kB) (discarded)\n",
					pos->packet_size / CHAR_BIT / 1024);
				return;
			}
			continue;
		} else {
			break;
		}
	}

	write_event_header(pos, line, &tline, len, &tlen, &ts);
	if (!ctf_align_pos(pos, sizeof(uint8_t) * CHAR_BIT))
		goto error;
	memcpy(ctf_get_pos_addr(pos), tline, tlen);
	if (!ctf_move_pos(pos, tlen * CHAR_BIT))
		goto error;
	return;

error:
	fprintf(stderr, "[error] Out of packet bounds when writing event payload\n");
	abort();
}