aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Oliveira Carvalho <felipekde@gmail.com>2014-03-26 16:22:31 -0300
committerThiago de Arruda <tpadilha84@gmail.com>2014-03-26 18:29:17 -0300
commit83161200c473293b2d8d69e3ee1899c6a7199e38 (patch)
tree8223ec9275425e55acfb3cf0ce61948c59b090f6
parentbd78282940b246bad34c629fa81150d4073cc330 (diff)
downloadrneovim-83161200c473293b2d8d69e3ee1899c6a7199e38.tar.gz
rneovim-83161200c473293b2d8d69e3ee1899c6a7199e38.tar.bz2
rneovim-83161200c473293b2d8d69e3ee1899c6a7199e38.zip
Remove MEM_PROFILE related code
Code around `#ifdef MEM_PROFILE` was used to profile vim's memory comsumption. It's very likely broken as new code is using malloc() and free() directly. In this day and age, valgrind can solve in a much reliable way what this code was trying to do.
-rw-r--r--src/main.c4
-rw-r--r--src/misc2.c125
-rw-r--r--src/misc2.h2
-rw-r--r--src/normal.c9
-rw-r--r--src/vim.h6
5 files changed, 1 insertions, 145 deletions
diff --git a/src/main.c b/src/main.c
index 43045d7ae4..e5a773e1d4 100644
--- a/src/main.c
+++ b/src/main.c
@@ -169,10 +169,6 @@ static char *(main_errors[]) =
* copied, so that they can be changed. */
init_params(&params, argc, argv);
-#ifdef MEM_PROFILE
- atexit(vim_mem_profile_dump);
-#endif
-
init_startuptime(&params);
(void)mb_init(); /* init mb_bytelen_tab[] to ones */
diff --git a/src/misc2.c b/src/misc2.c
index 20e137ba09..e8bb0c6522 100644
--- a/src/misc2.c
+++ b/src/misc2.c
@@ -598,101 +598,6 @@ int leftcol_changed(void)
* Various routines dealing with allocation and deallocation of memory.
*/
-#if defined(MEM_PROFILE) || defined(PROTO)
-
-# define MEM_SIZES 8200
-static long_u mem_allocs[MEM_SIZES];
-static long_u mem_frees[MEM_SIZES];
-static long_u mem_allocated;
-static long_u mem_freed;
-static long_u mem_peak;
-static long_u num_alloc;
-static long_u num_freed;
-
-static void mem_pre_alloc_s(size_t *sizep);
-static void mem_pre_alloc_l(long_u *sizep);
-static void mem_post_alloc(void **pp, size_t size);
-static void mem_pre_free(void **pp);
-
-static void mem_pre_alloc_s(size_t *sizep)
-{
- *sizep += sizeof(size_t);
-}
-
-static void mem_pre_alloc_l(long_u *sizep)
-{
- *sizep += sizeof(size_t);
-}
-
-static void mem_post_alloc(void **pp, size_t size)
-{
- if (*pp == NULL)
- return;
- size -= sizeof(size_t);
- *(long_u *)*pp = size;
- if (size <= MEM_SIZES-1)
- mem_allocs[size-1]++;
- else
- mem_allocs[MEM_SIZES-1]++;
- mem_allocated += size;
- if (mem_allocated - mem_freed > mem_peak)
- mem_peak = mem_allocated - mem_freed;
- num_alloc++;
- *pp = (void *)((char *)*pp + sizeof(size_t));
-}
-
-static void mem_pre_free(void **pp)
-{
- long_u size;
-
- *pp = (void *)((char *)*pp - sizeof(size_t));
- size = *(size_t *)*pp;
- if (size <= MEM_SIZES-1)
- mem_frees[size-1]++;
- else
- mem_frees[MEM_SIZES-1]++;
- mem_freed += size;
- num_freed++;
-}
-
-/*
- * called on exit via atexit()
- */
-void vim_mem_profile_dump(void)
-{
- int i, j;
-
- printf("\r\n");
- j = 0;
- for (i = 0; i < MEM_SIZES - 1; i++) {
- if (mem_allocs[i] || mem_frees[i]) {
- if (mem_frees[i] > mem_allocs[i])
- printf("\r\n%s", _("ERROR: "));
- printf("[%4d / %4lu-%-4lu] ", i + 1, mem_allocs[i], mem_frees[i]);
- j++;
- if (j > 3) {
- j = 0;
- printf("\r\n");
- }
- }
- }
-
- i = MEM_SIZES - 1;
- if (mem_allocs[i]) {
- printf("\r\n");
- if (mem_frees[i] > mem_allocs[i])
- puts(_("ERROR: "));
- printf("[>%d / %4lu-%-4lu]", i, mem_allocs[i], mem_frees[i]);
- }
-
- printf(_("\n[bytes] total alloc-freed %lu-%lu, in use %lu, peak use %lu\n"),
- mem_allocated, mem_freed, mem_allocated - mem_freed, mem_peak);
- printf(_("[calls] total re/malloc()'s %lu, total free()'s %lu\n\n"),
- num_alloc, num_freed);
-}
-
-#endif /* MEM_PROFILE */
-
/*
* Some memory is reserved for error messages and for being able to
* call mf_release_all(), which needs some memory for mf_trans_add().
@@ -772,11 +677,6 @@ char_u *lalloc(long_u size, int message)
return NULL;
}
-#ifdef MEM_PROFILE
- mem_pre_alloc_l(&size);
-#endif
-
-
/*
* Loop when out of memory: Try to release some memfile blocks and
* if some blocks are released call malloc again.
@@ -831,31 +731,9 @@ char_u *lalloc(long_u size, int message)
do_outofmem_msg(size);
theend:
-#ifdef MEM_PROFILE
- mem_post_alloc((void **)&p, (size_t)size);
-#endif
return p;
}
-#if defined(MEM_PROFILE) || defined(PROTO)
-/*
- * realloc() with memory profiling.
- */
-void *mem_realloc(void *ptr, size_t size)
-{
- void *p;
-
- mem_pre_free(&ptr);
- mem_pre_alloc_s(&size);
-
- p = realloc(ptr, size);
-
- mem_post_alloc(&p, size);
-
- return p;
-}
-#endif
-
/*
* Avoid repeating the error message many times (they take 1 second each).
* Did_outofmem_msg is reset when a character is read.
@@ -1401,9 +1279,6 @@ int copy_option_part(char_u **option, char_u *buf, int maxlen, char *sep_chars)
void vim_free(void *x)
{
if (x != NULL && !really_exiting) {
-#ifdef MEM_PROFILE
- mem_pre_free(&x);
-#endif
free(x);
}
}
diff --git a/src/misc2.h b/src/misc2.h
index a5ef378bcd..09b608de43 100644
--- a/src/misc2.h
+++ b/src/misc2.h
@@ -20,13 +20,11 @@ void check_cursor_col_win(win_T *win);
void check_cursor(void);
void adjust_cursor_col(void);
int leftcol_changed(void);
-void vim_mem_profile_dump(void);
char_u *alloc(unsigned size);
char_u *alloc_clear(unsigned size);
char_u *alloc_check(unsigned size);
char_u *lalloc_clear(long_u size, int message);
char_u *lalloc(long_u size, int message);
-void *mem_realloc(void *ptr, size_t size);
void do_outofmem_msg(long_u size);
void free_all_mem(void);
char_u *vim_strsave(char_u *string);
diff --git a/src/normal.c b/src/normal.c
index 1c06f998bc..6e6875b244 100644
--- a/src/normal.c
+++ b/src/normal.c
@@ -6129,15 +6129,6 @@ static void nv_g_cmd(cmdarg_T *cap)
int flag = FALSE;
switch (cap->nchar) {
-#ifdef MEM_PROFILE
- /*
- * "g^A": dump log of used memory.
- */
- case Ctrl_A:
- vim_mem_profile_dump();
- break;
-#endif
-
/*
* "gR": Enter virtual replace mode.
*/
diff --git a/src/vim.h b/src/vim.h
index 7818855da2..f8ec4c5714 100644
--- a/src/vim.h
+++ b/src/vim.h
@@ -1388,11 +1388,7 @@ typedef int VimClipboard; /* This is required for the prototypes. */
/* Note: a NULL argument for vim_realloc() is not portable, don't use it. */
-#if defined(MEM_PROFILE)
-# define vim_realloc(ptr, size) mem_realloc((ptr), (size))
-#else
-# define vim_realloc(ptr, size) realloc((ptr), (size))
-#endif
+#define vim_realloc(ptr, size) realloc((ptr), (size))
/*
* The following macros stop display/event loop nesting at the wrong time.