+/*
+ * Print timestamp, in cycles
+ */
+static
+void ctf_print_timestamp_cycles(FILE *fp,
+ struct ctf_stream_definition *stream,
+ uint64_t timestamp)
+{
+ fprintf(fp, "%020" PRIu64, timestamp);
+}
+
+void ctf_print_timestamp(FILE *fp,
+ struct ctf_stream_definition *stream,
+ uint64_t timestamp)
+{
+ if (opt_clock_cycles) {
+ ctf_print_timestamp_cycles(fp, stream, timestamp);
+ } else {
+ ctf_print_timestamp_real(fp, stream, timestamp);
+ }
+}
+
+static
+void print_uuid(FILE *fp, unsigned char *uuid)
+{
+ int i;
+
+ for (i = 0; i < BABELTRACE_UUID_LEN; i++)
+ fprintf(fp, "%x", (unsigned int) uuid[i]);
+}
+
+/*
+ * Discarded events can be either:
+ * - discarded after end of previous buffer due to buffer full:
+ * happened within range: [ prev_timestamp_end, timestamp_begin ]
+ * - discarded within current buffer due to either event too large or
+ * nested wrap-around:
+ * happened within range: [ timestamp_begin, timestamp_end ]
+ *
+ * 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 ]
+ */
+static
+void ctf_print_discarded(FILE *fp, struct ctf_stream_definition *stream)
+{
+ if (!stream->events_discarded || !babeltrace_ctf_console_output) {
+ return;
+ }
+ fflush(stdout);
+ fprintf(fp, "[warning] Tracer discarded %" PRIu64 " events between [",
+ stream->events_discarded);
+ if (opt_clock_cycles) {
+ ctf_print_timestamp(fp, stream,
+ stream->prev.cycles.end);
+ fprintf(fp, "] and [");
+ ctf_print_timestamp(fp, stream,
+ stream->current.cycles.end);
+ } else {
+ ctf_print_timestamp(fp, stream,
+ stream->prev.real.end);
+ fprintf(fp, "] and [");
+ ctf_print_timestamp(fp, stream,
+ stream->current.real.end);
+ }
+ fprintf(fp, "] in trace UUID ");
+ print_uuid(fp, stream->stream_class->trace->uuid);
+ if (stream->stream_class->trace->parent.path[0])
+ fprintf(fp, ", at path: \"%s\"",
+ stream->stream_class->trace->parent.path);
+
+ fprintf(fp, ", within stream id %" PRIu64, stream->stream_id);
+ if (stream->path[0])
+ fprintf(fp, ", at relative path: \"%s\"", stream->path);
+ fprintf(fp, ". ");
+ fprintf(fp, "You should consider recording a new trace with larger "
+ "buffers or with fewer events enabled.\n");
+ fflush(fp);
+}
+