-----BEGIN PGP SIGNATURE-----

Version: GnuPG v1
 
 iQEcBAABAgAGBQJWsiEWAAoJEJykq7OBq3PIGXYIALsxSU9HYOBqt/7J5E07EUxS
 ef3pu/CnMSHw3I/oLVe+pdpwyKMEhRRa75t8DSl4+UodsPXyZ/YtuBTm2v7J+FXD
 tjOoDYimAuDqeJU+km4O3PRUKSUKIlo0V4g7DRWF1qCCC4xw8SwmkBvfax7oFf3a
 ew3s0Lw/v11/foe5lKTkgTBgoXKk/Oc1E3rhSsOb7WvZq0CbrhRV3R5Lp0jbXkjF
 1LMijbsQvzQY7v07r4FcZ2vwhdI5eUXQOKg6sHMBqBbNdrR0zEQeylgdXq7H2rqm
 RhdkK4Dd1bs4K1gk4TXNhysd7/U5gRJhGqeBkYCI12lNY9AJwyH0OBcBxGZBV6U=
 =pTqw
 -----END PGP SIGNATURE-----

Merge remote-tracking branch 'remotes/stefanha/tags/tracing-pull-request' into staging

# gpg: Signature made Wed 03 Feb 2016 15:47:34 GMT using RSA key ID 81AB73C8
# gpg: Good signature from "Stefan Hajnoczi <stefanha@redhat.com>"
# gpg:                 aka "Stefan Hajnoczi <stefanha@gmail.com>"

* remotes/stefanha/tags/tracing-pull-request:
  log: add "-d trace:PATTERN"
  trace: switch default backend to "log"
  trace: convert stderr backend to log
  log: move qemu-log.c into util/ directory
  log: do not unnecessarily include qom/cpu.h
  trace: add "-trace help"
  trace: add "-trace enable=..."
  trace: no need to call trace_backend_init in different branches now
  trace: split trace_init_file out of trace_init_backends
  trace: split trace_init_events out of trace_init_backends
  trace: fix documentation
  trace: track enabled events in a separate array
  trace: count number of enabled events

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
Peter Maydell 2016-02-03 19:00:33 +00:00
commit 382d34ff9f
57 changed files with 293 additions and 137 deletions

View File

@ -78,7 +78,7 @@ matrix:
compiler: gcc compiler: gcc
# All the trace backends (apart from dtrace) # All the trace backends (apart from dtrace)
- env: TARGETS=i386-softmmu,x86_64-softmmu - env: TARGETS=i386-softmmu,x86_64-softmmu
EXTRA_CONFIG="--enable-trace-backends=stderr" EXTRA_CONFIG="--enable-trace-backends=log"
compiler: gcc compiler: gcc
- env: TARGETS=i386-softmmu,x86_64-softmmu - env: TARGETS=i386-softmmu,x86_64-softmmu
EXTRA_CONFIG="--enable-trace-backends=simple" EXTRA_CONFIG="--enable-trace-backends=simple"

View File

@ -89,7 +89,6 @@ endif
####################################################################### #######################################################################
# Target-independent parts used in system and user emulation # Target-independent parts used in system and user emulation
common-obj-y += qemu-log.o
common-obj-y += tcg-runtime.o common-obj-y += tcg-runtime.o
common-obj-y += hw/ common-obj-y += hw/
common-obj-y += qom/ common-obj-y += qom/

View File

@ -33,6 +33,7 @@
#include "tcg.h" #include "tcg.h"
#include "qemu/timer.h" #include "qemu/timer.h"
#include "qemu/envlist.h" #include "qemu/envlist.h"
#include "exec/log.h"
int singlestep; int singlestep;
unsigned long mmap_min_addr; unsigned long mmap_min_addr;

6
configure vendored
View File

@ -303,7 +303,7 @@ pkgversion=""
pie="" pie=""
zero_malloc="" zero_malloc=""
qom_cast_debug="yes" qom_cast_debug="yes"
trace_backends="nop" trace_backends="log"
trace_file="trace" trace_file="trace"
spice="" spice=""
rbd="" rbd=""
@ -5445,8 +5445,8 @@ if have_backend "simple"; then
# Set the appropriate trace file. # Set the appropriate trace file.
trace_file="\"$trace_file-\" FMT_pid" trace_file="\"$trace_file-\" FMT_pid"
fi fi
if have_backend "stderr"; then if have_backend "log"; then
echo "CONFIG_TRACE_STDERR=y" >> $config_host_mak echo "CONFIG_TRACE_LOG=y" >> $config_host_mak
fi fi
if have_backend "ust"; then if have_backend "ust"; then
echo "CONFIG_TRACE_UST=y" >> $config_host_mak echo "CONFIG_TRACE_UST=y" >> $config_host_mak

View File

@ -27,6 +27,7 @@
#include "exec/address-spaces.h" #include "exec/address-spaces.h"
#include "qemu/rcu.h" #include "qemu/rcu.h"
#include "exec/tb-hash.h" #include "exec/tb-hash.h"
#include "exec/log.h"
#if defined(TARGET_I386) && !defined(CONFIG_USER_ONLY) #if defined(TARGET_I386) && !defined(CONFIG_USER_ONLY)
#include "hw/i386/apic.h" #include "hw/i386/apic.h"
#endif #endif

1
exec.c
View File

@ -52,6 +52,7 @@
#include "exec/memory-internal.h" #include "exec/memory-internal.h"
#include "exec/ram_addr.h" #include "exec/ram_addr.h"
#include "exec/log.h"
#include "qemu/range.h" #include "qemu/range.h"
#ifndef _WIN32 #ifndef _WIN32

View File

@ -12,6 +12,7 @@
#include "qemu/osdep.h" #include "qemu/osdep.h"
#include "hw/hw.h" #include "hw/hw.h"
#include "hw/acpi/cpu_hotplug.h" #include "hw/acpi/cpu_hotplug.h"
#include "qom/cpu.h"
static uint64_t cpu_status_read(void *opaque, hwaddr addr, unsigned int size) static uint64_t cpu_status_read(void *opaque, hwaddr addr, unsigned int size)
{ {

View File

@ -25,6 +25,7 @@
#include "qemu/timer.h" #include "qemu/timer.h"
#include "qemu/bitops.h" #include "qemu/bitops.h"
#include "qemu/log.h" #include "qemu/log.h"
#include "qom/cpu.h"
#ifndef A9_GTIMER_ERR_DEBUG #ifndef A9_GTIMER_ERR_DEBUG
#define A9_GTIMER_ERR_DEBUG 0 #define A9_GTIMER_ERR_DEBUG 0

60
include/exec/log.h Normal file
View File

@ -0,0 +1,60 @@
#ifndef QEMU_EXEC_LOG_H
#define QEMU_EXEC_LOG_H
#include "qemu/log.h"
#include "qom/cpu.h"
#include "disas/disas.h"
/* cpu_dump_state() logging functions: */
/**
* log_cpu_state:
* @cpu: The CPU whose state is to be logged.
* @flags: Flags what to log.
*
* Logs the output of cpu_dump_state().
*/
static inline void log_cpu_state(CPUState *cpu, int flags)
{
if (qemu_log_enabled()) {
cpu_dump_state(cpu, qemu_logfile, fprintf, flags);
}
}
/**
* log_cpu_state_mask:
* @mask: Mask when to log.
* @cpu: The CPU whose state is to be logged.
* @flags: Flags what to log.
*
* Logs the output of cpu_dump_state() if loglevel includes @mask.
*/
static inline void log_cpu_state_mask(int mask, CPUState *cpu, int flags)
{
if (qemu_loglevel & mask) {
log_cpu_state(cpu, flags);
}
}
#ifdef NEED_CPU_H
/* disas() and target_disas() to qemu_logfile: */
static inline void log_target_disas(CPUState *cpu, target_ulong start,
target_ulong len, int flags)
{
target_disas(qemu_logfile, cpu, start, len, flags);
}
static inline void log_disas(void *code, unsigned long size)
{
disas(qemu_logfile, code, size);
}
#if defined(CONFIG_USER_ONLY)
/* page_dump() output to the log file: */
static inline void log_page_dump(void)
{
page_dump(qemu_logfile);
}
#endif
#endif
#endif

View File

@ -5,10 +5,6 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include "qemu/compiler.h" #include "qemu/compiler.h"
#include "qom/cpu.h"
#ifdef NEED_CPU_H
#include "disas/disas.h"
#endif
/* Private global variables, don't use */ /* Private global variables, don't use */
extern FILE *qemu_logfile; extern FILE *qemu_logfile;
@ -49,6 +45,7 @@ static inline bool qemu_log_separate(void)
#define CPU_LOG_MMU (1 << 12) #define CPU_LOG_MMU (1 << 12)
#define CPU_LOG_TB_NOCHAIN (1 << 13) #define CPU_LOG_TB_NOCHAIN (1 << 13)
#define CPU_LOG_PAGE (1 << 14) #define CPU_LOG_PAGE (1 << 14)
#define LOG_TRACE (1 << 15)
/* Returns true if a bit is set in the current loglevel mask /* Returns true if a bit is set in the current loglevel mask
*/ */
@ -78,61 +75,6 @@ qemu_log_vprintf(const char *fmt, va_list va)
void GCC_FMT_ATTR(2, 3) qemu_log_mask(int mask, const char *fmt, ...); void GCC_FMT_ATTR(2, 3) qemu_log_mask(int mask, const char *fmt, ...);
/* Special cases: */
/* cpu_dump_state() logging functions: */
/**
* log_cpu_state:
* @cpu: The CPU whose state is to be logged.
* @flags: Flags what to log.
*
* Logs the output of cpu_dump_state().
*/
static inline void log_cpu_state(CPUState *cpu, int flags)
{
if (qemu_log_enabled()) {
cpu_dump_state(cpu, qemu_logfile, fprintf, flags);
}
}
/**
* log_cpu_state_mask:
* @mask: Mask when to log.
* @cpu: The CPU whose state is to be logged.
* @flags: Flags what to log.
*
* Logs the output of cpu_dump_state() if loglevel includes @mask.
*/
static inline void log_cpu_state_mask(int mask, CPUState *cpu, int flags)
{
if (qemu_loglevel & mask) {
log_cpu_state(cpu, flags);
}
}
#ifdef NEED_CPU_H
/* disas() and target_disas() to qemu_logfile: */
static inline void log_target_disas(CPUState *cpu, target_ulong start,
target_ulong len, int flags)
{
target_disas(qemu_logfile, cpu, start, len, flags);
}
static inline void log_disas(void *code, unsigned long size)
{
disas(qemu_logfile, code, size);
}
#if defined(CONFIG_USER_ONLY)
/* page_dump() output to the log file: */
static inline void log_page_dump(void)
{
page_dump(qemu_logfile);
}
#endif
#endif
/* Maintenance: */ /* Maintenance: */
/* fflush() the log file */ /* fflush() the log file */

View File

@ -28,6 +28,7 @@
#include "qemu/timer.h" #include "qemu/timer.h"
#include "qemu/envlist.h" #include "qemu/envlist.h"
#include "elf.h" #include "elf.h"
#include "exec/log.h"
char *exec_path; char *exec_path;

View File

@ -435,7 +435,7 @@ int main(int argc, char **argv)
} }
break; break;
case 'T': case 'T':
if (!trace_init_backends(optarg, NULL)) { if (!trace_init_backends()) {
exit(1); /* error message will have been printed */ exit(1); /* error message will have been printed */
} }
break; break;

View File

@ -3544,7 +3544,7 @@ config files on @var{sysconfdir}, but won't make it skip the QEMU-provided confi
files from @var{datadir}. files from @var{datadir}.
ETEXI ETEXI
DEF("trace", HAS_ARG, QEMU_OPTION_trace, DEF("trace", HAS_ARG, QEMU_OPTION_trace,
"-trace [events=<file>][,file=<file>]\n" "-trace [[enable=]<pattern>][,events=<file>][,file=<file>]\n"
" specify tracing options\n", " specify tracing options\n",
QEMU_ARCH_ALL) QEMU_ARCH_ALL)
STEXI STEXI
@ -3556,15 +3556,25 @@ HXCOMM HX does not support conditional compilation of text.
Specify tracing options. Specify tracing options.
@table @option @table @option
@item [enable=]@var{pattern}
Immediately enable events matching @var{pattern}.
The file must contain one event name (as listed in the @file{trace-events} file)
per line; globbing patterns are accepted too. This option is only
available if QEMU has been compiled with the @var{simple}, @var{stderr}
or @var{ftrace} tracing backend. To specify multiple events or patterns,
specify the @option{-trace} option multiple times.
Use @code{-trace help} to print a list of names of trace points.
@item events=@var{file} @item events=@var{file}
Immediately enable events listed in @var{file}. Immediately enable events listed in @var{file}.
The file must contain one event name (as listed in the @var{trace-events} file) The file must contain one event name (as listed in the @file{trace-events} file)
per line. per line; globbing patterns are accepted too. This option is only
This option is only available if QEMU has been compiled with available if QEMU has been compiled with the @var{simple}, @var{stderr} or
either @var{simple} or @var{stderr} tracing backend. @var{ftrace} tracing backend.
@item file=@var{file} @item file=@var{file}
Log output traces to @var{file}. Log output traces to @var{file}.
This option is only available if QEMU has been compiled with This option is only available if QEMU has been compiled with
the @var{simple} tracing backend. the @var{simple} tracing backend.
@end table @end table

View File

@ -23,6 +23,7 @@
#include "sysemu/kvm.h" #include "sysemu/kvm.h"
#include "qemu/notify.h" #include "qemu/notify.h"
#include "qemu/log.h" #include "qemu/log.h"
#include "exec/log.h"
#include "qemu/error-report.h" #include "qemu/error-report.h"
#include "sysemu/sysemu.h" #include "sysemu/sysemu.h"

View File

@ -25,6 +25,7 @@ def generate_h_begin(events):
'#include <sys/types.h>', '#include <sys/types.h>',
'#include <unistd.h>', '#include <unistd.h>',
'#include "trace/control.h"', '#include "trace/control.h"',
'#include "qemu/log.h"',
'') '')
@ -36,7 +37,7 @@ def generate_h(event):
out(' if (trace_event_get_state(%(event_id)s)) {', out(' if (trace_event_get_state(%(event_id)s)) {',
' struct timeval _now;', ' struct timeval _now;',
' gettimeofday(&_now, NULL);', ' gettimeofday(&_now, NULL);',
' fprintf(stderr, "%%d@%%zd.%%06zd:%(name)s " %(fmt)s "\\n",', ' qemu_log_mask(LOG_TRACE, "%%d@%%zd.%%06zd:%(name)s " %(fmt)s "\\n",',
' getpid(),', ' getpid(),',
' (size_t)_now.tv_sec, (size_t)_now.tv_usec', ' (size_t)_now.tv_sec, (size_t)_now.tv_usec',
' %(argnames)s);', ' %(argnames)s);',

View File

@ -27,7 +27,7 @@ def generate(events, backend):
out('TraceEvent trace_events[TRACE_EVENT_COUNT] = {') out('TraceEvent trace_events[TRACE_EVENT_COUNT] = {')
for e in events: for e in events:
out(' { .id = %(id)s, .name = \"%(name)s\", .sstate = %(sstate)s, .dstate = 0 },', out(' { .id = %(id)s, .name = \"%(name)s\", .sstate = %(sstate)s },',
id = "TRACE_" + e.name.upper(), id = "TRACE_" + e.name.upper(),
name = e.name, name = e.name,
sstate = "TRACE_%s_ENABLED" % e.name.upper()) sstate = "TRACE_%s_ENABLED" % e.name.upper())

View File

@ -28,6 +28,7 @@
#include "exec/helper-gen.h" #include "exec/helper-gen.h"
#include "trace-tcg.h" #include "trace-tcg.h"
#include "exec/log.h"
#undef ALPHA_DEBUG_DISAS #undef ALPHA_DEBUG_DISAS

View File

@ -31,6 +31,7 @@
#include "exec/helper-proto.h" #include "exec/helper-proto.h"
#include "exec/helper-gen.h" #include "exec/helper-gen.h"
#include "exec/log.h"
#include "trace-tcg.h" #include "trace-tcg.h"

View File

@ -32,6 +32,7 @@
#include "exec/helper-gen.h" #include "exec/helper-gen.h"
#include "trace-tcg.h" #include "trace-tcg.h"
#include "exec/log.h"
#define ENABLE_ARCH_4T arm_dc_feature(s, ARM_FEATURE_V4T) #define ENABLE_ARCH_4T arm_dc_feature(s, ARM_FEATURE_V4T)

View File

@ -35,6 +35,7 @@
#include "exec/helper-gen.h" #include "exec/helper-gen.h"
#include "trace-tcg.h" #include "trace-tcg.h"
#include "exec/log.h"
#define DISAS_CRIS 0 #define DISAS_CRIS 0

View File

@ -23,6 +23,7 @@
#include "qemu/log.h" #include "qemu/log.h"
#include "exec/helper-proto.h" #include "exec/helper-proto.h"
#include "exec/cpu_ldst.h" #include "exec/cpu_ldst.h"
#include "exec/log.h"
//#define DEBUG_PCALL //#define DEBUG_PCALL

View File

@ -20,6 +20,7 @@
#include "qemu/osdep.h" #include "qemu/osdep.h"
#include "cpu.h" #include "cpu.h"
#include "exec/helper-proto.h" #include "exec/helper-proto.h"
#include "exec/log.h"
/* SMM support */ /* SMM support */

View File

@ -28,6 +28,7 @@
#include "exec/helper-gen.h" #include "exec/helper-gen.h"
#include "trace-tcg.h" #include "trace-tcg.h"
#include "exec/log.h"
#define PREFIX_REPZ 0x01 #define PREFIX_REPZ 0x01

View File

@ -22,6 +22,7 @@
#include "qemu/host-utils.h" #include "qemu/host-utils.h"
#include "sysemu/sysemu.h" #include "sysemu/sysemu.h"
#include "exec/semihost.h" #include "exec/semihost.h"
#include "exec/log.h"
int lm32_cpu_handle_mmu_fault(CPUState *cs, vaddr address, int rw, int lm32_cpu_handle_mmu_fault(CPUState *cs, vaddr address, int rw,
int mmu_idx) int mmu_idx)

View File

@ -29,6 +29,7 @@
#include "exec/helper-gen.h" #include "exec/helper-gen.h"
#include "trace-tcg.h" #include "trace-tcg.h"
#include "exec/log.h"
#define DISAS_LM32 1 #define DISAS_LM32 1

View File

@ -29,6 +29,7 @@
#include "exec/helper-gen.h" #include "exec/helper-gen.h"
#include "trace-tcg.h" #include "trace-tcg.h"
#include "exec/log.h"
//#define DEBUG_DISPATCH 1 //#define DEBUG_DISPATCH 1

View File

@ -21,6 +21,7 @@
#include "qemu/osdep.h" #include "qemu/osdep.h"
#include "cpu.h" #include "cpu.h"
#include "qemu/host-utils.h" #include "qemu/host-utils.h"
#include "exec/log.h"
#define D(x) #define D(x)

View File

@ -28,6 +28,7 @@
#include "exec/helper-gen.h" #include "exec/helper-gen.h"
#include "trace-tcg.h" #include "trace-tcg.h"
#include "exec/log.h"
#define SIM_COMPAT 0 #define SIM_COMPAT 0

View File

@ -21,6 +21,7 @@
#include "cpu.h" #include "cpu.h"
#include "sysemu/kvm.h" #include "sysemu/kvm.h"
#include "exec/cpu_ldst.h" #include "exec/cpu_ldst.h"
#include "exec/log.h"
enum { enum {
TLBRET_XI = -6, TLBRET_XI = -6,

View File

@ -33,6 +33,7 @@
#include "exec/semihost.h" #include "exec/semihost.h"
#include "trace-tcg.h" #include "trace-tcg.h"
#include "exec/log.h"
#define MIPS_DEBUG_DISAS 0 #define MIPS_DEBUG_DISAS 0

View File

@ -31,6 +31,7 @@
#include "exec/helper-proto.h" #include "exec/helper-proto.h"
#include "exec/helper-gen.h" #include "exec/helper-gen.h"
#include "exec/log.h"
/* This is the state at translation time. */ /* This is the state at translation time. */
typedef struct DisasContext { typedef struct DisasContext {

View File

@ -32,6 +32,7 @@
#include "exec/helper-gen.h" #include "exec/helper-gen.h"
#include "trace-tcg.h" #include "trace-tcg.h"
#include "exec/log.h"
#define OPENRISC_DISAS #define OPENRISC_DISAS

View File

@ -24,6 +24,7 @@
#include "sysemu/kvm.h" #include "sysemu/kvm.h"
#include "kvm_ppc.h" #include "kvm_ppc.h"
#include "mmu-hash32.h" #include "mmu-hash32.h"
#include "exec/log.h"
//#define DEBUG_BAT //#define DEBUG_BAT

View File

@ -25,6 +25,7 @@
#include "qemu/error-report.h" #include "qemu/error-report.h"
#include "kvm_ppc.h" #include "kvm_ppc.h"
#include "mmu-hash64.h" #include "mmu-hash64.h"
#include "exec/log.h"
//#define DEBUG_SLB //#define DEBUG_SLB

View File

@ -24,6 +24,7 @@
#include "mmu-hash64.h" #include "mmu-hash64.h"
#include "mmu-hash32.h" #include "mmu-hash32.h"
#include "exec/cpu_ldst.h" #include "exec/cpu_ldst.h"
#include "exec/log.h"
//#define DEBUG_MMU //#define DEBUG_MMU
//#define DEBUG_BATS //#define DEBUG_BATS

View File

@ -29,6 +29,7 @@
#include "exec/helper-gen.h" #include "exec/helper-gen.h"
#include "trace-tcg.h" #include "trace-tcg.h"
#include "exec/log.h"
#define CPU_SINGLE_STEP 0x1 #define CPU_SINGLE_STEP 0x1

View File

@ -44,6 +44,7 @@ static TCGv_ptr cpu_env;
#include "exec/helper-gen.h" #include "exec/helper-gen.h"
#include "trace-tcg.h" #include "trace-tcg.h"
#include "exec/log.h"
/* Information that (most) every instruction needs to manipulate. */ /* Information that (most) every instruction needs to manipulate. */

View File

@ -19,6 +19,7 @@
#include "qemu/osdep.h" #include "qemu/osdep.h"
#include "cpu.h" #include "cpu.h"
#include "exec/log.h"
#if !defined(CONFIG_USER_ONLY) #if !defined(CONFIG_USER_ONLY)
#include "hw/sh4/sh_intc.h" #include "hw/sh4/sh_intc.h"

View File

@ -29,6 +29,7 @@
#include "exec/helper-gen.h" #include "exec/helper-gen.h"
#include "trace-tcg.h" #include "trace-tcg.h"
#include "exec/log.h"
typedef struct DisasContext { typedef struct DisasContext {

View File

@ -21,6 +21,7 @@
#include "cpu.h" #include "cpu.h"
#include "trace.h" #include "trace.h"
#include "sysemu/sysemu.h" #include "sysemu/sysemu.h"
#include "exec/log.h"
#define DEBUG_PCALL #define DEBUG_PCALL

View File

@ -20,6 +20,7 @@
#include "qemu/osdep.h" #include "qemu/osdep.h"
#include "cpu.h" #include "cpu.h"
#include "exec/helper-proto.h" #include "exec/helper-proto.h"
#include "exec/log.h"
#include "trace.h" #include "trace.h"
#define DEBUG_PCALL #define DEBUG_PCALL

View File

@ -29,6 +29,7 @@
#include "exec/helper-gen.h" #include "exec/helper-gen.h"
#include "trace-tcg.h" #include "trace-tcg.h"
#include "exec/log.h"
#define DEBUG_DISAS #define DEBUG_DISAS

View File

@ -21,6 +21,7 @@
#include "qemu/osdep.h" #include "qemu/osdep.h"
#include "cpu.h" #include "cpu.h"
#include "qemu/log.h" #include "qemu/log.h"
#include "exec/log.h"
#include "disas/disas.h" #include "disas/disas.h"
#include "tcg-op.h" #include "tcg-op.h"
#include "exec/cpu_ldst.h" #include "exec/cpu_ldst.h"

View File

@ -28,6 +28,7 @@
#include "exec/helper-gen.h" #include "exec/helper-gen.h"
#include "tricore-opcodes.h" #include "tricore-opcodes.h"
#include "exec/log.h"
/* /*
* TCG registers * TCG registers

View File

@ -20,6 +20,7 @@
#include "exec/helper-gen.h" #include "exec/helper-gen.h"
#include "trace-tcg.h" #include "trace-tcg.h"
#include "exec/log.h"
/* internal defines */ /* internal defines */

View File

@ -43,6 +43,7 @@
#include "exec/helper-gen.h" #include "exec/helper-gen.h"
#include "trace-tcg.h" #include "trace-tcg.h"
#include "exec/log.h"
typedef struct DisasContext { typedef struct DisasContext {

View File

@ -60,6 +60,7 @@
#endif #endif
#include "elf.h" #include "elf.h"
#include "exec/log.h"
/* Forward declarations for functions declared in tcg-target.c and used here. */ /* Forward declarations for functions declared in tcg-target.c and used here. */
static void tcg_target_init(TCGContext *s); static void tcg_target_init(TCGContext *s);

View File

@ -14,6 +14,8 @@
extern TraceEvent trace_events[]; extern TraceEvent trace_events[];
extern bool trace_events_dstate[];
extern int trace_events_enabled_count;
static inline TraceEventID trace_event_count(void) static inline TraceEventID trace_event_count(void)
@ -51,17 +53,24 @@ static inline bool trace_event_get_state_static(TraceEvent *ev)
return ev->sstate; return ev->sstate;
} }
static inline bool trace_event_get_state_dynamic_by_id(int id)
{
return unlikely(trace_events_enabled_count) && trace_events_dstate[id];
}
static inline bool trace_event_get_state_dynamic(TraceEvent *ev) static inline bool trace_event_get_state_dynamic(TraceEvent *ev)
{ {
assert(ev != NULL); int id = trace_event_get_id(ev);
return ev->dstate; return trace_event_get_state_dynamic_by_id(id);
} }
static inline void trace_event_set_state_dynamic(TraceEvent *ev, bool state) static inline void trace_event_set_state_dynamic(TraceEvent *ev, bool state)
{ {
int id = trace_event_get_id(ev);
assert(ev != NULL); assert(ev != NULL);
assert(trace_event_get_state_static(ev)); assert(trace_event_get_state_static(ev));
ev->dstate = state; trace_events_enabled_count += state - trace_events_dstate[id];
trace_events_dstate[id] = state;
} }
#endif /* TRACE__CONTROL_INTERNAL_H */ #endif /* TRACE__CONTROL_INTERNAL_H */

View File

@ -14,8 +14,14 @@
#ifdef CONFIG_TRACE_FTRACE #ifdef CONFIG_TRACE_FTRACE
#include "trace/ftrace.h" #include "trace/ftrace.h"
#endif #endif
#ifdef CONFIG_TRACE_LOG
#include "qemu/log.h"
#endif
#include "qemu/error-report.h" #include "qemu/error-report.h"
int trace_events_enabled_count;
bool trace_events_dstate[TRACE_EVENT_COUNT];
TraceEvent *trace_event_name(const char *name) TraceEvent *trace_event_name(const char *name)
{ {
assert(name != NULL); assert(name != NULL);
@ -85,7 +91,52 @@ TraceEvent *trace_event_pattern(const char *pat, TraceEvent *ev)
return NULL; return NULL;
} }
static void trace_init_events(const char *fname) void trace_list_events(void)
{
int i;
for (i = 0; i < trace_event_count(); i++) {
TraceEvent *res = trace_event_id(i);
fprintf(stderr, "%s\n", trace_event_get_name(res));
}
}
static void do_trace_enable_events(const char *line_buf)
{
const bool enable = ('-' != line_buf[0]);
const char *line_ptr = enable ? line_buf : line_buf + 1;
if (trace_event_is_pattern(line_ptr)) {
TraceEvent *ev = NULL;
while ((ev = trace_event_pattern(line_ptr, ev)) != NULL) {
if (trace_event_get_state_static(ev)) {
trace_event_set_state_dynamic(ev, enable);
}
}
} else {
TraceEvent *ev = trace_event_name(line_ptr);
if (ev == NULL) {
error_report("WARNING: trace event '%s' does not exist",
line_ptr);
} else if (!trace_event_get_state_static(ev)) {
error_report("WARNING: trace event '%s' is not traceable",
line_ptr);
} else {
trace_event_set_state_dynamic(ev, enable);
}
}
}
void trace_enable_events(const char *line_buf)
{
if (is_help_option(line_buf)) {
trace_list_events();
exit(0);
} else {
do_trace_enable_events(line_buf);
}
}
void trace_init_events(const char *fname)
{ {
Location loc; Location loc;
FILE *fp; FILE *fp;
@ -111,27 +162,7 @@ static void trace_init_events(const char *fname)
if ('#' == line_buf[0]) { /* skip commented lines */ if ('#' == line_buf[0]) { /* skip commented lines */
continue; continue;
} }
const bool enable = ('-' != line_buf[0]); trace_enable_events(line_buf);
char *line_ptr = enable ? line_buf : line_buf + 1;
if (trace_event_is_pattern(line_ptr)) {
TraceEvent *ev = NULL;
while ((ev = trace_event_pattern(line_ptr, ev)) != NULL) {
if (trace_event_get_state_static(ev)) {
trace_event_set_state_dynamic(ev, enable);
}
}
} else {
TraceEvent *ev = trace_event_name(line_ptr);
if (ev == NULL) {
error_report("WARNING: trace event '%s' does not exist",
line_ptr);
} else if (!trace_event_get_state_static(ev)) {
error_report("WARNING: trace event '%s' is not traceable",
line_ptr);
} else {
trace_event_set_state_dynamic(ev, enable);
}
}
} }
} }
if (fclose(fp) != 0) { if (fclose(fp) != 0) {
@ -142,17 +173,31 @@ static void trace_init_events(const char *fname)
loc_pop(&loc); loc_pop(&loc);
} }
bool trace_init_backends(const char *events, const char *file) void trace_init_file(const char *file)
{ {
#ifdef CONFIG_TRACE_SIMPLE #ifdef CONFIG_TRACE_SIMPLE
if (!st_init(file)) { st_set_trace_file(file);
fprintf(stderr, "failed to initialize simple tracing backend.\n"); #elif defined CONFIG_TRACE_LOG
return false; /* If both the simple and the log backends are enabled, "-trace file"
* only applies to the simple backend; use "-D" for the log backend.
*/
if (file) {
qemu_set_log_filename(file);
} }
#else #else
if (file) { if (file) {
fprintf(stderr, "error: -trace file=...: " fprintf(stderr, "error: -trace file=...: "
"option not supported by the selected tracing backends\n"); "option not supported by the selected tracing backends\n");
exit(1);
}
#endif
}
bool trace_init_backends(void)
{
#ifdef CONFIG_TRACE_SIMPLE
if (!st_init()) {
fprintf(stderr, "failed to initialize simple tracing backend.\n");
return false; return false;
} }
#endif #endif
@ -164,6 +209,5 @@ bool trace_init_backends(const char *events, const char *file)
} }
#endif #endif
trace_init_events(events);
return true; return true;
} }

View File

@ -104,7 +104,7 @@ static const char * trace_event_get_name(TraceEvent *ev);
* As a down side, you must always use an immediate #TraceEventID value. * As a down side, you must always use an immediate #TraceEventID value.
*/ */
#define trace_event_get_state(id) \ #define trace_event_get_state(id) \
((id ##_ENABLED) && trace_event_get_state_dynamic(trace_event_id(id))) ((id ##_ENABLED) && trace_event_get_state_dynamic_by_id(id))
/** /**
* trace_event_get_state_static: * trace_event_get_state_static:
@ -150,8 +150,6 @@ static void trace_event_set_state_dynamic(TraceEvent *ev, bool state);
/** /**
* trace_init_backends: * trace_init_backends:
* @events: Name of file with events to be enabled at startup; may be NULL.
* Corresponds to commandline option "-trace events=...".
* @file: Name of trace output file; may be NULL. * @file: Name of trace output file; may be NULL.
* Corresponds to commandline option "-trace file=...". * Corresponds to commandline option "-trace file=...".
* *
@ -159,7 +157,45 @@ static void trace_event_set_state_dynamic(TraceEvent *ev, bool state);
* *
* Returns: Whether the backends could be successfully initialized. * Returns: Whether the backends could be successfully initialized.
*/ */
bool trace_init_backends(const char *events, const char *file); bool trace_init_backends(void);
/**
* trace_init_events:
* @events: Name of file with events to be enabled at startup; may be NULL.
* Corresponds to commandline option "-trace events=...".
*
* Read the list of enabled tracing events.
*
* Returns: Whether the backends could be successfully initialized.
*/
void trace_init_events(const char *file);
/**
* trace_init_file:
* @file: Name of trace output file; may be NULL.
* Corresponds to commandline option "-trace file=...".
*
* Record the name of the output file for the tracing backend.
* Exits if no selected backend does not support specifying the
* output file, and a non-NULL file was passed.
*/
void trace_init_file(const char *file);
/**
* trace_list_events:
*
* List all available events.
*/
void trace_list_events(void);
/**
* trace_enable_events:
* @line_buf: A string with a glob pattern of events to be enabled or,
* if the string starts with '-', disabled.
*
* Enable or disable matching events.
*/
void trace_enable_events(const char *line_buf);
#include "trace/control-internal.h" #include "trace/control-internal.h"

View File

@ -18,7 +18,6 @@
* @id: Unique event identifier. * @id: Unique event identifier.
* @name: Event name. * @name: Event name.
* @sstate: Static tracing state. * @sstate: Static tracing state.
* @dstate: Dynamic tracing state.
* *
* Opaque generic description of a tracing event. * Opaque generic description of a tracing event.
*/ */
@ -26,7 +25,6 @@ typedef struct TraceEvent {
TraceEventID id; TraceEventID id;
const char * name; const char * name;
const bool sstate; const bool sstate;
bool dstate;
} TraceEvent; } TraceEvent;

View File

@ -322,7 +322,7 @@ void st_set_trace_file_enabled(bool enable)
* @file The trace file name or NULL for the default name-<pid> set at * @file The trace file name or NULL for the default name-<pid> set at
* config time * config time
*/ */
bool st_set_trace_file(const char *file) void st_set_trace_file(const char *file)
{ {
st_set_trace_file_enabled(false); st_set_trace_file_enabled(false);
@ -336,7 +336,6 @@ bool st_set_trace_file(const char *file)
} }
st_set_trace_file_enabled(true); st_set_trace_file_enabled(true);
return true;
} }
void st_print_trace_file_status(FILE *stream, int (*stream_printf)(FILE *stream, const char *fmt, ...)) void st_print_trace_file_status(FILE *stream, int (*stream_printf)(FILE *stream, const char *fmt, ...))
@ -374,7 +373,7 @@ static GThread *trace_thread_create(GThreadFunc fn)
return thread; return thread;
} }
bool st_init(const char *file) bool st_init(void)
{ {
GThread *thread; GThread *thread;
@ -387,6 +386,5 @@ bool st_init(const char *file)
} }
atexit(st_flush_trace_buffer); atexit(st_flush_trace_buffer);
st_set_trace_file(file);
return true; return true;
} }

View File

@ -20,8 +20,8 @@
void st_print_trace_file_status(FILE *stream, fprintf_function stream_printf); void st_print_trace_file_status(FILE *stream, fprintf_function stream_printf);
void st_set_trace_file_enabled(bool enable); void st_set_trace_file_enabled(bool enable);
bool st_set_trace_file(const char *file); void st_set_trace_file(const char *file);
bool st_init(const char *file); bool st_init(void);
void st_flush_trace_buffer(void); void st_flush_trace_buffer(void);
typedef struct { typedef struct {

View File

@ -55,6 +55,7 @@
#include "translate-all.h" #include "translate-all.h"
#include "qemu/bitmap.h" #include "qemu/bitmap.h"
#include "qemu/timer.h" #include "qemu/timer.h"
#include "exec/log.h"
//#define DEBUG_TB_INVALIDATE //#define DEBUG_TB_INVALIDATE
//#define DEBUG_FLUSH //#define DEBUG_FLUSH

View File

@ -31,3 +31,4 @@ util-obj-y += coroutine-$(CONFIG_COROUTINE_BACKEND).o
util-obj-y += buffer.o util-obj-y += buffer.o
util-obj-y += timed-average.o util-obj-y += timed-average.o
util-obj-y += base64.o util-obj-y += base64.o
util-obj-y += log.o

View File

@ -19,6 +19,7 @@
#include "qemu-common.h" #include "qemu-common.h"
#include "qemu/log.h" #include "qemu/log.h"
#include "trace/control.h"
static char *logfilename; static char *logfilename;
FILE *qemu_logfile; FILE *qemu_logfile;
@ -51,6 +52,9 @@ void qemu_log_mask(int mask, const char *fmt, ...)
void do_qemu_set_log(int log_flags, bool use_own_buffers) void do_qemu_set_log(int log_flags, bool use_own_buffers)
{ {
qemu_loglevel = log_flags; qemu_loglevel = log_flags;
#ifdef CONFIG_TRACE_LOG
qemu_loglevel |= LOG_TRACE;
#endif
if (qemu_loglevel && !qemu_logfile) { if (qemu_loglevel && !qemu_logfile) {
if (logfilename) { if (logfilename) {
qemu_logfile = fopen(logfilename, log_append ? "a" : "w"); qemu_logfile = fopen(logfilename, log_append ? "a" : "w");
@ -151,6 +155,11 @@ int qemu_str_to_log_mask(const char *str)
for (item = qemu_log_items; item->mask != 0; item++) { for (item = qemu_log_items; item->mask != 0; item++) {
mask |= item->mask; mask |= item->mask;
} }
#ifdef CONFIG_TRACE_LOG
} else if (strncmp(p, "trace:", 6) == 0 && p + 6 != p1) {
trace_enable_events(p + 6);
mask |= LOG_TRACE;
#endif
} else { } else {
for (item = qemu_log_items; item->mask != 0; item++) { for (item = qemu_log_items; item->mask != 0; item++) {
if (cmp1(p, p1 - p, item->name)) { if (cmp1(p, p1 - p, item->name)) {
@ -158,9 +167,9 @@ int qemu_str_to_log_mask(const char *str)
} }
} }
return 0; return 0;
}
found: found:
mask |= item->mask; mask |= item->mask;
}
if (*p1 != ',') { if (*p1 != ',') {
break; break;
} }
@ -174,6 +183,10 @@ void qemu_print_log_usage(FILE *f)
const QEMULogItem *item; const QEMULogItem *item;
fprintf(f, "Log items (comma separated):\n"); fprintf(f, "Log items (comma separated):\n");
for (item = qemu_log_items; item->mask != 0; item++) { for (item = qemu_log_items; item->mask != 0; item++) {
fprintf(f, "%-10s %s\n", item->name, item->help); fprintf(f, "%-15s %s\n", item->name, item->help);
} }
#ifdef CONFIG_TRACE_LOG
fprintf(f, "trace:PATTERN enable trace events\n");
fprintf(f, "\nUse \"-d trace:help\" to get a list of trace events.\n\n");
#endif
} }

36
vl.c
View File

@ -270,9 +270,13 @@ static QemuOptsList qemu_sandbox_opts = {
static QemuOptsList qemu_trace_opts = { static QemuOptsList qemu_trace_opts = {
.name = "trace", .name = "trace",
.implied_opt_name = "trace", .implied_opt_name = "enable",
.head = QTAILQ_HEAD_INITIALIZER(qemu_trace_opts.head), .head = QTAILQ_HEAD_INITIALIZER(qemu_trace_opts.head),
.desc = { .desc = {
{
.name = "enable",
.type = QEMU_OPT_STRING,
},
{ {
.name = "events", .name = "events",
.type = QEMU_OPT_STRING, .type = QEMU_OPT_STRING,
@ -2988,8 +2992,7 @@ int main(int argc, char **argv, char **envp)
bool userconfig = true; bool userconfig = true;
const char *log_mask = NULL; const char *log_mask = NULL;
const char *log_file = NULL; const char *log_file = NULL;
const char *trace_events = NULL; char *trace_file = NULL;
const char *trace_file = NULL;
ram_addr_t maxram_size; ram_addr_t maxram_size;
uint64_t ram_slots = 0; uint64_t ram_slots = 0;
FILE *vmstate_dump_file = NULL; FILE *vmstate_dump_file = NULL;
@ -3901,12 +3904,19 @@ int main(int argc, char **argv, char **envp)
case QEMU_OPTION_trace: case QEMU_OPTION_trace:
{ {
opts = qemu_opts_parse_noisily(qemu_find_opts("trace"), opts = qemu_opts_parse_noisily(qemu_find_opts("trace"),
optarg, false); optarg, true);
if (!opts) { if (!opts) {
exit(1); exit(1);
} }
trace_events = qemu_opt_get(opts, "events"); if (qemu_opt_get(opts, "enable")) {
trace_file = qemu_opt_get(opts, "file"); trace_enable_events(qemu_opt_get(opts, "enable"));
}
trace_init_events(qemu_opt_get(opts, "events"));
if (trace_file) {
g_free(trace_file);
}
trace_file = g_strdup(qemu_opt_get(opts, "file"));
qemu_opts_del(opts);
break; break;
} }
case QEMU_OPTION_readconfig: case QEMU_OPTION_readconfig:
@ -4089,6 +4099,8 @@ int main(int argc, char **argv, char **envp)
exit(0); exit(0);
} }
trace_init_file(trace_file);
/* Open the logfile at this point and set the log mask if necessary. /* Open the logfile at this point and set the log mask if necessary.
*/ */
if (log_file) { if (log_file) {
@ -4103,13 +4115,13 @@ int main(int argc, char **argv, char **envp)
exit(1); exit(1);
} }
qemu_set_log(mask); qemu_set_log(mask);
} else {
qemu_set_log(0);
} }
if (!is_daemonized()) { if (!trace_init_backends()) {
if (!trace_init_backends(trace_events, trace_file)) {
exit(1); exit(1);
} }
}
/* If no data_dir is specified then try to find it relative to the /* If no data_dir is specified then try to find it relative to the
executable path. */ executable path. */
@ -4652,12 +4664,6 @@ int main(int argc, char **argv, char **envp)
os_setup_post(); os_setup_post();
if (is_daemonized()) {
if (!trace_init_backends(trace_events, trace_file)) {
exit(1);
}
}
main_loop(); main_loop();
replay_disable_events(); replay_disable_events();