bin_PROGRAMS = babeltrace
+#lib_LTLIBRARIES = libbabeltrace.la
+#
+#libbabeltrace_la_SOURCES = \
+# babeltrace-lib.c
+#
+#libbabeltrace_la_LIBADD = \
+# $(top_builddir)/types/libbabeltrace_types.la \
+# $(top_builddir)/formats/libbabeltrace_registry.la \
+# $(top_builddir)/formats/ctf/libctf.la
+
babeltrace_SOURCES = \
babeltrace.c
+#babeltrace_LDADD = \
+# libbabeltrace.la
+
babeltrace_LDADD = \
$(top_builddir)/types/libbabeltrace_types.la \
$(top_builddir)/formats/libbabeltrace_registry.la \
--- /dev/null
+/*
+ * babeltrace-lib.c
+ *
+ * Babeltrace Trace Converter Library
+ *
+ * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@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.
+ */
+
+#include <stdlib.h>
+#include <errno.h>
+#include <stdio.h>
+#include <babeltrace/babeltrace.h>
+#include <babeltrace/format.h>
+#include <babeltrace/ctf/types.h>
+#include <babeltrace/ctf/metadata.h>
+#include <babeltrace/ctf-text/types.h>
+
+static
+int print_event(struct format *fmt_write, struct ctf_text_stream_pos *sout,
+ struct format *fmt_read, struct ctf_file_stream *sin)
+{
+ struct ctf_stream *stream_class = sin->stream;
+ struct ctf_event *event_class;
+ uint64_t id = 0;
+ int len_index;
+
+ /* Read and print event header */
+ if (stream_class->event_header) {
+ fmt_read->struct_read(&sin->pos.parent, stream_class->event_header);
+
+ /* lookup event id */
+ len_index = struct_declaration_lookup_field_index(td->packet_header->declaration,
+ g_quark_from_static_string("id"));
+ if (len_index >= 0) {
+ struct definition_integer *defint;
+ struct field *field;
+
+ field = struct_definition_get_field_from_index(stream_class->event_header, len_index);
+ assert(field->definition->declaration->id == CTF_TYPE_INTEGER);
+ defint = container_of(field->definition, struct definition_integer, p);
+ assert(defint->declaration->signedness == FALSE);
+ id = defint->value._unsigned; /* set id */
+ }
+
+ fmt_write->struct_write(&sout->parent, stream_class->event_header);
+ }
+
+ /* Read and print stream-declared event context */
+ if (stream_class->event_context) {
+ fmt_read->struct_read(&sin->pos.parent, stream_class->event_context);
+ fmt_write->struct_write(&sout->parent, stream_class->event_context);
+ }
+
+ if (id >= stream_class->events_by_id->len) {
+ fprintf(stdout, "[error] Event id %" PRIu64 " is outside range.\n", id);
+ return -EINVAL;
+ }
+ event_class = g_ptr_array_index(stream_class->events_by_id, id);
+ if (!event_class) {
+ fprintf(stdout, "[error] Event id %" PRIu64 " is unknown.\n", id);
+ return -EINVAL;
+ }
+
+ /* Read and print event-declared event context */
+ if (event_class->context) {
+ fmt_read->struct_read(&sin->pos.parent, event_class->context);
+ fmt_write->struct_write(&sout->parent, event_class->context);
+ }
+
+ /* Read and print event payload */
+ if (event_class->fields) {
+ fmt_read->struct_read(&sin->pos.parent, event_class->fields);
+ fmt_write->struct_write(&sout->parent, event_class->fields);
+ }
+
+ return 0;
+}
+
+static
+int print_stream(struct format *fmt_write, struct ctf_text_stream_pos *sout,
+ struct format *fmt_read, struct ctf_file_stream *sin)
+{
+ int ret;
+
+ /* For each event, print header, context, payload */
+ /* TODO: order events by timestamps across streams */
+ for (;;) {
+ ret = print_event(fmt_write, sout, fmt_read, sin);
+ if (ret == -EOF)
+ break;
+ else if (ret) {
+ fprintf(stdout, "[error] Printing event failed.\n");
+ goto error;
+ }
+ }
+
+ return 0;
+
+error:
+ return ret;
+}
+
+int print_trace(struct format *fmt_write,
+ struct trace_descriptor *td_write,
+ struct format *fmt_read,
+ struct trace_descriptor *td_read)
+{
+ struct ctf_trace *tin = container_of(td_read, struct ctf_trace, parent);
+ struct ctf_text_stream_pos *sout = container_of(td_write, struct ctf_text_stream_pos, parent);
+ int stream_id, filenr;
+ int ret;
+
+ /* For each stream (TODO: order events by timestamp) */
+ for (stream_id = 0; stream_id < tin->streams->len; stream_id++) {
+ struct ctf_stream *stream = g_ptr_array_index(tin->streams, stream_id);
+
+ if (!stream)
+ continue;
+ for (filenr = 0; filenr < stream->files->len; filenr++) {
+ struct ctf_file_stream *file_stream = g_ptr_array_index(stream->files, filenr);
+ ret = print_stream(fmt_write, sout, fmt_read, file_stream);
+ if (ret) {
+ fprintf(stdout, "[error] Printing stream %d failed.\n", stream_id);
+ goto error;
+ }
+ }
+ }
+
+ return 0;
+
+error:
+ return ret;
+}
opt_output_path);
goto error_td_write;
}
-
+#if 0
+ ret = print_trace(fmt_write, td_write, fmt_read, td_read);
+ if (ret) {
+ fprintf(stdout, "Error printing trace.\n\n");
+ goto error_copy_trace;
+ }
+#endif //0
fmt_write->close_trace(td_write);
fmt_read->close_trace(td_read);
exit(EXIT_SUCCESS);
/* Error handling */
+error_copy_trace:
fmt_write->close_trace(td_write);
error_td_write:
fmt_read->close_trace(td_read);
extern int yydebug;
-struct trace_descriptor {
- struct ctf_trace ctf_trace;
-};
-
struct trace_descriptor *ctf_open_trace(const char *path, int flags);
void ctf_close_trace(struct trace_descriptor *descriptor);
.close_trace = ctf_close_trace,
};
-void init_pos(struct stream_pos *pos, int fd)
+void ctf_init_pos(struct ctf_stream_pos *pos, int fd)
{
pos->fd = fd;
pos->mmap_offset = 0;
case O_RDWR:
pos->prot = PROT_WRITE; /* Write has priority */
pos->flags = MAP_SHARED;
- move_pos_slow(pos, 0); /* position for write */
+ ctf_move_pos_slow(pos, 0); /* position for write */
break;
default:
assert(0);
}
}
-void fini_pos(struct stream_pos *pos)
+void ctf_fini_pos(struct ctf_stream_pos *pos)
{
int ret;
/* unmap old base */
ret = munmap(pos->base, pos->packet_size / CHAR_BIT);
if (ret) {
- fprintf(stdout, "Unable to unmap old base: %s.\n",
+ fprintf(stdout, "[error] Unable to unmap old base: %s.\n",
strerror(errno));
assert(0);
}
(void) g_array_free(pos->packet_index, TRUE);
}
-void move_pos_slow(struct stream_pos *pos, size_t offset)
+void ctf_move_pos_slow(struct ctf_stream_pos *pos, size_t offset)
{
int ret;
off_t off;
/* unmap old base */
ret = munmap(pos->base, pos->packet_size / CHAR_BIT);
if (ret) {
- fprintf(stdout, "Unable to unmap old base: %s.\n",
+ fprintf(stdout, "[error] Unable to unmap old base: %s.\n",
strerror(errno));
assert(0);
}
}
/*
- * The caller should never ask for move_pos across packets,
+ * The caller should never ask for ctf_move_pos across packets,
* except to get exactly at the beginning of the next packet.
*/
if (pos->prot == PROT_WRITE) {
* (without any header nor packets nor padding).
*/
static
-int ctf_open_trace_metadata_read(struct trace_descriptor *td)
+int ctf_open_trace_metadata_read(struct ctf_trace *td)
{
struct ctf_scanner *scanner;
FILE *fp;
int ret = 0;
- td->ctf_trace.metadata.pos.fd = openat(td->ctf_trace.dirfd,
- "metadata", O_RDONLY);
- if (td->ctf_trace.metadata.pos.fd < 0) {
+ td->metadata.pos.fd = openat(td->dirfd, "metadata", O_RDONLY);
+ if (td->metadata.pos.fd < 0) {
fprintf(stdout, "Unable to open metadata.\n");
- return td->ctf_trace.metadata.pos.fd;
+ return td->metadata.pos.fd;
}
if (babeltrace_debug)
yydebug = 1;
- fp = fdopen(td->ctf_trace.metadata.pos.fd, "r");
+ fp = fdopen(td->metadata.pos.fd, "r");
if (!fp) {
- fprintf(stdout, "Unable to open metadata stream.\n");
+ fprintf(stdout, "[error] Unable to open metadata stream.\n");
ret = -errno;
goto end_stream;
}
scanner = ctf_scanner_alloc(fp);
if (!scanner) {
- fprintf(stdout, "Error allocating scanner\n");
+ fprintf(stdout, "[error] Error allocating scanner\n");
ret = -ENOMEM;
goto end_scanner_alloc;
}
ret = ctf_scanner_append_ast(scanner);
if (ret) {
- fprintf(stdout, "Error creating AST\n");
+ fprintf(stdout, "[error] Error creating AST\n");
goto end;
}
if (babeltrace_debug) {
ret = ctf_visitor_print_xml(stdout, 0, &scanner->ast->root);
if (ret) {
- fprintf(stdout, "Error visiting AST for XML output\n");
+ fprintf(stdout, "[error] Error visiting AST for XML output\n");
goto end;
}
}
ret = ctf_visitor_semantic_check(stdout, 0, &scanner->ast->root);
if (ret) {
- fprintf(stdout, "Error in CTF semantic validation %d\n", ret);
+ fprintf(stdout, "[error] Error in CTF semantic validation %d\n", ret);
goto end;
}
ret = ctf_visitor_construct_metadata(stdout, 0, &scanner->ast->root,
- &td->ctf_trace, BYTE_ORDER);
+ td, BYTE_ORDER);
if (ret) {
- fprintf(stdout, "Error in CTF metadata constructor %d\n", ret);
+ fprintf(stdout, "[error] Error in CTF metadata constructor %d\n", ret);
goto end;
}
end:
end_scanner_alloc:
fclose(fp);
end_stream:
- close(td->ctf_trace.metadata.pos.fd);
+ close(td->metadata.pos.fd);
return ret;
}
static
-int create_stream_packet_index(struct trace_descriptor *td,
+int create_stream_packet_index(struct ctf_trace *td,
struct ctf_file_stream *file_stream)
{
struct ctf_stream *stream;
int len_index;
- struct stream_pos *pos;
+ struct ctf_stream_pos *pos;
struct stat filestats;
struct packet_index packet_index;
int first_packet = 1;
/* unmap old base */
ret = munmap(pos->base, pos->packet_size / CHAR_BIT);
if (ret) {
- fprintf(stdout, "Unable to unmap old base: %s.\n",
+ fprintf(stdout, "[error] Unable to unmap old base: %s.\n",
strerror(errno));
return ret;
}
packet_index.packet_size = 0;
/* read and check header, set stream id (and check) */
- if (td->ctf_trace.packet_header) {
+ if (td->packet_header) {
/* Read packet header */
- td->ctf_trace.packet_header->p.declaration->copy(NULL, NULL,
- pos, &ctf_format, &td->ctf_trace.packet_header->p);
+ td->packet_header->p.declaration->copy(NULL, NULL,
+ &pos->parent, &ctf_format, &td->packet_header->p);
- len_index = struct_declaration_lookup_field_index(td->ctf_trace.packet_header->declaration, g_quark_from_static_string("magic"));
+ len_index = struct_declaration_lookup_field_index(td->packet_header->declaration, g_quark_from_static_string("magic"));
if (len_index >= 0) {
struct definition_integer *defint;
struct field *field;
- field = struct_definition_get_field_from_index(td->ctf_trace.packet_header, len_index);
+ field = struct_definition_get_field_from_index(td->packet_header, len_index);
assert(field->definition->declaration->id == CTF_TYPE_INTEGER);
defint = container_of(field->definition, struct definition_integer, p);
assert(defint->declaration->signedness == FALSE);
}
/* check uuid */
- len_index = struct_declaration_lookup_field_index(td->ctf_trace.packet_header->declaration, g_quark_from_static_string("trace_uuid"));
+ len_index = struct_declaration_lookup_field_index(td->packet_header->declaration, g_quark_from_static_string("trace_uuid"));
if (len_index >= 0) {
struct definition_array *defarray;
struct field *field;
uint64_t i;
uint8_t uuidval[UUID_LEN];
- field = struct_definition_get_field_from_index(td->ctf_trace.packet_header, len_index);
+ field = struct_definition_get_field_from_index(td->packet_header, len_index);
assert(field->definition->declaration->id == CTF_TYPE_ARRAY);
defarray = container_of(field->definition, struct definition_array, p);
assert(array_len(defarray) == UUID_LEN);
defint = container_of(elem, struct definition_integer, p);
uuidval[i] = defint->value._unsigned;
}
- ret = uuid_compare(td->ctf_trace.uuid, uuidval);
+ ret = uuid_compare(td->uuid, uuidval);
if (ret) {
fprintf(stdout, "[error] Unique Universal Identifiers do not match.\n");
return -EINVAL;
}
- len_index = struct_declaration_lookup_field_index(td->ctf_trace.packet_header->declaration, g_quark_from_static_string("stream_id"));
+ len_index = struct_declaration_lookup_field_index(td->packet_header->declaration, g_quark_from_static_string("stream_id"));
if (len_index >= 0) {
struct definition_integer *defint;
struct field *field;
- field = struct_definition_get_field_from_index(td->ctf_trace.packet_header, len_index);
+ field = struct_definition_get_field_from_index(td->packet_header, len_index);
assert(field->definition->declaration->id == CTF_TYPE_INTEGER);
defint = container_of(field->definition, struct definition_integer, p);
assert(defint->declaration->signedness == FALSE);
}
if (first_packet) {
file_stream->stream_id = stream_id;
- if (stream_id >= td->ctf_trace.streams->len) {
+ if (stream_id >= td->streams->len) {
fprintf(stdout, "[error] Stream %" PRIu64 " is not declared in metadata.\n", stream_id);
return -EINVAL;
}
- stream = g_ptr_array_index(td->ctf_trace.streams, stream_id);
+ stream = g_ptr_array_index(td->streams, stream_id);
if (!stream) {
fprintf(stdout, "[error] Stream %" PRIu64 " is not declared in metadata.\n", stream_id);
return -EINVAL;
if (stream->packet_context) {
/* Read packet context */
stream->packet_context->p.declaration->copy(NULL, NULL,
- pos, &ctf_format, &stream->packet_context->p);
+ &pos->parent, &ctf_format, &stream->packet_context->p);
/* read content size from header */
len_index = struct_declaration_lookup_field_index(stream->packet_context->declaration, g_quark_from_static_string("content_size"));
* description (metadata).
*/
static
-int ctf_open_file_stream_read(struct trace_descriptor *td, const char *path, int flags)
+int ctf_open_file_stream_read(struct ctf_trace *td, const char *path, int flags)
{
int ret;
struct ctf_file_stream *file_stream;
- ret = openat(td->ctf_trace.dirfd, path, flags);
+ ret = openat(td->dirfd, path, flags);
if (ret < 0)
goto error;
file_stream = g_new0(struct ctf_file_stream, 1);
- init_pos(&file_stream->pos, ret);
+ ctf_init_pos(&file_stream->pos, ret);
ret = create_stream_packet_index(td, file_stream);
if (ret)
goto error_index;
return 0;
error_index:
- fini_pos(&file_stream->pos);
+ ctf_fini_pos(&file_stream->pos);
close(file_stream->pos.fd);
g_free(file_stream);
error:
}
static
-int ctf_open_trace_read(struct trace_descriptor *td, const char *path, int flags)
+int ctf_open_trace_read(struct ctf_trace *td, const char *path, int flags)
{
int ret;
struct dirent *dirent;
struct dirent *diriter;
size_t dirent_len;
- td->ctf_trace.flags = flags;
+ td->flags = flags;
/* Open trace directory */
- td->ctf_trace.dir = opendir(path);
- if (!td->ctf_trace.dir) {
+ td->dir = opendir(path);
+ if (!td->dir) {
fprintf(stdout, "[error] Unable to open trace directory.\n");
ret = -ENOENT;
goto error;
}
- td->ctf_trace.dirfd = open(path, 0);
- if (td->ctf_trace.dirfd < 0) {
+ td->dirfd = open(path, 0);
+ if (td->dirfd < 0) {
fprintf(stdout, "[error] Unable to open trace directory file descriptor.\n");
ret = -ENOENT;
goto error_dirfd;
}
- td->ctf_trace.streams = g_ptr_array_new();
+ td->streams = g_ptr_array_new();
/*
* Keep the metadata file separate.
*/
dirent_len = offsetof(struct dirent, d_name) +
- fpathconf(td->ctf_trace.dirfd, _PC_NAME_MAX) + 1;
+ fpathconf(td->dirfd, _PC_NAME_MAX) + 1;
dirent = malloc(dirent_len);
for (;;) {
- ret = readdir_r(td->ctf_trace.dir, dirent, &diriter);
+ ret = readdir_r(td->dir, dirent, &diriter);
if (ret) {
fprintf(stdout, "[error] Readdir error.\n");
goto readdir_error;
readdir_error:
free(dirent);
error_metadata:
- g_ptr_array_free(td->ctf_trace.streams, TRUE);
- close(td->ctf_trace.dirfd);
+ g_ptr_array_free(td->streams, TRUE);
+ close(td->dirfd);
error_dirfd:
- closedir(td->ctf_trace.dir);
+ closedir(td->dir);
error:
return ret;
}
static
-int ctf_open_trace_write(struct trace_descriptor *td, const char *path, int flags)
+int ctf_open_trace_write(struct ctf_trace *td, const char *path, int flags)
{
int ret;
return ret;
/* Open trace directory */
- td->ctf_trace.dir = opendir(path);
- if (!td->ctf_trace.dir) {
- fprintf(stdout, "Unable to open trace directory.\n");
+ td->dir = opendir(path);
+ if (!td->dir) {
+ fprintf(stdout, "[error] Unable to open trace directory.\n");
ret = -ENOENT;
goto error;
}
struct trace_descriptor *ctf_open_trace(const char *path, int flags)
{
- struct trace_descriptor *td;
+ struct ctf_trace *td;
int ret;
- td = g_new0(struct trace_descriptor, 1);
+ td = g_new0(struct ctf_trace, 1);
switch (flags & O_ACCMODE) {
case O_RDONLY:
goto error;
break;
case O_WRONLY:
+ fprintf(stdout, "[error] Opening CTF traces for output is not supported yet.\n");
+ goto error;
+#if 0
ret = ctf_open_trace_write(td, path, flags);
if (ret)
goto error;
+#endif //0
break;
default:
- fprintf(stdout, "Incorrect open flags.\n");
+ fprintf(stdout, "[error] Incorrect open flags.\n");
goto error;
}
- return td;
+ return &td->parent;
error:
g_free(td);
return NULL;
static
void ctf_close_file_stream(struct ctf_file_stream *file_stream)
{
- fini_pos(&file_stream->pos);
+ ctf_fini_pos(&file_stream->pos);
close(file_stream->pos.fd);
}
-void ctf_close_trace(struct trace_descriptor *td)
+void ctf_close_trace(struct trace_descriptor *tdp)
{
+ struct ctf_trace *td = container_of(tdp, struct ctf_trace, parent);
int i;
- if (td->ctf_trace.streams) {
- for (i = 0; i < td->ctf_trace.streams->len; i++) {
+ if (td->streams) {
+ for (i = 0; i < td->streams->len; i++) {
struct ctf_stream *stream;
int j;
- stream = g_ptr_array_index(td->ctf_trace.streams, i);
+ stream = g_ptr_array_index(td->streams, i);
for (j = 0; j < stream->files->len; j++) {
struct ctf_file_stream *file_stream;
- file_stream = g_ptr_array_index(td->ctf_trace.streams, j);
+ file_stream = g_ptr_array_index(td->streams, j);
ctf_close_file_stream(file_stream);
}
}
- g_ptr_array_free(td->ctf_trace.streams, TRUE);
+ g_ptr_array_free(td->streams, TRUE);
}
- closedir(td->ctf_trace.dir);
+ closedir(td->dir);
g_free(td);
}
void ctf_float_copy(struct stream_pos *dest, struct stream_pos *src,
const struct declaration_float *float_declaration)
{
- align_pos(src, float_declaration->p.alignment);
- align_pos(dest, float_declaration->p.alignment);
+ ctf_align_pos(ctf_pos(src), float_declaration->p.alignment);
+ ctf_align_pos(ctf_pos(dest), float_declaration->p.alignment);
_ctf_float_copy(dest, float_declaration, src, float_declaration);
}
sizeof(double) * CHAR_BIT - DBL_MANT_DIG,
BYTE_ORDER,
__alignof__(double));
- struct stream_pos destp;
+ struct ctf_stream_pos destp;
- align_pos(srcp, float_declaration->p.alignment);
- init_pos(&destp, -1);
+ ctf_align_pos(ctf_pos(srcp), float_declaration->p.alignment);
+ ctf_init_pos(&destp, -1);
destp.base = (char *) u.bits;
- _ctf_float_copy(&destp, dest_declaration, srcp, float_declaration);
+ _ctf_float_copy(&destp.parent, dest_declaration, srcp, float_declaration);
declaration_unref(&dest_declaration->p);
return u.v;
}
sizeof(double) * CHAR_BIT - DBL_MANT_DIG,
BYTE_ORDER,
__alignof__(double));
- struct stream_pos srcp;
+ struct ctf_stream_pos srcp;
u.v = v;
- align_pos(destp, float_declaration->p.alignment);
- init_pos(&srcp, -1);
+ ctf_align_pos(ctf_pos(destp), float_declaration->p.alignment);
+ ctf_init_pos(&srcp, -1);
srcp.base = (char *) u.bits;
- _ctf_float_copy(destp, float_declaration, &srcp, src_declaration);
+ _ctf_float_copy(destp, float_declaration, &srcp.parent, src_declaration);
declaration_unref(&src_declaration->p);
}
sizeof(long double) * CHAR_BIT - LDBL_MANT_DIG,
BYTE_ORDER,
__alignof__(long double));
- struct stream_pos destp;
+ struct ctf_stream_pos destp;
- align_pos(srcp, float_declaration->p.alignment);
- init_pos(&destp, -1);
+ ctf_align_pos(ctf_pos(srcp), float_declaration->p.alignment);
+ ctf_init_pos(&destp, -1);
destp.base = (char *) u.bits;
- _ctf_float_copy(&destp, dest_declaration, srcp, float_declaration);
+ _ctf_float_copy(&destp.parent, dest_declaration, srcp, float_declaration);
declaration_unref(&dest_declaration->p);
return u.v;
}
sizeof(long double) * CHAR_BIT - LDBL_MANT_DIG,
BYTE_ORDER,
__alignof__(long double));
- struct stream_pos srcp;
+ struct ctf_stream_pos srcp;
u.v = v;
- align_pos(destp, float_declaration->p.alignment);
- init_pos(&srcp, -1);
+ ctf_align_pos(ctf_pos(destp), float_declaration->p.alignment);
+ ctf_init_pos(&srcp, -1);
srcp.base = (char *) u.bits;
- _ctf_float_copy(destp, float_declaration, &srcp, src_declaration);
+ _ctf_float_copy(destp, float_declaration, &srcp.parent, src_declaration);
declaration_unref(&src_declaration->p);
}
#include <endian.h>
static
-uint64_t _aligned_uint_read(struct stream_pos *pos,
- const struct declaration_integer *integer_declaration)
+uint64_t _aligned_uint_read(struct stream_pos *ppos,
+ const struct declaration_integer *integer_declaration)
{
+ struct ctf_stream_pos *pos = ctf_pos(ppos);
int rbo = (integer_declaration->byte_order != BYTE_ORDER); /* reverse byte order */
- align_pos(pos, integer_declaration->p.alignment);
+ ctf_align_pos(pos, integer_declaration->p.alignment);
assert(!(pos->offset % CHAR_BIT));
switch (integer_declaration->len) {
case 8:
uint8_t v;
v = *(const uint8_t *)pos->base;
- move_pos(pos, integer_declaration->len);
+ ctf_move_pos(pos, integer_declaration->len);
return v;
}
case 16:
uint16_t v;
v = *(const uint16_t *)pos->base;
- move_pos(pos, integer_declaration->len);
+ ctf_move_pos(pos, integer_declaration->len);
return rbo ? GUINT16_SWAP_LE_BE(v) : v;
}
case 32:
uint32_t v;
v = *(const uint32_t *)pos->base;
- move_pos(pos, integer_declaration->len);
+ ctf_move_pos(pos, integer_declaration->len);
return rbo ? GUINT32_SWAP_LE_BE(v) : v;
}
case 64:
uint64_t v;
v = *(const uint64_t *)pos->base;
- move_pos(pos, integer_declaration->len);
+ ctf_move_pos(pos, integer_declaration->len);
return rbo ? GUINT64_SWAP_LE_BE(v) : v;
}
default:
}
static
-int64_t _aligned_int_read(struct stream_pos *pos,
- const struct declaration_integer *integer_declaration)
+int64_t _aligned_int_read(struct stream_pos *ppos,
+ const struct declaration_integer *integer_declaration)
{
+ struct ctf_stream_pos *pos = ctf_pos(ppos);
int rbo = (integer_declaration->byte_order != BYTE_ORDER); /* reverse byte order */
- align_pos(pos, integer_declaration->p.alignment);
+ ctf_align_pos(pos, integer_declaration->p.alignment);
assert(!(pos->offset % CHAR_BIT));
switch (integer_declaration->len) {
case 8:
int8_t v;
v = *(const int8_t *)pos->base;
- move_pos(pos, integer_declaration->len);
+ ctf_move_pos(pos, integer_declaration->len);
return v;
}
case 16:
int16_t v;
v = *(const int16_t *)pos->base;
- move_pos(pos, integer_declaration->len);
+ ctf_move_pos(pos, integer_declaration->len);
return rbo ? GUINT16_SWAP_LE_BE(v) : v;
}
case 32:
int32_t v;
v = *(const int32_t *)pos->base;
- move_pos(pos, integer_declaration->len);
+ ctf_move_pos(pos, integer_declaration->len);
return rbo ? GUINT32_SWAP_LE_BE(v) : v;
}
case 64:
int64_t v;
v = *(const int64_t *)pos->base;
- move_pos(pos, integer_declaration->len);
+ ctf_move_pos(pos, integer_declaration->len);
return rbo ? GUINT64_SWAP_LE_BE(v) : v;
}
default:
}
static
-void _aligned_uint_write(struct stream_pos *pos,
- const struct declaration_integer *integer_declaration,
- uint64_t v)
+void _aligned_uint_write(struct stream_pos *ppos,
+ const struct declaration_integer *integer_declaration,
+ uint64_t v)
{
+ struct ctf_stream_pos *pos = ctf_pos(ppos);
int rbo = (integer_declaration->byte_order != BYTE_ORDER); /* reverse byte order */
- align_pos(pos, integer_declaration->p.alignment);
+ ctf_align_pos(pos, integer_declaration->p.alignment);
assert(!(pos->offset % CHAR_BIT));
if (pos->dummy)
goto end;
switch (integer_declaration->len) {
- case 8: *(uint8_t *) get_pos_addr(pos) = (uint8_t) v;
+ case 8: *(uint8_t *) ctf_get_pos_addr(pos) = (uint8_t) v;
break;
case 16:
- *(uint16_t *) get_pos_addr(pos) = rbo ?
+ *(uint16_t *) ctf_get_pos_addr(pos) = rbo ?
GUINT16_SWAP_LE_BE((uint16_t) v) :
(uint16_t) v;
break;
case 32:
- *(uint32_t *) get_pos_addr(pos) = rbo ?
+ *(uint32_t *) ctf_get_pos_addr(pos) = rbo ?
GUINT32_SWAP_LE_BE((uint32_t) v) :
(uint32_t) v;
break;
case 64:
- *(uint64_t *) get_pos_addr(pos) = rbo ?
+ *(uint64_t *) ctf_get_pos_addr(pos) = rbo ?
GUINT64_SWAP_LE_BE(v) : v;
break;
default:
assert(0);
}
end:
- move_pos(pos, integer_declaration->len);
+ ctf_move_pos(pos, integer_declaration->len);
}
static
-void _aligned_int_write(struct stream_pos *pos,
- const struct declaration_integer *integer_declaration,
- int64_t v)
+void _aligned_int_write(struct stream_pos *ppos,
+ const struct declaration_integer *integer_declaration,
+ int64_t v)
{
+ struct ctf_stream_pos *pos = ctf_pos(ppos);
int rbo = (integer_declaration->byte_order != BYTE_ORDER); /* reverse byte order */
- align_pos(pos, integer_declaration->p.alignment);
+ ctf_align_pos(pos, integer_declaration->p.alignment);
assert(!(pos->offset % CHAR_BIT));
if (pos->dummy)
goto end;
switch (integer_declaration->len) {
- case 8: *(int8_t *) get_pos_addr(pos) = (int8_t) v;
+ case 8: *(int8_t *) ctf_get_pos_addr(pos) = (int8_t) v;
break;
case 16:
- *(int16_t *) get_pos_addr(pos) = rbo ?
+ *(int16_t *) ctf_get_pos_addr(pos) = rbo ?
GUINT16_SWAP_LE_BE((int16_t) v) :
(int16_t) v;
break;
case 32:
- *(int32_t *) get_pos_addr(pos) = rbo ?
+ *(int32_t *) ctf_get_pos_addr(pos) = rbo ?
GUINT32_SWAP_LE_BE((int32_t) v) :
(int32_t) v;
break;
case 64:
- *(int64_t *) get_pos_addr(pos) = rbo ?
+ *(int64_t *) ctf_get_pos_addr(pos) = rbo ?
GUINT64_SWAP_LE_BE(v) : v;
break;
default:
assert(0);
}
end:
- move_pos(pos, integer_declaration->len);
+ ctf_move_pos(pos, integer_declaration->len);
return;
}
-uint64_t ctf_uint_read(struct stream_pos *pos,
+uint64_t ctf_uint_read(struct stream_pos *ppos,
const struct declaration_integer *integer_declaration)
{
+ struct ctf_stream_pos *pos = ctf_pos(ppos);
uint64_t v = 0;
- align_pos(pos, integer_declaration->p.alignment);
+ ctf_align_pos(pos, integer_declaration->p.alignment);
if (integer_declaration->byte_order == LITTLE_ENDIAN)
bt_bitfield_read_le(pos->base, unsigned long, pos->offset,
integer_declaration->len, &v);
else
bt_bitfield_read_be(pos->base, unsigned long, pos->offset,
integer_declaration->len, &v);
- move_pos(pos, integer_declaration->len);
+ ctf_move_pos(pos, integer_declaration->len);
return v;
}
-int64_t ctf_int_read(struct stream_pos *pos,
+int64_t ctf_int_read(struct stream_pos *ppos,
const struct declaration_integer *integer_declaration)
{
+ struct ctf_stream_pos *pos = ctf_pos(ppos);
int64_t v = 0;
- align_pos(pos, integer_declaration->p.alignment);
+ ctf_align_pos(pos, integer_declaration->p.alignment);
if (integer_declaration->byte_order == LITTLE_ENDIAN)
bt_bitfield_read_le(pos->base, unsigned long, pos->offset,
integer_declaration->len, &v);
else
bt_bitfield_read_be(pos->base, unsigned long, pos->offset,
integer_declaration->len, &v);
- move_pos(pos, integer_declaration->len);
+ ctf_move_pos(pos, integer_declaration->len);
return v;
}
-void ctf_uint_write(struct stream_pos *pos,
- const struct declaration_integer *integer_declaration,
- uint64_t v)
+void ctf_uint_write(struct stream_pos *ppos,
+ const struct declaration_integer *integer_declaration,
+ uint64_t v)
{
- align_pos(pos, integer_declaration->p.alignment);
+ struct ctf_stream_pos *pos = ctf_pos(ppos);
+
+ ctf_align_pos(pos, integer_declaration->p.alignment);
if (pos->dummy)
goto end;
if (integer_declaration->byte_order == LITTLE_ENDIAN)
bt_bitfield_write_be(pos->base, unsigned long, pos->offset,
integer_declaration->len, v);
end:
- move_pos(pos, integer_declaration->len);
+ ctf_move_pos(pos, integer_declaration->len);
}
-void ctf_int_write(struct stream_pos *pos,
- const struct declaration_integer *integer_declaration,
- int64_t v)
+void ctf_int_write(struct stream_pos *ppos,
+ const struct declaration_integer *integer_declaration,
+ int64_t v)
{
- align_pos(pos, integer_declaration->p.alignment);
+ struct ctf_stream_pos *pos = ctf_pos(ppos);
+
+ ctf_align_pos(pos, integer_declaration->p.alignment);
if (pos->dummy)
goto end;
if (integer_declaration->byte_order == LITTLE_ENDIAN)
bt_bitfield_write_be(pos->base, unsigned long, pos->offset,
integer_declaration->len, v);
end:
- move_pos(pos, integer_declaration->len);
+ ctf_move_pos(pos, integer_declaration->len);
}
#include <babeltrace/ctf/types.h>
-void ctf_sequence_begin(struct stream_pos *pos,
+void ctf_sequence_begin(struct stream_pos *ppos,
const struct declaration_sequence *sequence_declaration)
{
- align_pos(pos, sequence_declaration->p.alignment);
+ struct ctf_stream_pos *pos = ctf_pos(ppos);
+
+ ctf_align_pos(pos, sequence_declaration->p.alignment);
}
void ctf_sequence_end(struct stream_pos *pos,
#include <limits.h> /* C99 limits */
#include <string.h>
-void ctf_string_copy(struct stream_pos *dest, struct stream_pos *src,
+void ctf_string_copy(struct stream_pos *pdest, struct stream_pos *psrc,
const struct declaration_string *string_declaration)
{
+ struct ctf_stream_pos *dest = ctf_pos(pdest);
+ struct ctf_stream_pos *src = ctf_pos(psrc);
size_t len;
char *destaddr, *srcaddr;
- align_pos(src, string_declaration->p.alignment);
- srcaddr = get_pos_addr(src);
+ ctf_align_pos(src, string_declaration->p.alignment);
+ srcaddr = ctf_get_pos_addr(src);
len = strlen(srcaddr) + 1;
if (dest->dummy)
goto end;
- align_pos(dest, string_declaration->p.alignment);
- destaddr = get_pos_addr(dest);
+ ctf_align_pos(dest, string_declaration->p.alignment);
+ destaddr = ctf_get_pos_addr(dest);
strcpy(destaddr, srcaddr);
end:
- move_pos(dest, len);
- move_pos(src, len);
+ ctf_move_pos(dest, len);
+ ctf_move_pos(src, len);
}
-void ctf_string_read(char **dest, struct stream_pos *src,
+void ctf_string_read(char **dest, struct stream_pos *psrc,
const struct declaration_string *string_declaration)
{
+ struct ctf_stream_pos *src = ctf_pos(psrc);
size_t len;
char *srcaddr;
- align_pos(src, string_declaration->p.alignment);
- srcaddr = get_pos_addr(src);
+ ctf_align_pos(src, string_declaration->p.alignment);
+ srcaddr = ctf_get_pos_addr(src);
len = strlen(srcaddr) + 1;
*dest = g_realloc(*dest, len);
strcpy(*dest, srcaddr);
- move_pos(src, len);
+ ctf_move_pos(src, len);
}
-void ctf_string_write(struct stream_pos *dest, const char *src,
+void ctf_string_write(struct stream_pos *pdest, const char *src,
const struct declaration_string *string_declaration)
{
+ struct ctf_stream_pos *dest = ctf_pos(pdest);
size_t len;
char *destaddr;
- align_pos(dest, string_declaration->p.alignment);
+ ctf_align_pos(dest, string_declaration->p.alignment);
len = strlen(src) + 1;
if (dest->dummy)
goto end;
- destaddr = get_pos_addr(dest);
+ destaddr = ctf_get_pos_addr(dest);
strcpy(destaddr, src);
end:
- move_pos(dest, len);
+ ctf_move_pos(dest, len);
}
void ctf_string_free_temp(char *string)
#include <babeltrace/ctf/types.h>
-void ctf_struct_begin(struct stream_pos *pos,
+void ctf_struct_begin(struct stream_pos *ppos,
const struct declaration_struct *struct_declaration)
{
- align_pos(pos, struct_declaration->p.alignment);
+ struct ctf_stream_pos *pos = ctf_pos(ppos);
+
+ ctf_align_pos(pos, struct_declaration->p.alignment);
}
-void ctf_struct_end(struct stream_pos *pos,
+void ctf_struct_end(struct stream_pos *ppos,
const struct declaration_struct *struct_declaration)
{
}
printf("[debug] " fmt, ## args); \
} while (0)
+struct trace_descriptor;
+
+int copy_trace(struct trace_descriptor *td_write, struct trace_descriptor *td_read);
+
#endif
--- /dev/null
+#ifndef _BABELTRACE_CTF_TEXT_TYPES_H
+#define _BABELTRACE_CTF_TEXT_TYPES_H
+
+/*
+ * Common Trace Format (Text Output)
+ *
+ * Type header
+ *
+ * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@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.
+ */
+
+#include <sys/mman.h>
+#include <errno.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <glib.h>
+#include <babeltrace/babeltrace.h>
+#include <babeltrace/types.h>
+
+struct ctf_text_stream_pos {
+ struct trace_descriptor parent;
+ FILE *fp; /* File pointer. NULL if unset. */
+};
+
+/*
+ * IMPORTANT: All lengths (len) and offsets (start, end) are expressed in bits,
+ * *not* in bytes.
+ *
+ * All write primitives, as well as read for dynamically sized entities, can
+ * receive a NULL ptr/dest parameter. In this case, no write is performed, but
+ * the size is returned.
+ */
+
+void ctf_text_uint_write(struct stream_pos *pos,
+ const struct declaration_integer *integer_declaration,
+ uint64_t v);
+void ctf_text_int_write(struct stream_pos *pos,
+ const struct declaration_integer *integer_declaration,
+ int64_t v);
+
+void ctf_text_double_write(struct stream_pos *pos,
+ const struct declaration_float *dest,
+ double v);
+void ctf_text_ldouble_write(struct stream_pos *pos,
+ const struct declaration_float *dest,
+ long double v);
+
+void ctf_text_string_write(struct stream_pos *dest, const char *src,
+ const struct declaration_string *string_declaration);
+
+void ctf_text_enum_write(struct stream_pos *pos,
+ const struct declaration_enum *dest,
+ GQuark q);
+void ctf_text_struct_begin(struct stream_pos *pos,
+ const struct declaration_struct *struct_declaration);
+void ctf_text_struct_end(struct stream_pos *pos,
+ const struct declaration_struct *struct_declaration);
+void ctf_text_variant_begin(struct stream_pos *pos,
+ const struct declaration_variant *variant_declaration);
+void ctf_text_variant_end(struct stream_pos *pos,
+ const struct declaration_variant *variant_declaration);
+void ctf_text_array_begin(struct stream_pos *pos,
+ const struct declaration_array *array_declaration);
+void ctf_text_array_end(struct stream_pos *pos,
+ const struct declaration_array *array_declaration);
+void ctf_text_sequence_begin(struct stream_pos *pos,
+ const struct declaration_sequence *sequence_declaration);
+void ctf_text_sequence_end(struct stream_pos *pos,
+ const struct declaration_sequence *sequence_declaration);
+
+#endif /* _BABELTRACE_CTF_TEXT_TYPES_H */
*/
#include <babeltrace/types.h>
+#include <babeltrace/format.h>
#include <babeltrace/ctf/types.h>
#include <sys/types.h>
#include <dirent.h>
struct ctf_file_stream {
uint64_t stream_id;
struct ctf_stream *stream;
- struct stream_pos pos; /* current stream position */
+ struct ctf_stream_pos pos; /* current stream position */
};
#define CTF_TRACE_SET_FIELD(ctf_trace, field) \
struct ctf_trace {
+ struct trace_descriptor parent;
/* root scope */
struct declaration_scope *root_declaration_scope;
};
/*
- * Always update stream_pos with move_pos and init_pos.
+ * Always update ctf_stream_pos with ctf_move_pos and ctf_init_pos.
*/
-struct stream_pos {
+struct ctf_stream_pos {
+ struct stream_pos parent;
int fd; /* backing file fd. -1 if unset. */
GArray *packet_index; /* contains struct packet_index */
int prot; /* mmap protection */
int dummy; /* dummy position, for length calculation */
};
+static inline
+struct ctf_stream_pos *ctf_pos(struct stream_pos *pos)
+{
+ return container_of(pos, struct ctf_stream_pos, parent);
+}
+
/*
* IMPORTANT: All lengths (len) and offsets (start, end) are expressed in bits,
* *not* in bytes.
void ctf_sequence_end(struct stream_pos *pos,
const struct declaration_sequence *sequence_declaration);
-void move_pos_slow(struct stream_pos *pos, size_t offset);
+void ctf_move_pos_slow(struct ctf_stream_pos *pos, size_t offset);
-void init_pos(struct stream_pos *pos, int fd);
-void fini_pos(struct stream_pos *pos);
+void ctf_init_pos(struct ctf_stream_pos *pos, int fd);
+void ctf_fini_pos(struct ctf_stream_pos *pos);
/*
* move_pos - move position of a relative bit offset
* TODO: allow larger files by updating base too.
*/
static inline
-void move_pos(struct stream_pos *pos, size_t bit_offset)
+void ctf_move_pos(struct ctf_stream_pos *pos, size_t bit_offset)
{
if (pos->fd >= 0) {
if (((pos->prot == PROT_READ)
&& (pos->offset + bit_offset >= pos->content_size))
|| ((pos->prot == PROT_WRITE)
&& (pos->offset + bit_offset >= pos->packet_size))) {
- move_pos_slow(pos, bit_offset);
+ ctf_move_pos_slow(pos, bit_offset);
return;
}
}
* TODO: allow larger files by updating base too.
*/
static inline
-void align_pos(struct stream_pos *pos, size_t bit_offset)
+void ctf_align_pos(struct ctf_stream_pos *pos, size_t bit_offset)
{
- move_pos(pos, offset_align(pos->offset, bit_offset));
+ ctf_move_pos(pos, offset_align(pos->offset, bit_offset));
}
static inline
-char *get_pos_addr(struct stream_pos *pos)
+char *ctf_get_pos_addr(struct ctf_stream_pos *pos)
{
/* Only makes sense to get the address after aligning on CHAR_BIT */
assert(!(pos->offset % CHAR_BIT));
}
static inline
-void dummy_pos(struct stream_pos *pos, struct stream_pos *dummy)
+void ctf_dummy_pos(struct ctf_stream_pos *pos, struct ctf_stream_pos *dummy)
{
- memcpy(dummy, pos, sizeof(struct stream_pos));
+ memcpy(dummy, pos, sizeof(struct ctf_stream_pos));
dummy->dummy = 1;
dummy->fd = -1;
}
* Returns 0 for success, negative error otherwise.
*/
static inline
-int pos_packet(struct stream_pos *dummy)
+int ctf_pos_packet(struct ctf_stream_pos *dummy)
{
if (dummy->offset > dummy->packet_size)
return -ENOSPC;
}
static inline
-void pos_pad_packet(struct stream_pos *pos)
+void ctf_pos_pad_packet(struct ctf_stream_pos *pos)
{
- move_pos(pos, pos->packet_size - pos->offset);
+ ctf_move_pos(pos, pos->packet_size - pos->offset);
}
#endif /* _BABELTRACE_CTF_TYPES_H */
#include <stdio.h>
#include <glib.h>
-struct trace_descriptor;
+/* Parent trace descriptor */
+struct trace_descriptor {
+};
struct format {
GQuark name;
struct format;
struct definition;
+/* Parent of per-plugin positions */
+struct stream_pos {
+};
+
/* type scope */
struct declaration_scope {
/* Hash table mapping type name GQuark to "struct declaration" */
static uuid_t s_uuid;
static
-void write_packet_header(struct stream_pos *pos, uuid_t uuid)
+void write_packet_header(struct ctf_stream_pos *pos, uuid_t uuid)
{
- struct stream_pos dummy;
+ struct ctf_stream_pos dummy;
/* magic */
- dummy_pos(pos, &dummy);
- align_pos(&dummy, sizeof(uint32_t) * CHAR_BIT);
- move_pos(&dummy, sizeof(uint32_t) * CHAR_BIT);
- assert(!pos_packet(&dummy));
+ 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));
- align_pos(pos, sizeof(uint32_t) * CHAR_BIT);
- *(uint32_t *) get_pos_addr(pos) = 0xC1FC1FC1;
- move_pos(pos, sizeof(uint32_t) * CHAR_BIT);
+ 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);
/* trace_uuid */
- dummy_pos(pos, &dummy);
- align_pos(&dummy, sizeof(uint8_t) * CHAR_BIT);
- move_pos(&dummy, 16 * CHAR_BIT);
- assert(!pos_packet(&dummy));
-
- align_pos(pos, sizeof(uint8_t) * CHAR_BIT);
- memcpy(get_pos_addr(pos), uuid, 16);
- move_pos(pos, 16 * CHAR_BIT);
+ 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, 16);
+ ctf_move_pos(pos, 16 * CHAR_BIT);
}
static
-void write_packet_context(struct stream_pos *pos)
+void write_packet_context(struct ctf_stream_pos *pos)
{
- struct stream_pos dummy;
+ struct ctf_stream_pos dummy;
/* content_size */
- dummy_pos(pos, &dummy);
- align_pos(&dummy, sizeof(uint32_t) * CHAR_BIT);
- move_pos(&dummy, sizeof(uint32_t) * CHAR_BIT);
- assert(!pos_packet(&dummy));
+ 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));
- align_pos(pos, sizeof(uint32_t) * CHAR_BIT);
- *(uint32_t *) get_pos_addr(pos) = -1U; /* Not known yet */
- pos->content_size_loc = (uint32_t *) get_pos_addr(pos);
- move_pos(pos, sizeof(uint32_t) * CHAR_BIT);
+ ctf_align_pos(pos, sizeof(uint32_t) * CHAR_BIT);
+ *(uint32_t *) ctf_get_pos_addr(pos) = -1U; /* Not known yet */
+ pos->content_size_loc = (uint32_t *) ctf_get_pos_addr(pos);
+ ctf_move_pos(pos, sizeof(uint32_t) * CHAR_BIT);
/* packet_size */
- dummy_pos(pos, &dummy);
- align_pos(&dummy, sizeof(uint32_t) * CHAR_BIT);
- move_pos(&dummy, sizeof(uint32_t) * CHAR_BIT);
- assert(!pos_packet(&dummy));
+ 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));
- align_pos(pos, sizeof(uint32_t) * CHAR_BIT);
- *(uint32_t *) get_pos_addr(pos) = pos->packet_size;
- move_pos(pos, sizeof(uint32_t) * CHAR_BIT);
+ ctf_align_pos(pos, sizeof(uint32_t) * CHAR_BIT);
+ *(uint32_t *) ctf_get_pos_addr(pos) = pos->packet_size;
+ ctf_move_pos(pos, sizeof(uint32_t) * CHAR_BIT);
}
static
-void trace_string(char *line, struct stream_pos *pos, size_t len)
+void trace_string(char *line, struct ctf_stream_pos *pos, size_t len)
{
- struct stream_pos dummy;
+ struct ctf_stream_pos dummy;
int attempt = 0;
printf_debug("read: %s\n", line);
retry:
- dummy_pos(pos, &dummy);
- align_pos(&dummy, sizeof(uint8_t) * CHAR_BIT);
- move_pos(&dummy, len * CHAR_BIT);
- if (pos_packet(&dummy)) {
+ ctf_dummy_pos(pos, &dummy);
+ ctf_align_pos(&dummy, sizeof(uint8_t) * CHAR_BIT);
+ ctf_move_pos(&dummy, len * CHAR_BIT);
+ if (ctf_pos_packet(&dummy)) {
/* TODO write content size */
- pos_pad_packet(pos);
+ ctf_pos_pad_packet(pos);
write_packet_header(pos, s_uuid);
write_packet_context(pos);
if (attempt++ == 1) {
goto retry;
}
- align_pos(pos, sizeof(uint8_t) * CHAR_BIT);
- memcpy(get_pos_addr(pos), line, len);
- move_pos(pos, len * CHAR_BIT);
+ ctf_align_pos(pos, sizeof(uint8_t) * CHAR_BIT);
+ memcpy(ctf_get_pos_addr(pos), line, len);
+ ctf_move_pos(pos, len * CHAR_BIT);
}
static
void trace_text(FILE *input, int output)
{
- struct stream_pos pos;
+ struct ctf_stream_pos pos;
ssize_t len;
char *line = NULL, *nl;
size_t linesize;
- init_pos(&pos, output);
+ ctf_init_pos(&pos, output);
write_packet_header(&pos, s_uuid);
write_packet_context(&pos);
*nl = '\0';
trace_string(line, &pos, nl - line + 1);
}
- fini_pos(&pos);
+ ctf_fini_pos(&pos);
}
int main(int argc, char **argv)