From nobody Mon May 6 08:32:17 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 80.81.252.135 is neither permitted nor denied by domain of seabios.org) client-ip=80.81.252.135; envelope-from=seabios-bounces@seabios.org; helo=mail.coreboot.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 80.81.252.135 is neither permitted nor denied by domain of seabios.org) smtp.mailfrom=seabios-bounces@seabios.org Return-Path: Received: from mail.coreboot.org (mail.coreboot.org [80.81.252.135]) by mx.zohomail.com with SMTPS id 1513739252586213.23757352075177; Tue, 19 Dec 2017 19:07:32 -0800 (PST) Received: from [127.0.0.1] (helo=ra.coreboot.org) by mail.coreboot.org with esmtp (Exim 4.86_2) (envelope-from ) id 1eRUil-0002Pb-By; Wed, 20 Dec 2017 04:07:03 +0100 Received: from mail-vk0-f68.google.com ([209.85.213.68]) by mail.coreboot.org with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.86_2) (envelope-from ) id 1eR709-0004Rn-3x for seabios@seabios.org; Tue, 19 Dec 2017 02:47:32 +0100 Received: by mail-vk0-f68.google.com with SMTP id 189so10621135vkc.9 for ; Mon, 18 Dec 2017 17:47:36 -0800 (PST) Received: by 10.31.107.211 with HTTP; Mon, 18 Dec 2017 17:46:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=AnMSiyh4/WUxkzMzrJF4scHLoXWOMnAWhTxDtJh+c/I=; b=um/u2D3qKW5H0ZcAfVxATSeSlPiadCVlgcSOaJ4gH7nmkSCK+zRLNtAkTefru84/XY oov/a2lrml8oo5TgQgEyT54xia0HeLtflPL9mBjYDq7FHK1/udATuOgBLNM3VG2QFDxQ Vj8dGHFrHdhaUAVi40x4cuBIFeZ7KaISILHJC3MjPVgiY7z612sIbIyyv9RhEEo+DHjK 2+VvM/Gi1IljkqGg5AqDckdjiGehKqnMySa2d5McJbzTAfU1wq/X+D2NWTDWvuCTneV+ qdL8fB06TTTLx7gRiyIus3eDCmPC+VfQ8zAyXfZiiKuvFF3nN+A2UwP+pQ2Tp7DqRGDW 98pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=AnMSiyh4/WUxkzMzrJF4scHLoXWOMnAWhTxDtJh+c/I=; b=HeKZiCR5FfgZahiS1fMH41oxyuRO+mrf67FKpeLKZozJ5+w+V82p92SGoTCIHvMD4e CqMIqWL3Xb9enza+EFgZPMAWWfw7w1hzDO+I7rgQR/QmLV8QzdT8zyT3bLjyIilZPpEt Vrazz16krO53y/dqUKc6ruZmr9qC08X/tnMTgwMUu/T5/HEuUBlyw2ciqazyzqRRymTB ybYLXB95rFEQ6dTknK0KeyaaJD0SgeUC91RHhlSzNcYBC5nujJwQRwOUK0+rIZXwSYyn I+USf/O+h+KM909g8XSF6JKPiI9TAVK2yV+u0V42ty1/dGL0Bop9E7z3c2YR0yJZyS5q elEg== X-Gm-Message-State: AKGB3mJihsWNOYJlSFUhFwczjO0PniqF7NEjLa9RGJWClIIvAw9bUORi 6B1jGWUyzCi48BwQmmourx0tgcONMIE5oKMbbIbLJOqvMsQ= X-Google-Smtp-Source: ACJfBossVv6FxrFbNjn2XeYefRFg6w7ZSZ9DbcsmIVE/cQus23sG4uq89okGPzu2C3OFay+vtzg4LVswgLqtx/wdPq4= X-Received: by 10.31.157.77 with SMTP id g74mr1887708vke.130.1513648053457; Mon, 18 Dec 2017 17:47:33 -0800 (PST) MIME-Version: 1.0 From: =?UTF-8?B?VmFkaW0gQmVuZGVidXJ5ICjQstCxKQ==?= Date: Mon, 18 Dec 2017 17:46:52 -0800 Message-ID: To: seabios@seabios.org X-Spam-Score: -3.1 (---) X-Mailman-Approved-At: Wed, 20 Dec 2017 04:07:00 +0100 Subject: [SeaBIOS] [PATCH] readserial: allow setting real time timestamps X-BeenThere: seabios@seabios.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SeaBIOS mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Errors-To: seabios-bounces@seabios.org Sender: "SeaBIOS" X-Duff: Orig. Duff, Duff Lite, Duff Dry, Duff Dark, Raspberry Duff, Lady Duff, Red Duff, Tartar Control Duff X-ZohoMail-DKIM: fail (Computed bodyhash is different from the expected one) X-ZohoMail: RDKM_2 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Sometimes it is beneficial to attach real time stamps to console output, for instance when there is a need to correlate two independently captured logs. This patch adds another command line option (-r,--realtime), when given the generated log is printed with second's resolution real time timestamps. Signed-off-by: Vadim Bendebury --- scripts/readserial.py | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/scripts/readserial.py b/scripts/readserial.py index a7383e8..dc294eb 100755 --- a/scripts/readserial.py +++ b/scripts/readserial.py @@ -8,7 +8,7 @@ # Usage: # scripts/readserial.py /dev/ttyUSB0 115200 -import sys, os, time, select, optparse +import datetime, sys, os, time, select, optparse from python23compat import as_bytes @@ -54,8 +54,10 @@ def calibrateserialread(infile, byteadjust): totalchars +=3D len(d) lasttime =3D curtime -def readserial(infile, logfile, byteadjust): +def readserial(infile, logfile, byteadjust, real_time): lasttime =3D 0 + isnewline =3D 0 + charcount =3D 0 while 1: # Read data try: @@ -74,25 +76,29 @@ def readserial(infile, logfile, byteadjust): return 0 datatime =3D time.time() - datatime -=3D len(d) * byteadjust + if not real_time: + datatime -=3D len(d) * byteadjust - # Reset start time if no data for some time - if datatime - lasttime > RESTARTINTERVAL: - starttime =3D datatime - charcount =3D 0 - isnewline =3D 1 - msg =3D "\n\n=3D=3D=3D=3D=3D=3D=3D %s (adjust=3D%.1fus)\n" % ( - time.asctime(time.localtime(datatime)), byteadjust * 10000= 00) - sys.stdout.write(msg) - logfile.write(as_bytes(msg)) - lasttime =3D datatime + # Reset start time if no data for some time + if datatime - lasttime > RESTARTINTERVAL: + starttime =3D datatime + charcount =3D 0 + isnewline =3D 1 + msg =3D "\n\n=3D=3D=3D=3D=3D=3D=3D %s (adjust=3D%.1fus)\n"= % ( + time.asctime(time.localtime(datatime)), byteadjust * 1000000) + sys.stdout.write(msg) + logfile.write(as_bytes(msg)) + lasttime =3D datatime # Translate unprintable chars; add timestamps out =3D as_bytes("") for c in d: if isnewline: - delta =3D datatime - starttime - (charcount * byteadjust) - out +=3D "%06.3f: " % delta + if real_time: + out +=3D datetime.datetime.now().strftime('%H:%M:%S: ') + else: + delta =3D datatime - starttime - (charcount * byteadju= st) + out +=3D "%06.3f: " % delta isnewline =3D 0 oc =3D ord(c) charcount +=3D 1 @@ -138,6 +144,10 @@ def main(): opts.add_option("-t", "--time", type=3D"float", dest=3D"time", default=3DNone, help=3D"time to write one byte on serial port (in us)") + opts.add_option("-r", "--realtime", + action=3D"store_true", dest=3D"realtime", default=3DFa= lse, + help=3D"print real time timestamps instead of deltas") + options, args =3D opts.parse_args() serialport =3D 0 baud =3D 115200 @@ -176,12 +186,12 @@ Or: apt-get install python-serial logname =3D time.strftime("seriallog-%Y%m%d_%H%M%S.log") f =3D open(logname, 'wb') if options.serial: - readserial(ser, f, byteadjust) + readserial(ser, f, byteadjust, options.realtime) else: # Read from a pipe while 1: ser =3D os.fdopen(os.open(serialport, os.O_RDONLY|os.O_NONBLOCK), 'rb') - res =3D readserial(ser, f, byteadjust) + res =3D readserial(ser, f, byteadjust, options.realtime) ser.close() if res < 0: break --=20 2.15.1.504.g5279b80103-goog _______________________________________________ SeaBIOS mailing list SeaBIOS@seabios.org https://mail.coreboot.org/mailman/listinfo/seabios