{
struct lttng_viewer_cmd cmd;
struct lttng_viewer_connect connect;
+ const size_t cmd_buf_len = sizeof(cmd) + sizeof(connect);
+ char cmd_buf[cmd_buf_len];
int ret;
ssize_t ret_len;
connect.minor = htobe32(LTTNG_LIVE_MINOR);
connect.type = htobe32(LTTNG_VIEWER_CLIENT_COMMAND);
- ret_len = lttng_live_send(ctx->control_sock, &cmd, sizeof(cmd));
- if (ret_len < 0) {
- perror("[error] Error sending cmd");
- goto error;
- }
- assert(ret_len == sizeof(cmd));
+ /*
+ * Merge the cmd and connection request to prevent a write-write
+ * sequence on the TCP socket. Otherwise, a delayed ACK will prevent the
+ * second write to be performed quickly in presence of Nagle's algorithm.
+ */
+ memcpy(cmd_buf, &cmd, sizeof(cmd));
+ memcpy(cmd_buf + sizeof(cmd), &connect, sizeof(connect));
- ret_len = lttng_live_send(ctx->control_sock, &connect, sizeof(connect));
+ ret_len = lttng_live_send(ctx->control_sock, cmd_buf, cmd_buf_len);
if (ret_len < 0) {
- perror("[error] Error sending version");
+ perror("[error] Error sending cmd for establishing session");
goto error;
}
- assert(ret_len == sizeof(connect));
+ assert(ret_len == cmd_buf_len);
ret_len = lttng_live_recv(ctx->control_sock, &connect, sizeof(connect));
if (ret_len == 0) {
struct lttng_viewer_attach_session_request rq;
struct lttng_viewer_attach_session_response rp;
struct lttng_viewer_stream stream;
+ const size_t cmd_buf_len = sizeof(cmd) + sizeof(rq);
+ char cmd_buf[cmd_buf_len];
int ret, i;
ssize_t ret_len;
// rq.seek = htobe32(LTTNG_VIEWER_SEEK_BEGINNING);
rq.seek = htobe32(LTTNG_VIEWER_SEEK_LAST);
- ret_len = lttng_live_send(ctx->control_sock, &cmd, sizeof(cmd));
- if (ret_len < 0) {
- perror("[error] Error sending cmd");
- goto error;
- }
- assert(ret_len == sizeof(cmd));
+ /*
+ * Merge the cmd and connection request to prevent a write-write
+ * sequence on the TCP socket. Otherwise, a delayed ACK will prevent the
+ * second write to be performed quickly in presence of Nagle's algorithm.
+ */
+ memcpy(cmd_buf, &cmd, sizeof(cmd));
+ memcpy(cmd_buf + sizeof(cmd), &rq, sizeof(rq));
- ret_len = lttng_live_send(ctx->control_sock, &rq, sizeof(rq));
+ ret_len = lttng_live_send(ctx->control_sock, cmd_buf, cmd_buf_len);
if (ret_len < 0) {
- perror("[error] Error sending attach request");
+ perror("[error] Error sending attach command and request");
goto error;
}
- assert(ret_len == sizeof(rq));
+ assert(ret_len == cmd_buf_len);
ret_len = lttng_live_recv(ctx->control_sock, &rp, sizeof(rp));
if (ret_len == 0) {
struct lttng_live_viewer_stream *metadata;
char *metadata_buf = NULL;
+ if (!viewer_stream->ctf_trace->handle) {
+ printf_verbose("append_metadata: trace handle not ready yet.\n");
+ return 0;
+ }
+
printf_verbose("get_next_index: new metadata needed\n");
ret = get_new_metadata(ctx, viewer_stream, &metadata_buf);
if (ret < 0) {
struct lttng_viewer_cmd cmd;
struct lttng_viewer_get_packet rq;
struct lttng_viewer_trace_packet rp;
+ const size_t cmd_buf_len = sizeof(cmd) + sizeof(rq);
+ char cmd_buf[cmd_buf_len];
ssize_t ret_len;
int ret;
goto end;
}
- /*
- * Flush the output between attempts to grab a packet, thus
- * ensuring we flush at least at the periodical timer period.
- * This ensures the output remains reactive for interactive users and
- * that the output is flushed when redirected to a file by the shell.
- */
- if (fflush(LTTNG_LIVE_OUTPUT_FP) < 0) {
- perror("fflush");
- goto error;
- }
-
cmd.cmd = htobe32(LTTNG_VIEWER_GET_PACKET);
cmd.data_size = htobe64((uint64_t) sizeof(rq));
cmd.cmd_version = htobe32(0);
rq.offset = htobe64(offset);
rq.len = htobe32(len);
- ret_len = lttng_live_send(ctx->control_sock, &cmd, sizeof(cmd));
- if (ret_len < 0) {
- perror("[error] Error sending cmd");
- goto error;
- }
- assert(ret_len == sizeof(cmd));
+ /*
+ * Merge the cmd and connection request to prevent a write-write
+ * sequence on the TCP socket. Otherwise, a delayed ACK will prevent the
+ * second write to be performed quickly in presence of Nagle's algorithm.
+ */
+ memcpy(cmd_buf, &cmd, sizeof(cmd));
+ memcpy(cmd_buf + sizeof(cmd), &rq, sizeof(rq));
- ret_len = lttng_live_send(ctx->control_sock, &rq, sizeof(rq));
+ ret_len = lttng_live_send(ctx->control_sock, cmd_buf, cmd_buf_len);
if (ret_len < 0) {
- perror("[error] Error sending get_data_packet request");
+ perror("[error] Error sending get_data_packet cmd and request");
goto error;
}
- assert(ret_len == sizeof(rq));
+ assert(ret_len == cmd_buf_len);
ret_len = lttng_live_recv(ctx->control_sock, &rp, sizeof(rp));
if (ret_len == 0) {
struct lttng_viewer_metadata_packet rp;
char *data = NULL;
ssize_t ret_len;
+ const size_t cmd_buf_len = sizeof(cmd) + sizeof(rq);
+ char cmd_buf[cmd_buf_len];
if (lttng_live_should_quit()) {
ret = -1;
cmd.data_size = htobe64((uint64_t) sizeof(rq));
cmd.cmd_version = htobe32(0);
- ret_len = lttng_live_send(ctx->control_sock, &cmd, sizeof(cmd));
- if (ret_len < 0) {
- perror("[error] Error sending cmd");
- goto error;
- }
- assert(ret_len == sizeof(cmd));
+ /*
+ * Merge the cmd and connection request to prevent a write-write
+ * sequence on the TCP socket. Otherwise, a delayed ACK will prevent the
+ * second write to be performed quickly in presence of Nagle's algorithm.
+ */
+ memcpy(cmd_buf, &cmd, sizeof(cmd));
+ memcpy(cmd_buf + sizeof(cmd), &rq, sizeof(rq));
- ret_len = lttng_live_send(ctx->control_sock, &rq, sizeof(rq));
+ ret_len = lttng_live_send(ctx->control_sock, cmd_buf, cmd_buf_len);
if (ret_len < 0) {
- perror("[error] Error sending get_metadata request");
+ perror("[error] Error sending get_metadata cmd and request");
goto error;
}
- assert(ret_len == sizeof(rq));
+ assert(ret_len == cmd_buf_len);
ret_len = lttng_live_recv(ctx->control_sock, &rp, sizeof(rp));
if (ret_len == 0) {
int ret;
ssize_t ret_len;
struct lttng_viewer_index *rp = &viewer_stream->current_index;
+ const size_t cmd_buf_len = sizeof(cmd) + sizeof(rq);
+ char cmd_buf[cmd_buf_len];
cmd.cmd = htobe32(LTTNG_VIEWER_GET_NEXT_INDEX);
cmd.data_size = htobe64((uint64_t) sizeof(rq));
memset(&rq, 0, sizeof(rq));
rq.stream_id = htobe64(viewer_stream->id);
+ /*
+ * Merge the cmd and connection request to prevent a write-write
+ * sequence on the TCP socket. Otherwise, a delayed ACK will prevent the
+ * second write to be performed quickly in presence of Nagle's algorithm.
+ */
+ memcpy(cmd_buf, &cmd, sizeof(cmd));
+ memcpy(cmd_buf + sizeof(cmd), &rq, sizeof(rq));
retry:
if (lttng_live_should_quit()) {
ret = -1;
goto end;
}
- ret_len = lttng_live_send(ctx->control_sock, &cmd, sizeof(cmd));
+ ret_len = lttng_live_send(ctx->control_sock, &cmd_buf, cmd_buf_len);
if (ret_len < 0) {
- perror("[error] Error sending cmd");
+ perror("[error] Error sending get_next_index cmd and request");
goto error;
}
- assert(ret_len == sizeof(cmd));
-
- ret_len = lttng_live_send(ctx->control_sock, &rq, sizeof(rq));
- if (ret_len < 0) {
- perror("[error] Error sending get_next_index request");
- goto error;
- }
- assert(ret_len == sizeof(rq));
+ assert(ret_len == cmd_buf_len);
ret_len = lttng_live_recv(ctx->control_sock, rp, sizeof(*rp));
if (ret_len == 0) {
switch (be32toh(rp->status)) {
case LTTNG_VIEWER_INDEX_INACTIVE:
printf_verbose("get_next_index: inactive\n");
+
+ if (index->ts_cycles.timestamp_end ==
+ be64toh(rp->timestamp_end)) {
+ /* Already seen this timestamp. */
+ (void) poll(NULL, 0, ACTIVE_POLL_DELAY);
+ }
+
memset(index, 0, sizeof(struct packet_index));
index->ts_cycles.timestamp_end = be64toh(rp->timestamp_end);
*stream_id = be64toh(rp->stream_id);
}
if (cur_index->content_size == 0) {
+ /* Beacon packet index */
if (file_stream->parent.stream_class) {
file_stream->parent.cycles_timestamp =
cur_index->ts_cycles.timestamp_end;
file_stream->parent.real_timestamp = ctf_get_real_timestamp(
&file_stream->parent,
cur_index->ts_cycles.timestamp_end);
+
+ /*
+ * Duplicate the data from the previous index, because
+ * the one we just received is only a beacon with no
+ * relevant information except the timestamp_end. We
+ * don't need to keep this timestamp_end because we already
+ * updated the file_stream timestamps, so we only need
+ * to keep the last real index data as prev_index. That
+ * way, we keep the original prev timestamps and
+ * discarded events counter. This is the same behaviour
+ * as if we were reading a local trace, we would not
+ * have fake indexes between real indexes.
+ */
+ memcpy(cur_index, prev_index, sizeof(struct packet_index));
}
} else {
+ /* Real packet index */
if (file_stream->parent.stream_class) {
/* Convert the timestamps and append to the real_index. */
cur_index->ts_real.timestamp_begin = ctf_get_real_timestamp(
ctf_update_current_packet_index(&file_stream->parent,
prev_index, cur_index);
+ /*
+ * We need to check if we are in trace read or called
+ * from packet indexing. In this last case, the
+ * collection is not there, so we cannot print the
+ * timestamps.
+ */
+ if ((&file_stream->parent)->stream_class->trace->parent.collection) {
+ ctf_print_discarded_lost(stderr, &file_stream->parent);
+ }
+
file_stream->parent.cycles_timestamp =
cur_index->ts_cycles.timestamp_begin;
file_stream->parent.real_timestamp =
cur_index->ts_real.timestamp_begin;
}
+ /*
+ * Flush the output between attempts to grab a packet, thus
+ * ensuring we flush at least at the periodical timer period.
+ * This ensures the output remains reactive for interactive users and
+ * that the output is flushed when redirected to a file by the shell.
+ */
+ if (fflush(LTTNG_LIVE_OUTPUT_FP) < 0) {
+ perror("fflush");
+ goto end;
+ }
+
if (pos->packet_size == 0 || pos->offset == EOF) {
goto end;
}
int ret, i, nb_streams = 0;
ssize_t ret_len;
uint32_t stream_count;
+ const size_t cmd_buf_len = sizeof(cmd) + sizeof(rq);
+ char cmd_buf[cmd_buf_len];
if (lttng_live_should_quit()) {
ret = -1;
memset(&rq, 0, sizeof(rq));
rq.session_id = htobe64(id);
- ret_len = lttng_live_send(ctx->control_sock, &cmd, sizeof(cmd));
- if (ret_len < 0) {
- perror("[error] Error sending cmd");
- goto error;
- }
- assert(ret_len == sizeof(cmd));
+ /*
+ * Merge the cmd and connection request to prevent a write-write
+ * sequence on the TCP socket. Otherwise, a delayed ACK will prevent the
+ * second write to be performed quickly in presence of Nagle's algorithm.
+ */
+ memcpy(cmd_buf, &cmd, sizeof(cmd));
+ memcpy(cmd_buf + sizeof(cmd), &rq, sizeof(rq));
- ret_len = lttng_live_send(ctx->control_sock, &rq, sizeof(rq));
+ ret_len = lttng_live_send(ctx->control_sock, cmd_buf, cmd_buf_len);
if (ret_len < 0) {
- perror("[error] Error sending get_new_streams request");
+ perror("[error] Error sending get_new_streams cmd and request");
goto error;
}
- assert(ret_len == sizeof(rq));
+ assert(ret_len == cmd_buf_len);
ret_len = lttng_live_recv(ctx->control_sock, &rp, sizeof(rp));
if (ret_len == 0) {