Skip to contentSkip to conversation

Output a warning if packets are lost

PATCH New Julien Desfossez 2 participants 3 messages Aug 20, 2015 – Oct 27, 2015 2 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 2/2 Output a warning if packets are lost

Depends on the packet_seq_num fields available in the CTF index v1.1 (produced by LTTng 2.8).
Same limitation as the events discarded information: if a stream is split in multiple files, the counters might not report the appropriate information for now.

---
 formats/ctf/ctf.c                    | 40 +++++++++++++++++++++++++++++++-----
 include/babeltrace/ctf-ir/metadata.h |  2 ++
 2 files changed, 37 insertions(+), 5 deletions(-)
formats/ctf/ctf.c +35 -5
index c5bb6eb..db237ad 100644
@@ -420,16 +420,26 @@ void print_uuid(FILE *fp, unsigned char *uuid)
  * Given we have discarded counters of those two types merged into the
  * events_discarded counter, we need to use the union of those ranges:
  *   [ prev_timestamp_end, timestamp_end ]
+ *
+ * Lost packets occur if the tracer overwrote some subbuffer(s) before the
+ * consumer had time to extract them. We keep track of those gaps with the
+ * packet sequence number in each packet.
  */
 static
-void ctf_print_discarded(FILE *fp, struct ctf_stream_definition *stream)
+void ctf_print_discarded_lost(FILE *fp, struct ctf_stream_definition *stream)
 {
-	if (!stream->events_discarded || !babeltrace_ctf_console_output) {
+	if ((!stream->events_discarded && !stream->packets_lost) ||
+			!babeltrace_ctf_console_output) {
 		return;
 	}
 	fflush(stdout);
-	fprintf(fp, "[warning] Tracer discarded %" PRIu64 " events between [",
-		stream->events_discarded);
+	if (stream->events_discarded) {
+		fprintf(fp, "[warning] Tracer discarded %" PRIu64 " events between [",
+				stream->events_discarded);
+	} else if (stream->packets_lost) {
+		fprintf(fp, "[warning] Tracer lost %" PRIu64 " trace packets between [",
+				stream->packets_lost);
+	}
 	if (opt_clock_cycles) {
 		ctf_print_timestamp(fp, stream,
 				stream->prev.cycles.end);
@@ -800,6 +810,7 @@ void ctf_update_current_packet_index(struct ctf_stream_definition *stream,
 		struct packet_index *cur_index)
 {
 	uint64_t events_discarded_diff;
+	uint64_t packets_lost_diff = 0;
 
 	/* Update packet index time information */
 
@@ -827,6 +838,11 @@ void ctf_update_current_packet_index(struct ctf_stream_definition *stream,
 			prev_index->ts_real.timestamp_end;
 
 		events_discarded_diff -= prev_index->events_discarded;
+		/* packet_seq_num stays at 0 if not produced by the tracer */
+		if (cur_index->packet_seq_num) {
+			packets_lost_diff = cur_index->packet_seq_num -
+				prev_index->packet_seq_num - 1;
+		}
 		/*
 		 * Deal with 32-bit wrap-around if the tracer provided a
 		 * 32-bit field.
@@ -847,6 +863,7 @@ void ctf_update_current_packet_index(struct ctf_stream_definition *stream,
 				stream->current.real.begin;
 	}
 	stream->events_discarded = events_discarded_diff;
+	stream->packets_lost = packets_lost_diff;
 }
 
 /*
@@ -956,7 +973,7 @@ void ctf_packet_seek(struct bt_stream_pos *stream_pos, size_t index, int whence)
 		 * timestamps.
 		 */
 		if ((&file_stream->parent)->stream_class->trace->parent.collection) {
-			ctf_print_discarded(stderr, &file_stream->parent);
+			ctf_print_discarded_lost(stderr, &file_stream->parent);
 		}
 
 		packet_index = &g_array_index(pos->packet_index,
@@ -1695,6 +1712,19 @@ begin:
 			packet_index.events_discarded = bt_get_unsigned_int(field);
 			packet_index.events_discarded_len = bt_get_int_len(field);
 		}
+
+		/* read packet_seq_num from header */
+		len_index = bt_struct_declaration_lookup_field_index(
+				file_stream->parent.stream_packet_context->declaration,
+				g_quark_from_static_string("packet_seq_num"));
+		if (len_index >= 0) {
+			struct bt_definition *field;
+
+			field = bt_struct_definition_get_field_from_index(
+					file_stream->parent.stream_packet_context,
+					len_index);
+			packet_index.packet_seq_num = bt_get_unsigned_int(field);
+		}
 	} else {
 		/* Use file size for packet size */
 		packet_index.packet_size = filesize * CHAR_BIT;
include/babeltrace/ctf-ir/metadata.h +2 -0
index 6753695..bc68580 100644
@@ -74,6 +74,8 @@ struct ctf_stream_definition {
 
 	/* Event discarded information */
 	uint64_t events_discarded;
+	/* Trace packets lost */
+	uint64_t packets_lost;
 	struct ctf_stream_packet_timestamp prev;
 	struct ctf_stream_packet_timestamp current;
 	char path[PATH_MAX];			/* Path to stream. '\0' for mmap traces */
Signature · 1 line
1.9.1
#2 lore raw

Re: [BABELTRACE PATCH 1/2] Support ctf index version 1.1

In reply to a message not in the archive

Merged in master, thanks!

Quoted 91 lines · Julien Desfossez

Produced by LTTng as of 2.8 (no compatibility breakage with 1.0)

---
 formats/ctf/ctf.c                  | 10 +++++++++-
 include/babeltrace/ctf/ctf-index.h |  5 ++++-
 include/babeltrace/ctf/types.h     |  3 +++
 3 files changed, 16 insertions(+), 2 deletions(-)
formats/ctf/ctf.c +9 -1
index 74fcb5b..c5bb6eb 100644
@@ -1547,6 +1547,8 @@ begin:
        packet_index.ts_cycles.timestamp_end = 0;
        packet_index.events_discarded = 0;
        packet_index.events_discarded_len = 0;
+       packet_index.stream_instance_id = 0;
+       packet_index.packet_seq_num = 0;
 
        /* read and check header, set stream id (and check) */
        if (file_stream->parent.trace_packet_header) {
@@ -1833,7 +1835,7 @@ int import_stream_packet_index(struct ctf_trace *td,
        struct ctf_packet_index *ctf_index = NULL;
        struct ctf_packet_index_file_hdr index_hdr;
        struct packet_index index;
-       uint32_t packet_index_len;
+       uint32_t packet_index_len, index_minor;
        int ret = 0;
        int first_packet = 1;
        size_t len;
@@ -1861,6 +1863,8 @@ int import_stream_packet_index(struct ctf_trace *td,
                ret = -1;
                goto error;
        }
+       index_minor = be32toh(index_hdr.index_minor);
+
        packet_index_len = be32toh(index_hdr.packet_index_len);
        if (packet_index_len == 0) {
                fprintf(stderr, "[error] Packet index length cannot be 0.\n");
@@ -1887,6 +1891,10 @@ int import_stream_packet_index(struct ctf_trace *td,
                index.events_discarded_len = 64;
                index.data_offset = -1;
                stream_id = be64toh(ctf_index->stream_id);
+               if (index_minor >= 1) {
+                       index.stream_instance_id = be64toh(ctf_index->stream_instance_id);
+                       index.packet_seq_num = be64toh(ctf_index->packet_seq_num);
+               }
 
                if (!first_packet) {
                        /* add index to packet array */
include/babeltrace/ctf/ctf-index.h +4 -1
index b39b523..8880c2f 100644
@@ -29,7 +29,7 @@
 
 #define CTF_INDEX_MAGIC 0xC1F1DCC1
 #define CTF_INDEX_MAJOR 1
-#define CTF_INDEX_MINOR 0
+#define CTF_INDEX_MINOR 1
 
 /*
  * Header at the beginning of each index file.
@@ -55,6 +55,9 @@ struct ctf_packet_index {
        uint64_t timestamp_end;
        uint64_t events_discarded;
        uint64_t stream_id;
+       /* CTF_INDEX 1.0 limit */
+       uint64_t stream_instance_id;    /* ID of the channel instance */
+       uint64_t packet_seq_num;        /* packet sequence number */
 } __attribute__((__packed__));
 
 #endif /* LTTNG_INDEX_H */
include/babeltrace/ctf/types.h +3 -1
index c336632..cc8acbf 100644
@@ -58,6 +58,9 @@ struct packet_index {
        uint64_t events_discarded_len;  /* length of the field, in bits */
        struct packet_index_time ts_cycles;     /* timestamp in cycles */
        struct packet_index_time ts_real;       /* realtime timestamp */
+       /* CTF_INDEX 1.0 limit */
+       uint64_t stream_instance_id;    /* ID of the channel instance */
+       uint64_t packet_seq_num;        /* packet sequence number */
 };
 
 /*
--

1.9.1

Signature · 8 lines
Jérémie Galarneau
EfficiOS Inc.
http://www.efficios.com

_______________________________________________
lttng-dev mailing list
[email protected]
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw

Merged in master, thanks!

Jérémie

Quoted 120 lines · Julien Desfossez

Depends on the packet_seq_num fields available in the CTF index v1.1 (produced by LTTng 2.8).
Same limitation as the events discarded information: if a stream is split in multiple files, the counters might not report the appropriate information for now.

---
 formats/ctf/ctf.c                    | 40 +++++++++++++++++++++++++++++++-----
 include/babeltrace/ctf-ir/metadata.h |  2 ++
 2 files changed, 37 insertions(+), 5 deletions(-)
formats/ctf/ctf.c +35 -5
index c5bb6eb..db237ad 100644
@@ -420,16 +420,26 @@ void print_uuid(FILE *fp, unsigned char *uuid)
  * Given we have discarded counters of those two types merged into the
  * events_discarded counter, we need to use the union of those ranges:
  *   [ prev_timestamp_end, timestamp_end ]
+ *
+ * Lost packets occur if the tracer overwrote some subbuffer(s) before the
+ * consumer had time to extract them. We keep track of those gaps with the
+ * packet sequence number in each packet.
  */
 static
-void ctf_print_discarded(FILE *fp, struct ctf_stream_definition *stream)
+void ctf_print_discarded_lost(FILE *fp, struct ctf_stream_definition *stream)
 {
-       if (!stream->events_discarded || !babeltrace_ctf_console_output) {
+       if ((!stream->events_discarded && !stream->packets_lost) ||
+                       !babeltrace_ctf_console_output) {
                return;
        }
        fflush(stdout);
-       fprintf(fp, "[warning] Tracer discarded %" PRIu64 " events between [",
-               stream->events_discarded);
+       if (stream->events_discarded) {
+               fprintf(fp, "[warning] Tracer discarded %" PRIu64 " events between [",
+                               stream->events_discarded);
+       } else if (stream->packets_lost) {
+               fprintf(fp, "[warning] Tracer lost %" PRIu64 " trace packets between [",
+                               stream->packets_lost);
+       }
        if (opt_clock_cycles) {
                ctf_print_timestamp(fp, stream,
                                stream->prev.cycles.end);
@@ -800,6 +810,7 @@ void ctf_update_current_packet_index(struct ctf_stream_definition *stream,
                struct packet_index *cur_index)
 {
        uint64_t events_discarded_diff;
+       uint64_t packets_lost_diff = 0;
 
        /* Update packet index time information */
 
@@ -827,6 +838,11 @@ void ctf_update_current_packet_index(struct ctf_stream_definition *stream,
                        prev_index->ts_real.timestamp_end;
 
                events_discarded_diff -= prev_index->events_discarded;
+               /* packet_seq_num stays at 0 if not produced by the tracer */
+               if (cur_index->packet_seq_num) {
+                       packets_lost_diff = cur_index->packet_seq_num -
+                               prev_index->packet_seq_num - 1;
+               }
                /*
                 * Deal with 32-bit wrap-around if the tracer provided a
                 * 32-bit field.
@@ -847,6 +863,7 @@ void ctf_update_current_packet_index(struct ctf_stream_definition *stream,
                                stream->current.real.begin;
        }
        stream->events_discarded = events_discarded_diff;
+       stream->packets_lost = packets_lost_diff;
 }
 
 /*
@@ -956,7 +973,7 @@ void ctf_packet_seek(struct bt_stream_pos *stream_pos, size_t index, int whence)
                 * timestamps.
                 */
                if ((&file_stream->parent)->stream_class->trace->parent.collection) {
-                       ctf_print_discarded(stderr, &file_stream->parent);
+                       ctf_print_discarded_lost(stderr, &file_stream->parent);
                }
 
                packet_index = &g_array_index(pos->packet_index,
@@ -1695,6 +1712,19 @@ begin:
                        packet_index.events_discarded = bt_get_unsigned_int(field);
                        packet_index.events_discarded_len = bt_get_int_len(field);
                }
+
+               /* read packet_seq_num from header */
+               len_index = bt_struct_declaration_lookup_field_index(
+                               file_stream->parent.stream_packet_context->declaration,
+                               g_quark_from_static_string("packet_seq_num"));
+               if (len_index >= 0) {
+                       struct bt_definition *field;
+
+                       field = bt_struct_definition_get_field_from_index(
+                                       file_stream->parent.stream_packet_context,
+                                       len_index);
+                       packet_index.packet_seq_num = bt_get_unsigned_int(field);
+               }
        } else {
                /* Use file size for packet size */
                packet_index.packet_size = filesize * CHAR_BIT;
include/babeltrace/ctf-ir/metadata.h +2 -1
index 6753695..bc68580 100644
@@ -74,6 +74,8 @@ struct ctf_stream_definition {
 
        /* Event discarded information */
        uint64_t events_discarded;
+       /* Trace packets lost */
+       uint64_t packets_lost;
        struct ctf_stream_packet_timestamp prev;
        struct ctf_stream_packet_timestamp current;
        char path[PATH_MAX];                    /* Path to stream. '\0' for mmap traces */
--

1.9.1

Signature · 8 lines
Jérémie Galarneau
EfficiOS Inc.
http://www.efficios.com

_______________________________________________
lttng-dev mailing list
[email protected]
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev