Whamcloud - gitweb
LU-12461 contrib: Add epython scripts for crash dump analysis
[fs/lustre-release.git] / contrib / debug_tools / epython_scripts / jiffies2date.py
1 #!usr/bin/env python
2 from pykdump.API import *
3 """
4 Copyright (c) 2019 Cray Inc. All Rights Reserved.
5 Utility to print jiffies as date and time
6 """
7
8 import argparse
9 import time
10 import crashlib.time
11
12 description_short = "Print the date and time for a jiffies timestamp."
13
14 # Get current time in jiffies and in seconds. Compute the offset of
15 # the timestamp in jiffies from current time and convert to seconds.
16 # Subtract the offset from current time in seconds and convert result
17 # to a datetime string.
18 def jiffies2date(jts):
19     scur = crashlib.time.get_wallclock_seconds()
20
21     jcur = readSymbol('jiffies')
22     if jts == 0:
23         jts = jcur
24     soffset = (jcur - int(jts)) / sys_info.HZ
25
26     stime = scur - soffset
27     date = time.asctime(time.localtime(stime))
28     print '%s (epoch: %d)' % (date, stime)
29
30 if __name__ == "__main__":
31     description = "Print the date and time of a given jiffies timestamp. " + \
32                   "Also includes seconds since epoch."
33     parser = argparse.ArgumentParser(description=description)
34     parser.add_argument("timestamp", nargs="?", default=0, type=int,
35         help="the timestamp in jiffies to be converted to date/time")
36     args = parser.parse_args()
37     jiffies2date(args.timestamp)