Whamcloud - gitweb
LU-17744 ldiskfs: mballoc stats fixes
[fs/lustre-release.git] / contrib / debug_tools / epython_scripts / crashlib / time.py
1 """
2 Routines for retrieving and manipulating kernel time
3 Copyright 2017 Cray Inc.  All Rights Reserved
4 """
5
6 from pykdump.API import readSymbol, symbol_exists
7 from crashlib.exceptions import *
8
9 # --------------------------------------------------------------------------
10 # get_wallclock_seconds()
11 #
12 # There are multiple variants, depending on kernel version.  Attempt to
13 # discern the proper method for retrieving the current wall clock time.
14 #
15
16 if symbol_exists('xtime'):
17     # SLES 11 uses struct timespec xtime to hold the wall time.
18     _wallclock_xtime = readSymbol('xtime')
19     def get_wallclock_seconds():
20         '''Return current time in seconds'''
21         return _wallclock_xtime.tv_sec
22
23 elif symbol_exists('timekeeper'):
24     # SLES 12 has a new timekeeper struct for that purpose
25     _wallclock_timekeeper = readSymbol('timekeeper')
26     def get_wallclock_seconds():
27         '''Return current time in seconds'''
28         return _wallclock_timekeeper.xtime_sec
29
30 elif symbol_exists('tk_core'):
31     # SLES 12 SP2 embeds the timekeeper struct in tk_core
32     _wallclock_tk_core = readSymbol('tk_core')
33     def get_wallclock_seconds():
34         '''Return current time in seconds'''
35         return _wallclock_tk_core.timekeeper.xtime_sec
36
37 else:
38     # Unknown how to read wallclock time in this kernel
39     def get_wallclock_seconds():
40         raise CompatibilityError('Could not find wallclock time in the kernel')
41
42 # --------------------------------------------------------------------------