[PATCH 00/16] tracetool: add Rust support

Paolo Bonzini posted 16 patches 1 week, 2 days ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20250919112536.141782-1-pbonzini@redhat.com
Maintainers: John Snow <jsnow@redhat.com>, Peter Maydell <peter.maydell@linaro.org>, Mauro Carvalho Chehab <mchehab+huawei@kernel.org>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Manos Pitsidianakis <manos.pitsidianakis@linaro.org>, Cleber Rosa <crosa@redhat.com>, Alexander Bulekov <alxndr@bu.edu>, Bandan Das <bsd@redhat.com>, Stefan Hajnoczi <stefanha@redhat.com>, Fabiano Rosas <farosas@suse.de>, Darren Kenny <darren.kenny@oracle.com>, Qiuhao Li <Qiuhao.Li@outlook.com>, "Alex Bennée" <alex.bennee@linaro.org>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Markus Armbruster <armbru@redhat.com>, Michael Roth <michael.roth@amd.com>, Alexandre Iooss <erdnaxe@crans.org>, Mahmoud Mandour <ma.mandourr@gmail.com>, Pierrick Bouvier <pierrick.bouvier@linaro.org>, Mads Ynddal <mads@ynddal.dk>
docs/conf.py                                  |   2 -
docs/sphinx-static/theme_overrides.css        |   3 +-
include/qemu/log-for-trace.h                  |   4 +-
include/qemu/log.h                            |  44 ++--
tests/tracetool/ftrace.h                      |  28 +--
tests/tracetool/log.h                         |  16 +-
trace/ftrace.h                                |   1 +
trace/ftrace.c                                |  15 ++
util/log.c                                    |   2 +-
hw/char/trace-events                          |  14 +-
rust/Cargo.lock                               |   8 +
rust/Cargo.toml                               |   1 +
rust/hw/char/pl011/Cargo.toml                 |   1 +
rust/hw/char/pl011/meson.build                |   1 +
rust/hw/char/pl011/src/device.rs              |  57 +++--
rust/hw/core/src/qdev.rs                      |  33 +++
rust/meson.build                              |   2 +-
rust/trace/Cargo.toml                         |  19 ++
rust/trace/meson.build                        |  19 ++
rust/trace/src/lib.rs                         |  39 ++++
rust/util/src/log.rs                          |   2 +-
scripts/analyse-locks-simpletrace.py          |   1 -
scripts/modinfo-collect.py                    |   1 -
scripts/modinfo-generate.py                   |   1 -
scripts/oss-fuzz/minimize_qtest_trace.py      |   1 -
scripts/oss-fuzz/output_reproducer.py         |   1 -
.../oss-fuzz/reorder_fuzzer_qtest_trace.py    |   1 -
scripts/probe-gdb-support.py                  |   1 -
scripts/qapi/error.py                         |   2 -
scripts/qapi/expr.py                          |   2 -
scripts/qapi/gen.py                           |   2 -
scripts/qapi/parser.py                        |   2 -
scripts/qapi/schema.py                        |   2 -
scripts/qemu-plugin-symbols.py                |   1 -
scripts/qemugdb/tcg.py                        |   2 -
scripts/qemugdb/timers.py                     |   1 -
scripts/replay-dump.py                        |   1 -
scripts/tracetool.py                          |   1 -
scripts/tracetool/__init__.py                 | 201 ++++++++++++++----
scripts/tracetool/backend/__init__.py         |  43 ++--
scripts/tracetool/backend/dtrace.py           |   2 +-
scripts/tracetool/backend/ftrace.py           |  26 +--
scripts/tracetool/backend/log.py              |  22 +-
scripts/tracetool/backend/simple.py           |  17 +-
scripts/tracetool/backend/syslog.py           |  17 +-
scripts/tracetool/backend/ust.py              |   2 +-
scripts/tracetool/format/__init__.py          |   4 +-
scripts/tracetool/format/c.py                 |   2 +-
scripts/tracetool/format/d.py                 |   2 +-
scripts/tracetool/format/h.py                 |  18 +-
scripts/tracetool/format/log_stap.py          |   2 +-
scripts/tracetool/format/rs.py                |  71 +++++++
scripts/tracetool/format/simpletrace_stap.py  |   2 +-
scripts/tracetool/format/stap.py              |   2 +-
scripts/tracetool/format/ust_events_c.py      |   2 +-
scripts/tracetool/format/ust_events_h.py      |   2 +-
tests/tracetool/ftrace.rs                     |  40 ++++
tests/tracetool/log.rs                        |  44 ++++
tests/tracetool/simple.rs                     |  40 ++++
tests/tracetool/syslog.rs                     |  40 ++++
tests/tracetool/tracetool-test.py             |   2 +
trace/meson.build                             |   8 +-
62 files changed, 727 insertions(+), 218 deletions(-)
create mode 100644 rust/trace/Cargo.toml
create mode 100644 rust/trace/meson.build
create mode 100644 rust/trace/src/lib.rs
create mode 100644 scripts/tracetool/format/rs.py
create mode 100644 tests/tracetool/ftrace.rs
create mode 100644 tests/tracetool/log.rs
create mode 100644 tests/tracetool/simple.rs
create mode 100644 tests/tracetool/syslog.rs
[PATCH 00/16] tracetool: add Rust support
Posted by Paolo Bonzini 1 week, 2 days ago
This is the result of the summer project of Tanish Desai.  It mostly
consists of changes to tracetool, which I used to add tracepoint support
to the pl011 device.  All the backends are supported except dtrace and
ust; support for Linux in dtrace should be easy using the "probe" crate,
the rest (ust, and dtrace on macOS or Solaris) less so.  For ust, the
plan is to deprecate it, since LTTng can use uprobes.  For dtrace on
macOS or Solaris, support would have to be added to the "probe" crate.

Patches 1-5 are cleanups that could be committed separately.

Patches 6-7 are tracetool patches that have been posted before, now
rebased on top of the "make check-tracetool" series.  Their purpose
is to simplify .h code generation for tracetool backends, and these
simplifications translate directly to the new .rs code generation.

Patches 8-9 add the minimal support for adding tracepoint functions
in Rust, albeit with no content and thus no actual tracing.

Patches 10-11 add back tracepoints to the Rust pl011 device model.

Patches 12-16 finally add Rust code generation to the supported
tracing backends.

The tracetool testsuite is now part of QEMU and is extended to
cover the generated Rust code.

Paolo

v1->v2:
- new patch "tracetool: fix usage of try_import()"
- new patch "tracetool: remove dead code" [Manos]
- new patch "treewide: remove unnessary "coding" header" [Manos]
- new patch "tracetool: add SPDX headers" [Manos]
- dropped patch "treewide: write "unsigned long int" instead of "long unsigned int""
- merge patch "rust: move dependencies to rust/Cargo.toml"
- gathered Reviewed-by tags
- sort keywords for primitive C types [Manos]
- fix incorrect string "_{name}" in "tracetool: Add Rust format support" [Manos, Daniel]
- adjust for moved crates
- add SPDX headers to generated file [Daniel]
- add @generated tag to generated file [Manos]
- add #[allow()] to include_trace macro, in order to pacify clippy
- tweaks to trace/Cargo.toml [Manos]
- fix more clippy issues in generated code
- change include_trace! macro to not require the "trace-" prefix [Zhao]
- rename Clock::get() and get_hz() methods to period() and hz() respectively [Zhao]
- drop the "..._ENABLED" symbols [Daniel]

Paolo Bonzini (8):
  tracetool: fix usage of try_import()
  tracetool: remove dead code
  treewide: remove unnessary "coding" header
  tracetool: add SPDX headers
  trace/ftrace: move snprintf+write from tracepoints to ftrace.c
  rust: qdev: add minimal clock bindings
  rust: pl011: add tracepoints
  log: change qemu_loglevel to unsigned

Tanish Desai (8):
  tracetool: add CHECK_TRACE_EVENT_GET_STATE
  tracetool/backend: remove redundant trace event checks
  tracetool: Add Rust format support
  rust: add trace crate
  tracetool/simple: add Rust support
  tracetool/log: add Rust support
  tracetool/ftrace: add Rust support
  tracetool/syslog: add Rust support

 docs/conf.py                                  |   2 -
 docs/sphinx-static/theme_overrides.css        |   3 +-
 include/qemu/log-for-trace.h                  |   4 +-
 include/qemu/log.h                            |  44 ++--
 tests/tracetool/ftrace.h                      |  28 +--
 tests/tracetool/log.h                         |  16 +-
 trace/ftrace.h                                |   1 +
 trace/ftrace.c                                |  15 ++
 util/log.c                                    |   2 +-
 hw/char/trace-events                          |  14 +-
 rust/Cargo.lock                               |   8 +
 rust/Cargo.toml                               |   1 +
 rust/hw/char/pl011/Cargo.toml                 |   1 +
 rust/hw/char/pl011/meson.build                |   1 +
 rust/hw/char/pl011/src/device.rs              |  57 +++--
 rust/hw/core/src/qdev.rs                      |  33 +++
 rust/meson.build                              |   2 +-
 rust/trace/Cargo.toml                         |  19 ++
 rust/trace/meson.build                        |  19 ++
 rust/trace/src/lib.rs                         |  39 ++++
 rust/util/src/log.rs                          |   2 +-
 scripts/analyse-locks-simpletrace.py          |   1 -
 scripts/modinfo-collect.py                    |   1 -
 scripts/modinfo-generate.py                   |   1 -
 scripts/oss-fuzz/minimize_qtest_trace.py      |   1 -
 scripts/oss-fuzz/output_reproducer.py         |   1 -
 .../oss-fuzz/reorder_fuzzer_qtest_trace.py    |   1 -
 scripts/probe-gdb-support.py                  |   1 -
 scripts/qapi/error.py                         |   2 -
 scripts/qapi/expr.py                          |   2 -
 scripts/qapi/gen.py                           |   2 -
 scripts/qapi/parser.py                        |   2 -
 scripts/qapi/schema.py                        |   2 -
 scripts/qemu-plugin-symbols.py                |   1 -
 scripts/qemugdb/tcg.py                        |   2 -
 scripts/qemugdb/timers.py                     |   1 -
 scripts/replay-dump.py                        |   1 -
 scripts/tracetool.py                          |   1 -
 scripts/tracetool/__init__.py                 | 201 ++++++++++++++----
 scripts/tracetool/backend/__init__.py         |  43 ++--
 scripts/tracetool/backend/dtrace.py           |   2 +-
 scripts/tracetool/backend/ftrace.py           |  26 +--
 scripts/tracetool/backend/log.py              |  22 +-
 scripts/tracetool/backend/simple.py           |  17 +-
 scripts/tracetool/backend/syslog.py           |  17 +-
 scripts/tracetool/backend/ust.py              |   2 +-
 scripts/tracetool/format/__init__.py          |   4 +-
 scripts/tracetool/format/c.py                 |   2 +-
 scripts/tracetool/format/d.py                 |   2 +-
 scripts/tracetool/format/h.py                 |  18 +-
 scripts/tracetool/format/log_stap.py          |   2 +-
 scripts/tracetool/format/rs.py                |  71 +++++++
 scripts/tracetool/format/simpletrace_stap.py  |   2 +-
 scripts/tracetool/format/stap.py              |   2 +-
 scripts/tracetool/format/ust_events_c.py      |   2 +-
 scripts/tracetool/format/ust_events_h.py      |   2 +-
 tests/tracetool/ftrace.rs                     |  40 ++++
 tests/tracetool/log.rs                        |  44 ++++
 tests/tracetool/simple.rs                     |  40 ++++
 tests/tracetool/syslog.rs                     |  40 ++++
 tests/tracetool/tracetool-test.py             |   2 +
 trace/meson.build                             |   8 +-
 62 files changed, 727 insertions(+), 218 deletions(-)
 create mode 100644 rust/trace/Cargo.toml
 create mode 100644 rust/trace/meson.build
 create mode 100644 rust/trace/src/lib.rs
 create mode 100644 scripts/tracetool/format/rs.py
 create mode 100644 tests/tracetool/ftrace.rs
 create mode 100644 tests/tracetool/log.rs
 create mode 100644 tests/tracetool/simple.rs
 create mode 100644 tests/tracetool/syslog.rs

-- 
2.51.0
Re: [PATCH 00/16] tracetool: add Rust support
Posted by Stefan Hajnoczi 4 days, 19 hours ago
On Fri, Sep 19, 2025 at 01:25:20PM +0200, Paolo Bonzini wrote:
> This is the result of the summer project of Tanish Desai.  It mostly
> consists of changes to tracetool, which I used to add tracepoint support
> to the pl011 device.  All the backends are supported except dtrace and
> ust; support for Linux in dtrace should be easy using the "probe" crate,
> the rest (ust, and dtrace on macOS or Solaris) less so.  For ust, the
> plan is to deprecate it, since LTTng can use uprobes.  For dtrace on
> macOS or Solaris, support would have to be added to the "probe" crate.
> 
> Patches 1-5 are cleanups that could be committed separately.
> 
> Patches 6-7 are tracetool patches that have been posted before, now
> rebased on top of the "make check-tracetool" series.  Their purpose
> is to simplify .h code generation for tracetool backends, and these
> simplifications translate directly to the new .rs code generation.
> 
> Patches 8-9 add the minimal support for adding tracepoint functions
> in Rust, albeit with no content and thus no actual tracing.
> 
> Patches 10-11 add back tracepoints to the Rust pl011 device model.
> 
> Patches 12-16 finally add Rust code generation to the supported
> tracing backends.
> 
> The tracetool testsuite is now part of QEMU and is extended to
> cover the generated Rust code.

Looks very close. The main issue I noticed in the Rust code is that the
dynamic state of trace events is not being checked correctly
(trace_event_get_state_dynamic_by_id()).

> 
> Paolo
> 
> v1->v2:
> - new patch "tracetool: fix usage of try_import()"
> - new patch "tracetool: remove dead code" [Manos]
> - new patch "treewide: remove unnessary "coding" header" [Manos]
> - new patch "tracetool: add SPDX headers" [Manos]
> - dropped patch "treewide: write "unsigned long int" instead of "long unsigned int""
> - merge patch "rust: move dependencies to rust/Cargo.toml"
> - gathered Reviewed-by tags
> - sort keywords for primitive C types [Manos]
> - fix incorrect string "_{name}" in "tracetool: Add Rust format support" [Manos, Daniel]
> - adjust for moved crates
> - add SPDX headers to generated file [Daniel]
> - add @generated tag to generated file [Manos]
> - add #[allow()] to include_trace macro, in order to pacify clippy
> - tweaks to trace/Cargo.toml [Manos]
> - fix more clippy issues in generated code
> - change include_trace! macro to not require the "trace-" prefix [Zhao]
> - rename Clock::get() and get_hz() methods to period() and hz() respectively [Zhao]
> - drop the "..._ENABLED" symbols [Daniel]
> 
> Paolo Bonzini (8):
>   tracetool: fix usage of try_import()
>   tracetool: remove dead code
>   treewide: remove unnessary "coding" header
>   tracetool: add SPDX headers
>   trace/ftrace: move snprintf+write from tracepoints to ftrace.c
>   rust: qdev: add minimal clock bindings
>   rust: pl011: add tracepoints
>   log: change qemu_loglevel to unsigned
> 
> Tanish Desai (8):
>   tracetool: add CHECK_TRACE_EVENT_GET_STATE
>   tracetool/backend: remove redundant trace event checks
>   tracetool: Add Rust format support
>   rust: add trace crate
>   tracetool/simple: add Rust support
>   tracetool/log: add Rust support
>   tracetool/ftrace: add Rust support
>   tracetool/syslog: add Rust support
> 
>  docs/conf.py                                  |   2 -
>  docs/sphinx-static/theme_overrides.css        |   3 +-
>  include/qemu/log-for-trace.h                  |   4 +-
>  include/qemu/log.h                            |  44 ++--
>  tests/tracetool/ftrace.h                      |  28 +--
>  tests/tracetool/log.h                         |  16 +-
>  trace/ftrace.h                                |   1 +
>  trace/ftrace.c                                |  15 ++
>  util/log.c                                    |   2 +-
>  hw/char/trace-events                          |  14 +-
>  rust/Cargo.lock                               |   8 +
>  rust/Cargo.toml                               |   1 +
>  rust/hw/char/pl011/Cargo.toml                 |   1 +
>  rust/hw/char/pl011/meson.build                |   1 +
>  rust/hw/char/pl011/src/device.rs              |  57 +++--
>  rust/hw/core/src/qdev.rs                      |  33 +++
>  rust/meson.build                              |   2 +-
>  rust/trace/Cargo.toml                         |  19 ++
>  rust/trace/meson.build                        |  19 ++
>  rust/trace/src/lib.rs                         |  39 ++++
>  rust/util/src/log.rs                          |   2 +-
>  scripts/analyse-locks-simpletrace.py          |   1 -
>  scripts/modinfo-collect.py                    |   1 -
>  scripts/modinfo-generate.py                   |   1 -
>  scripts/oss-fuzz/minimize_qtest_trace.py      |   1 -
>  scripts/oss-fuzz/output_reproducer.py         |   1 -
>  .../oss-fuzz/reorder_fuzzer_qtest_trace.py    |   1 -
>  scripts/probe-gdb-support.py                  |   1 -
>  scripts/qapi/error.py                         |   2 -
>  scripts/qapi/expr.py                          |   2 -
>  scripts/qapi/gen.py                           |   2 -
>  scripts/qapi/parser.py                        |   2 -
>  scripts/qapi/schema.py                        |   2 -
>  scripts/qemu-plugin-symbols.py                |   1 -
>  scripts/qemugdb/tcg.py                        |   2 -
>  scripts/qemugdb/timers.py                     |   1 -
>  scripts/replay-dump.py                        |   1 -
>  scripts/tracetool.py                          |   1 -
>  scripts/tracetool/__init__.py                 | 201 ++++++++++++++----
>  scripts/tracetool/backend/__init__.py         |  43 ++--
>  scripts/tracetool/backend/dtrace.py           |   2 +-
>  scripts/tracetool/backend/ftrace.py           |  26 +--
>  scripts/tracetool/backend/log.py              |  22 +-
>  scripts/tracetool/backend/simple.py           |  17 +-
>  scripts/tracetool/backend/syslog.py           |  17 +-
>  scripts/tracetool/backend/ust.py              |   2 +-
>  scripts/tracetool/format/__init__.py          |   4 +-
>  scripts/tracetool/format/c.py                 |   2 +-
>  scripts/tracetool/format/d.py                 |   2 +-
>  scripts/tracetool/format/h.py                 |  18 +-
>  scripts/tracetool/format/log_stap.py          |   2 +-
>  scripts/tracetool/format/rs.py                |  71 +++++++
>  scripts/tracetool/format/simpletrace_stap.py  |   2 +-
>  scripts/tracetool/format/stap.py              |   2 +-
>  scripts/tracetool/format/ust_events_c.py      |   2 +-
>  scripts/tracetool/format/ust_events_h.py      |   2 +-
>  tests/tracetool/ftrace.rs                     |  40 ++++
>  tests/tracetool/log.rs                        |  44 ++++
>  tests/tracetool/simple.rs                     |  40 ++++
>  tests/tracetool/syslog.rs                     |  40 ++++
>  tests/tracetool/tracetool-test.py             |   2 +
>  trace/meson.build                             |   8 +-
>  62 files changed, 727 insertions(+), 218 deletions(-)
>  create mode 100644 rust/trace/Cargo.toml
>  create mode 100644 rust/trace/meson.build
>  create mode 100644 rust/trace/src/lib.rs
>  create mode 100644 scripts/tracetool/format/rs.py
>  create mode 100644 tests/tracetool/ftrace.rs
>  create mode 100644 tests/tracetool/log.rs
>  create mode 100644 tests/tracetool/simple.rs
>  create mode 100644 tests/tracetool/syslog.rs
> 
> -- 
> 2.51.0
>