aboutsummaryrefslogtreecommitdiff
path: root/qemu-malloc.c
diff options
context:
space:
mode:
authorStefan Hajnoczi <stefanha@linux.vnet.ibm.com>2010-05-22 18:09:25 +0100
committerAnthony Liguori <aliguori@us.ibm.com>2010-09-09 16:22:45 -0500
commitcd245a19329edfcd968b00d05ad92de7a0e2daa1 (patch)
treea06ff5d63af8ce74d30d58083442b977165b1c71 /qemu-malloc.c
parent81a97d9d9786f54c613efaee9950f037a9229f1f (diff)
downloadqemu-cd245a19329edfcd968b00d05ad92de7a0e2daa1.zip
qemu-cd245a19329edfcd968b00d05ad92de7a0e2daa1.tar.gz
qemu-cd245a19329edfcd968b00d05ad92de7a0e2daa1.tar.bz2
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 'qemu-malloc.c')
-rw-r--r--qemu-malloc.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/qemu-malloc.c b/qemu-malloc.c
index 36b0b36..ecffb67 100644
--- a/qemu-malloc.c
+++ b/qemu-malloc.c
@@ -22,6 +22,7 @@
* THE SOFTWARE.
*/
#include "qemu-common.h"
+#include "trace.h"
#include <stdlib.h>
static void *oom_check(void *ptr)
@@ -34,6 +35,7 @@ static void *oom_check(void *ptr)
void qemu_free(void *ptr)
{
+ trace_qemu_free(ptr);
free(ptr);
}
@@ -48,18 +50,24 @@ static int allow_zero_malloc(void)
void *qemu_malloc(size_t size)
{
+ void *ptr;
if (!size && !allow_zero_malloc()) {
abort();
}
- return oom_check(malloc(size ? size : 1));
+ ptr = oom_check(malloc(size ? size : 1));
+ trace_qemu_malloc(size, ptr);
+ return ptr;
}
void *qemu_realloc(void *ptr, size_t size)
{
+ void *newptr;
if (!size && !allow_zero_malloc()) {
abort();
}
- return oom_check(realloc(ptr, size ? size : 1));
+ newptr = oom_check(realloc(ptr, size ? size : 1));
+ trace_qemu_realloc(ptr, size, newptr);
+ return newptr;
}
void *qemu_mallocz(size_t size)