Tracing patches
The following changes since commit 2d591ce2aeebf9620ff527c7946844a3122afeec:
Merge remote-tracking branch 'remotes/mdroth/qga-pull-2014-08-08' into staging (2014-08-08 14:16:05 +0100)
are available in the git repository at:
git://github.com/stefanha/qemu.git tags/tracing-pull-request
for you to fetch changes up to 4ac4458076e1aaf3b01a6361154117df20e22215:
virtio-rng: add some trace events (2014-08-12 14:29:55 +0100)
----------------------------------------------------------------
Tracing pull request
----------------------------------------------------------------
Alex Bennée (2):
trace: teach lttng backend to use format strings
trace: add some tcg tracing support
Amit Shah (1):
virtio-rng: add some trace events
Lluís Vilanova (11):
trace: [tcg] Add documentation
trace: [tcg] Argument type transformation rules
trace: [tcg] Argument type transformation machinery
trace: [tcg] Add 'tcg' event property
trace: [tcg] Declare TCG tracing helper routines
trace: [tcg] Define TCG tracing helper routines
trace: [tcg] Define TCG tracing helper routine wrappers
trace: [tcg] Include TCG-tracing helpers
trace: [tcg] Generate TCG tracing routines
trace: [tcg] Include event definitions in "trace.h"
trace: [tcg] Include TCG-tracing header on all targets
Stefan Hajnoczi (4):
trace: extract stap_escape() function for reuse
trace: add tracetool simpletrace_stap format
simpletrace: add simpletrace.py --no-header option
trace: install simpletrace SystemTap tapset
.gitignore | 4 + Makefile | 6 + Makefile.objs | 7 +- Makefile.target | 15 +- cpu-exec.c | 6 + docs/tracing.txt | 40 ++++++ hw/virtio/virtio-rng.c | 6 + include/exec/helper-gen.h | 2 + include/exec/helper-proto.h | 1 + include/exec/helper-tcg.h | 1 + include/trace-tcg.h | 7 + include/trace.h | 1 + scripts/simpletrace.py | 24 +++- scripts/tracetool/__init__.py | 105 +++++++++++++- scripts/tracetool/format/events_h.py | 5 + scripts/tracetool/format/simpletrace_stap.py | 71 ++++++++++ scripts/tracetool/format/stap.py | 11 +- scripts/tracetool/format/tcg_h.py | 57 ++++++++ scripts/tracetool/format/tcg_helper_c.py | 50 +++++++ scripts/tracetool/format/tcg_helper_h.py | 50 +++++++ scripts/tracetool/format/tcg_helper_wrapper_h.py | 70 ++++++++++ scripts/tracetool/format/ust_events_h.py | 15 +- scripts/tracetool/transform.py | 166 +++++++++++++++++++++++ target-alpha/translate.c | 3 + target-arm/translate-a64.c | 2 + target-arm/translate.c | 3 + target-cris/translate.c | 3 + target-i386/translate.c | 3 + target-lm32/translate.c | 3 + target-m68k/translate.c | 3 + target-microblaze/translate.c | 3 + target-mips/translate.c | 3 + target-openrisc/translate.c | 3 + target-ppc/translate.c | 3 + target-s390x/translate.c | 2 + target-sh4/translate.c | 3 + target-sparc/translate.c | 3 + target-unicore32/translate.c | 3 + target-xtensa/translate.c | 3 + trace-events | 14 ++ trace/Makefile.objs | 53 +++++++- translate-all.c | 3 + 42 files changed, 808 insertions(+), 28 deletions(-) create mode 100644 include/trace-tcg.h create mode 100644 scripts/tracetool/format/simpletrace_stap.py create mode 100644 scripts/tracetool/format/tcg_h.py create mode 100644 scripts/tracetool/format/tcg_helper_c.py create mode 100644 scripts/tracetool/format/tcg_helper_h.py create mode 100644 scripts/tracetool/format/tcg_helper_wrapper_h.py create mode 100644 scripts/tracetool/transform.py
Signature · 1 line
1.9.3
[Qemu-devel] [PULL 02/18] trace: add tracetool simpletrace_stap format
This new tracetool "format" generates a SystemTap .stp file that outputs simpletrace binary trace data.
In contrast to simpletrace or ftrace, SystemTap does not define its own trace format. All output from SystemTap is generated by .stp files. This patch lets us generate a .stp file that outputs in the simpletrace binary format.
This makes it possible to reuse simpletrace.py to analyze traces recorded using SystemTap. The simpletrace binary format is especially useful for long-running traces like flight-recorder mode where string formatting can be expensive.
--- scripts/tracetool/format/simpletrace_stap.py | 71 ++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 scripts/tracetool/format/simpletrace_stap.py
scripts/tracetool/format/simpletrace_stap.py new file +71 -0
@@ -0,0 +1,71 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +Generate .stp file that outputs simpletrace binary traces (DTrace with SystemTAP only). +""" + +__author__ = "Stefan Hajnoczi <redhat.com>" +__copyright__ = "Copyright (C) 2014, Red Hat, Inc." +__license__ = "GPL version 2 or (at your option) any later version" + +__maintainer__ = "Stefan Hajnoczi" +__email__ = "[email protected]" + + +from tracetool import out +from tracetool.backend.dtrace import binary, probeprefix +from tracetool.backend.simple import is_string +from tracetool.format.stap import stap_escape + + +def generate(events, backend): + out('/* This file is autogenerated by tracetool, do not edit. */', + '') + + for event_id, e in enumerate(events): + if 'disable' in e.properties: + continue + + out('probe %(probeprefix)s.simpletrace.%(name)s = %(probeprefix)s.%(name)s ?', + '{', + probeprefix=probeprefix(), + name=e.name) + + # Calculate record size + sizes = ['24'] # sizeof(TraceRecord) + for type_, name in e.args: + name = stap_escape(name) + if is_string(type_): + out(' try {', + ' arg%(name)s_str = %(name)s ? user_string_n(%(name)s, 512) : "<null>"', + ' } catch {}', + ' arg%(name)s_len = strlen(arg%(name)s_str)', + name=name) + sizes.append('4 + arg%s_len' % name) + else: + sizes.append('8') + sizestr = ' + '.join(sizes) + + # Generate format string and value pairs for record header and arguments + fields = [('8b', str(event_id)), + ('8b', 'gettimeofday_ns()'), + ('4b', sizestr), + ('4b', 'pid()')] + for type_, name in e.args: + name = stap_escape(name) + if is_string(type_): + fields.extend([('4b', 'arg%s_len' % name), + ('.*s', 'arg%s_len, arg%s_str' % (name, name))]) + else: + fields.append(('8b', name)) + + # Emit the entire record in a single SystemTap printf() + fmt_str = '%'.join(fmt for fmt, _ in fields) + arg_str = ', '.join(arg for _, arg in fields) + out(' printf("%%%(fmt_str)s", %(arg_str)s)', + fmt_str=fmt_str, arg_str=arg_str) + + out('}') + + out()
Signature · 1 line
1.9.3
[Qemu-devel] [PULL 01/18] trace: extract stap_escape() function for reuse
In reply to Stefan HajnocziSystemTap reserved words sometimes conflict with QEMU variable names. We escape them to prevent conflicts.
Move escaping into its own function so the next patch can reuse it.
--- scripts/tracetool/format/stap.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
scripts/tracetool/format/stap.py +8 -3
@@ -27,6 +27,13 @@ RESERVED_WORDS = ( ) +def stap_escape(identifier): + # Append underscore to reserved keywords + if identifier in RESERVED_WORDS: + return identifier + '_' + return identifier + + def generate(events, backend): events = [e for e in events if "disable" not in e.properties]
@@ -45,9 +52,7 @@ def generate(events, backend): i = 1 if len(e.args) > 0: for name in e.args.names(): - # Append underscore to reserved keywords - if name in RESERVED_WORDS: - name += '_' + name = stap_escape(name) out(' %s = $arg%d;' % (name, i)) i += 1
Signature · 1 line
1.9.3
[Qemu-devel] [PULL 03/18] simpletrace: add simpletrace.py --no-header option
In reply to Stefan HajnocziIt can be useful to read simpletrace files that have no header. For example, a ring buffer may not have a header record but can still be processed if the user is sure the file format version is compatible.
$ scripts/simpletrace.py --no-header trace-events trace-file
--- scripts/simpletrace.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-)
scripts/simpletrace.py +17 -7
@@ -58,8 +58,8 @@ def read_record(edict, fobj): rechdr = read_header(fobj, rec_header_fmt) return get_record(edict, rechdr, fobj) # return tuple of record elements -def read_trace_file(edict, fobj): - """Deserialize trace records from a file, yielding record tuples (event_num, timestamp, pid, arg1, ..., arg6).""" +def read_trace_header(fobj): + """Read and verify trace file header""" header = read_header(fobj, log_header_fmt) if header is None or \ header[0] != header_event_id or \
@@ -73,6 +73,8 @@ def read_trace_file(edict, fobj): raise ValueError('Log format %d not supported with this QEMU release!' % log_version) +def read_trace_records(edict, fobj): + """Deserialize trace records from a file, yielding record tuples (event_num, timestamp, pid, arg1, ..., arg6).""" while True: rec = read_record(edict, fobj) if rec is None:
@@ -102,13 +104,16 @@ class Analyzer(object): """Called at the end of the trace.""" pass -def process(events, log, analyzer): +def process(events, log, analyzer, read_header=True): """Invoke an analyzer on each event in a log.""" if isinstance(events, str): events = _read_events(open(events, 'r')) if isinstance(log, str): log = open(log, 'rb') + if read_header: + read_trace_header(log) + dropped_event = Event.build("Dropped_Event(uint64_t num_events_dropped)") edict = {dropped_event_id: dropped_event}
@@ -137,7 +142,7 @@ def process(events, log, analyzer): analyzer.begin() fn_cache = {} - for rec in read_trace_file(edict, log): + for rec in read_trace_records(edict, log): event_num = rec[0] event = edict[event_num] if event_num not in fn_cache:
@@ -152,12 +157,17 @@ def run(analyzer): advanced scripts will want to call process() instead.""" import sys - if len(sys.argv) != 3: - sys.stderr.write('usage: %s <trace-events> <trace-file>\n' % sys.argv[0]) + read_header = True + if len(sys.argv) == 4 and sys.argv[1] == '--no-header': + read_header = False + del sys.argv[1] + elif len(sys.argv) != 3: + sys.stderr.write('usage: %s [--no-header] <trace-events> ' \ + '<trace-file>\n' % sys.argv[0]) sys.exit(1) events = _read_events(open(sys.argv[1], 'r')) - process(events, sys.argv[2], analyzer) + process(events, sys.argv[2], analyzer, read_header=read_header) if __name__ == '__main__': class Formatter(Analyzer):
Signature · 1 line
1.9.3
[Qemu-devel] [PULL 04/18] trace: install simpletrace SystemTap tapset
In reply to Stefan HajnocziThe simpletrace SystemTap tapset outputs simpletrace binary traces for SystemTap probes. This is useful because SystemTap has no default way to format or store traces. The simpletrace SystemTap tapset provides an easy way to store traces.
The simpletrace.py tool or custom Python scripts using the simpletrace.py API can analyze SystemTap these traces:
$ ./configure --enable-trace-backends=dtrace ...
$ make && make install
$ stap -e 'probe qemu.system.x86_64.simpletrace.* {}' \
-c qemu-system-x86_64 >/tmp/trace.out
$ scripts/simpletrace.py --no-header trace-events /tmp/trace.out
g_malloc 4.531 pid=15519 size=0xb ptr=0x7f8639c10470
g_malloc 3.264 pid=15519 size=0x300 ptr=0x7f8639c10490
g_free 5.155 pid=15519 ptr=0x7f8639c0f7b0Note that, unlike qemu-system-x86_64.stp and qemu-system-x86_64.stp-installed, only one file is needed since the simpletrace SystemTap tapset does not reference the QEMU binary by path. Therefore it doesn't matter whether the QEMU binary is installed or not.
--- Makefile.target | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
Makefile.target +9 -1
@@ -38,7 +38,7 @@ config-target.h: config-target.h-timestamp config-target.h-timestamp: config-target.mak ifdef CONFIG_TRACE_SYSTEMTAP -stap: $(QEMU_PROG).stp-installed $(QEMU_PROG).stp +stap: $(QEMU_PROG).stp-installed $(QEMU_PROG).stp $(QEMU_PROG)-simpletrace.stp ifdef CONFIG_USER_ONLY TARGET_TYPE=user
@@ -64,6 +64,13 @@ $(QEMU_PROG).stp: $(SRC_PATH)/trace-events --target-type=$(TARGET_TYPE) \ < $< > $@," GEN $(TARGET_DIR)$(QEMU_PROG).stp") +$(QEMU_PROG)-simpletrace.stp: $(SRC_PATH)/trace-events + $(call quiet-command,$(TRACETOOL) \ + --format=simpletrace-stap \ + --backends=$(TRACE_BACKENDS) \ + --probe-prefix=qemu.$(TARGET_TYPE).$(TARGET_NAME) \ + < $< > $@," GEN $(TARGET_DIR)$(QEMU_PROG)-simpletrace.stp") + else stap: endif
@@ -191,6 +198,7 @@ endif ifdef CONFIG_TRACE_SYSTEMTAP $(INSTALL_DIR) "$(DESTDIR)$(qemu_datadir)/../systemtap/tapset" $(INSTALL_DATA) $(QEMU_PROG).stp-installed "$(DESTDIR)$(qemu_datadir)/../systemtap/tapset/$(QEMU_PROG).stp" + $(INSTALL_DATA) $(QEMU_PROG)-simpletrace.stp "$(DESTDIR)$(qemu_datadir)/../systemtap/tapset/$(QEMU_PROG)-simpletrace.stp" endif GENERATED_HEADERS += config-target.h
Signature · 1 line
1.9.3
[Qemu-devel] [PULL 06/18] trace: [tcg] Argument type transformation rules
In reply to Stefan HajnocziFrom: Lluís Vilanova <[email protected]>
--- scripts/tracetool/transform.py | 166 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 scripts/tracetool/transform.py
scripts/tracetool/transform.py new file +166 -0
@@ -0,0 +1,166 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +Type-transformation rules. +""" + +__author__ = "Lluís Vilanova <[email protected]>" +__copyright__ = "Copyright 2012-2014, Lluís Vilanova <[email protected]>" +__license__ = "GPL version 2 or (at your option) any later version" + +__maintainer__ = "Stefan Hajnoczi" +__email__ = "[email protected]" + + +def _transform_type(type_, trans): + if isinstance(trans, str): + return trans + elif isinstance(trans, dict): + if type_ in trans: + return _transform_type(type_, trans[type_]) + elif None in trans: + return _transform_type(type_, trans[None]) + else: + return type_ + elif callable(trans): + return trans(type_) + else: + raise ValueError("Invalid type transformation rule: %s" % trans) + + +def transform_type(type_, *trans): + """Return a new type transformed according to the given rules. + + Applies each of the transformation rules in trans in order. + + If an element of trans is a string, return it. + + If an element of trans is a function, call it with type_ as its only + argument. + + If an element of trans is a dict, search type_ in its keys. If type_ is + a key, use the value as a transformation rule for type_. Otherwise, if + None is a key use the value as a transformation rule for type_. + + Otherwise, return type_. + + Parameters + ---------- + type_ : str + Type to transform. + trans : list of function or dict + Type transformation rules. + """ + if len(trans) == 0: + raise ValueError + res = type_ + for t in trans: + res = _transform_type(res, t) + return res + + +################################################## +# tcg -> host + +def _tcg_2_host(type_): + if type_ == "TCGv": + # force a fixed-size type (target-independent) + return "uint64_t" + else: + return type_ + +TCG_2_HOST = { + "TCGv_i32": "uint32_t", + "TCGv_i64": "uint64_t", + "TCGv_ptr": "void *", + None: _tcg_2_host, + } + + +################################################## +# host -> host compatible with tcg sizes + +HOST_2_TCG_COMPAT = { + "uint8_t": "uint32_t", + } + + +################################################## +# host/tcg -> tcg + +def _host_2_tcg(type_): + if type_.startswith("TCGv"): + return type_ + raise ValueError("Don't know how to translate '%s' into a TCG type\n" % type_) + +HOST_2_TCG = { + "uint32_t": "TCGv_i32", + "uint64_t": "TCGv_i64", + "void *" : "TCGv_ptr", + None: _host_2_tcg, + } + + +################################################## +# tcg -> tcg helper definition + +def _tcg_2_helper_def(type_): + if type_ == "TCGv": + return "target_ulong" + else: + return type_ + +TCG_2_TCG_HELPER_DEF = { + "TCGv_i32": "uint32_t", + "TCGv_i64": "uint64_t", + "TCGv_ptr": "void *", + None: _tcg_2_helper_def, + } + + +################################################## +# tcg -> tcg helper declaration + +def _tcg_2_tcg_helper_decl_error(type_): + raise ValueError("Don't know how to translate type '%s' into a TCG helper declaration type\n" % type_) + +TCG_2_TCG_HELPER_DECL = { + "TCGv" : "tl", + "TCGv_ptr": "ptr", + "TCGv_i32": "i32", + "TCGv_i64": "i64", + None: _tcg_2_tcg_helper_decl_error, + } + + +################################################## +# host/tcg -> tcg temporal constant allocation + +def _host_2_tcg_tmp_new(type_): + if type_.startswith("TCGv"): + return "tcg_temp_new_nop" + raise ValueError("Don't know how to translate type '%s' into a TCG temporal allocation" % type_) + +HOST_2_TCG_TMP_NEW = { + "uint32_t": "tcg_const_i32", + "uint64_t": "tcg_const_i64", + "void *" : "tcg_const_ptr", + None: _host_2_tcg_tmp_new, + } + + +################################################## +# host/tcg -> tcg temporal constant deallocation + +def _host_2_tcg_tmp_free(type_): + if type_.startswith("TCGv"): + return "tcg_temp_free_nop" + raise ValueError("Don't know how to translate type '%s' into a TCG temporal deallocation" % type_) + +HOST_2_TCG_TMP_FREE = { + "uint32_t": "tcg_temp_free_i32", + "uint64_t": "tcg_temp_free_i64", + "void *" : "tcg_temp_free_ptr", + None: _host_2_tcg_tmp_free, + }
Signature · 1 line
1.9.3
[Qemu-devel] [PULL 05/18] trace: [tcg] Add documentation
In reply to Stefan HajnocziFrom: Lluís Vilanova <[email protected]>
--- docs/tracing.txt | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)
docs/tracing.txt +40 -0
@@ -307,3 +307,43 @@ guard such computations and avoid its compilation when the event is disabled: You can check both if the event has been disabled and is dynamically enabled at the same time using the 'trace_event_get_state' routine (see header "trace/control.h" for more information). + +=== "tcg" === + +Guest code generated by TCG can be traced by defining an event with the "tcg" +event property. Internally, this property generates two events: +"<eventname>_trans" to trace the event at translation time, and +"<eventname>_exec" to trace the event at execution time. + +Instead of using these two events, you should instead use the function +"trace_<eventname>_tcg" during translation (TCG code generation). This function +will automatically call "trace_<eventname>_trans", and will generate the +necessary TCG code to call "trace_<eventname>_exec" during guest code execution. + +Events with the "tcg" property can be declared in the "trace-events" file with a +mix of native and TCG types, and "trace_<eventname>_tcg" will gracefully forward +them to the "<eventname>_trans" and "<eventname>_exec" events. Since TCG values +are not known at translation time, these are ignored by the "<eventname>_trans" +event. Because of this, the entry in the "trace-events" file needs two printing +formats (separated by a comma): + + tcg foo(uint8_t a1, TCGv_i32 a2) "a1=%d", "a1=%d a2=%d" + +For example: + + #include "trace-tcg.h" + + void some_disassembly_func (...) + { + uint8_t a1 = ...; + TCGv_i32 a2 = ...; + trace_foo_tcg(a1, a2); + } + +This will immediately call: + + void trace_foo_trans(uint8_t a1); + +and will generate the TCG code to call: + + void trace_foo(uint8_t a1, uint32_t a2);
Signature · 1 line
1.9.3
[Qemu-devel] [PULL 07/18] trace: [tcg] Argument type transformation machinery
In reply to Stefan HajnocziFrom: Lluís Vilanova <[email protected]>
--- scripts/tracetool/__init__.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-)
scripts/tracetool/__init__.py +29 -1
@@ -15,6 +15,7 @@ __email__ = "[email protected]" import re import sys +import weakref import tracetool.format import tracetool.backend
@@ -108,6 +109,18 @@ class Arguments: """List of argument types.""" return [ type_ for type_, _ in self._args ] + def transform(self, *trans): + """Return a new Arguments instance with transformed types. + + The types in the resulting Arguments instance are transformed according + to tracetool.transform.transform_type. + """ + res = [] + for type_, name in self._args: + res.append((tracetool.transform.transform_type(type_, *trans), + name)) + return Arguments(res) + class Event(object): """Event description.
@@ -128,7 +141,7 @@ class Event(object): _VALID_PROPS = set(["disable"]) - def __init__(self, name, props, fmt, args): + def __init__(self, name, props, fmt, args, orig=None): """ Parameters ----------
@@ -140,12 +153,19 @@ class Event(object): Event printing format. args : Arguments Event arguments. + orig : Event or None + Original Event before transformation. """ self.name = name self.properties = props self.fmt = fmt self.args = args + if orig is None: + self.original = weakref.ref(self) + else: + self.original = orig + unknown_props = set(self.properties) - self._VALID_PROPS if len(unknown_props) > 0: raise ValueError("Unknown properties: %s"
@@ -190,6 +210,14 @@ class Event(object): fmt = Event.QEMU_TRACE return fmt % {"name": self.name} + def transform(self, *trans): + """Return a new Event with transformed Arguments.""" + return Event(self.name, + list(self.properties), + self.fmt, + self.args.transform(*trans), + self) + def _read_events(fobj): res = []
Signature · 1 line
1.9.3
[Qemu-devel] [PULL 08/18] trace: [tcg] Add 'tcg' event property
In reply to Stefan HajnocziFrom: Lluís Vilanova <[email protected]>
Transforms event:
tcg name(...) "...", "..."
into two internal events:
tcg-trans name_trans(...) "..."
tcg-exec name_exec(...) "..."
--- scripts/tracetool/__init__.py | 64 +++++++++++++++++++++++++++++++++--- scripts/tracetool/format/events_h.py | 5 +++ 2 files changed, 64 insertions(+), 5 deletions(-)
scripts/tracetool/__init__.py +59 -5
@@ -19,6 +19,7 @@ import weakref import tracetool.format import tracetool.backend +import tracetool.transform def error_write(*lines):
@@ -137,9 +138,14 @@ class Event(object): The event arguments. """ - _CRE = re.compile("((?P<props>.*)\s+)?(?P<name>[^(\s]+)\((?P<args>[^)]*)\)\s*(?P<fmt>\".*)?") + _CRE = re.compile("((?P<props>.*)\s+)?" + "(?P<name>[^(\s]+)" + "\((?P<args>[^)]*)\)" + "\s*" + "(?:(?:(?P<fmt_trans>\".+),)?\s*(?P<fmt>\".+))?" + "\s*") - _VALID_PROPS = set(["disable"]) + _VALID_PROPS = set(["disable", "tcg", "tcg-trans", "tcg-exec"]) def __init__(self, name, props, fmt, args, orig=None): """
@@ -149,8 +155,8 @@ class Event(object): Event name. props : list of str Property names. - fmt : str - Event printing format. + fmt : str, list of str + Event printing format (or formats). args : Arguments Event arguments. orig : Event or None
@@ -170,6 +176,7 @@ class Event(object): if len(unknown_props) > 0: raise ValueError("Unknown properties: %s" % ", ".join(unknown_props)) + assert isinstance(self.fmt, str) or len(self.fmt) == 2 def copy(self): """Create a new copy."""
@@ -192,16 +199,32 @@ class Event(object): name = groups["name"] props = groups["props"].split() fmt = groups["fmt"] + fmt_trans = groups["fmt_trans"] + if len(fmt_trans) > 0: + fmt = [fmt_trans, fmt] args = Arguments.build(groups["args"]) + if "tcg-trans" in props: + raise ValueError("Invalid property 'tcg-trans'") + if "tcg-exec" in props: + raise ValueError("Invalid property 'tcg-exec'") + if "tcg" not in props and not isinstance(fmt, str): + raise ValueError("Only events with 'tcg' property can have two formats") + if "tcg" in props and isinstance(fmt, str): + raise ValueError("Events with 'tcg' property must have two formats") + return Event(name, props, fmt, args) def __repr__(self): """Evaluable string representation for this object.""" + if isinstance(self.fmt, str): + fmt = self.fmt + else: + fmt = "%s, %s" % (self.fmt[0], self.fmt[1]) return "Event('%s %s(%s) %s')" % (" ".join(self.properties), self.name, self.args, - self.fmt) + fmt) QEMU_TRACE = "trace_%(name)s"
@@ -300,4 +323,35 @@ def generate(fevents, format, backends, events = _read_events(fevents) + # transform TCG-enabled events + new_events = [] + for event in events: + if "tcg" not in event.properties: + new_events.append(event) + else: + event_trans = event.copy() + event_trans.name += "_trans" + event_trans.properties += ["tcg-trans"] + event_trans.fmt = event.fmt[0] + args_trans = [] + for atrans, aorig in zip( + event_trans.transform(tracetool.transform.TCG_2_HOST).args, + event.args): + if atrans == aorig: + args_trans.append(atrans) + event_trans.args = Arguments(args_trans) + event_trans = event_trans.copy() + + event_exec = event.copy() + event_exec.name += "_exec" + event_exec.properties += ["tcg-exec"] + event_exec.fmt = event.fmt[1] + event_exec = event_exec.transform(tracetool.transform.TCG_2_HOST) + + new_event = [event_trans, event_exec] + event.event_trans, event.event_exec = new_event + + new_events.extend(new_event) + events = new_events + tracetool.format.generate(events, format, backend)
scripts/tracetool/format/events_h.py +5 -0
@@ -40,6 +40,11 @@ def generate(events, backend): enabled = 0 else: enabled = 1 + if "tcg-trans" in e.properties: + # a single define for the two "sub-events" + out('#define TRACE_%(name)s_ENABLED %(enabled)d', + name=e.original.original.name.upper(), + enabled=enabled) out('#define TRACE_%s_ENABLED %d' % (e.name.upper(), enabled)) out('#include "trace/event-internal.h"',
Signature · 1 line
1.9.3
[Qemu-devel] [PULL 10/18] trace: [tcg] Define TCG tracing helper routines
In reply to Stefan HajnocziFrom: Lluís Vilanova <[email protected]>
Generates file "trace/generated-helpers.c" with TCG helper definitions to trace events in guest code at execution time.
The helpers ('helper_trace_${event}_exec_proxy') cast the TCG-compatible native argument types to their original types (as defined in "trace-events") and call the tracing routine ('trace_${event}_exec').
--- .gitignore | 1 + Makefile | 1 + Makefile.objs | 7 ++++- Makefile.target | 5 ++++ scripts/tracetool/format/tcg_helper_c.py | 50 ++++++++++++++++++++++++++++++++ trace/Makefile.objs | 12 ++++++++ 6 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 scripts/tracetool/format/tcg_helper_c.py
.gitignore +1 -0
@@ -12,6 +12,7 @@ /trace/generated-events.h /trace/generated-events.c /trace/generated-helpers.h +/trace/generated-helpers.c /trace/generated-ust-provider.h /trace/generated-ust.c /libcacard/trace/generated-tracers.c
Makefile +1 -0
@@ -58,6 +58,7 @@ endif GENERATED_SOURCES += trace/generated-tracers.c GENERATED_HEADERS += trace/generated-helpers.h +GENERATED_SOURCES += trace/generated-helpers.c ifeq ($(findstring ust,$(TRACE_BACKENDS)),ust) GENERATED_HEADERS += trace/generated-ust-provider.h
Makefile.objs +6 -1
@@ -1,7 +1,7 @@ ####################################################################### # Common libraries for tools and emulators stub-obj-y = stubs/ -util-obj-y = util/ qobject/ qapi/ trace/ +util-obj-y = util/ qobject/ qapi/ ####################################################################### # block-obj-y is code used by both qemu system emulation and qemu-img
@@ -107,6 +107,11 @@ version-obj-$(CONFIG_WIN32) += $(BUILD_DIR)/version.o version-lobj-$(CONFIG_WIN32) += $(BUILD_DIR)/version.lo ###################################################################### +# tracing +util-obj-y += trace/ +target-obj-y += trace/ + +###################################################################### # guest agent # FIXME: a few definitions from qapi-types.o/qapi-visit.o are needed
Makefile.target +5 -0
@@ -159,15 +159,20 @@ endif # CONFIG_SOFTMMU dummy := $(call unnest-vars,,obj-y) all-obj-y := $(obj-y) +target-obj-y := block-obj-y := common-obj-y := include $(SRC_PATH)/Makefile.objs +dummy := $(call unnest-vars,,target-obj-y) +target-obj-y-save := $(target-obj-y) dummy := $(call unnest-vars,.., \ block-obj-y \ block-obj-m \ common-obj-y \ common-obj-m) +target-obj-y := $(target-obj-y-save) all-obj-y += $(common-obj-y) +all-obj-y += $(target-obj-y) all-obj-$(CONFIG_SOFTMMU) += $(block-obj-y) # build either PROG or PROGW
scripts/tracetool/format/tcg_helper_c.py new file +50 -0
50 lines not on this page · raw message
trace/Makefile.objs +12 -0
@@ -107,6 +107,18 @@ $(obj)/generated-helpers.h-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/conf < $< > $@," GEN $(patsubst %-timestamp,%,$@)") @cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst %-timestamp,%,$@) +$(obj)/generated-helpers.c: $(obj)/generated-helpers.c-timestamp +$(obj)/generated-helpers.c-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak + $(call quiet-command,$(TRACETOOL) \ + --format=tcg-helper-c \ + --backend=$(TRACE_BACKENDS) \ + < $< > $@," GEN $(patsubst %-timestamp,%,$@)") + @cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst %-timestamp,%,$@) + +$(obj)/generated-helpers.o: $(obj)/generated-helpers.c + +target-obj-y += generated-helpers.o + ###################################################################### # Backend code
Signature · 1 line
1.9.3
[Qemu-devel] [PULL 09/18] trace: [tcg] Declare TCG tracing helper routines
In reply to Stefan HajnocziFrom: Lluís Vilanova <[email protected]>
Generates file "trace/generated-helpers.h" with TCG helper declarations to trace events in guest code at execution time ('trace_${event}_exec_proxy').
--- .gitignore | 1 + Makefile | 2 ++ scripts/tracetool/__init__.py | 1 + scripts/tracetool/format/tcg_helper_h.py | 50 ++++++++++++++++++++++++++++++++ trace/Makefile.objs | 24 +++++++++++---- 5 files changed, 73 insertions(+), 5 deletions(-) create mode 100644 scripts/tracetool/format/tcg_helper_h.py
.gitignore +1 -0
@@ -11,6 +11,7 @@ /trace/generated-tracers.dtrace /trace/generated-events.h /trace/generated-events.c +/trace/generated-helpers.h /trace/generated-ust-provider.h /trace/generated-ust.c /libcacard/trace/generated-tracers.c
Makefile +2 -0
@@ -57,6 +57,8 @@ GENERATED_HEADERS += trace/generated-tracers-dtrace.h endif GENERATED_SOURCES += trace/generated-tracers.c +GENERATED_HEADERS += trace/generated-helpers.h + ifeq ($(findstring ust,$(TRACE_BACKENDS)),ust) GENERATED_HEADERS += trace/generated-ust-provider.h GENERATED_SOURCES += trace/generated-ust.c
scripts/tracetool/__init__.py +1 -0
@@ -227,6 +227,7 @@ class Event(object): fmt) QEMU_TRACE = "trace_%(name)s" + QEMU_TRACE_TCG = QEMU_TRACE + "_tcg" def api(self, fmt=None): if fmt is None:
scripts/tracetool/format/tcg_helper_h.py new file +50 -0
50 lines not on this page · raw message
trace/Makefile.objs +19 -5
@@ -49,6 +49,9 @@ util-obj-y += generated-events.o ###################################################################### # Auto-generated tracing routines +################################################## +# Execution level + $(obj)/generated-tracers.h: $(obj)/generated-tracers.h-timestamp @cmp -s $< $@ || cp $< $@ $(obj)/generated-tracers.h-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak
@@ -57,8 +60,8 @@ $(obj)/generated-tracers.h-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/conf --backends=$(TRACE_BACKENDS) \ < $< > $@," GEN $(patsubst %-timestamp,%,$@)") -###################################################################### -# Auto-generated tracing routines (non-DTrace) +############################## +# non-DTrace $(obj)/generated-tracers.c: $(obj)/generated-tracers.c-timestamp @cmp -s $< $@ || cp $< $@
@@ -70,9 +73,8 @@ $(obj)/generated-tracers.c-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/conf $(obj)/generated-tracers.o: $(obj)/generated-tracers.c $(obj)/generated-tracers.h - -###################################################################### -# Auto-generated DTrace code +############################## +# DTrace # Normal practice is to name DTrace probe file with a '.d' extension # but that gets picked up by QEMU's Makefile as an external dependency
@@ -94,6 +96,18 @@ $(obj)/generated-tracers-dtrace.o: $(obj)/generated-tracers-dtrace.dtrace util-obj-y += generated-tracers-dtrace.o endif +################################################## +# Translation level + +$(obj)/generated-helpers.h: $(obj)/generated-helpers.h-timestamp +$(obj)/generated-helpers.h-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak + $(call quiet-command,$(TRACETOOL) \ + --format=tcg-helper-h \ + --backend=$(TRACE_BACKENDS) \ + < $< > $@," GEN $(patsubst %-timestamp,%,$@)") + @cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst %-timestamp,%,$@) + + ###################################################################### # Backend code
Signature · 1 line
1.9.3
[Qemu-devel] [PULL 11/18] trace: [tcg] Define TCG tracing helper routine wrappers
In reply to Stefan HajnocziFrom: Lluís Vilanova <[email protected]>
Generates header "trace/generated-helpers-wrappers.h" with definitions for TCG helper wrappers.
These wrappers ('gen_helper_trace_${event}_exec_wrapper') transform mixed native and TCG argument types to TCG types and call the actual TCG helpers ('gen_helper_trace_${event}_exec_proxy').
--- .gitignore | 1 + Makefile | 1 + scripts/tracetool/format/tcg_helper_wrapper_h.py | 70 ++++++++++++++++++++++++ trace/Makefile.objs | 8 +++ 4 files changed, 80 insertions(+) create mode 100644 scripts/tracetool/format/tcg_helper_wrapper_h.py
.gitignore +1 -0
@@ -11,6 +11,7 @@ /trace/generated-tracers.dtrace /trace/generated-events.h /trace/generated-events.c +/trace/generated-helpers-wrappers.h /trace/generated-helpers.h /trace/generated-helpers.c /trace/generated-ust-provider.h
Makefile +1 -0
@@ -57,6 +57,7 @@ GENERATED_HEADERS += trace/generated-tracers-dtrace.h endif GENERATED_SOURCES += trace/generated-tracers.c +GENERATED_HEADERS += trace/generated-helpers-wrappers.h GENERATED_HEADERS += trace/generated-helpers.h GENERATED_SOURCES += trace/generated-helpers.c
scripts/tracetool/format/tcg_helper_wrapper_h.py new file +70 -0
70 lines not on this page · raw message
trace/Makefile.objs +8 -0
@@ -99,6 +99,14 @@ endif ################################################## # Translation level +$(obj)/generated-helpers-wrappers.h: $(obj)/generated-helpers-wrappers.h-timestamp +$(obj)/generated-helpers-wrappers.h-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak + $(call quiet-command,$(TRACETOOL) \ + --format=tcg-helper-wrapper-h \ + --backend=$(TRACE_BACKENDS) \ + < $< > $@," GEN $(patsubst %-timestamp,%,$@)") + @cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst %-timestamp,%,$@) + $(obj)/generated-helpers.h: $(obj)/generated-helpers.h-timestamp $(obj)/generated-helpers.h-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak $(call quiet-command,$(TRACETOOL) \
Signature · 1 line
1.9.3
[Qemu-devel] [PULL 12/18] trace: [tcg] Include TCG-tracing helpers
In reply to Stefan HajnocziFrom: Lluís Vilanova <[email protected]>
--- include/exec/helper-gen.h | 2 ++ include/exec/helper-proto.h | 1 + include/exec/helper-tcg.h | 1 + 3 files changed, 4 insertions(+)
include/exec/helper-gen.h +2 -0
@@ -57,6 +57,8 @@ static inline void glue(gen_helper_, name)(dh_retvar_decl(ret) \ }#include "helper.h" +#include "trace/generated-helpers.h" +#include "trace/generated-helpers-wrappers.h" #include "tcg-runtime.h" #undef DEF_HELPER_FLAGS_0
include/exec/helper-proto.h +1 -0
@@ -27,6 +27,7 @@ dh_ctype(ret) HELPER(name) (dh_ctype(t1), dh_ctype(t2), dh_ctype(t3), \ dh_ctype(t4), dh_ctype(t5));#include "helper.h" +#include "trace/generated-helpers.h" #include "tcg-runtime.h" #undef DEF_HELPER_FLAGS_0
include/exec/helper-tcg.h +1 -0
@@ -36,6 +36,7 @@ | dh_sizemask(t5, 5) },#include "helper.h" +#include "trace/generated-helpers.h" #include "tcg-runtime.h" #undef DEF_HELPER_FLAGS_0
Signature · 1 line
1.9.3
[Qemu-devel] [PULL 13/18] trace: [tcg] Generate TCG tracing routines
In reply to Stefan HajnocziFrom: Lluís Vilanova <[email protected]>
Generate header "trace/generated-tcg-tracers.h" with the necessary routines for tracing events in guest code:
* trace_${event}_tcg
Convenience wrapper that calls the translation-time tracer 'trace_${event}_trans', and calls 'gen_helper_trace_${event}_exec to generate the TCG code to later trace the event at execution time.
--- .gitignore | 1 + Makefile | 2 ++ include/trace-tcg.h | 7 +++++ scripts/tracetool/format/tcg_h.py | 57 +++++++++++++++++++++++++++++++++++++++ trace/Makefile.objs | 9 +++++++ 5 files changed, 76 insertions(+) create mode 100644 include/trace-tcg.h create mode 100644 scripts/tracetool/format/tcg_h.py
.gitignore +1 -0
@@ -14,6 +14,7 @@ /trace/generated-helpers-wrappers.h /trace/generated-helpers.h /trace/generated-helpers.c +/trace/generated-tcg-tracers.h /trace/generated-ust-provider.h /trace/generated-ust.c /libcacard/trace/generated-tracers.c
Makefile +2 -0
@@ -57,6 +57,8 @@ GENERATED_HEADERS += trace/generated-tracers-dtrace.h endif GENERATED_SOURCES += trace/generated-tracers.c +GENERATED_HEADERS += trace/generated-tcg-tracers.h + GENERATED_HEADERS += trace/generated-helpers-wrappers.h GENERATED_HEADERS += trace/generated-helpers.h GENERATED_SOURCES += trace/generated-helpers.c
include/trace-tcg.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef TRACE_TCG_H +#define TRACE_TCG_H + +#include "trace/generated-tcg-tracers.h" +#include "trace/generated-events.h" + +#endif /* TRACE_TCG_H */
scripts/tracetool/format/tcg_h.py new file +57 -0
57 lines not on this page · raw message
trace/Makefile.objs +9 -0
@@ -128,6 +128,15 @@ $(obj)/generated-helpers.o: $(obj)/generated-helpers.c target-obj-y += generated-helpers.o +$(obj)/generated-tcg-tracers.h: $(obj)/generated-tcg-tracers.h-timestamp +$(obj)/generated-tcg-tracers.h-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak + $(call quiet-command,$(TRACETOOL) \ + --format=tcg-h \ + --backend=$(TRACE_BACKENDS) \ + < $< > $@," GEN $(patsubst %-timestamp,%,$@)") + @cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst %-timestamp,%,$@) + + ###################################################################### # Backend code
Signature · 1 line
1.9.3
[Qemu-devel] [PULL 14/18] trace: [tcg] Include event definitions in "trace.h"
In reply to Stefan HajnocziFrom: Lluís Vilanova <[email protected]>
Otherwise the user has to explicitly include an auto-generated header.
--- include/trace.h | 1 + 1 file changed, 1 insertion(+)
include/trace.h +1 -0
@@ -2,5 +2,6 @@#define TRACE_H #include "trace/generated-tracers.h" +#include "trace/generated-events.h" #endif /* TRACE_H */
Signature · 1 line
1.9.3
[Qemu-devel] [PULL 15/18] trace: [tcg] Include TCG-tracing header on all targets
In reply to Stefan HajnocziFrom: Lluís Vilanova <[email protected]>
--- target-alpha/translate.c | 3 +++ target-arm/translate-a64.c | 2 ++ target-arm/translate.c | 3 +++ target-cris/translate.c | 3 +++ target-i386/translate.c | 3 +++ target-lm32/translate.c | 3 +++ target-m68k/translate.c | 3 +++ target-microblaze/translate.c | 3 +++ target-mips/translate.c | 3 +++ target-openrisc/translate.c | 3 +++ target-ppc/translate.c | 3 +++ target-s390x/translate.c | 2 ++ target-sh4/translate.c | 3 +++ target-sparc/translate.c | 3 +++ target-unicore32/translate.c | 3 +++ target-xtensa/translate.c | 3 +++ 16 files changed, 46 insertions(+)
target-alpha/translate.c +3 -0
@@ -26,6 +26,9 @@#include "exec/helper-proto.h" #include "exec/helper-gen.h" +#include "trace-tcg.h" + +#undef ALPHA_DEBUG_DISAS#define CONFIG_SOFTFLOAT_INLINE
target-arm/translate-a64.c +2 -0
@@ -35,6 +35,8 @@#include "exec/helper-proto.h" #include "exec/helper-gen.h" +#include "trace-tcg.h" +static TCGv_i64 cpu_X[32 ];static TCGv_i64 cpu_pc;static TCGv_i32 cpu_NF, cpu_ZF, cpu_CF, cpu_VF;
target-arm/translate.c +3 -0
@@ -35,6 +35,9 @@#include "exec/helper-proto.h" #include "exec/helper-gen.h" +#include "trace-tcg.h" + +#define ENABLE_ARCH_4T arm_feature(env, ARM_FEATURE_V4T)#define ENABLE_ARCH_5 arm_feature(env, ARM_FEATURE_V5)/* currently all emulated v5 cores are also v5TE, so don't bother */
target-cris/translate.c +3 -0
@@ -33,6 +33,9 @@#include "exec/helper-gen.h" +#include "trace-tcg.h" + +#define DISAS_CRIS 0#if DISAS_CRIS # define LOG_DIS (...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
target-i386/translate.c +3 -0
@@ -32,6 +32,9 @@#include "exec/helper-proto.h" #include "exec/helper-gen.h" +#include "trace-tcg.h" + +#define PREFIX_REPZ 0x01#define PREFIX_REPNZ 0x02#define PREFIX_LOCK 0x04
target-lm32/translate.c +3 -0
@@ -27,6 +27,9 @@#include "exec/helper-gen.h" +#include "trace-tcg.h" + +#define DISAS_LM32 1#if DISAS_LM32 # define LOG_DIS (...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
target-m68k/translate.c +3 -0
@@ -27,6 +27,9 @@#include "exec/helper-proto.h" #include "exec/helper-gen.h" +#include "trace-tcg.h" + +//#define DEBUG_DISPATCH 1 /* Fake floating point. */
target-microblaze/translate.c +3 -0
@@ -26,6 +26,9 @@#include "exec/cpu_ldst.h" #include "exec/helper-gen.h" +#include "trace-tcg.h" + +#define SIM_COMPAT 0#define DISAS_GNU 1#define DISAS_MB 1
target-mips/translate.c +3 -0
@@ -30,6 +30,9 @@#include "exec/helper-gen.h" #include "sysemu/kvm.h" +#include "trace-tcg.h" + +#define MIPS_DEBUG_DISAS 0//#define MIPS_DEBUG_SIGN_EXTENSIONS
target-openrisc/translate.c +3 -0
@@ -31,6 +31,9 @@#include "exec/helper-proto.h" #include "exec/helper-gen.h" +#include "trace-tcg.h" + +#define OPENRISC_DISAS #ifdef OPENRISC_DISAS
target-ppc/translate.c +3 -0
@@ -27,6 +27,9 @@#include "exec/helper-proto.h" #include "exec/helper-gen.h" +#include "trace-tcg.h" + +#define CPU_SINGLE_STEP 0x1#define CPU_BRANCH_STEP 0x2#define GDBSTUB_SINGLE_STEP 0x4
target-s390x/translate.c +2 -0
@@ -42,6 +42,8 @@ static TCGv_ptr cpu_env;#include "exec/helper-proto.h" #include "exec/helper-gen.h" +#include "trace-tcg.h" +/* Information that (most) every instruction needs to manipulate. */ typedef struct DisasContext DisasContext ;
target-sh4/translate.c +3 -0
@@ -28,6 +28,9 @@#include "exec/helper-proto.h" #include "exec/helper-gen.h" +#include "trace-tcg.h" + + typedef struct DisasContext { struct TranslationBlock *tb; target_ulong pc;
target-sparc/translate.c +3 -0
@@ -32,6 +32,9 @@#include "exec/helper-gen.h" +#include "trace-tcg.h" + +#define DEBUG_DISAS #define DYNAMIC_PC 1/* dynamic pc value */
target-unicore32/translate.c +3 -0
@@ -23,6 +23,9 @@#include "exec/helper-proto.h" #include "exec/helper-gen.h" +#include "trace-tcg.h" + +/* internal defines */ typedef struct DisasContext { target_ulong pc;
target-xtensa/translate.c +3 -0
@@ -41,6 +41,9 @@#include "exec/helper-proto.h" #include "exec/helper-gen.h" +#include "trace-tcg.h" + + typedef struct DisasContext { const XtensaConfig *config; TranslationBlock *tb;
Signature · 1 line
1.9.3
[Qemu-devel] [PULL 16/18] trace: teach lttng backend to use format strings
In reply to Stefan HajnocziFrom: Alex Bennée <[email protected]>
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.
--- scripts/tracetool/__init__.py | 12 ++++++++++-- scripts/tracetool/format/ust_events_h.py | 15 +++++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-)
scripts/tracetool/__init__.py +10 -2
@@ -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."""
scripts/tracetool/format/ust_events_h.py +11 -4
@@ -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 + ')')
Signature · 1 line
1.9.3
[Qemu-devel] [PULL 17/18] trace: add some tcg tracing support
In reply to Stefan HajnocziFrom: Alex Bennée <[email protected]>
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.
--- cpu-exec.c | 6 ++++++ trace-events | 9 +++++++++ translate-all.c | 3 +++ 3 files changed, 18 insertions(+)
cpu-exec.c +6 -0
@@ -18,6 +18,7 @@*/ #include "config.h" #include "cpu.h" +#include "trace.h" #include "disas/disas.h" #include "tcg.h" #include "qemu/atomic.h"
@@ -168,6 +169,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
@@ -208,6 +212,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 );
@@ -749,6 +754,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);
trace-events +9 -0
@@ -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"
translate-all.c +3 -0
@@ -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_ptrgen_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 ;
Signature · 1 line
1.9.3
[Qemu-devel] [PULL 18/18] virtio-rng: add some trace events
In reply to Stefan HajnocziFrom: Amit Shah <[email protected]>
Add some trace events to virtio-rng for easier debugging
--- hw/virtio/virtio-rng.c | 6 ++++++ trace-events | 5 +++++ 2 files changed, 11 insertions(+)
hw/virtio/virtio-rng.c +6 -0
@@ -16,6 +16,7 @@#include "hw/virtio/virtio-rng.h" #include "sysemu/rng.h" #include "qom/object_interfaces.h" +#include "trace.h" static bool is_guest_ready (VirtIORNG *vrng) {
@@ -24,6 +25,7 @@ static bool is_guest_ready(VirtIORNG *vrng) && (vdev->status & VIRTIO_CONFIG_S_DRIVER_OK)) {return true; } +trace_virtio_rng_guest_not_ready (vrng);return false; }
@@ -62,6 +64,7 @@ static void chr_read(void *opaque, const void *buf, size_t size) offset += len;virtqueue_push (vrng->vq, &elem, len); +trace_virtio_rng_pushed (vrng, len); }virtio_notify (vdev, vrng->vq); }
@@ -81,6 +84,9 @@ static void virtio_rng_process(VirtIORNG *vrng) quota =MIN ((uint64_t )vrng->quota_remaining, (uint64_t )UINT32_MAX ); } size =get_request_size (vrng->vq, quota); + +trace_virtio_rng_request (vrng, size, quota); + size =MIN (vrng->quota_remaining, size);if (size) {rng_backend_request_entropy (vrng->rng, size, chr_read, vrng);
trace-events +5 -0
@@ -41,6 +41,11 @@ virtio_irq(void *vq) "vq %p" virtio_notify(void *vdev, void *vq) "vdev %p vq %p" virtio_set_status(void *vdev, uint8_t val) "vdev %p val %u" +# hw/virtio/virtio-rng.c +virtio_rng_guest_not_ready(void *rng) "rng %p: guest not ready" +virtio_rng_pushed(void *rng, size_t len) "rng %p: %zd bytes pushed" +virtio_rng_request(void *rng, size_t size, unsigned quota) "rng %p: %zd bytes requested, %u bytes quota left" + # hw/char/virtio-serial-bus.c virtio_serial_send_control_event(unsigned int port, uint16_t event, uint16_t value) "port %u, event %u, value %u" virtio_serial_throttle_port(unsigned int port, bool throttle) "port %u, throttle %d"
Signature · 1 line
1.9.3
Peter Maydell
AppliedQuoted 7 lines · Stefan Hajnoczi
The following changes since commit
2d591ce2aeebf9620ff527c7946844a3122afeec:Merge remote-tracking branch 'remotes/mdroth/qga-pull-2014-08-08' into staging (2014-08-08 14:16:05 +0100)
are available in the git repository at:
Quoted 8 lines
git://github.com/stefanha/qemu.gittags/tracing-pull-requestfor you to fetch changes up to
4ac4458076e1aaf3b01a6361154117df20e22215:virtio-rng: add some trace events (2014-08-12 14:29:55 +0100)
----------------------------------------------------------------
Tracing pull request
Applied, thanks (with a minor conflict fix in Makefile.objs).
-- PMM