aboutsummaryrefslogtreecommitdiff
path: root/chattymalloc.c
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fl.fischer@fau.de>2018-08-24 22:00:03 +0200
committerFlorian Fischer <florian.fl.fischer@fau.de>2018-08-24 22:03:29 +0200
commitcb79bac50ca1da1f0f02455bd0e564578ab9ef05 (patch)
treea2212ea2c2fb910e45fcedd90d0ee91ef123d383 /chattymalloc.c
parent51ba31ed4a2548fb12d9e1e2f2115213a0aaa1f4 (diff)
downloadallocbench-cb79bac50ca1da1f0f02455bd0e564578ab9ef05.tar.gz
allocbench-cb79bac50ca1da1f0f02455bd0e564578ab9ef05.zip
intruduce new way of handling analyse and cleanup mysql
chattymalloc writes now to chattymalloc.data
Diffstat (limited to 'chattymalloc.c')
-rw-r--r--chattymalloc.c72
1 files changed, 21 insertions, 51 deletions
diff --git a/chattymalloc.c b/chattymalloc.c
index f94afde..f3db0d2 100644
--- a/chattymalloc.c
+++ b/chattymalloc.c
@@ -3,33 +3,34 @@
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
char tmpbuff[1024];
unsigned long tmppos = 0;
unsigned long tmpallocs = 0;
-void *memset(void*,int,size_t);
-void *memmove(void *to, const void *from, size_t size);
+FILE* out = NULL;
/*=========================================================
* * interception points
* */
-static void * (*myfn_calloc)(size_t nmemb, size_t size);
static void * (*myfn_malloc)(size_t size);
-static void (*myfn_free)(void *ptr);
-static void * (*myfn_realloc)(void *ptr, size_t size);
-static void * (*myfn_memalign)(size_t blocksize, size_t bytes);
+static void * (*myfn_free)(void* ptr);
static void init()
{
+ out = fopen("chattymalloc.data", "w");
+ if (out == NULL)
+ {
+ fprintf(stderr, "failed to open output file\n");
+ exit(1);
+ }
+
myfn_malloc = dlsym(RTLD_NEXT, "malloc");
myfn_free = dlsym(RTLD_NEXT, "free");
- myfn_calloc = dlsym(RTLD_NEXT, "calloc");
- myfn_realloc = dlsym(RTLD_NEXT, "realloc");
- myfn_memalign = dlsym(RTLD_NEXT, "memalign");
- if (!myfn_malloc || !myfn_free || !myfn_calloc || !myfn_realloc || !myfn_memalign)
+ if (!myfn_malloc || !myfn_free)
{
fprintf(stderr, "Error in `dlsym`: %s\n", dlerror());
exit(1);
@@ -39,6 +40,8 @@ static void init()
void *malloc(size_t size)
{
static int initializing = 0;
+ static int in_fprintf = 0;
+
if (myfn_malloc == NULL)
{
if (!initializing)
@@ -47,7 +50,6 @@ void *malloc(size_t size)
init();
initializing = 0;
- fprintf(stdout, "jcheck: allocated %lu bytes of temp memory in %lu chunks during initialization\n", tmppos, tmpallocs);
}
else
{
@@ -60,13 +62,18 @@ void *malloc(size_t size)
}
else
{
- fprintf(stdout, "jcheck: too much memory requested during initialisation - increase tmpbuff size\n");
+ fprintf(stderr, "jcheck: too much memory requested during initialisation - increase tmpbuff size\n");
exit(1);
}
}
}
- fprintf(stderr, "chattymalloc: %d\n", size);
+ if (!in_fprintf)
+ {
+ in_fprintf = 1;
+ fprintf(out, "%d\n", size);
+ in_fprintf = 0;
+ }
void *ptr = myfn_malloc(size);
return ptr;
}
@@ -76,43 +83,6 @@ void free(void *ptr)
// something wrong if we call free before one of the allocators!
if (myfn_malloc == NULL)
init();
- if (ptr >= (void*) tmpbuff && ptr <= (void*)(tmpbuff + tmppos))
- fprintf(stdout, "freeing temp memory\n");
- else
+ if (!(ptr >= (void*) tmpbuff && ptr <= (void*)(tmpbuff + tmppos)))
myfn_free(ptr);
}
-
-void *realloc(void *ptr, size_t size)
-{
- if (myfn_malloc == NULL)
- {
- void *nptr = malloc(size);
- if (nptr && ptr)
- {
- memmove(nptr, ptr, size);
- free(ptr);
- }
- return nptr;
- }
- void *nptr = myfn_realloc(ptr, size);
- return nptr;
-}
-
-void *calloc(size_t nmemb, size_t size)
-{
- if (myfn_malloc == NULL)
- {
- void *ptr = malloc(nmemb*size);
- if (ptr)
- memset(ptr, 0, nmemb*size);
- return ptr;
- }
- void *ptr = myfn_calloc(nmemb, size);
- return ptr;
-}
-
-void *memalign(size_t blocksize, size_t bytes)
-{
- void *ptr = myfn_memalign(blocksize, bytes);
- return ptr;
-}