2
0
Fork 0

Make profiler optional

This commit is contained in:
Stefan Bühler 2010-05-13 12:17:33 +02:00
parent 8fa282ffaf
commit 4afebee1c7
7 changed files with 69 additions and 32 deletions

View File

@ -111,6 +111,8 @@ fi
AM_CONDITIONAL([USE_LUA], [test "$USE_LUA" = "true"])
# Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_UID_T
@ -274,6 +276,14 @@ AC_SUBST(BZ_LIB)
AM_CONDITIONAL([USE_MOD_DEFLATE], [test "x$use_mod_deflate" = "xyes"])
AC_ARG_ENABLE(profiler,
AC_HELP_STRING([--enable-profiler],[enable memory profiler support]),[
profiler=yes
AC_DEFINE([WITH_PROFILER], [1], [profiler])
AC_CHECK_HEADERS([execinfo.h])],[])
AM_CONDITIONAL([WITH_PROFILER], [test "x$profiler" = "xyes"])
save_LIBS=$LIBS
LIBS=
AC_SEARCH_LIBS(crypt_r,crypt,[

View File

@ -25,6 +25,7 @@ OPTION(BUILD_STATIC "build a static lighttpd with all modules added")
OPTION(BUILD_EXTRA_WARNINGS "extra warnings")
OPTION(WITH_BZIP "with bzip2-support for mod_deflate")
OPTION(WITH_ZLIB "with deflate-support for mod_deflate")
OPTION(WITH_PROFILER "with memory profiler")
OPTION(BUILD_UNIT_TESTS "build unit tests for testing")
IF(BUILD_STATIC)
@ -130,6 +131,10 @@ IF(WITH_ZLIB)
ENDIF(HAVE_ZLIB_H AND HAVE_LIBZ)
ENDIF(WITH_ZLIB)
IF(WITH_PROFILER)
CHECK_INCLUDE_FILES(execinfo.h HAVE_EXECINFO_H)
ENDIF(WITH_PROFILER)
IF(NOT BUILD_STATIC)
CHECK_INCLUDE_FILES(dlfcn.h HAVE_DLFCN_H)
ENDIF(NOT BUILD_STATIC)
@ -202,7 +207,6 @@ SET(LIGHTTPD_SHARED_SRC
network_sendfile.c
options.c
plugin.c
profiler.c
request.c
response.c
server.c
@ -217,11 +221,18 @@ SET(LIGHTTPD_SHARED_SRC
)
IF(NOT WITHOUT_CONFIG_PARSER)
SET(LIGHTTPD_SHARED_SRC ${LIGHTTPD_SHARED_SRC}
config_parser.c
)
SET(LIGHTTPD_SHARED_SRC ${LIGHTTPD_SHARED_SRC}
config_parser.c
)
ENDIF(NOT WITHOUT_CONFIG_PARSER)
IF(WITH_PROFILER)
SET(LIGHTTPD_SHARED_SRC ${LIGHTTPD_SHARED_SRC}
profiler.c
)
ENDIF(WITH_PROFILER)
IF(WITH_LUA)
SET(LIGHTTPD_SHARED_SRC ${LIGHTTPD_SHARED_SRC}
actions_lua.c

View File

@ -30,6 +30,7 @@
#cmakedefine HAVE_INET_ATON
#cmakedefine HAVE_IPV6
#cmakedefine HAVE_SOCKADDR_STORAGE
#cmakedefine HAVE_EXECINFO_H
/* XATTR */
#cmakedefine HAVE_ATTR_ATTRIBUTES_H
@ -157,3 +158,4 @@
/* features */
#cmakedefine WITHOUT_CONFIG_PARSER
#cmakedefine LIGHTTPD_STATIC
#cmakedefine WITH_PROFILER

View File

@ -29,7 +29,6 @@ lighttpd_shared_src= \
network_sendfile.c \
options.c \
plugin.c \
profiler.c \
request.c \
response.c \
server.c \
@ -64,7 +63,10 @@ lua_src= \
if USE_LUA
lighttpd_shared_src+=$(lua_src)
endif
EXTRA_lighttpd2_SOURCES=$(lua_src)
if WITH_PROFILER
lighttpd_shared_src+= profiler.c
endif
EXTRA_lighttpd2_SOURCES=$(lua_src) profiler.c
BUILT_SOURCES=config_parser.c http_range_parser.c http_request_parser.c http_response_parser.c url_parser.c

View File

@ -1,10 +1,13 @@
#include <lighttpd/base.h>
#include <lighttpd/profiler.h>
#include <lighttpd/plugin_core.h>
#include <lighttpd/version.h>
#ifdef WITH_PROFILER
# include <lighttpd/profiler.h>
#endif
#ifdef HAVE_LUA_H
# include <lighttpd/config_lua.h>
#endif
@ -44,15 +47,19 @@ int main(int argc, char *argv[]) {
{ NULL, 0, 0, 0, NULL, NULL, NULL }
};
/* check for environment variable LIGHTY_PROFILE_MEM */
gchar *profile_mem = getenv("LIGHTY_PROFILE_MEM");
if (profile_mem) {
/*g_mem_set_vtable(glib_mem_profiler_table);*/
li_profiler_enable(profile_mem);
atexit(li_profiler_finish);
atexit(li_profiler_dump);
/*atexit(profiler_dump_table);*/
#ifdef WITH_PROFILER
{
/* check for environment variable LIGHTY_PROFILE_MEM */
gchar *profile_mem = getenv("LIGHTY_PROFILE_MEM");
if (profile_mem) {
/*g_mem_set_vtable(glib_mem_profiler_table);*/
li_profiler_enable(profile_mem);
atexit(li_profiler_finish);
atexit(li_profiler_dump);
/*atexit(profiler_dump_table);*/
}
}
#endif
/* parse commandline options */
context = g_option_context_new("- fast and lightweight webserver");

View File

@ -11,13 +11,13 @@
#include <fcntl.h>
#ifdef HAVE_EXECINFO_H
#include <execinfo.h>
# include <execinfo.h>
#endif
#if defined(LIGHTY_OS_MACOSX)
#include <malloc/malloc.h>
# include <malloc/malloc.h>
#elif defined(LIGHTY_OS_LINUX)
#include <malloc.h>
# include <malloc.h>
#endif
#define PROFILER_HASHTABLE_SIZE 65521
@ -79,9 +79,9 @@ static void profiler_hashtable_insert(gpointer addr, gsize size) {
block = profiler_block_new();
block->addr = addr;
block->size = size;
#ifdef HAVE_EXECINFO_H
#ifdef HAVE_EXECINFO_H
block->stackframes_num = backtrace(block->stackframes, 12);
#endif
#endif
block->next = profiler_hashtable[hash % PROFILER_HASHTABLE_SIZE];
profiler_hashtable[hash % PROFILER_HASHTABLE_SIZE] = block;
@ -119,11 +119,11 @@ static gpointer profiler_try_malloc(gsize n_bytes) {
if (p) {
g_static_mutex_lock(&profiler_mutex);
#if defined(LIGHTY_OS_MACOSX)
#if defined(LIGHTY_OS_MACOSX)
n_bytes = malloc_size(p);
#elif defined(LIGHTY_OS_LINUX)
#elif defined(LIGHTY_OS_LINUX)
n_bytes = malloc_usable_size(p);
#endif
#endif
profiler_hashtable_insert(p, n_bytes);
g_static_mutex_unlock(&profiler_mutex);
}
@ -155,11 +155,11 @@ static gpointer profiler_try_realloc(gpointer mem, gsize n_bytes) {
if (p) {
g_static_mutex_lock(&profiler_mutex);
profiler_hashtable_remove(mem);
#if defined(LIGHTY_OS_MACOSX)
#if defined(LIGHTY_OS_MACOSX)
n_bytes = malloc_size(p);
#elif defined(LIGHTY_OS_LINUX)
#elif defined(LIGHTY_OS_LINUX)
n_bytes = malloc_usable_size(p);
#endif
#endif
profiler_hashtable_insert(p, n_bytes);
g_static_mutex_unlock(&profiler_mutex);
}
@ -183,11 +183,11 @@ static gpointer profiler_calloc(gsize n_blocks, gsize n_bytes) {
if (p) {
g_static_mutex_lock(&profiler_mutex);
#if defined(LIGHTY_OS_MACOSX)
#if defined(LIGHTY_OS_MACOSX)
n_bytes = malloc_size(p);
#elif defined(LIGHTY_OS_LINUX)
#elif defined(LIGHTY_OS_LINUX)
n_bytes = malloc_usable_size(p);
#endif
#endif
profiler_hashtable_insert(p, n_bytes);
g_static_mutex_unlock(&profiler_mutex);
}
@ -295,9 +295,9 @@ void li_profiler_dump() {
leaked_size += block->size;
len = sprintf(str, "--------------- unfreed block of %"G_GSIZE_FORMAT" bytes @ %p ---------------\n", block->size, block->addr);
profiler_write(str, len);
#ifdef HAVE_EXECINFO_H
#ifdef HAVE_EXECINFO_H
backtrace_symbols_fd(block->stackframes, block->stackframes_num, profiler_output_fd);
#endif
#endif
}
}

View File

@ -34,7 +34,10 @@
*/
#include <lighttpd/base.h>
#include <lighttpd/profiler.h>
#ifdef WITH_PROFILER
# include <lighttpd/profiler.h>
#endif
LI_API gboolean mod_debug_init(liModules *mods, liModule *mod);
LI_API gboolean mod_debug_free(liModules *mods, liModule *mod);
@ -312,10 +315,12 @@ static liAction* debug_show_connections_create(liServer *srv, liWorker *wrk, liP
static liHandlerResult debug_profiler_dump(liVRequest *vr, gpointer param, gpointer *context) {
UNUSED(vr); UNUSED(param); UNUSED(context);
#ifdef WITH_PROFILER
if (!getenv("LIGHTY_PROFILE_MEM"))
return LI_HANDLER_GO_ON;
li_profiler_dump();
#endif
return LI_HANDLER_GO_ON;
}