Skip to contentSkip to conversation

fix tracing for modules

RFC PATCH Superseded Gerd Hoffmann 2 participants 8 messages Nov 24, 2020 – Dec 15, 2020 Arm/Amlogic Meson SoC support

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover fix tracing for modules

First version that actually works. Only qxl covered for this RfC, other modules will follow once the basics are hashed out.

More context:
https://bugzilla.redhat.com/show_bug.cgi?id=1898700
https://bugzilla.redhat.com/show_bug.cgi?id=1869642

take care,
Gerd

Gerd Hoffmann (4):
meson: add trace_events_config[]
meson: move up hw subdir (specifically before trace subdir)
meson: add module_trace & module_trace_src
meson: move qxl trace events to separate file

 hw/display/qxl-render.c     |  1 +
 hw/display/qxl.c            |  1 +
 hw/display/meson.build      |  5 +++
 hw/display/trace-events     | 67 -------------------------------------
 hw/display/trace-events-qxl | 66 ++++++++++++++++++++++++++++++++++++
 meson.build                 |  7 ++--
 trace/meson.build           | 37 +++++++++++++++-----
 7 files changed, 106 insertions(+), 78 deletions(-)
 create mode 100644 hw/display/trace-events-qxl
Signature · 1 line
2.27.0
#1 lore raw

PATCH v2 1/4 meson: add trace_events_config[]

It's an array of dicts, where each dict holds the configuration for one trace-events file. For now just fill it from trace_events_subdirs.

---
 meson.build       |  1 +
 trace/meson.build | 21 ++++++++++++++++-----
 2 files changed, 17 insertions(+), 5 deletions(-)
meson.build +1 -0
index 5062407c7052..b62f71c6b4f1 100644
@@ -1386,6 +1386,7 @@ target_softmmu_arch = {}
 
 # TODO: add each directory to the subdirs from its own meson.build, once
 # we have those
+trace_events_config = []
 trace_events_subdirs = [
   'accel/kvm',
   'accel/tcg',
trace/meson.build +16 -5
index 843ea1449540..552371b84241 100644
@@ -1,12 +1,23 @@
 specific_ss.add(files('control-target.c'))
 
 trace_events_files = []
-foreach dir : [ '.' ] + trace_events_subdirs
-  trace_events_file = meson.source_root() / dir / 'trace-events'
+
+trace_events_config += {
+  'file'  : meson.source_root() / 'trace-events',
+  'group' : 'root',
+}
+foreach dir : trace_events_subdirs
+  trace_events_config += {
+    'file'  : meson.source_root() / dir / 'trace-events',
+    'group' : dir.underscorify(),
+  }
+endforeach
+
+foreach c : trace_events_config
+  trace_events_file = c.get('file')
   trace_events_files += [ trace_events_file ]
-  group_name = dir == '.' ? 'root' : dir.underscorify()
-  group = '--group=' + group_name
-  fmt = '@0@-' + group_name + '.@1@'
+  group = '--group=' + c.get('group')
+  fmt = '@0@-' + c.get('group') + '.@1@'
 
   trace_h = custom_target(fmt.format('trace', 'h'),
                           output: fmt.format('trace', 'h'),
Signature · 1 line
2.27.0
#2 lore raw

PATCH v2 2/4 meson: move up hw subdir (specifically before trace subdir)

In reply to Gerd Hoffmann

Needed so trace/meson.build can see
stuff done in hw/*/meson.build.

---
 meson.build | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
meson.build +2 -1
index b62f71c6b4f1..a85d331668fa 100644
@@ -1477,6 +1477,8 @@ trace_events_subdirs += [
   'util',
 ]
 
+subdir('hw')
+
 subdir('contrib/libvhost-user')
 subdir('qapi')
 subdir('qobject')
@@ -1564,7 +1566,6 @@ subdir('migration')
 subdir('monitor')
 subdir('net')
 subdir('replay')
-subdir('hw')
 subdir('accel')
 subdir('plugins')
 subdir('bsd-user')
Signature · 1 line
2.27.0
#3 lore raw

PATCH v2 3/4 meson: add module_trace & module_trace_src

In reply to Gerd Hoffmann
---
 meson.build       |  3 ++-
 trace/meson.build | 16 ++++++++++++----
 2 files changed, 14 insertions(+), 5 deletions(-)
meson.build +2 -1
index a85d331668fa..0000cc286120 100644
@@ -1591,7 +1591,8 @@ foreach d, list : modules
   foreach m, module_ss : list
     if enable_modules and targetos != 'windows'
       module_ss = module_ss.apply(config_all, strict: false)
-      sl = static_library(d + '-' + m, [genh, module_ss.sources()],
+      module_trace_src = module_trace.get(d + '-' + m, [])
+      sl = static_library(d + '-' + m, [genh, module_ss.sources(), module_trace_src],
                           dependencies: [modulecommon, module_ss.dependencies()], pic: true)
       if d == 'block'
         block_mods += sl
trace/meson.build +12 -4
index 552371b84241..b4e59ce9668b 100644
@@ -1,6 +1,7 @@
 specific_ss.add(files('control-target.c'))
 
 trace_events_files = []
+module_trace = {}
 
 trace_events_config += {
   'file'  : meson.source_root() / 'trace-events',
@@ -18,6 +19,8 @@ foreach c : trace_events_config
   trace_events_files += [ trace_events_file ]
   group = '--group=' + c.get('group')
   fmt = '@0@-' + c.get('group') + '.@1@'
+  mod = c.get('module', '')
+  module_trace_src = []
 
   trace_h = custom_target(fmt.format('trace', 'h'),
                           output: fmt.format('trace', 'h'),
@@ -36,10 +39,10 @@ foreach c : trace_events_config
                                 input: trace_events_file,
                                 command: [ tracetool, group, '--format=ust-events-h', '@INPUT@' ],
                                 capture: true)
-    trace_ss.add(trace_ust_h, lttng, urcubp)
+    module_trace_src += [ trace_ust_h, lttng, urcubp ]
     genh += trace_ust_h
   endif
-  trace_ss.add(trace_h, trace_c)
+  module_trace_src += [ trace_h, trace_c ]
   if 'CONFIG_TRACE_DTRACE' in config_host
     trace_dtrace = custom_target(fmt.format('trace-dtrace', 'dtrace'),
                                  output: fmt.format('trace-dtrace', 'dtrace'),
@@ -50,17 +53,22 @@ foreach c : trace_events_config
                                    output: fmt.format('trace-dtrace', 'h'),
                                    input: trace_dtrace,
                                    command: [ 'dtrace', '-DSTAP_SDT_V2', '-o', '@OUTPUT@', '-h', '-s', '@INPUT@' ])
-    trace_ss.add(trace_dtrace_h)
+    module_trace_src += trace_dtrace_h
     if host_machine.system() != 'darwin'
       trace_dtrace_o = custom_target(fmt.format('trace-dtrace', 'o'),
                                      output: fmt.format('trace-dtrace', 'o'),
                                      input: trace_dtrace,
                                      command: [ 'dtrace', '-DSTAP_SDT_V2', '-o', '@OUTPUT@', '-G', '-s', '@INPUT@' ])
-      trace_ss.add(trace_dtrace_o)
+      module_trace_src += trace_dtrace_o
     endif
 
     genh += trace_dtrace_h
   endif
+  if enable_modules and mod != ''
+    module_trace += { mod : module_trace_src }
+  else
+    trace_ss.add(module_trace_src)
+  endif
 endforeach
 
 trace_events_all = custom_target('trace-events-all',
Signature · 1 line
2.27.0
#4 lore raw

PATCH v2 4/4 meson: move qxl trace events to separate file

In reply to Gerd Hoffmann

Move qxl trace events to separate trace-events-qxl file.

---
 hw/display/qxl-render.c     |  1 +
 hw/display/qxl.c            |  1 +
 hw/display/meson.build      |  5 +++
 hw/display/trace-events     | 67 -------------------------------------
 hw/display/trace-events-qxl | 66 ++++++++++++++++++++++++++++++++++++
 5 files changed, 73 insertions(+), 67 deletions(-)
 create mode 100644 hw/display/trace-events-qxl
hw/display/qxl-render.c +1 -0
index 3ce2e57b8feb..cc4862e26eb6 100644
@@ -23,6 +23,7 @@
 #include "qxl.h"
 #include "sysemu/runstate.h"
 #include "trace.h"
+#include "trace/trace-hw_display_qxl.h"
 
 static void qxl_blit(PCIQXLDevice *qxl, QXLRect *rect)
 {
hw/display/qxl.c +1 -0
index 431c1070967a..4e8d1bb8d77b 100644
@@ -33,6 +33,7 @@
 #include "migration/blocker.h"
 #include "migration/vmstate.h"
 #include "trace.h"
+#include "trace/trace-hw_display_qxl.h"
 
 #include "qxl.h"
 
hw/display/meson.build +5 -0
index dad3bd2b414b..d4a0e0204ee2 100644
@@ -43,6 +43,11 @@ if config_all_devices.has_key('CONFIG_QXL')
   qxl_ss = ss.source_set()
   qxl_ss.add(when: 'CONFIG_QXL', if_true: [files('qxl.c', 'qxl-logger.c', 'qxl-render.c'),
                                            pixman, spice])
+  trace_events_config += {
+    'file'   : meson.source_root() / 'hw' / 'display' / 'trace-events-qxl',
+    'group'  : 'hw_display_qxl',
+    'module' : 'hw-display-qxl',
+  }
   hw_display_modules += {'qxl': qxl_ss}
 endif
 
hw/display/trace-events +0 -67

73 lines not on this page · raw message

hw/display/trace-events-qxl new file +66 -0

66 lines not on this page · raw message

Signature · 1 line
2.27.0
#5 lore raw
In reply to Gerd Hoffmann
Quoted 7 lines · Gerd Hoffmann

First version that actually works. Only qxl covered for this RfC, other modules will follow once the basics are hashed out.

More context:
https://bugzilla.redhat.com/show_bug.cgi?id=1898700
https://bugzilla.redhat.com/show_bug.cgi?id=1869642

Quoted 8 lines

take care,
Gerd

Gerd Hoffmann (4):
meson: add trace_events_config[]
meson: move up hw subdir (specifically before trace subdir)
meson: add module_trace & module_trace_src
meson: move qxl trace events to separate file

Awesome, thank you for working on this!

I noticed an issue with simpletrace: the trace file does not contain qxl_* TRACE_RECORD_TYPE_MAPPING records when ./configure --enable-modules is used. This happens because st_write_event_mapping() is called before the qxl module calls trace_event_register_group().

(The mapping records describe the integer ID to string name mapping used in a simpletrace file.)

You can check this using "grep -a qxl_ trace-$LAST_QEMU_PID" after running qemu --device qxl built with ./configure --enable-modules --enable-trace-backend=simple.

Remove --enable-modules and the file will contain the qxl_ trace events.

This means the trace file is broken because the simpletrace records cannot be mapped to a trace event name.

One way to solve this is by modifying trace_event_register_group() to call into trace/simple.c (maybe with a TraceEventIter initialized to iterate over the newly registered trace events group?).

Alternatively, simpletrace.c might be able to emit TRACE_RECORD_TYPE_MAPPING on demand instead of ahead of time.

Stefan

#6 lore raw

Hi,

Quoted 7 lines

I noticed an issue with simpletrace: the trace file does not contain qxl_* TRACE_RECORD_TYPE_MAPPING records when ./configure --enable-modules is used. This happens because st_write_event_mapping() is called before the qxl module calls trace_event_register_group().

(The mapping records describe the integer ID to string name mapping used in a simpletrace file.)

It's not the only initialization issue. "qemu-system-x86_64 -vga qxl -trace qxl*" doesn't work either for simliar reasons.

Quoted 6 lines

One way to solve this is by modifying trace_event_register_group() to call into trace/simple.c (maybe with a TraceEventIter initialized to iterate over the newly registered trace events group?).

Alternatively, simpletrace.c might be able to emit TRACE_RECORD_TYPE_MAPPING on demand instead of ahead of time.

I guess I'll have a look at the first option, or more general at per-group initialization, that looks like the better approach on a quick glance.

take care,
Gerd