Esempio n. 1
0
def generate(backend, format, events):
    """Generate the per-event output for the given (backend, format) pair."""
    if not compatible(backend, format):
        raise ValueError("backend '%s' not compatible with format '%s'" % (backend, format))

    backend = backend.replace("-", "_")
    format = format.replace("-", "_")

    if backend == "nop":
        func = tracetool.try_import("tracetool.format." + format, "nop", _empty)[1]
    else:
        func = tracetool.try_import("tracetool.backend." + backend, format, None)[1]

    func(events)
Esempio n. 2
0
def transform_args(format, event, *args, **kwargs):
    """Transforms the arguments to suit the specified format.

    The format module must implement function 'vcpu_args', which receives the
    implicit arguments added by the 'vcpu' property, and must return suitable
    arguments for the given format.

    The function is only called for events with the 'vcpu' property.

    Parameters
    ==========
    format : str
        Format module name.
    event : Event
    args, kwargs
        Passed to 'vcpu_transform_args'.

    Returns
    =======
    Arguments
        The transformed arguments, including the non-implicit ones.

    """
    if "vcpu" in event.properties:
        ok, func = try_import("tracetool.format." + format,
                              "vcpu_transform_args")
        assert ok
        assert func
        return Arguments(
            [func(event.args[:1], *args, **kwargs), event.args[1:]])
    else:
        return event.args
Esempio n. 3
0
def get_list(only_public=False):
    """Get a list of (name, description) pairs."""
    res = [("nop", "Tracing disabled.")]
    modnames = []
    for filename in os.listdir(tracetool.backend.__path__[0]):
        if filename.endswith('.py') and filename != '__init__.py':
            modnames.append(filename.rsplit('.', 1)[0])
    for modname in modnames:
        module = tracetool.try_import("tracetool.backend." + modname)

        # just in case; should never fail unless non-module files are put there
        if not module[0]:
            continue
        module = module[1]

        public = getattr(module, "PUBLIC", False)
        if only_public and not public:
            continue

        doc = module.__doc__
        if doc is None:
            doc = ""
        doc = doc.strip().split("\n")[0]

        name = modname.replace("_", "-")
        res.append((name, doc))
    return res
Esempio n. 4
0
def get_list(only_public = False):
    """Get a list of (name, description) pairs."""
    res = [("nop", "Tracing disabled.")]
    modnames = []
    for filename in os.listdir(tracetool.backend.__path__[0]):
        if filename.endswith('.py') and filename != '__init__.py':
            modnames.append(filename.rsplit('.', 1)[0])
    for modname in sorted(modnames):
        module = tracetool.try_import("tracetool.backend." + modname)

        # just in case; should never fail unless non-module files are put there
        if not module[0]:
            continue
        module = module[1]

        public = getattr(module, "PUBLIC", False)
        if only_public and not public:
            continue

        doc = module.__doc__
        if doc is None:
            doc = ""
        doc = doc.strip().split("\n")[0]

        name = modname.replace("_", "-")
        res.append((name, doc))
    return res
Esempio n. 5
0
def transform_args(format, event, *args, **kwargs):
    """Transforms the arguments to suit the specified format.

    The format module must implement function 'vcpu_args', which receives the
    implicit arguments added by the 'vcpu' property, and must return suitable
    arguments for the given format.

    The function is only called for events with the 'vcpu' property.

    Parameters
    ==========
    format : str
        Format module name.
    event : Event
    args, kwargs
        Passed to 'vcpu_transform_args'.

    Returns
    =======
    Arguments
        The transformed arguments, including the non-implicit ones.

    """
    if "vcpu" in event.properties:
        ok, func = try_import("tracetool.format." + format,
                              "vcpu_transform_args")
        assert ok
        assert func
        return Arguments([func(event.args[:1], *args, **kwargs),
                          event.args[1:]])
    else:
        return event.args
Esempio n. 6
0
def generate(events, format, backend):
    if not exists(format):
        raise ValueError("unknown format: %s" % format)
    format = format.replace("-", "_")
    func = tracetool.try_import("tracetool.format." + format, "generate")[1]
    if func is None:
        raise AttributeError("format has no 'generate': %s" % format)
    func(events, backend)
Esempio n. 7
0
def exists(name):
    """Return whether the given backend exists."""
    if len(name) == 0:
        return False
    if name == "nop":
        return True
    name = name.replace("-", "_")
    return tracetool.try_import("tracetool.backend." + name)[1]
Esempio n. 8
0
def exists(name):
    """Return whether the given backend exists."""
    if len(name) == 0:
        return False
    if name == "nop":
        return True
    name = name.replace("-", "_")
    return tracetool.try_import("tracetool.backend." + name)[1]
Esempio n. 9
0
def generate(backend, format, events):
    """Generate the per-event output for the given (backend, format) pair."""
    if not compatible(backend, format):
        raise ValueError("backend '%s' not compatible with format '%s'" %
                         (backend, format))

    backend = backend.replace("-", "_")
    format = format.replace("-", "_")

    if backend == "nop":
        func = tracetool.try_import("tracetool.format." + format, "nop",
                                    _empty)[1]
    else:
        func = tracetool.try_import("tracetool.backend." + backend, format,
                                    None)[1]

    func(events)
Esempio n. 10
0
def generate_end(name, events):
    """Generate the footer of the format-specific file."""
    if not exists(name):
        raise ValueError("unknown format: %s" % name)

    name = name.replace("-", "_")
    func = tracetool.try_import("tracetool.format." + name, "end", _empty)[1]
    func(events)
Esempio n. 11
0
def generate_end(name, events):
    """Generate the footer of the format-specific file."""
    if not exists(name):
        raise ValueError("unknown format: %s" % name)

    name = name.replace("-", "_")
    func = tracetool.try_import("tracetool.format." + name,
                                "end", _empty)[1]
    func(events)
Esempio n. 12
0
def generate(events, format, backend, group):
    if not exists(format):
        raise ValueError("unknown format: %s" % format)
    format = format.replace("-", "_")
    func = tracetool.try_import("tracetool.format." + format,
                                "generate")[1]
    if func is None:
        raise AttributeError("format has no 'generate': %s" % format)
    func(events, backend, group)
Esempio n. 13
0
def compatible(backend, format):
    """Whether a backend is compatible with the given format."""
    if not exists(backend):
        raise ValueError("unknown backend: %s" % backend)

    backend = backend.replace("-", "_")
    format = format.replace("-", "_")

    if backend == "nop":
        return True
    else:
        func = tracetool.try_import("tracetool.backend." + backend, format, None)[1]
        return func is not None
Esempio n. 14
0
def compatible(backend, format):
    """Whether a backend is compatible with the given format."""
    if not exists(backend):
        raise ValueError("unknown backend: %s" % backend)

    backend = backend.replace("-", "_")
    format = format.replace("-", "_")

    if backend == "nop":
        return True
    else:
        func = tracetool.try_import("tracetool.backend." + backend, format,
                                    None)[1]
        return func is not None
Esempio n. 15
0
def get_list():
    """Get a list of (name, description) pairs."""
    res = [("nop", "Tracing disabled.")]
    for _, modname, _ in pkgutil.iter_modules(tracetool.backend.__path__):
        module = tracetool.try_import("tracetool.backend." + modname)

        # just in case; should never fail unless non-module files are put there
        if not module[0]:
            continue
        module = module[1]

        doc = module.__doc__
        if doc is None:
            doc = ""
        doc = doc.strip().split("\n")[0]

        name = modname.replace("_", "-")
        res.append((name, doc))
    return res
Esempio n. 16
0
def get_list():
    """Get a list of (name, description) pairs."""
    res = []
    for _, modname, _ in pkgutil.iter_modules(tracetool.format.__path__):
        module = tracetool.try_import("tracetool.format." + modname)

        # just in case; should never fail unless non-module files are put there
        if not module[0]:
            continue
        module = module[1]

        doc = module.__doc__
        if doc is None:
            doc = ""
        doc = doc.strip().split("\n")[0]

        name = modname.replace("_", "-")
        res.append((name, doc))
    return res
Esempio n. 17
0
def get_list():
    """Get a list of (name, description) pairs."""
    res = []
    modnames = []
    for filename in os.listdir(tracetool.format.__path__[0]):
        if filename.endswith('.py') and filename != '__init__.py':
            modnames.append(filename.rsplit('.', 1)[0])
    for modname in sorted(modnames):
        module = tracetool.try_import("tracetool.format." + modname)

        # just in case; should never fail unless non-module files are put there
        if not module[0]:
            continue
        module = module[1]

        doc = module.__doc__
        if doc is None:
            doc = ""
        doc = doc.strip().split("\n")[0]

        name = modname.replace("_", "-")
        res.append((name, doc))
    return res
Esempio n. 18
0
def get_list():
    """Get a list of (name, description) pairs."""
    res = []
    modnames = []
    for filename in os.listdir(tracetool.format.__path__[0]):
        if filename.endswith('.py') and filename != '__init__.py':
            modnames.append(filename.rsplit('.', 1)[0])
    for modname in sorted(modnames):
        module = tracetool.try_import("tracetool.format." + modname)

        # just in case; should never fail unless non-module files are put there
        if not module[0]:
            continue
        module = module[1]

        doc = module.__doc__
        if doc is None:
            doc = ""
        doc = doc.strip().split("\n")[0]

        name = modname.replace("_", "-")
        res.append((name, doc))
    return res
Esempio n. 19
0
def get_list():
    """Get a list of (name, description) pairs."""
    res = [("nop", "Tracing disabled.")]
    modnames = []
    for filename in os.listdir(tracetool.backend.__path__[0]):
        if filename.endswith(".py") and filename != "__init__.py":
            modnames.append(filename.rsplit(".", 1)[0])
    for modname in modnames:
        module = tracetool.try_import("tracetool.backend." + modname)

        # just in case; should never fail unless non-module files are put there
        if not module[0]:
            continue
        module = module[1]

        doc = module.__doc__
        if doc is None:
            doc = ""
        doc = doc.strip().split("\n")[0]

        name = modname.replace("_", "-")
        res.append((name, doc))
    return res
Esempio n. 20
0
 def _run_function(self, name, *args, **kwargs):
     for backend in self._backends:
         func = tracetool.try_import("tracetool.backend." + backend,
                                     name % self._format, None)[1]
         if func is not None:
             func(*args, **kwargs)
Esempio n. 21
0
def exists(name):
    """Return whether the given format exists."""
    if len(name) == 0:
        return False
    name = name.replace("-", "_")
    return tracetool.try_import("tracetool.format." + name)[1]
Esempio n. 22
0
def exists(name):
    """Return whether the given format exists."""
    if len(name) == 0:
        return False
    name = name.replace("-", "_")
    return tracetool.try_import("tracetool.format." + name)[1]
Esempio n. 23
0
 def _run_function(self, name, *args, **kwargs):
     func = tracetool.try_import("tracetool.backend." + self._backend,
                                 name % self._format, None)[1]
     if func is not None:
         func(*args, **kwargs)