From e29e7d53ff688d9d3e810b8b6edbc4de2381858a Mon Sep 17 00:00:00 2001
From: Oliver Breitwieser <oliver.breitwieser@kip.uni-heidelberg.de>
Date: Wed, 19 Jun 2019 10:40:43 +0200
Subject: [PATCH] Add quick awk script to parse jenkins log

Change-Id: Ic49ddb2b2200339984252266e58508de90660f0c
---
 misc-files/parselog.awk | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
 create mode 100755 misc-files/parselog.awk

diff --git a/misc-files/parselog.awk b/misc-files/parselog.awk
new file mode 100755
index 00000000..20be6672
--- /dev/null
+++ b/misc-files/parselog.awk
@@ -0,0 +1,40 @@
+#!/usr/bin/awk -f
+
+# Parses timestamp and counts seconds
+# Only prints commands that took longer than a second.
+
+function date_to_sec(date)
+{
+	if ( ! ( date ~ /\[[\-0-9]*T[:.0-9]*Z\]/ ) )
+	{
+		return "FAIL"
+	}
+	# clear brackets from date
+	gsub(/(\[|\])/, "", date)
+	date = sprintf("(date +%%s.%%N -d '%s' || echo FAIL) 2>/dev/null", date)
+	date | getline secs
+	close(date)
+	return secs
+}
+
+{
+	secs = date_to_sec($1)
+
+	if (secs != "FAIL")
+	{
+		elapsed = secs - last
+
+		last = secs
+
+		if (elapsed > 0)
+		{
+			if ( ! (last_command ~ /^$/ ))
+			{
+				# the elapsed time is for the PREVIOUS line of input
+				print elapsed last_command
+			}
+		}
+		$1 = ""
+		last_command = $0
+	}
+}
-- 
GitLab