diff options
author | Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> | 2010-05-22 18:09:25 +0100 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2010-09-09 16:22:45 -0500 |
commit | cd245a19329edfcd968b00d05ad92de7a0e2daa1 (patch) | |
tree | a06ff5d63af8ce74d30d58083442b977165b1c71 /osdep.c | |
parent | 81a97d9d9786f54c613efaee9950f037a9229f1f (diff) | |
download | qemu-cd245a19329edfcd968b00d05ad92de7a0e2daa1.tar.gz qemu-cd245a19329edfcd968b00d05ad92de7a0e2daa1.tar.bz2 qemu-cd245a19329edfcd968b00d05ad92de7a0e2daa1.zip |
trace: Trace qemu_malloc() and qemu_vmalloc()
It is often useful to instrument memory management functions in order to
find leaks or performance problems. This patch adds trace events for
the memory allocation primitives.
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Diffstat (limited to 'osdep.c')
-rw-r--r-- | osdep.c | 24 |
1 files changed, 18 insertions, 6 deletions
@@ -50,6 +50,7 @@ #endif #include "qemu-common.h" +#include "trace.h" #include "sysemu.h" #include "qemu_socket.h" @@ -71,25 +72,34 @@ static void *oom_check(void *ptr) #if defined(_WIN32) void *qemu_memalign(size_t alignment, size_t size) { + void *ptr; + if (!size) { abort(); } - return oom_check(VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE)); + ptr = oom_check(VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE)); + trace_qemu_memalign(alignment, size, ptr); + return ptr; } void *qemu_vmalloc(size_t size) { + void *ptr; + /* FIXME: this is not exactly optimal solution since VirtualAlloc has 64Kb granularity, but at least it guarantees us that the memory is page aligned. */ if (!size) { abort(); } - return oom_check(VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE)); + ptr = oom_check(VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE)); + trace_qemu_vmalloc(size, ptr); + return ptr; } void qemu_vfree(void *ptr) { + trace_qemu_vfree(ptr); VirtualFree(ptr, 0, MEM_RELEASE); } @@ -97,21 +107,22 @@ void qemu_vfree(void *ptr) void *qemu_memalign(size_t alignment, size_t size) { + void *ptr; #if defined(_POSIX_C_SOURCE) && !defined(__sun__) int ret; - void *ptr; ret = posix_memalign(&ptr, alignment, size); if (ret != 0) { fprintf(stderr, "Failed to allocate %zu B: %s\n", size, strerror(ret)); abort(); } - return ptr; #elif defined(CONFIG_BSD) - return oom_check(valloc(size)); + ptr = oom_check(valloc(size)); #else - return oom_check(memalign(alignment, size)); + ptr = oom_check(memalign(alignment, size)); #endif + trace_qemu_memalign(alignment, size, ptr); + return ptr; } /* alloc shared memory pages */ @@ -122,6 +133,7 @@ void *qemu_vmalloc(size_t size) void qemu_vfree(void *ptr) { + trace_qemu_vfree(ptr); free(ptr); } |