Common Trace Format 2 generation
[deliverable/lttng-tools.git] / src / common / consumer / metadata-bucket.cpp
index 160185def7b77fe5e05ff5434c486eae9c405092..6dd26675e615ba3770259f56ab9e9f4fa539fcea 100644 (file)
@@ -5,13 +5,13 @@
  *
  */
 
-#include "metadata-bucket.h"
+#include "metadata-bucket.hpp"
 
-#include <common/buffer-view.h>
-#include <common/consumer/consumer.h>
-#include <common/dynamic-buffer.h>
-#include <common/macros.h>
-#include <common/error.h>
+#include <common/buffer-view.hpp>
+#include <common/consumer/consumer.hpp>
+#include <common/dynamic-buffer.hpp>
+#include <common/macros.hpp>
+#include <common/error.hpp>
 
 struct metadata_bucket {
        struct lttng_dynamic_buffer content;
@@ -62,6 +62,25 @@ void metadata_bucket_reset(struct metadata_bucket *bucket)
        bucket->buffer_count = 0;
 }
 
+struct metadata_packet_header {
+       uint32_t magic;                 /* 0x75D11D57 */
+       uint8_t  uuid[16];              /* Unique Universal Identifier */
+       uint32_t checksum;              /* 0 if unused */
+       uint32_t content_size;          /* in bits */
+       uint32_t packet_size;           /* in bits */
+       uint8_t  compression_scheme;    /* 0 if unused */
+       uint8_t  encryption_scheme;     /* 0 if unused */
+       uint8_t  checksum_scheme;       /* 0 if unused */
+       uint8_t  major;                 /* CTF spec major version number */
+       uint8_t  minor;                 /* CTF spec minor version number */
+       uint8_t  header_end[0];
+};
+
+static size_t metadata_length(void)
+{
+       return offsetof(struct metadata_packet_header, header_end);
+}
+
 enum metadata_bucket_status metadata_bucket_fill(struct metadata_bucket *bucket,
                const struct stream_subbuffer *buffer)
 {
@@ -71,10 +90,6 @@ enum metadata_bucket_status metadata_bucket_fill(struct metadata_bucket *bucket,
        enum metadata_bucket_status status;
        const bool should_flush =
                        LTTNG_OPTIONAL_GET(buffer->info.metadata.coherent);
-       const size_t padding_this_buffer =
-                       buffer->info.metadata.padded_subbuf_size -
-                       buffer->info.metadata.subbuf_size;
-       size_t flush_size;
 
        DBG("Metadata bucket filled with %zu bytes buffer view, sub-buffer size: %lu, padded sub-buffer size: %lu, coherent: %s",
                        buffer->buffer.buffer.size,
@@ -86,22 +101,20 @@ enum metadata_bucket_status metadata_bucket_fill(struct metadata_bucket *bucket,
         * flushed, don't copy it unecessarily; just flush it directly.
         */
        if (!should_flush || bucket->buffer_count != 0) {
+               struct lttng_buffer_view append_view;
+
                /*
-                * Append the _padded_ subbuffer since they are combined
+                * Append the subbuffer since they are combined
                 * into a single "virtual" subbuffer that will be
                 * flushed at once.
                 *
-                * This means that some padding will be sent over the
-                * network, but should not represent a large amount
-                * of data as incoherent subbuffers are typically
-                * pretty full.
-                *
-                * The padding of the last subbuffer (coherent) added to
-                * the bucket is not sent, which is what really matters
-                * from an efficiency point of view.
+                * Peel off metadata header and padding, only preserve
+                * the json-seq metadata.
                 */
+               append_view = lttng_buffer_view_from_view(&buffer->buffer.buffer, metadata_length(),
+                               buffer->info.metadata.subbuf_size - metadata_length());
                ret = lttng_dynamic_buffer_append_view(
-                       &bucket->content, &buffer->buffer.buffer);
+                       &bucket->content, &append_view);
                if (ret) {
                        status = METADATA_BUCKET_STATUS_ERROR;
                        goto end;
@@ -116,14 +129,8 @@ enum metadata_bucket_status metadata_bucket_fill(struct metadata_bucket *bucket,
 
        flushed_view = bucket->content.size != 0 ?
                lttng_buffer_view_from_dynamic_buffer(&bucket->content, 0, -1) :
-               lttng_buffer_view_from_view(&buffer->buffer.buffer, 0, -1);
-
-       /*
-        * The flush is done with the size of all padded sub-buffers, except
-        * for the last one which we can safely "trim". The padding of the last
-        * packet will be reconstructed by the relay daemon.
-        */
-       flush_size = flushed_view.size - padding_this_buffer;
+               lttng_buffer_view_from_view(&buffer->buffer.buffer, metadata_length(),
+                               buffer->info.metadata.subbuf_size - metadata_length());
 
        flushed_subbuffer = (typeof(flushed_subbuffer)) {
                .buffer = {
@@ -131,7 +138,7 @@ enum metadata_bucket_status metadata_bucket_fill(struct metadata_bucket *bucket,
                },
                .info = {
                        .metadata = {
-                               .subbuf_size = flush_size,
+                               .subbuf_size = flushed_view.size,
                                .padded_subbuf_size = flushed_view.size,
                                .version = buffer->info.metadata.version,
                                .coherent = buffer->info.metadata.coherent,
This page took 0.026706 seconds and 5 git commands to generate.