+ stream->prev_cycles_timestamp = stream->cycles_timestamp;
+ stream->cycles_timestamp = updateval;
+
+ /* convert to real timestamp */
+ stream->prev_real_timestamp = ctf_get_real_timestamp(stream,
+ stream->prev_cycles_timestamp);
+ stream->real_timestamp = ctf_get_real_timestamp(stream,
+ stream->cycles_timestamp);
+}
+
+/*
+ * Print timestamp, rescaling clock frequency to nanoseconds and
+ * applying offsets as needed (unix time).
+ */
+static
+void ctf_print_timestamp_real(FILE *fp,
+ struct ctf_stream_definition *stream,
+ uint64_t timestamp)
+{
+ uint64_t ts_sec = 0, ts_nsec;
+
+ ts_nsec = timestamp;
+
+ /* Add command-line offset */
+ ts_sec += opt_clock_offset;
+
+ ts_sec += ts_nsec / NSEC_PER_SEC;
+ ts_nsec = ts_nsec % NSEC_PER_SEC;
+
+ if (!opt_clock_seconds) {
+ struct tm tm;
+ time_t time_s = (time_t) ts_sec;
+
+ if (!opt_clock_gmt) {
+ struct tm *res;
+
+ res = localtime_r(&time_s, &tm);
+ if (!res) {
+ fprintf(stderr, "[warning] Unable to get localtime.\n");
+ goto seconds;
+ }
+ } else {
+ struct tm *res;
+
+ res = gmtime_r(&time_s, &tm);
+ if (!res) {
+ fprintf(stderr, "[warning] Unable to get gmtime.\n");
+ goto seconds;
+ }
+ }
+ if (opt_clock_date) {
+ char timestr[26];
+ size_t res;
+
+ /* Print date and time */
+ res = strftime(timestr, sizeof(timestr),
+ "%F ", &tm);
+ if (!res) {
+ fprintf(stderr, "[warning] Unable to print ascii time.\n");
+ goto seconds;
+ }
+ fprintf(fp, "%s", timestr);
+ }
+ /* Print time in HH:MM:SS.ns */
+ fprintf(fp, "%02d:%02d:%02d.%09" PRIu64,
+ tm.tm_hour, tm.tm_min, tm.tm_sec, ts_nsec);
+ goto end;
+ }
+seconds:
+ fprintf(fp, "%3" PRIu64 ".%09" PRIu64,
+ ts_sec, ts_nsec);
+
+end:
+ return;
+}
+
+/*
+ * 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]);
+}
+
+void ctf_print_discarded(FILE *fp, struct ctf_stream_definition *stream,
+ int end_stream)
+{
+ fprintf(fp, "[warning] Tracer discarded %" PRIu64 " events %sbetween [",
+ stream->events_discarded,
+ end_stream ? "at end of stream " : "");
+ if (opt_clock_cycles) {
+ ctf_print_timestamp(fp, stream,
+ stream->prev_cycles_timestamp);
+ fprintf(fp, "] and [");
+ ctf_print_timestamp(fp, stream,
+ stream->prev_cycles_timestamp_end);
+ } else {
+ ctf_print_timestamp(fp, stream,
+ stream->prev_real_timestamp);
+ fprintf(fp, "] and [");
+ ctf_print_timestamp(fp, stream,
+ stream->prev_real_timestamp_end);
+ }
+ fprintf(fp, "] in trace UUID ");
+ print_uuid(fp, stream->stream_class->trace->uuid);
+ if (stream->stream_class->trace->path[0])
+ fprintf(fp, ", at path: \"%s\"",
+ stream->stream_class->trace->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);