aboutsummaryrefslogtreecommitdiff
path: root/vl.c
diff options
context:
space:
mode:
authorAnthony Liguori <aliguori@us.ibm.com>2011-08-20 22:38:31 -0500
committerAnthony Liguori <aliguori@us.ibm.com>2011-08-20 23:01:09 -0500
commit0750112af49b6f1a91a26d76e99badbca1e27b41 (patch)
treedf64869e0ea4ad1cca93fcbbf0a911307a99ab00 /vl.c
parent41a748265f4879b52b0e87ff9c93bed975163886 (diff)
Add trace points for g_malloc/g_free functions
Derived from a patch submitted by Avi Kivity. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'vl.c')
-rw-r--r--vl.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/vl.c b/vl.c
index 84054295fb..06a6f807a4 100644
--- a/vl.c
+++ b/vl.c
@@ -2075,6 +2075,26 @@ static const QEMUOption *lookup_opt(int argc, char **argv,
return popt;
}
+static gpointer malloc_and_trace(gsize n_bytes)
+{
+ void *ptr = malloc(n_bytes);
+ trace_qemu_malloc(n_bytes, ptr);
+ return ptr;
+}
+
+static gpointer realloc_and_trace(gpointer mem, gsize n_bytes)
+{
+ void *ptr = realloc(mem, n_bytes);
+ trace_qemu_realloc(mem, n_bytes, ptr);
+ return ptr;
+}
+
+static void free_and_trace(gpointer mem)
+{
+ trace_qemu_free(mem);
+ free(mem);
+}
+
int main(int argc, char **argv, char **envp)
{
const char *gdbstub_dev = NULL;
@@ -2103,10 +2123,17 @@ int main(int argc, char **argv, char **envp)
const char *trace_file = NULL;
const char *log_mask = NULL;
const char *log_file = NULL;
+ GMemVTable mem_trace = {
+ .malloc = malloc_and_trace,
+ .realloc = realloc_and_trace,
+ .free = free_and_trace,
+ };
atexit(qemu_run_exit_notifiers);
error_set_progname(argv[0]);
+ g_mem_set_vtable(&mem_trace);
+
init_clocks();
qemu_cache_utils_init(envp);