- break;
- case LTTNG_EVENT_MMAP:
- /* read the used subbuffer size */
- err = kernctl_get_padded_subbuf_size(infd, &len);
- if (err != 0) {
- errno = -err;
- perror("Getting sub-buffer len failed.");
- ret = -err;
- goto end;
- }
- /* write the subbuffer to the tracefile */
- ret = lttng_consumer_on_read_subbuffer_mmap(ctx, stream, len);
- if (ret != len) {
- /*
- * display the error but continue processing to try
- * to release the subbuffer
- */
- ERR("Error writing to tracefile");
- }
- break;
- default:
- ERR("Unknown output method");
- ret = -1;
+ /* splice the subbuffer to the tracefile */
+ ret = lttng_consumer_on_read_subbuffer_splice(ctx, stream, subbuf_size,
+ padding);
+ /*
+ * XXX: Splice does not support network streaming so the return value
+ * is simply checked against subbuf_size and not like the mmap() op.
+ */
+ if (ret != subbuf_size) {
+ /*
+ * display the error but continue processing to try
+ * to release the subbuffer
+ */
+ ERR("Error splicing to tracefile (ret: %zd != len: %lu)",
+ ret, subbuf_size);
+ }
+ break;
+ case LTTNG_EVENT_MMAP:
+ /* Get subbuffer size without padding */
+ err = kernctl_get_subbuf_size(infd, &subbuf_size);
+ if (err != 0) {
+ errno = -err;
+ perror("Getting sub-buffer len failed.");
+ ret = err;
+ goto end;
+ }
+
+ /* Make sure the tracer is not gone mad on us! */
+ assert(len >= subbuf_size);
+
+ padding = len - subbuf_size;
+
+ /* write the subbuffer to the tracefile */
+ ret = lttng_consumer_on_read_subbuffer_mmap(ctx, stream, subbuf_size,
+ padding);
+ /*
+ * The mmap operation should write subbuf_size amount of data when
+ * network streaming or the full padding (len) size when we are _not_
+ * streaming.
+ */
+ if ((ret != subbuf_size && stream->net_seq_idx != -1) ||
+ (ret != len && stream->net_seq_idx == -1)) {
+ /*
+ * Display the error but continue processing to try to release the
+ * subbuffer
+ */
+ ERR("Error writing to tracefile "
+ "(ret: %zd != len: %lu != subbuf_size: %lu)",
+ ret, len, subbuf_size);
+ }
+ break;
+ default:
+ ERR("Unknown output method");
+ ret = -1;