trace: avoid conditional code compilation during option parsing
A default implementation for backend-specific routines is provided in "trace/default.c", which backends can override by setting "trace_default=no" in "configure". Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
This commit is contained in:
parent
edb47ec498
commit
e4858974ec
|
@ -379,6 +379,8 @@ ifneq ($(TRACE_BACKEND),dtrace)
|
||||||
trace-obj-y = trace.o
|
trace-obj-y = trace.o
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
trace-nested-$(CONFIG_TRACE_DEFAULT) += default.o
|
||||||
|
|
||||||
trace-nested-$(CONFIG_TRACE_SIMPLE) += simple.o
|
trace-nested-$(CONFIG_TRACE_SIMPLE) += simple.o
|
||||||
trace-obj-$(CONFIG_TRACE_SIMPLE) += qemu-timer-common.o
|
trace-obj-$(CONFIG_TRACE_SIMPLE) += qemu-timer-common.o
|
||||||
|
|
||||||
|
|
|
@ -3064,12 +3064,15 @@ bsd)
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
# use default implementation for tracing backend-specific routines
|
||||||
|
trace_default=yes
|
||||||
echo "TRACE_BACKEND=$trace_backend" >> $config_host_mak
|
echo "TRACE_BACKEND=$trace_backend" >> $config_host_mak
|
||||||
if test "$trace_backend" = "nop"; then
|
if test "$trace_backend" = "nop"; then
|
||||||
echo "CONFIG_TRACE_NOP=y" >> $config_host_mak
|
echo "CONFIG_TRACE_NOP=y" >> $config_host_mak
|
||||||
fi
|
fi
|
||||||
if test "$trace_backend" = "simple"; then
|
if test "$trace_backend" = "simple"; then
|
||||||
echo "CONFIG_TRACE_SIMPLE=y" >> $config_host_mak
|
echo "CONFIG_TRACE_SIMPLE=y" >> $config_host_mak
|
||||||
|
trace_default=no
|
||||||
# Set the appropriate trace file.
|
# Set the appropriate trace file.
|
||||||
trace_file="\"$trace_file-\" FMT_pid"
|
trace_file="\"$trace_file-\" FMT_pid"
|
||||||
fi
|
fi
|
||||||
|
@ -3086,6 +3089,9 @@ if test "$trace_backend" = "dtrace"; then
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
echo "CONFIG_TRACE_FILE=$trace_file" >> $config_host_mak
|
echo "CONFIG_TRACE_FILE=$trace_file" >> $config_host_mak
|
||||||
|
if test "$trace_default" = "yes"; then
|
||||||
|
echo "CONFIG_TRACE_DEFAULT=y" >> $config_host_mak
|
||||||
|
fi
|
||||||
|
|
||||||
echo "TOOLS=$tools" >> $config_host_mak
|
echo "TOOLS=$tools" >> $config_host_mak
|
||||||
echo "ROMS=$roms" >> $config_host_mak
|
echo "ROMS=$roms" >> $config_host_mak
|
||||||
|
|
|
@ -303,7 +303,6 @@ static QemuOptsList qemu_mon_opts = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef CONFIG_TRACE_SIMPLE
|
|
||||||
static QemuOptsList qemu_trace_opts = {
|
static QemuOptsList qemu_trace_opts = {
|
||||||
.name = "trace",
|
.name = "trace",
|
||||||
.implied_opt_name = "trace",
|
.implied_opt_name = "trace",
|
||||||
|
@ -316,7 +315,6 @@ static QemuOptsList qemu_trace_opts = {
|
||||||
{ /* end of list */ }
|
{ /* end of list */ }
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
#endif
|
|
||||||
|
|
||||||
static QemuOptsList qemu_cpudef_opts = {
|
static QemuOptsList qemu_cpudef_opts = {
|
||||||
.name = "cpudef",
|
.name = "cpudef",
|
||||||
|
@ -517,9 +515,7 @@ static QemuOptsList *vm_config_groups[32] = {
|
||||||
&qemu_global_opts,
|
&qemu_global_opts,
|
||||||
&qemu_mon_opts,
|
&qemu_mon_opts,
|
||||||
&qemu_cpudef_opts,
|
&qemu_cpudef_opts,
|
||||||
#ifdef CONFIG_TRACE_SIMPLE
|
|
||||||
&qemu_trace_opts,
|
&qemu_trace_opts,
|
||||||
#endif
|
|
||||||
&qemu_option_rom_opts,
|
&qemu_option_rom_opts,
|
||||||
&qemu_machine_opts,
|
&qemu_machine_opts,
|
||||||
&qemu_boot_opts,
|
&qemu_boot_opts,
|
||||||
|
|
|
@ -2436,17 +2436,19 @@ Normally QEMU loads a configuration file from @var{sysconfdir}/qemu.conf and
|
||||||
@var{sysconfdir}/target-@var{ARCH}.conf on startup. The @code{-nodefconfig}
|
@var{sysconfdir}/target-@var{ARCH}.conf on startup. The @code{-nodefconfig}
|
||||||
option will prevent QEMU from loading these configuration files at startup.
|
option will prevent QEMU from loading these configuration files at startup.
|
||||||
ETEXI
|
ETEXI
|
||||||
#ifdef CONFIG_TRACE_SIMPLE
|
|
||||||
DEF("trace", HAS_ARG, QEMU_OPTION_trace,
|
DEF("trace", HAS_ARG, QEMU_OPTION_trace,
|
||||||
"-trace\n"
|
"-trace\n"
|
||||||
" Specify a trace file to log traces to\n",
|
" Specify a trace file to log traces to\n",
|
||||||
QEMU_ARCH_ALL)
|
QEMU_ARCH_ALL)
|
||||||
STEXI
|
STEXI
|
||||||
|
HXCOMM This line is not accurate, as the option is backend-specific but HX does
|
||||||
|
HXCOMM not support conditional compilation of text.
|
||||||
@item -trace
|
@item -trace
|
||||||
@findex -trace
|
@findex -trace
|
||||||
Specify a trace file to log output traces to.
|
Specify a trace file to log output traces to.
|
||||||
|
|
||||||
|
This option is available only when using the @var{simple} tracing backend.
|
||||||
ETEXI
|
ETEXI
|
||||||
#endif
|
|
||||||
|
|
||||||
HXCOMM This is the last statement. Insert new options before this line!
|
HXCOMM This is the last statement. Insert new options before this line!
|
||||||
STEXI
|
STEXI
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
/*
|
||||||
|
* Interface for configuring and controlling the state of tracing events.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2011 Lluís Vilanova <vilanova@ac.upc.edu>
|
||||||
|
*
|
||||||
|
* This work is licensed under the terms of the GNU GPL, version 2. See
|
||||||
|
* the COPYING file in the top-level directory.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TRACE_CONTROL_H
|
||||||
|
#define TRACE_CONTROL_H
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
|
||||||
|
/** Initialize the tracing backend.
|
||||||
|
*
|
||||||
|
* @file Name of trace output file; may be NULL.
|
||||||
|
* Corresponds to commandline option "-trace file=...".
|
||||||
|
* @return Whether the backend could be successfully initialized.
|
||||||
|
*/
|
||||||
|
bool trace_backend_init(const char *file);
|
||||||
|
|
||||||
|
#endif /* TRACE_CONTROL_H */
|
|
@ -0,0 +1,21 @@
|
||||||
|
/*
|
||||||
|
* Default implementation for backend initialization from commandline.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2011 Lluís Vilanova <vilanova@ac.upc.edu>
|
||||||
|
*
|
||||||
|
* This work is licensed under the terms of the GNU GPL, version 2. See
|
||||||
|
* the COPYING file in the top-level directory.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "trace/control.h"
|
||||||
|
|
||||||
|
|
||||||
|
bool trace_backend_init(const char *file)
|
||||||
|
{
|
||||||
|
if (file) {
|
||||||
|
fprintf(stderr, "error: -trace file=...: "
|
||||||
|
"option not supported by the selected tracing backend\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
|
@ -16,6 +16,7 @@
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include "qemu-timer.h"
|
#include "qemu-timer.h"
|
||||||
#include "trace.h"
|
#include "trace.h"
|
||||||
|
#include "trace/control.h"
|
||||||
|
|
||||||
/** Trace file header event ID */
|
/** Trace file header event ID */
|
||||||
#define HEADER_EVENT_ID (~(uint64_t)0) /* avoids conflicting with TraceEventIDs */
|
#define HEADER_EVENT_ID (~(uint64_t)0) /* avoids conflicting with TraceEventIDs */
|
||||||
|
@ -330,7 +331,7 @@ void st_flush_trace_buffer(void)
|
||||||
flush_trace_file(true);
|
flush_trace_file(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool st_init(const char *file)
|
bool trace_backend_init(const char *file)
|
||||||
{
|
{
|
||||||
pthread_t thread;
|
pthread_t thread;
|
||||||
pthread_attr_t attr;
|
pthread_attr_t attr;
|
||||||
|
@ -346,10 +347,11 @@ bool st_init(const char *file)
|
||||||
pthread_sigmask(SIG_SETMASK, &oldset, NULL);
|
pthread_sigmask(SIG_SETMASK, &oldset, NULL);
|
||||||
|
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
return false;
|
fprintf(stderr, "warning: unable to initialize simple trace backend\n");
|
||||||
|
} else {
|
||||||
|
atexit(st_flush_trace_buffer);
|
||||||
|
st_set_trace_file(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
atexit(st_flush_trace_buffer);
|
|
||||||
st_set_trace_file(file);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#ifdef CONFIG_TRACE_SIMPLE
|
|
||||||
typedef uint64_t TraceEventID;
|
typedef uint64_t TraceEventID;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -37,12 +36,5 @@ 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);
|
bool st_set_trace_file(const char *file);
|
||||||
void st_flush_trace_buffer(void);
|
void st_flush_trace_buffer(void);
|
||||||
bool st_init(const char *file);
|
|
||||||
#else
|
|
||||||
static inline bool st_init(const char *file)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
#endif /* !CONFIG_TRACE_SIMPLE */
|
|
||||||
|
|
||||||
#endif /* TRACE_SIMPLE_H */
|
#endif /* TRACE_SIMPLE_H */
|
||||||
|
|
17
vl.c
17
vl.c
|
@ -156,7 +156,7 @@ int main(int argc, char **argv)
|
||||||
#include "slirp/libslirp.h"
|
#include "slirp/libslirp.h"
|
||||||
|
|
||||||
#include "trace.h"
|
#include "trace.h"
|
||||||
#include "trace/simple.h"
|
#include "trace/control.h"
|
||||||
#include "qemu-queue.h"
|
#include "qemu-queue.h"
|
||||||
#include "cpus.h"
|
#include "cpus.h"
|
||||||
#include "arch_init.h"
|
#include "arch_init.h"
|
||||||
|
@ -2130,7 +2130,6 @@ int main(int argc, char **argv, char **envp)
|
||||||
int show_vnc_port = 0;
|
int show_vnc_port = 0;
|
||||||
#endif
|
#endif
|
||||||
int defconfig = 1;
|
int defconfig = 1;
|
||||||
const char *trace_file = NULL;
|
|
||||||
const char *log_mask = NULL;
|
const char *log_mask = NULL;
|
||||||
const char *log_file = NULL;
|
const char *log_file = NULL;
|
||||||
GMemVTable mem_trace = {
|
GMemVTable mem_trace = {
|
||||||
|
@ -2138,6 +2137,7 @@ int main(int argc, char **argv, char **envp)
|
||||||
.realloc = realloc_and_trace,
|
.realloc = realloc_and_trace,
|
||||||
.free = free_and_trace,
|
.free = free_and_trace,
|
||||||
};
|
};
|
||||||
|
const char *trace_file = NULL;
|
||||||
|
|
||||||
atexit(qemu_run_exit_notifiers);
|
atexit(qemu_run_exit_notifiers);
|
||||||
error_set_progname(argv[0]);
|
error_set_progname(argv[0]);
|
||||||
|
@ -2928,14 +2928,15 @@ int main(int argc, char **argv, char **envp)
|
||||||
}
|
}
|
||||||
xen_mode = XEN_ATTACH;
|
xen_mode = XEN_ATTACH;
|
||||||
break;
|
break;
|
||||||
#ifdef CONFIG_TRACE_SIMPLE
|
|
||||||
case QEMU_OPTION_trace:
|
case QEMU_OPTION_trace:
|
||||||
|
{
|
||||||
opts = qemu_opts_parse(qemu_find_opts("trace"), optarg, 0);
|
opts = qemu_opts_parse(qemu_find_opts("trace"), optarg, 0);
|
||||||
if (opts) {
|
if (!opts) {
|
||||||
trace_file = qemu_opt_get(opts, "file");
|
exit(1);
|
||||||
}
|
}
|
||||||
|
trace_file = qemu_opt_get(opts, "file");
|
||||||
break;
|
break;
|
||||||
#endif
|
}
|
||||||
case QEMU_OPTION_readconfig:
|
case QEMU_OPTION_readconfig:
|
||||||
{
|
{
|
||||||
int ret = qemu_read_config_file(optarg);
|
int ret = qemu_read_config_file(optarg);
|
||||||
|
@ -2993,8 +2994,8 @@ int main(int argc, char **argv, char **envp)
|
||||||
set_cpu_log(log_mask);
|
set_cpu_log(log_mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!st_init(trace_file)) {
|
if (!trace_backend_init(trace_file)) {
|
||||||
fprintf(stderr, "warning: unable to initialize simple trace backend\n");
|
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
|
||||||
|
|
Loading…
Reference in New Issue