From 1dad2ce97345f3424c4990cb232b40a35d5e936b Mon Sep 17 00:00:00 2001 From: Lluís Vilanova Date: Sun, 23 Feb 2014 20:37:40 +0100 Subject: trace: [tracetool] Minimize the amount of per-backend code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Backends now only contain the essential backend-specific code, and most of the work is moved to frontend code. Signed-off-by: Lluís Vilanova Signed-off-by: Stefan Hajnoczi --- scripts/tracetool/format/__init__.py | 46 +++++++++++------------------------- 1 file changed, 14 insertions(+), 32 deletions(-) (limited to 'scripts/tracetool/format/__init__.py') diff --git a/scripts/tracetool/format/__init__.py b/scripts/tracetool/format/__init__.py index 2bbbba7011..812570ff6f 100644 --- a/scripts/tracetool/format/__init__.py +++ b/scripts/tracetool/format/__init__.py @@ -20,17 +20,12 @@ All formats must generate their contents through the 'tracetool.out' routine. Format functions ---------------- -All the following functions are optional, and no output will be generated if -they do not exist. - -======== ======================================================================= +======== ================================================================== Function Description -======== ======================================================================= -begin Called to generate the format-specific file header. -end Called to generate the format-specific file footer. -nop Called to generate the per-event contents when the event is disabled or - the selected backend is 'nop'. -======== ======================================================================= +======== ================================================================== +generate Called to generate a format-specific file. +======== ================================================================== + """ __author__ = "Lluís Vilanova " @@ -79,25 +74,12 @@ def exists(name): return tracetool.try_import("tracetool.format." + name)[1] -def _empty(events): - pass - -def generate_begin(name, events): - """Generate the header 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, - "begin", _empty)[1] - func(events) - -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) +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) -- cgit 1.4.1