diff options
author | Peter Maydell <peter.maydell@linaro.org> | 2014-05-08 12:38:01 +0100 |
---|---|---|
committer | Peter Maydell <peter.maydell@linaro.org> | 2014-05-08 12:38:01 +0100 |
commit | 43cbeffb19877c62cbe0aaf08b2f235d98d71340 (patch) | |
tree | 90a1d70eb7a165a8ddc923169651da2ab68edaac /scripts/tracetool/backend/__init__.py | |
parent | 6b342cc9c872e82620fdd32730cd92affa8a19b3 (diff) | |
parent | e00e36fb913217d49f57cc19d8d605270dd82bc5 (diff) |
Merge remote-tracking branch 'remotes/stefanha/tags/tracing-pull-request' into staging
Tracing pull request
# gpg: Signature made Wed 07 May 2014 18:14:02 BST using RSA key ID 81AB73C8
# gpg: Good signature from "Stefan Hajnoczi <stefanha@redhat.com>"
# gpg: aka "Stefan Hajnoczi <stefanha@gmail.com>"
* remotes/stefanha/tags/tracing-pull-request:
configure: Show trace output file conditionally
trace: [tracetool] Minimize the amount of per-backend code
trace: [simple] Bump up log version number
trace: [tracetool] Change format docs to point to the generated file
trace: [tracetool] Show list of frontends and backends sorted by name
trace: [tracetool] Cosmetic changes
trace: [tracetool] Spacing changes
trace: [tracetool] Add methods 'Event.copy' and 'Arguments.copy'
trace: [tracetool] Add method 'Event.api' to build event names
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'scripts/tracetool/backend/__init__.py')
-rw-r--r-- | scripts/tracetool/backend/__init__.py | 74 |
1 files changed, 33 insertions, 41 deletions
diff --git a/scripts/tracetool/backend/__init__.py b/scripts/tracetool/backend/__init__.py index f0314ee376..5e36f0415d 100644 --- a/scripts/tracetool/backend/__init__.py +++ b/scripts/tracetool/backend/__init__.py @@ -30,17 +30,24 @@ PUBLIC If exists and is set to 'True', the backend is considered "public". Backend functions ----------------- -======== ======================================================================= -Function Description -======== ======================================================================= -<format> Called to generate the format- and backend-specific code for each of - the specified events. If the function does not exist, the backend is - considered not compatible with the given format. -======== ======================================================================= +All the following functions are optional, and no output will be generated if +they do not exist. + +=============================== ============================================== +Function Description +=============================== ============================================== +generate_<format>_begin(events) Generate backend- and format-specific file + header contents. +generate_<format>_end(events) Generate backend- and format-specific file + footer contents. +generate_<format>(event) Generate backend- and format-specific contents + for the given event. +=============================== ============================================== + """ __author__ = "Lluís Vilanova <vilanova@ac.upc.edu>" -__copyright__ = "Copyright 2012, Lluís Vilanova <vilanova@ac.upc.edu>" +__copyright__ = "Copyright 2012-2014, Lluís Vilanova <vilanova@ac.upc.edu>" __license__ = "GPL version 2 or (at your option) any later version" __maintainer__ = "Stefan Hajnoczi" @@ -59,7 +66,7 @@ def get_list(only_public = False): 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: + 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 @@ -91,39 +98,24 @@ def exists(name): return tracetool.try_import("tracetool.backend." + name)[1] -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 - - -def _empty(events): - pass +class Wrapper: + def __init__(self, backend, format): + self._backend = backend.replace("-", "_") + self._format = format.replace("-", "_") + assert exists(self._backend) + assert tracetool.format.exists(self._format) -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)) + 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) - backend = backend.replace("-", "_") - format = format.replace("-", "_") + def generate_begin(self, events): + self._run_function("generate_%s_begin", events) - if backend == "nop": - func = tracetool.try_import("tracetool.format." + format, - "nop", _empty)[1] - else: - func = tracetool.try_import("tracetool.backend." + backend, - format, None)[1] + def generate(self, event): + self._run_function("generate_%s", event) - func(events) + def generate_end(self, events): + self._run_function("generate_%s_end", events) |