diff mbox series

[RFC,13/21] tracetool: generate plugin snippets

Message ID 20181005154910.3099-14-alex.bennee@linaro.org
State New
Headers show
Series Trace updates and plugin RFC | expand

Commit Message

Alex Bennée Oct. 5, 2018, 3:49 p.m. UTC
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

---
 scripts/tracetool/backend/plugin.py | 79 +++++++++++++++++++++++++++++
 1 file changed, 79 insertions(+)
 create mode 100644 scripts/tracetool/backend/plugin.py

-- 
2.17.1

Comments

Richard Henderson Oct. 15, 2018, 5:02 p.m. UTC | #1
On 10/5/18 8:49 AM, Alex Bennée wrote:
> +def generate_h_begin(events, group):

> +    for event in events:

> +        # prototype for plugin event

> +        out('bool _plugin_%(api)s(%(args)s);',

> +            api=event.api(),

> +            args=event.args)

> +        # prototype for plugin fn

> +        out("typedef bool (* _plugin_%(api)s_fn)(%(args)s);",

> +            api=event.api(),

> +            args=event.args)


Do you really want the _fn typedef to be a pointer?
Not doing that would allow declarations like

  _plugin_apis_fn _plugin_apis;


> +def generate_h(event, group):

> +    out('    if (!_plugin_%(api)s(%(args)s)) {',

> +        '        return;',

> +        '    };',


Extra ;

> +    # Forst the pre-amble, bail early if the event is not enabled and


First.

> +    # if it is but no plugin is enabled let the reset of the events proceed.

> +

> +    out('',

> +        '    if (!%(cond)s) {',

> +        '        return false;',

> +        '    }',

> +        '',

> +        '    uintptr_t fp = trace_event_get_plugin(&_%(event)s_EVENT);',


Declaration in the middle of a block.
Which, honestly, we should just allow via -std=gnu99 or gnu01.
But until then...

> +    out('',

> +        '    _plugin_%(api)s_fn plug_fn = (_plugin_%(api)s_fn) fp;',


Likewise.


r~
diff mbox series

Patch

diff --git a/scripts/tracetool/backend/plugin.py b/scripts/tracetool/backend/plugin.py
new file mode 100644
index 0000000000..d96b2df00a
--- /dev/null
+++ b/scripts/tracetool/backend/plugin.py
@@ -0,0 +1,79 @@ 
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+Plugin backend.
+"""
+
+__author__     = "Alex Bennée <alex.bennee@linaro.org>"
+__copyright__  = "Copyright 2018, Alex Bennée <alex.bennee@linaro.org>"
+__license__    = "GPL version 2 or (at your option) any later version"
+
+__maintainer__ = "Alex Bennée"
+__email__      = "alex.bennee@linaro.org"
+
+
+from tracetool import out
+
+
+PUBLIC = True
+
+
+def generate_h_begin(events, group):
+    for event in events:
+        # prototype for plugin event
+        out('bool _plugin_%(api)s(%(args)s);',
+            api=event.api(),
+            args=event.args)
+        # prototype for plugin fn
+        out("typedef bool (* _plugin_%(api)s_fn)(%(args)s);",
+            api=event.api(),
+            args=event.args)
+
+
+def generate_h(event, group):
+    out('    if (!_plugin_%(api)s(%(args)s)) {',
+        '        return;',
+        '    };',
+        api=event.api(),
+        args=", ".join(event.args.names()))
+
+def generate_c_begin(events, group):
+    out('#include "qemu/osdep.h"',
+        '#include "trace/control.h"',
+        '')
+
+def generate_c(event, group):
+    out('bool _plugin_%(api)s(%(args)s)',
+        '{',
+        api=event.api(),
+        args=event.args)
+
+    event_id = 'TRACE_' + event.name.upper()
+    cond = "trace_event_get_state(%s)" % event_id
+
+    # Forst the pre-amble, bail early if the event is not enabled and
+    # if it is but no plugin is enabled let the reset of the events proceed.
+
+    out('',
+        '    if (!%(cond)s) {',
+        '        return false;',
+        '    }',
+        '',
+        '    uintptr_t fp = trace_event_get_plugin(&_%(event)s_EVENT);',
+        '    if (!fp) {',
+        '        return true;',
+        '    }',
+        '',
+        cond=cond,
+        event=event_id)
+
+    # We need to construct cast to the correct fn pointer to now call the plugin
+
+    out('',
+        '    _plugin_%(api)s_fn plug_fn = (_plugin_%(api)s_fn) fp;',
+        '    return plug_fn(%(names)s);',
+        '}',
+        '',
+        api=event.api(),
+        names=", ".join(event.args.names()))