Package: devscripts
Version: 2.15.8
Severity: wishlist
Tags: patch

Hi,

I sometimes use annotate-output with a constant prefix (not containing a
time format string) to mark the output of several programs that run at
the same time. In this case, it is not necessary to call 'date' for each
line. The attached patch adds an optimization for this case.

On my machine, for a 10000 line FILE, a call to

annotate-output +PREFIX cat FILE

takes > 10s without my patch and < 0.3s with my patch. The output is the
same in both cases.

Cheers,
Stefan
--- /usr/bin/annotate-output	2015-08-02 15:08:42.000000000 +0200
+++ annotate-output	2015-09-20 10:51:32.953880510 +0200
@@ -32,6 +32,16 @@
 	fi
 }
 
+addprefix ()
+{
+	while IFS= read -r line; do
+		echo "$1: $line"
+	done
+	if [ ! -z "$line" ]; then
+		echo "$1: $line"
+	fi
+}
+
 usage ()
 {
 	echo \
@@ -75,8 +85,15 @@
 
 mkfifo $OUT $ERR || exit 1
 
-addtime O < $OUT &
-addtime E < $ERR &
+if [ "${FMT/\%}" != "${FMT}" ] ; then
+	addtime O < $OUT &
+	addtime E < $ERR &
+else
+	# If FMT does not contain a %, use the optimized version that
+	# does not call 'date'.
+	addprefix "${FMT#+} O" < $OUT &
+	addprefix "${FMT#+} E" < $ERR &
+fi
 
 echo "Started $@" | addtime I
 "$@" > $OUT 2> $ERR ; EXIT=$?

Reply via email to