@@ -7,18 +7,23 @@ CFLAGS ?= -O0 -g -W -Wall -Wno-unused-parameter -Iinclude
LDFLAGS ?=
LIBS := -lm
GEN-IMAGE := gen-image
+MONOTONIC-TS := monotonic-ts
%.o : %.c
$(CC) $(CFLAGS) -c -o $@ $<
-all: $(GEN-IMAGE)
+all: $(GEN-IMAGE) $(MONOTONIC-TS)
$(GEN-IMAGE): gen-image.o
$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
+$(MONOTONIC-TS): monotonic-ts.o
+ $(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
+
clean:
-rm -f *.o
- -rm -f $(GEN-IMAGE)
+ -rm -f $(GEN-IMAGE) $(MONOTONIC_TS)
install:
cp $(GEN-IMAGE) $(INSTALL_DIR)/
+ cp $(MONOTONIC-TS) $(INSTALL_DIR)/
new file mode 100644
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/* SPDX-FileCopyrightText: 2020 Kieran Bingham <kieran.bingham@ideasonboard.com> */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+
+int main(int argc, char ** argv)
+{
+ struct timespec tp;
+ char *line = NULL;
+ size_t size = 0;
+ const char *label = "";
+
+ if (argc > 1)
+ label = argv[1];
+
+ /*
+ * Explicitly set line buffering on stdin to be sure it is delivered
+ * in a timely fashion for our timestamping purposes when data is fed
+ * through a pipe.
+ */
+ setlinebuf(stdin);
+
+ do {
+ if (getline(&line, &size, stdin) <= 0)
+ break;
+
+ clock_gettime(CLOCK_MONOTONIC, &tp);
+ printf("[%ld.%.9ld]%s %s", tp.tv_sec, tp.tv_nsec, label, line);
+ } while (!feof(stdin));
+
+ free(line);
+
+ return 0;
+}