Commit 743bddb4 authored by Anthony Liguori's avatar Anthony Liguori
Browse files

Merge remote-tracking branch 'stefanha/tracing' into staging



# By Eiichi Tsukata (2) and Kazuya Saito (2)
# Via Stefan Hajnoczi
* stefanha/tracing:
  trace: document ftrace backend
  trace: Add ftrace tracing backend
  kvm-all: add kvm_run_exit tracepoint
  kvm-all: add kvm_ioctl, kvm_vm_ioctl, kvm_vcpu_ioctl tracepoints

Message-id: 1367582485-15579-1-git-send-email-stefanha@redhat.com
Signed-off-by: default avatarAnthony Liguori <aliguori@us.ibm.com>
parents a612925b e64dd5ef
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -4004,6 +4004,14 @@ if test "$trace_backend" = "dtrace"; then
    echo "CONFIG_TRACE_SYSTEMTAP=y" >> $config_host_mak
  fi
fi
if test "$trace_backend" = "ftrace"; then
  if test "$linux" = "yes" ; then
    echo "CONFIG_TRACE_FTRACE=y" >> $config_host_mak
    trace_default=no
  else
    feature_not_found "ftrace(trace backend)"
  fi
fi
echo "CONFIG_TRACE_FILE=$trace_file" >> $config_host_mak
if test "$trace_default" = "yes"; then
  echo "CONFIG_TRACE_DEFAULT=y" >> $config_host_mak
+16 −0
Original line number Diff line number Diff line
@@ -175,6 +175,22 @@ unless you have specific needs for more advanced backends.
The "simple" backend currently does not capture string arguments, it simply
records the char* pointer value instead of the string that is pointed to.

=== Ftrace ===

The "ftrace" backend writes trace data to ftrace marker. This effectively
sends trace events to ftrace ring buffer, and you can compare qemu trace
data and kernel(especially kvm.ko when using KVM) trace data.

if you use KVM, enable kvm events in ftrace:

   # echo 1 > /sys/kernel/debug/tracing/events/kvm/enable

After running qemu by root user, you can get the trace:

   # cat /sys/kernel/debug/tracing/trace

Restriction: "ftrace" backend is restricted to Linux only.

==== Monitor commands ====

* trace-file on|off|flush|set <path>
+5 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@
#include "exec/memory.h"
#include "exec/address-spaces.h"
#include "qemu/event_notifier.h"
#include "trace.h"

/* This check must be after config-host.h is included */
#ifdef CONFIG_EVENTFD
@@ -1626,6 +1627,7 @@ int kvm_cpu_exec(CPUArchState *env)
            abort();
        }

        trace_kvm_run_exit(cpu->cpu_index, run->exit_reason);
        switch (run->exit_reason) {
        case KVM_EXIT_IO:
            DPRINTF("handle_io\n");
@@ -1687,6 +1689,7 @@ int kvm_ioctl(KVMState *s, int type, ...)
    arg = va_arg(ap, void *);
    va_end(ap);

    trace_kvm_ioctl(type, arg);
    ret = ioctl(s->fd, type, arg);
    if (ret == -1) {
        ret = -errno;
@@ -1704,6 +1707,7 @@ int kvm_vm_ioctl(KVMState *s, int type, ...)
    arg = va_arg(ap, void *);
    va_end(ap);

    trace_kvm_vm_ioctl(type, arg);
    ret = ioctl(s->vmfd, type, arg);
    if (ret == -1) {
        ret = -errno;
@@ -1721,6 +1725,7 @@ int kvm_vcpu_ioctl(CPUState *cpu, int type, ...)
    arg = va_arg(ap, void *);
    va_end(ap);

    trace_kvm_vcpu_ioctl(cpu->cpu_index, type, arg);
    ret = ioctl(cpu->kvm_fd, type, arg);
    if (ret == -1) {
        ret = -errno;
+54 −0
Original line number Diff line number Diff line
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
Ftrace built-in backend.
"""

__author__     = "Eiichi Tsukata <eiichi.tsukata.xh@hitachi.com>"
__copyright__  = "Copyright (C) 2013 Hitachi, Ltd."
__license__    = "GPL version 2 or (at your option) any later version"

__maintainer__ = "Stefan Hajnoczi"
__email__      = "stefanha@redhat.com"


from tracetool import out


PUBLIC = True


def c(events):
    pass

def h(events):
    out('#include "trace/ftrace.h"',
        '#include "trace/control.h"',
        '',
        )

    for e in events:
        argnames = ", ".join(e.args.names())
        if len(e.args) > 0:
            argnames = ", " + argnames

        out('static inline void trace_%(name)s(%(args)s)',
            '{',
            '    char ftrace_buf[MAX_TRACE_STRLEN];',
            '    int unused __attribute__ ((unused));',
            '    int trlen;',
            '    bool _state = trace_event_get_state(%(event_id)s);',
            '    if (_state) {',
            '        trlen = snprintf(ftrace_buf, MAX_TRACE_STRLEN,',
            '                         "%(name)s " %(fmt)s "\\n" %(argnames)s);',
            '        trlen = MIN(trlen, MAX_TRACE_STRLEN - 1);',
            '        unused = write(trace_marker_fd, ftrace_buf, trlen);',
            '    }',
            '}',
            name = e.name,
            args = e.args,
            event_id = "TRACE_" + e.name.upper(),
            fmt = e.fmt.rstrip("\n"),
            argnames = argnames,
            )
+7 −0
Original line number Diff line number Diff line
@@ -1153,3 +1153,10 @@ virtio_ccw_new_device(int cssid, int ssid, int schid, int devno, const char *dev

# migration.c
migrate_set_state(int new_state) "new state %d"

# kvm-all.c
kvm_ioctl(int type, void *arg) "type %d, arg %p"
kvm_vm_ioctl(int type, void *arg) "type %d, arg %p"
kvm_vcpu_ioctl(int cpu_index, int type, void *arg) "cpu_index %d, type %d, arg %p"
kvm_run_exit(int cpu_index, uint32_t reason) "cpu_index %d, reason %d"
Loading