Skip to content

Commit

Permalink
Debug: add mtrace(3) support
Browse files Browse the repository at this point in the history
Signed-off-by: Takahiro YAMASHITA <[email protected]>
  • Loading branch information
nokute78 committed Jun 3, 2016
1 parent a15c7ad commit 0521fac
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
11 changes: 6 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,19 @@ if(FLB_ALL)
set(FLB_OUT_LIB 1)
endif()

# Enable Debug symbols if specified
if(FLB_DEBUG)
set(CMAKE_BUILD_TYPE "Debug")
endif()

# Macro to set definitions
macro(FLB_DEFINITION var)
add_definitions(-D${var})
set(FLB_BUILD_FLAGS "${FLB_BUILD_FLAGS}#ifndef ${var}\n#define ${var}\n#endif\n")
set(FLB_INFO_FLAGS "${FLB_INFO_FLAGS} ${var}")
endmacro()

# Enable Debug symbols if specified
if(FLB_DEBUG)
set(CMAKE_BUILD_TYPE "Debug")
FLB_DEFINITION(FLB_HAVE_MTRACE)
endif()

# General Headers
include_directories(
include/
Expand Down
14 changes: 14 additions & 0 deletions src/flb_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
#include <fluent-bit/flb_output.h>
#include <fluent-bit/flb_utils.h>

#ifdef FLB_HAVE_MTRACE
#include <mcheck.h>
#endif

extern struct flb_input_plugin in_lib_plugin;

flb_ctx_t *flb_create()
Expand All @@ -35,6 +39,11 @@ flb_ctx_t *flb_create()
flb_ctx_t *ctx;
struct flb_config *config;

#ifdef FLB_HAVE_MTRACE
/* Start tracing malloc and free */
mtrace();
#endif

ctx = calloc(1, sizeof(flb_ctx_t));
if (!ctx) {
perror("malloc");
Expand Down Expand Up @@ -93,6 +102,11 @@ void flb_destroy(flb_ctx_t *ctx)
/* Remove resources from the event loop */
mk_event_loop_destroy(ctx->event_loop);
free(ctx);

#ifdef FLB_HAVE_MTRACE
/* Stop tracing malloc and free */
muntrace();
#endif
}

/* Defines a new input instance */
Expand Down
13 changes: 13 additions & 0 deletions src/fluent-bit.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
#include <fluent-bit/flb_output.h>
#include <fluent-bit/flb_engine.h>

#ifdef FLB_HAVE_MTRACE
#include <mcheck.h>
#endif

struct flb_config *config;

#define PLUGIN_INPUT 0
Expand Down Expand Up @@ -120,6 +124,10 @@ static void flb_signal_handler(int signal)
case SIGHUP:
case SIGTERM:
flb_engine_shutdown(config);
#ifdef FLB_HAVE_MTRACE
/* Stop tracing malloc and free */
muntrace();
#endif
_exit(EXIT_SUCCESS);
default:
break;
Expand Down Expand Up @@ -365,6 +373,11 @@ int main(int argc, char **argv)
{ NULL, 0, NULL, 0 }
};

#ifdef FLB_HAVE_MTRACE
/* Start tracing malloc and free */
mtrace();
#endif

/* Signal handler */
flb_signal_init();

Expand Down

0 comments on commit 0521fac

Please sign in to comment.