Esempio n. 1
0
class SimLogFormatter(logging.Formatter):

    sim_precision = simulator.get_precision()
    """Log formatter to provide consistent log message handling."""

    # Justify and truncate
    @staticmethod
    def ljust(string, chars):
        if len(string) > chars:
            return ".." + string[(chars - 2) * -1:]
        return string.ljust(chars)

    @staticmethod
    def rjust(string, chars):
        if len(string) > chars:
            return ".." + string[(chars - 2) * -1:]
        return string.rjust(chars)

    def _format(self, timeh, timel, level, record, msg):
        time_ns = (timeh << 32
                   | timel) * (10.0**SimLogFormatter.sim_precision) / 1e-9
        simtime = "%6.2fns" % (time_ns)
        prefix = simtime + ' ' + level + ' ' + \
            self.ljust(record.name, _RECORD_CHARS) + \
            self.rjust(os.path.split(record.filename)[1], _FILENAME_CHARS) + \
            ':' + self.ljust(str(record.lineno), _LINENO_CHARS) + \
            ' in ' + self.ljust(str(record.funcName), _FUNCNAME_CHARS) + ' '

        pad = "\n" + " " * (len(prefix))
        return prefix + pad.join(msg.split('\n'))

    def format(self, record):
        """pretify the log output, annotate with simulation time"""
        if record.args:
            msg = record.msg % record.args
        else:
            msg = record.msg

        msg = str(msg)
        level = record.levelname.ljust(_LEVEL_CHARS)
        timeh, timel = simulator.get_sim_time()

        return self._format(timeh, timel, level, record, msg)
Esempio n. 2
0
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""Collection of handy functions."""

import ctypes
import math
import os
import sys
import weakref
import functools
import warnings

if "COCOTB_SIM" in os.environ:
    import simulator
    _LOG_SIM_PRECISION = simulator.get_precision()  # request once and cache
else:
    simulator = None
    _LOG_SIM_PRECISION = -15


def get_python_integer_types():
    warnings.warn(
        "This is an internal cocotb function, use six.integer_types instead",
        DeprecationWarning)
    from cocotb import _py_compat
    return _py_compat.integer_types


# Simulator helper functions
def get_sim_time(units=None):
Esempio n. 3
0
"""
Everything related to logging
"""

import os
import sys
import logging
import inspect
# For autodocumentation don't need the extension modules
if "SPHINX_BUILD" in os.environ:
    simulator = None
    _SIM_PRECISION = 1000
else:
    import simulator
    _SIM_PRECISION = simulator.get_precision()

import cocotb.ANSI as ANSI
from pdb import set_trace

# Column alignment
_LEVEL_CHARS    = len("CRITICAL")  # noqa
_RECORD_CHARS   = 35  # noqa
_FILENAME_CHARS = 20  # noqa
_LINENO_CHARS   = 4  # noqa
_FUNCNAME_CHARS = 31  # noqa

class SimBaseLog(logging.getLoggerClass()):
    def __init__(self, name):
        hdlr = logging.StreamHandler(sys.stdout)
        want_ansi = os.getenv("COCOTB_ANSI_OUTPUT")
Esempio n. 4
0
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. '''

"""Collection of handy functions"""

import ctypes
import math
import os
import sys

# For autodocumentation don't need the extension modules
if "SPHINX_BUILD" in os.environ:
    simulator = None
    _LOG_SIM_PRECISION = -15
else:
    import simulator
    _LOG_SIM_PRECISION = simulator.get_precision() # request once and cache

# python2 to python3 helper functions
def get_python_integer_types():
    try:
        isinstance(1, long)
    except NameError:
        return (int,)  # python 3
    else:
        return (int, long)  # python 2

# Simulator helper functions
def get_sim_time(units=None):
    """Retrieves the simulation time from the simulator

    Kwargs:
Esempio n. 5
0
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. '''
"""
Everything related to logging
"""

import os
import sys
import logging
import inspect
# For autodocumentation don't need the extension modules
if "SPHINX_BUILD" in os.environ:
    simulator = None
    _SIM_PRECISION = 1000
else:
    import simulator
    _SIM_PRECISION = simulator.get_precision()

import cocotb.ANSI as ANSI
from pdb import set_trace

# Column alignment
_LEVEL_CHARS = len("CRITICAL")  # noqa
_RECORD_CHARS = 35  # noqa
_FILENAME_CHARS = 20  # noqa
_LINENO_CHARS = 4  # noqa
_FUNCNAME_CHARS = 31  # noqa


class SimBaseLog(logging.getLoggerClass()):
    def __init__(self, name):
        hdlr = logging.StreamHandler(sys.stdout)