mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-07 17:53:56 -06:00
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
9 changed files with 72 additions and 26 deletions
24
trace/control.h
Normal file
24
trace/control.h
Normal file
|
@ -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 */
|
21
trace/default.c
Normal file
21
trace/default.c
Normal file
|
@ -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 "qemu-timer.h"
|
||||
#include "trace.h"
|
||||
#include "trace/control.h"
|
||||
|
||||
/** Trace file header event ID */
|
||||
#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);
|
||||
}
|
||||
|
||||
bool st_init(const char *file)
|
||||
bool trace_backend_init(const char *file)
|
||||
{
|
||||
pthread_t thread;
|
||||
pthread_attr_t attr;
|
||||
|
@ -346,10 +347,11 @@ bool st_init(const char *file)
|
|||
pthread_sigmask(SIG_SETMASK, &oldset, NULL);
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef CONFIG_TRACE_SIMPLE
|
||||
typedef uint64_t TraceEventID;
|
||||
|
||||
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);
|
||||
bool st_set_trace_file(const char *file);
|
||||
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 */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue