Add a common, internal CTF serialization library; make CTF writer use it
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 5 Mar 2019 20:10:17 +0000 (15:10 -0500)
committerFrancis Deslauriers <francis.deslauriers@efficios.com>
Thu, 2 May 2019 20:50:15 +0000 (20:50 +0000)
commit013f35c63d8c005d7ffc8c4e52002c4661b98b38
tree8686d649a12220a4f33dad768a219ab6f82aab34
parentbd1a54fe26dea99d5f46714827d6c2fa970810bd
Add a common, internal CTF serialization library; make CTF writer use it

This patch adds the `bt_ctfser` API and implementation, a generic,
common, and internal CTF stream file serialization library. This patch
also makes CTF writer use this library instead of its internal
serialization API (on which `bt_ctfser` is based). The purpose of this
partition is to make the `sink.ctf.fs` component class depend on
`bt_ctfser` without depending on CTF writer (as the trace IR and the CTF
writer IR objects are not compatible anymore) while still reusing code.

After initializing a `struct bt_ctfser` with bt_ctfser_init(), you need
to call bt_ctfser_open_packet() to open a packet, then call one of the
bt_ctfser_write_*() functions to write individual fields or
bt_ctfser_align_offset_in_current_packet() to align the offset within
the current packet. The serialization and alignment functions resize the
current packet as needed, which is why they can fail if resizing is not
possible. Then call bt_ctfser_close_current_packet() with the required
packet size. Repeat for each packet to append to the stream file. When
done, call bt_ctfser_fini(). bt_ctfser_fini() truncates the stream file
as needed to remove any data after the last closed packet.

It is common for the packet context to be written after writing the
last event record because this is when you know the effective content
size. For this, the bt_ctfser_get_offset_in_current_packet_bits()
and bt_ctfser_set_offset_in_current_packet_bits() functions exist to
control the current offset within the current packet. The typical
packet writing algorithm is:

1. Open the packet.
2. Write the packet header.
3. Save the current offset (packet context offset).
4. Write the packet context, potentially with wrong/incomplete fields.
5. Write each event record.
6. Get the current offset which is the packet's content size, and also
   decide on a packet's total size (greater than content size).
7. Go to the (saved) packet context offset.
8. Write the packet context with updated fields.

Fast path serialization and alignment functions are `static inline`.

There is minimal verbose logging which always indicate the stream file's
path and its numeric descriptor.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
19 files changed:
Makefile.am
configure.ac
ctfser/Makefile.am [new file with mode: 0644]
ctfser/ctfser.c [new file with mode: 0644]
ctfser/logging.c [new file with mode: 0644]
ctfser/logging.h [new file with mode: 0644]
include/Makefile.am
include/babeltrace/ctf-writer/event-internal.h
include/babeltrace/ctf-writer/fields-internal.h
include/babeltrace/ctf-writer/serialize-internal.h [deleted file]
include/babeltrace/ctf-writer/stream-internal.h
include/babeltrace/ctfser-internal.h [new file with mode: 0644]
lib/Makefile.am
lib/ctf-writer/Makefile.am
lib/ctf-writer/event.c
lib/ctf-writer/fields.c
lib/ctf-writer/serialize.c [deleted file]
lib/ctf-writer/stream.c
lib/ctf-writer/writer.c
This page took 0.026091 seconds and 4 git commands to generate.