commit c3b972ee0b73d99cf0fd411268ec1d6a19d33d00
parent 306e4a301a59328975d8d4229b324c2d90128566
Author: sin <sin@2f30.org>
Date: Sun, 4 Aug 2013 17:09:41 +0100
Move debug routines to the end of the file
Diffstat:
M | lemoncake.c | | | 94 | ++++++++++++++++++++++++++++++++++++++++--------------------------------------- |
1 file changed, 48 insertions(+), 46 deletions(-)
diff --git a/lemoncake.c b/lemoncake.c
@@ -15,6 +15,8 @@
enum { ALIGN = 4 * sizeof(size_t) };
+static void dumpstats(void);
+
struct lemon_stats {
/* # of mmap calls */
unsigned long nr_mmap;
@@ -81,52 +83,6 @@ at_cmp(struct node *a, struct node *b)
return 0;
}
-static void
-writelog(int fd, const char *fmt, ...)
-{
- va_list ap;
- char buf[BUFSIZ];
-
- va_start(ap, fmt);
- vsnprintf(buf, sizeof(buf), fmt, ap);
- va_end(ap);
- write(fd, buf, strlen(buf));
-}
-
-static void
-dumpstats(void)
-{
- int fd;
- struct node *n;
- char *p;
-
- fd = open("lemoncake.out", O_WRONLY | O_CREAT | O_APPEND, 0644);
- if (fd != -1) {
- p = getenv("_");
- if (p)
- writelog(fd, "*** Lemoncake stats for process: %s ***\n", p);
- writelog(fd, "Number of mmap calls: %lu\n", st.nr_mmap);
- writelog(fd, "Number of malloc calls: %lu\n", st.nr_malloc);
- writelog(fd, "Number of realloc calls: %lu\n", st.nr_realloc);
- writelog(fd, "Number of shrinked realloc calls (no memcpy() required): %lu\n",
- st.nr_shrink_realloc);
- writelog(fd, "Number of free calls: %lu\n", st.nr_free);
- writelog(fd, "Number of new allocations: %lu\n", st.nr_alloc_new);
- writelog(fd, "Number of allocations from the free tree: %lu\n",
- st.nr_alloc_free);
- writelog(fd, "Number of invalid free calls: %lu\n", st.nr_invalid_free);
- RB_FOREACH(n, alloc_tree, &at)
- st.nr_at_nodes++;
- RB_FOREACH(n, free_tree, &ft)
- st.nr_ft_nodes++;
- writelog(fd, "Number of nodes in the allocation tree: %lu\n",
- st.nr_at_nodes);
- writelog(fd, "Number of nodes in the free tree: %lu\n",
- st.nr_ft_nodes);
- close(fd);
- }
-}
-
static inline void *
alloc_object(size_t siz)
{
@@ -429,3 +385,49 @@ malloc_size(void *p)
{
return malloc_usable_size(p);
}
+
+static void
+writelog(int fd, const char *fmt, ...)
+{
+ va_list ap;
+ char buf[BUFSIZ];
+
+ va_start(ap, fmt);
+ vsnprintf(buf, sizeof(buf), fmt, ap);
+ va_end(ap);
+ write(fd, buf, strlen(buf));
+}
+
+static void
+dumpstats(void)
+{
+ int fd;
+ struct node *n;
+ char *p;
+
+ fd = open("lemoncake.out", O_WRONLY | O_CREAT | O_APPEND, 0644);
+ if (fd != -1) {
+ p = getenv("_");
+ if (p)
+ writelog(fd, "*** Lemoncake stats for process: %s ***\n", p);
+ writelog(fd, "Number of mmap calls: %lu\n", st.nr_mmap);
+ writelog(fd, "Number of malloc calls: %lu\n", st.nr_malloc);
+ writelog(fd, "Number of realloc calls: %lu\n", st.nr_realloc);
+ writelog(fd, "Number of shrinked realloc calls (no memcpy() required): %lu\n",
+ st.nr_shrink_realloc);
+ writelog(fd, "Number of free calls: %lu\n", st.nr_free);
+ writelog(fd, "Number of new allocations: %lu\n", st.nr_alloc_new);
+ writelog(fd, "Number of allocations from the free tree: %lu\n",
+ st.nr_alloc_free);
+ writelog(fd, "Number of invalid free calls: %lu\n", st.nr_invalid_free);
+ RB_FOREACH(n, alloc_tree, &at)
+ st.nr_at_nodes++;
+ RB_FOREACH(n, free_tree, &ft)
+ st.nr_ft_nodes++;
+ writelog(fd, "Number of nodes in the allocation tree: %lu\n",
+ st.nr_at_nodes);
+ writelog(fd, "Number of nodes in the free tree: %lu\n",
+ st.nr_ft_nodes);
+ close(fd);
+ }
+}