diff mbox

trace: teach lttng backend to use format strings

Message ID 1395682526-7538-1-git-send-email-alex.bennee@linaro.org
State Superseded
Headers show

Commit Message

Alex Bennée March 24, 2014, 5:35 p.m. UTC
From: Alex Bennée <alex.bennee@linaro.org>

This makes the UST backend pay attention to the format string arguments
that are defined when defining payload data. With this you can now
ensure integers are reported in hex mode if you want.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

---

v2
  - remove silly debug statements
---
 scripts/tracetool/__init__.py    | 12 ++++++++++--
 scripts/tracetool/backend/ust.py | 17 ++++++++++++-----
 2 files changed, 22 insertions(+), 7 deletions(-)

Comments

Eric Blake March 24, 2014, 5:42 p.m. UTC | #1
On 03/24/2014 11:35 AM, alex.bennee@linaro.org wrote:
> From: Alex Bennée <alex.bennee@linaro.org>
> 
> This makes the UST backend pay attention to the format string arguments
> that are defined when defining payload data. With this you can now
> ensure integers are reported in hex mode if you want.
> 
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> 
> ---

>      args : Arguments
>          The event arguments.
> +    arg_fmts : str
> +        The format strings for each arugment.

s/arugment/argument/
Stefan Hajnoczi March 27, 2014, 8:42 a.m. UTC | #2
On Mon, Mar 24, 2014 at 05:35:26PM +0000, alex.bennee@linaro.org wrote:
> From: Alex Bennée <alex.bennee@linaro.org>
> 
> This makes the UST backend pay attention to the format string arguments
> that are defined when defining payload data. With this you can now
> ensure integers are reported in hex mode if you want.
> 
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> 
> ---
> 
> v2
>   - remove silly debug statements
> ---
>  scripts/tracetool/__init__.py    | 12 ++++++++++--
>  scripts/tracetool/backend/ust.py | 17 ++++++++++++-----
>  2 files changed, 22 insertions(+), 7 deletions(-)

This conflicts with Lluis' tracing cleanup patch series that is merged
for QEMU 2.1.

Please rebase on:

  git://github.com/stefanha/qemu.git tracing-next
diff mbox

Patch

diff --git a/scripts/tracetool/__init__.py b/scripts/tracetool/__init__.py
index 175df08..71e2ab5 100644
--- a/scripts/tracetool/__init__.py
+++ b/scripts/tracetool/__init__.py
@@ -118,13 +118,16 @@  class Event(object):
         Properties of the event.
     args : Arguments
         The event arguments.
+    arg_fmts : str
+        The format strings for each arugment.
     """
 
     _CRE = re.compile("((?P<props>.*)\s+)?(?P<name>[^(\s]+)\((?P<args>[^)]*)\)\s*(?P<fmt>\".*)?")
+    _FMT = re.compile("(%\w+|%.*PRI\S+)")
 
     _VALID_PROPS = set(["disable"])
 
-    def __init__(self, name, props, fmt, args):
+    def __init__(self, name, props, fmt, args, arg_fmts):
         """
         Parameters
         ----------
@@ -136,11 +139,15 @@  class Event(object):
             Event printing format.
         args : Arguments
             Event arguments.
+        arg_fmts : list of str
+            Format strings for each argument
+
         """
         self.name = name
         self.properties = props
         self.fmt = fmt
         self.args = args
+        self.arg_fmts = arg_fmts
 
         unknown_props = set(self.properties) - self._VALID_PROPS
         if len(unknown_props) > 0:
@@ -163,8 +170,9 @@  class Event(object):
         props = groups["props"].split()
         fmt = groups["fmt"]
         args = Arguments.build(groups["args"])
+        arg_fmts = Event._FMT.findall(fmt)
 
-        return Event(name, props, fmt, args)
+        return Event(name, props, fmt, args, arg_fmts)
 
     def __repr__(self):
         """Evaluable string representation for this object."""
diff --git a/scripts/tracetool/backend/ust.py b/scripts/tracetool/backend/ust.py
index 41c1c75..6223f20 100644
--- a/scripts/tracetool/backend/ust.py
+++ b/scripts/tracetool/backend/ust.py
@@ -56,13 +56,20 @@  def ust_events_h(events):
                 args = ", ".join(", ".join(i) for i in e.args),
                 )
 
-            for t,n in e.args:
-                if ('int' in t) or ('long' in t) or ('unsigned' in t) or ('size_t' in t):
+            types = e.args.types()
+            names = e.args.names()
+            fmts = e.arg_fmts
+            for t,n,f in zip(types, names, fmts):
+                if ('char *' in t) or ('char*' in t):
+                    out('       ctf_string(' + n + ', ' + n + ')')
+                elif ("%p" in f) or ("x" in f) or ("PRIx" in f):
+                    out('       ctf_integer_hex('+ t + ', ' + n + ', ' + n + ')')
+                elif ("ptr" in t) or ("*" in t):
+                    out('       ctf_integer_hex('+ t + ', ' + n + ', ' + n + ')')
+                elif ('int' in t) or ('long' in t) or ('unsigned' in t) or ('size_t' in t):
                     out('       ctf_integer(' + t + ', ' + n + ', ' + n + ')')
                 elif ('double' in t) or ('float' in t):
                     out('       ctf_float(' + t + ', ' + n + ', ' + n + ')')
-                elif ('char *' in t) or ('char*' in t):
-                    out('       ctf_string(' + n + ', ' + n + ')')
                 elif ('void *' in t) or ('void*' in t):
                     out('       ctf_integer_hex(unsigned long, ' + n + ', ' + n + ')')
 
@@ -79,4 +86,4 @@  def ust_events_h(events):
                 ')',
                 '',
                 name = e.name,
-                )
\ No newline at end of file
+                )