Skip to content

Instantly share code, notes, and snippets.

@zeen
Created March 20, 2020 13:34
Show Gist options
  • Save zeen/43df252a251ff6818a1800dadeadbe84 to your computer and use it in GitHub Desktop.
Save zeen/43df252a251ff6818a1800dadeadbe84 to your computer and use it in GitHub Desktop.
diff -r 35ff8e3c8093 Makefile
--- a/Makefile Mon Jul 22 06:08:14 2019 -0400
+++ b/Makefile Fri Mar 20 09:34:00 2020 -0400
@@ -9,7 +9,7 @@
gcc memmon.c -shared -o memmon.so -fPIC -I/usr/include/lua$(LUA_VERSION)/ -Wall -Werror
lua-memmon: memmon.c lua52.c
- gcc -Wall -Werror -DLUA_COMPAT_ALL -O0 memmon.c lua52.c -o lua-memmon -fPIC -I/usr/include/lua5.2/ /usr/lib/x86_64-linux-gnu/liblua5.2.so -ldl -lm -Wl,-dynamic-list,exports.txt
+ gcc -Wall -Werror -DENABLE_MALLOC_TRACE -DLUA_COMPAT_ALL -O0 memmon.c lua52.c -o lua-memmon -fPIC -I/usr/include/lua5.2/ /usr/lib/x86_64-linux-gnu/liblua5.2.so -ldl -lm -Wl,-dynamic-list,exports.txt
@echo
@echo Update first line of \"$(shell which prosody || echo /usr/bin/prosody)\" to have this shebang:
@echo
diff -r 35ff8e3c8093 memmon.c
--- a/memmon.c Mon Jul 22 06:08:14 2019 -0400
+++ b/memmon.c Fri Mar 20 09:34:00 2020 -0400
@@ -173,7 +173,8 @@
// OUR CUSTOM MALLOC FUNCTIONS
#ifdef ENABLE_MALLOC_TRACE
- #define MALLOC_TRACE(...) do { switch_to_libc(); printf(__VA_ARGS__); switch_to_custom(); } while(0);
+ static FILE *trace_file = NULL;
+ #define MALLOC_TRACE(...) do { switch_to_libc(); if (!trace_file) { trace_file = fopen("trace.log", "w"); } fprintf(trace_file, __VA_ARGS__); switch_to_custom(); } while(0);
static void switch_to_libc();
#else
#define MALLOC_TRACE(...) do {} while(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment