From: Erik Stromdahl <erik.stromdahl@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: Erik Stromdahl <erik.stromdahl@gmail.com>
Subject: [PATCH 1/2] scripts: show_delta: add time stamp rounding option
Date: Sat, 22 Apr 2017 19:52:32 +0200 [thread overview]
Message-ID: <1492883553-10349-2-git-send-email-erik.stromdahl@gmail.com> (raw)
In-Reply-To: <1492883553-10349-1-git-send-email-erik.stromdahl@gmail.com>
An additional feature for show_delta: -r <round_us>
With this option the delta time stamps are rounded to the
closest microsecond specified by the -r option.
Rationale: Make it easier to diff kernel logs when looking for
timing issues (less irrelevant diffs detected by a diff tool).
Signed-off-by: Erik Stromdahl <erik.stromdahl@gmail.com>
---
scripts/show_delta | 36 +++++++++++++++++++++++++++++++++---
1 file changed, 33 insertions(+), 3 deletions(-)
diff --git a/scripts/show_delta b/scripts/show_delta
index e386827..b85cf0f 100755
--- a/scripts/show_delta
+++ b/scripts/show_delta
@@ -20,7 +20,8 @@ have time data prefixed because the CONFIG_PRINTK_TIME option is set, or
the kernel command line option "time" is specified. When run with no
options, the time information is converted to show the time delta between
each printk line and the next. When run with the '-b' option, all times
-are relative to a single (base) point in time.
+are relative to a single (base) point in time. The '-r' option is optional
+and can be used to round the calculated delta times.
Options:
-h Show this usage help.
@@ -29,6 +30,10 @@ Options:
If it is a string, the first message line
which matches (at the beginning of the
line) is used as the time reference.
+ -r <round_us> Specify a a rounding time (in us) for all
+ delta timestamps.
+ All delta timestamps will be rounded to the
+ nearest 'round_us' microsecond
ex: $ dmesg >timefile
$ show_delta -b NET4 timefile
@@ -52,13 +57,23 @@ def get_time(line):
#print "time=", time
return (time, rest)
+# Round delta to the nearest micro second specified by the rounding_time_us
+# argument
+def round_delta_ts(delta, rounding_time_us):
+ div_floor = (delta * 1E6) // rounding_time_us
+ delta_floor = rounding_time_us / 1E6 * div_floor
+ delta_modulo_us = (delta - delta_floor) * 1E6
+ if (delta_modulo_us - rounding_time_us / 2) < 0:
+ return delta_floor
+ else:
+ return delta_floor + rounding_time_us / 1E6
# average line looks like:
# [ 0.084282] VFS: Mounted root (romfs filesystem) readonly
# time data is expressed in seconds.useconds,
# convert_line adds a delta for each line
last_time = 0.0
-def convert_line(line, base_time):
+def convert_line(line, base_time, rounding_time_us):
global last_time
try:
@@ -75,14 +90,20 @@ def convert_line(line, base_time):
delta = time - last_time
last_time = time
+ if rounding_time_us:
+ delta = round_delta_ts(delta, rounding_time_us)
+
return ("[%5.6f < %5.6f >]" % (time, delta)) + rest
def main():
base_str = ""
+ rounding_str = ""
filein = ""
for arg in sys.argv[1:]:
if arg=="-b":
base_str = sys.argv[sys.argv.index("-b")+1]
+ elif arg=="-r":
+ rounding_str = sys.argv[sys.argv.index("-r")+1]
elif arg=="-h":
usage()
else:
@@ -122,7 +143,16 @@ def main():
else:
base_time = 0.0
+ if rounding_str:
+ try:
+ rounding_time_us = int(rounding_str)
+ except:
+ print ('Bad -r option: "%s"' % rounding_str)
+ sys.exit(1)
+ else:
+ rounding_time_us = 0
+
for line in lines:
- print (convert_line(line, base_time),)
+ print (convert_line(line, base_time, rounding_time_us),)
main()
--
2.7.4
next prev parent reply other threads:[~2017-04-22 17:53 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-22 17:52 [PATCH 0/2] scripts: show_delta: additional features Erik Stromdahl
2017-04-22 17:52 ` Erik Stromdahl [this message]
2017-04-22 17:52 ` [PATCH 2/2] scripts: show_delta: add --delta-only option Erik Stromdahl
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1492883553-10349-2-git-send-email-erik.stromdahl@gmail.com \
--to=erik.stromdahl@gmail.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®