All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v4 0/2] a few simple trace fixes
@ 2014-08-01 16:08 Alex Bennée
  2014-08-01 16:08 ` [Qemu-devel] [PATCH v4 1/2] trace: teach lttng backend to use format strings Alex Bennée
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Alex Bennée @ 2014-08-01 16:08 UTC (permalink / raw)
  To: stefanha; +Cc: Alex Bennée, qemu-devel

Hi Stefan,

As v3 posted earlier today but with a format string fix which didn't
show up in the ust build I tested it on....

Alex Bennée (2):
  trace: teach lttng backend to use format strings
  trace: add some tcg tracing support

 cpu-exec.c                               |  6 ++++++
 scripts/tracetool/__init__.py            | 12 ++++++++++--
 scripts/tracetool/format/ust_events_h.py | 15 +++++++++++----
 trace-events                             |  9 +++++++++
 translate-all.c                          |  3 +++
 5 files changed, 39 insertions(+), 6 deletions(-)

-- 
2.0.3

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Qemu-devel] [PATCH v4 1/2] trace: teach lttng backend to use format strings
  2014-08-01 16:08 [Qemu-devel] [PATCH v4 0/2] a few simple trace fixes Alex Bennée
@ 2014-08-01 16:08 ` Alex Bennée
  2014-08-01 16:08 ` [Qemu-devel] [PATCH v4 2/2] trace: add some tcg tracing support Alex Bennée
  2014-08-05  9:59 ` [Qemu-devel] [PATCH v4 0/2] a few simple trace fixes Stefan Hajnoczi
  2 siblings, 0 replies; 4+ messages in thread
From: Alex Bennée @ 2014-08-01 16:08 UTC (permalink / raw)
  To: stefanha; +Cc: Alex Bennée, qemu-devel

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
v3
  - fix spelling
  - rebase to latest tracetool
v4:
  - rebase onto tracing-next

diff --git a/scripts/tracetool/__init__.py b/scripts/tracetool/__init__.py
index a51e0f2..36c789d 100644
--- a/scripts/tracetool/__init__.py
+++ b/scripts/tracetool/__init__.py
@@ -136,6 +136,8 @@ class Event(object):
         Properties of the event.
     args : Arguments
         The event arguments.
+    arg_fmts : str
+        The format strings for each argument.
     """
 
     _CRE = re.compile("((?P<props>.*)\s+)?"
@@ -144,10 +146,11 @@ class Event(object):
                       "\s*"
                       "(?:(?:(?P<fmt_trans>\".+),)?\s*(?P<fmt>\".+))?"
                       "\s*")
+    _FMT = re.compile("(%\w+|%.*PRI\S+)")
 
     _VALID_PROPS = set(["disable", "tcg", "tcg-trans", "tcg-exec"])
 
-    def __init__(self, name, props, fmt, args, orig=None):
+    def __init__(self, name, props, fmt, args, arg_fmts, orig=None):
         """
         Parameters
         ----------
@@ -159,13 +162,17 @@ class Event(object):
             Event printing format (or formats).
         args : Arguments
             Event arguments.
+        arg_fmts : list of str
+            Format strings for each argument.
         orig : Event or None
             Original Event before transformation.
+
         """
         self.name = name
         self.properties = props
         self.fmt = fmt
         self.args = args
+        self.arg_fmts = arg_fmts
 
         if orig is None:
             self.original = weakref.ref(self)
@@ -203,6 +210,7 @@ class Event(object):
         if len(fmt_trans) > 0:
             fmt = [fmt_trans, fmt]
         args = Arguments.build(groups["args"])
+        arg_fmts = Event._FMT.findall(fmt)
 
         if "tcg-trans" in props:
             raise ValueError("Invalid property 'tcg-trans'")
@@ -213,7 +221,7 @@ class Event(object):
         if "tcg" in props and isinstance(fmt, str):
             raise ValueError("Events with 'tcg' property must have two formats")
 
-        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/format/ust_events_h.py b/scripts/tracetool/format/ust_events_h.py
index 5102565..d189899 100644
--- a/scripts/tracetool/format/ust_events_h.py
+++ b/scripts/tracetool/format/ust_events_h.py
@@ -63,13 +63,20 @@ def generate(events, backend):
                 name=e.name,
                 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 + ')')
 
-- 
2.0.3

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [Qemu-devel] [PATCH v4 2/2] trace: add some tcg tracing support
  2014-08-01 16:08 [Qemu-devel] [PATCH v4 0/2] a few simple trace fixes Alex Bennée
  2014-08-01 16:08 ` [Qemu-devel] [PATCH v4 1/2] trace: teach lttng backend to use format strings Alex Bennée
@ 2014-08-01 16:08 ` Alex Bennée
  2014-08-05  9:59 ` [Qemu-devel] [PATCH v4 0/2] a few simple trace fixes Stefan Hajnoczi
  2 siblings, 0 replies; 4+ messages in thread
From: Alex Bennée @ 2014-08-01 16:08 UTC (permalink / raw)
  To: stefanha; +Cc: Alex Bennée, qemu-devel

This adds a couple of tcg specific trace-events which are useful for
tracing execution though tcg generated blocks. It's been tested with
lttng user space tracing but is generic enough for all systems. The tcg
events are:

  * translate_block - when a subject block is translated
  * exec_tb - when a translated block is entered
  * exec_tb_exit - when we exit the translated code
  * exec_tb_nocache - special case translations

Of course we can only trace the entrance to the first block of a chain
as each block will jump directly to the next when it can. See the -d
nochain patch to allow more complete tracing at the expense of
performance.

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

---
v2
  - rebase

v3:
  - checkpatch clean-ups
  - add sign-off
  - disable exec_tb by default

v4:
  - fix fmt strings for uintptr_t

diff --git a/cpu-exec.c b/cpu-exec.c
index 38e5f02..d209568 100644
--- a/cpu-exec.c
+++ b/cpu-exec.c
@@ -18,6 +18,7 @@
  */
 #include "config.h"
 #include "cpu.h"
+#include "trace.h"
 #include "disas/disas.h"
 #include "tcg.h"
 #include "qemu/atomic.h"
@@ -65,6 +66,9 @@ static inline tcg_target_ulong cpu_tb_exec(CPUState *cpu, uint8_t *tb_ptr)
 #endif /* DEBUG_DISAS */
 
     next_tb = tcg_qemu_tb_exec(env, tb_ptr);
+    trace_exec_tb_exit((void *) (next_tb & ~TB_EXIT_MASK),
+                       next_tb & TB_EXIT_MASK);
+
     if ((next_tb & TB_EXIT_MASK) > TB_EXIT_IDX1) {
         /* We didn't start executing this TB (eg because the instruction
          * counter hit zero); we must restore the guest PC to the address
@@ -105,6 +109,7 @@ static void cpu_exec_nocache(CPUArchState *env, int max_cycles,
                      max_cycles);
     cpu->current_tb = tb;
     /* execute the generated code */
+    trace_exec_tb_nocache(tb, tb->pc);
     cpu_tb_exec(cpu, tb->tc_ptr);
     cpu->current_tb = NULL;
     tb_phys_invalidate(tb, -1);
@@ -637,6 +642,7 @@ int cpu_exec(CPUArchState *env)
                 cpu->current_tb = tb;
                 barrier();
                 if (likely(!cpu->exit_request)) {
+                    trace_exec_tb(tb, tb->pc);
                     tc_ptr = tb->tc_ptr;
                     /* execute the generated code */
                     next_tb = cpu_tb_exec(cpu, tc_ptr);
diff --git a/trace-events b/trace-events
index 11a17a8..dcc33dd 100644
--- a/trace-events
+++ b/trace-events
@@ -1265,6 +1265,15 @@ kvm_failed_spr_get(int str, const char *msg) "Warning: Unable to retrieve SPR %d
 kvm_failed_reg_get(uint64_t id, const char *msg) "Warning: Unable to retrieve ONEREG %" PRIu64 " from KVM: %s"
 kvm_failed_reg_set(uint64_t id, const char *msg) "Warning: Unable to set ONEREG %" PRIu64 " to KVM: %s"
 
+# TCG related tracing (mostly disabled by default)
+# cpu-exec.c
+disable exec_tb(void *tb, uintptr_t pc) "tb:%p pc=0x%"PRIxPTR
+disable exec_tb_nocache(void *tb, uintptr_t pc) "tb:%p pc=0x%"PRIxPTR
+disable exec_tb_exit(void *next_tb, unsigned int flags) "tb:%p flags=%x"
+
+# translate-all.c
+translate_block(void *tb, uintptr_t pc, uint8_t *tb_code) "tb:%p, pc:0x%"PRIxPTR", tb_code:%p"
+
 # memory.c
 memory_region_ops_read(void *mr, uint64_t addr, uint64_t value, unsigned size) "mr %p addr %#"PRIx64" value %#"PRIx64" size %u"
 memory_region_ops_write(void *mr, uint64_t addr, uint64_t value, unsigned size) "mr %p addr %#"PRIx64" value %#"PRIx64" size %u"
diff --git a/translate-all.c b/translate-all.c
index 8f7e11b..2e0265a 100644
--- a/translate-all.c
+++ b/translate-all.c
@@ -33,6 +33,7 @@
 #include "qemu-common.h"
 #define NO_CPU_IO_DEFS
 #include "cpu.h"
+#include "trace.h"
 #include "disas/disas.h"
 #include "tcg.h"
 #if defined(CONFIG_USER_ONLY)
@@ -158,6 +159,8 @@ int cpu_gen_code(CPUArchState *env, TranslationBlock *tb, int *gen_code_size_ptr
 
     gen_intermediate_code(env, tb);
 
+    trace_translate_block(tb, tb->pc, tb->tc_ptr);
+
     /* generate machine code */
     gen_code_buf = tb->tc_ptr;
     tb->tb_next_offset[0] = 0xffff;
-- 
2.0.3

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH v4 0/2] a few simple trace fixes
  2014-08-01 16:08 [Qemu-devel] [PATCH v4 0/2] a few simple trace fixes Alex Bennée
  2014-08-01 16:08 ` [Qemu-devel] [PATCH v4 1/2] trace: teach lttng backend to use format strings Alex Bennée
  2014-08-01 16:08 ` [Qemu-devel] [PATCH v4 2/2] trace: add some tcg tracing support Alex Bennée
@ 2014-08-05  9:59 ` Stefan Hajnoczi
  2 siblings, 0 replies; 4+ messages in thread
From: Stefan Hajnoczi @ 2014-08-05  9:59 UTC (permalink / raw)
  To: Alex Bennée; +Cc: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 757 bytes --]

On Fri, Aug 01, 2014 at 05:08:55PM +0100, Alex Bennée wrote:
> As v3 posted earlier today but with a format string fix which didn't
> show up in the ust build I tested it on....
> 
> Alex Bennée (2):
>   trace: teach lttng backend to use format strings
>   trace: add some tcg tracing support
> 
>  cpu-exec.c                               |  6 ++++++
>  scripts/tracetool/__init__.py            | 12 ++++++++++--
>  scripts/tracetool/format/ust_events_h.py | 15 +++++++++++----
>  trace-events                             |  9 +++++++++
>  translate-all.c                          |  3 +++
>  5 files changed, 39 insertions(+), 6 deletions(-)

Thanks, applied to my tracing tree:
https://github.com/stefanha/qemu/commits/tracing

Stefan

[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-08-05  9:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-01 16:08 [Qemu-devel] [PATCH v4 0/2] a few simple trace fixes Alex Bennée
2014-08-01 16:08 ` [Qemu-devel] [PATCH v4 1/2] trace: teach lttng backend to use format strings Alex Bennée
2014-08-01 16:08 ` [Qemu-devel] [PATCH v4 2/2] trace: add some tcg tracing support Alex Bennée
2014-08-05  9:59 ` [Qemu-devel] [PATCH v4 0/2] a few simple trace fixes Stefan Hajnoczi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.