printk_timestamp_converter (version 3.0.0)
index

# Copyright (c) 2015, 2016, 2017 Tim Savannah under LGPLv3.
# You should have received a copy of this with this distribution as LICENSE
#
# This provides a library for dealing with printk drift between actual uptime.
#   This will provide a reasonable estimate for recent timestamps, but not a completely accurate picture for all timestamps (can drift by up to an hour in a month's time).
#   For accurate timing, this would need to constantly collect samples.
#   Alternativly, it can use every sample that IS present, and create a set of ranges.

 
Package Contents
       

 
Classes
       
builtins.Exception(builtins.BaseException)
NotRecentEnoughDriftDelta

 
class NotRecentEnoughDriftDelta(builtins.Exception)
    NotRecentEnoughDriftDelta - Exception raised when a close enough drift market cannot be found, and one cannot be created because you cannot write to /dev/kmsg.
 
 
Method resolution order:
NotRecentEnoughDriftDelta
builtins.Exception
builtins.BaseException
builtins.object

Data descriptors defined here:
__weakref__
list of weak references to the object (if defined)

Methods inherited from builtins.Exception:
__init__(self, /, *args, **kwargs)
Initialize self.  See help(type(self)) for accurate signature.
__new__(*args, **kwargs) from builtins.type
Create and return a new object.  See help(type) for accurate signature.

Methods inherited from builtins.BaseException:
__delattr__(self, name, /)
Implement delattr(self, name).
__getattribute__(self, name, /)
Return getattr(self, name).
__reduce__(...)
helper for pickle
__repr__(self, /)
Return repr(self).
__setattr__(self, name, value, /)
Implement setattr(self, name, value).
__setstate__(...)
__str__(self, /)
Return str(self).
with_traceback(...)
Exception.with_traceback(tb) --
set self.__traceback__ to tb and return self.

Data descriptors inherited from builtins.BaseException:
__cause__
exception cause
__context__
exception context
__dict__
__suppress_context__
__traceback__
args

 
Functions
       
getSystemUptime()
getSystemUptime - Gets system uptime in seconds
 
@return <int> - Seconds of uptime
printk_calculateCurrentDrift(dmesgContents=None, maxDriftRedetectTime=12000)
printk_calculateCurrentDrift - Convienance function for printk_calculateDrifts which just returns the latest drift.
 
This function will try to add a new entry if the last delta is outside the given threshold
 
@see printk_calculateDrifts
 
@return <int> - Latest delta
printk_calculateDrifts(dmesgContents=None, onlyLatest=False, maxDriftRedetectTime=12000, markIfRequired=True)
printk_calculateDrifts - Calculates the drifts for a dmesg log
 
    @param dmesgContents <str/None> Default None - Contents of dmesg, or None to fetch new
 
    @param onlyLatest  <bool> Default False    - Only fetch the most recent.
 
    @param maxDriftRedetectTime <int> Default PRINTK_DRIFT_REDETECT_TIME - Number of seconds that represents max tolerance between printk detections. If set to 0, any present
                                        delta is okay.
 
    @param markIfRequired <bool> default True - if a marker is not found within #maxDriftRedetectTime and this is set to True, a mark will be attempted (requires root and dmesgContents to be None). Otherwise, in the circumstance that there is not a recent enough marker, a NotRecentEnoughDriftDelta will be raised (more info below)
 
    This will add an entry if one has not been inserted in the last PRINTK_DRIFT_REDIRECT_TIME seconds.
    The entry compares the printk "time" with current uptime, to detect a drift.
 
    This function returns a dictionary with each line number containing a drift delta to that delta.
 
    @return dict - key is line number <0-origin> containing a drift delta, and value is that delta. Also an entry "latest" which contains most recent drift, and "earliest" which contains the oldest drift.
 
    Use these results to apply compounded deltas as you reach different lines in the output, or just use latest for a fuzzier view.
 
    @raises NotRecentEnoughDriftDelta - If onlyLatest is True and if a close enough sample (within #maxDriftRedetectTime seconds) is not present AND dmesgContents are provided, or a close enough sample is not present and /dev/kmsg is not writeable by current user. Exception message contains what the issue was and is suitable for printing.
 
    If maxDriftRedetectTime is 0, and there is no given delta, and one cannot be created, a NotRecentEnoughDriftDelta will be raised.
 
    This starts with a drift of 0 at zero. This could vary, depending on how far out the first delta is placed, and how off the clock was on boot from being corrected later. You may want to ignore this, maybe not. The most accurate option is to add a printk drift marker after ntpdate service on the boot
printk_convertTimestampToDatetime(timestamp, drift=None, uptime=None)
printk_convertTimestampToDatetime - Converts a printk timestamp to a local datetime object.
 
@see printk_convertTimestampToEpoch
 
@return - <datetime.datetime> - Datetime object in local time
printk_convertTimestampToEpoch(timestamp, drift=None, uptime=None)
printk_convertTimestampToEpoch - Converts a printk timestamp to a "seconds since epoch" time value
 
@param timestamp <str/float> - String/Float of the timestamp (e.x. [1234.14])
@param drift     <float> - Given drift, or None to calculate a drift. If calling often, calculate drift first with printk_calculateDrift(s)
@param uptime    <int> - Current uptime for calcluation, or None to calculate. If calling often, calcluate first with getSystemUptime
 
@return <int> - seconds since epoch. Can be used for a datetime.fromtimestamp
printk_convertTimestampToUTCDatetime(timestamp, drift=None, uptime=None)
printk_convertTimestampToUTCDatetime - Converts a printk timestamp to a utc datetime object
 
@see printk_convertTimestampToEpoch
 
@return - <datetime.datetime> - Datetime object in utc time
printk_markCurrentDrift()
printk_markCurrentDrift - Mark the current uptime in kmsg for calcuation of drift. The more often you do this, the more accurate your timestamps in between will be.
 
@return - Current uptime in seconds

 
Data
        __all__ = ('NotRecentEnoughDriftDelta', 'getSystemUptime', 'printk_calculateCurrentDrift', 'printk_calculateDrifts', 'printk_calculateDrift', 'printk_convertTimestampToDatetime', 'printk_convertTimestampToUTCDatetime', 'printk_convertTimestampToEpoch', 'printk_markCurrentDrift')
__version_tuple__ = (3, 0, 0)