Skip to content

Commit

Permalink
o Added option to print memory usage on entry to profiling functions.
Browse files Browse the repository at this point in the history
  To enable, set in GPTL build:
  - HAVE_BACKTRACE=yes in macros.make
  Then in application:
  - ret = GPTLsetoption (GPTLdopr_memusage, 1)
  - compile with -finstrument-functions -g -rdynamic
o Removed obsolete macros.make.sicortex
  • Loading branch information
jim rosinski committed Sep 7, 2013
1 parent 08687ec commit 2710da5
Show file tree
Hide file tree
Showing 24 changed files with 524 additions and 348 deletions.
3 changes: 3 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ dnl AC_FUNC_VPRINTF
AC_CHECK_LIB(papi,PAPI_library_init,[echo "PAPI library found: OK to set HAVE_PAPI=yes"],
[echo "PAPI library not found: HAVE_PAPI=no"])

AC_CHECK_FUNC(backtrace_symbols,[echo "backtrace_symbols found: OK to set HAVE_BACKTRACE=yes"],
[echo "backtrace_symbols NOT found: HAVE_BACKTRACE=no"])

unset usempich;
unset usempi;
AC_CHECK_LIB(mpich,MPI_Init,[echo "libmpich.a found: OK to set HAVE_MPI=yes";usempich=yes],
Expand Down
4 changes: 4 additions & 0 deletions ftests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ overhead: overhead.F90 ../lib$(LIBNAME).a
toomanythreads: toomanythreads.F90
$(FC) $(FFLAGS) -o $@ $< $(LDFLAGS)

# Hidden executable testbacktrace requires some strange flags so don't build it unless asked
testbacktrace: testbacktrace.F90
$(FC) $(FFLAGS) $(INSTRFLAG) -g -rdynamic -o $@ $< $(LDFLAGS)

# Built-in tests to ensure that GPTL is behaving as expected
# Invoke as "make test" from one dir above

Expand Down
59 changes: 59 additions & 0 deletions gptl.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
#include <sys/systemcfg.h>
#endif

#ifdef HAVE_BACKTRACE
#include <execinfo.h>
#endif

#include "private.h"
#include "gptl.h"

Expand Down Expand Up @@ -66,6 +70,7 @@ static bool dopr_preamble = true; /* whether to print preamble info */
static bool dopr_threadsort = true; /* whether to print sorted thread stats */
static bool dopr_multparent = true; /* whether to print multiple parent info */
static bool dopr_collision = true; /* whether to print hash collision info */
static bool dopr_memusage = false; /* whether to include memusage print when auto-profiling */

static time_t ref_gettimeofday = -1; /* ref start point for gettimeofday */
static time_t ref_clock_gettime = -1; /* ref start point for clock_gettime */
Expand Down Expand Up @@ -224,6 +229,8 @@ static char *clock_source = "UNKNOWN"; /* where clock found */
static int tablesize = DEFAULT_TABLE_SIZE; /* per-thread size of hash table (settable parameter) */
static char *outdir = 0; /* dir to write output files to (currently unused) */

#define MSGSIZ 64 /* max size of msg printed when dopr_memusage=true */

/* VERBOSE is a debugging ifdef local to the rest of this file */
#undef VERBOSE

Expand Down Expand Up @@ -310,6 +317,11 @@ int GPTLsetoption (const int option, /* option */
if (verbose)
printf ("%s: boolean dopr_collision = %d\n", thisfunc, val);
return 0;
case GPTLdopr_memusage:
dopr_memusage = (bool) val;
if (verbose)
printf ("%s: boolean dopr_memusage = %d\n", thisfunc, val);
return 0;
case GPTLprint_method:
method = (Method) val;
if (verbose)
Expand Down Expand Up @@ -2994,6 +3006,12 @@ void __func_trace_enter (const char *function_name,
int line_number,
void **const user_data)
{
char msg[MSGSIZ];

if (dopr_memusage) {
snprintf (msg, MSGSIZ, "begin %s", function_name);
(void) GPTLprint_memusage (msg);
}
(void) GPTLstart (function_name);
}

Expand All @@ -3003,20 +3021,61 @@ void __func_trace_exit (const char *function_name,
void **const user_data)
{
(void) GPTLstop (function_name);
if (dopr_memusage) {
snprintf (msg, MSGSIZ, "end %s", function_name);
(void) GPTLprint_memusage (msg);
}
}

#else

void __cyg_profile_func_enter (void *this_fn,
void *call_site)
{
#ifdef HAVE_BACKTRACE
void *buffer[2];
int nptrs;
char **strings;
#endif
char msg[MSGSIZ];

if (dopr_memusage) {
#ifdef HAVE_BACKTRACE
nptrs = backtrace (buffer, 2);
strings = backtrace_symbols (buffer, nptrs);
snprintf (msg, MSGSIZ, "begin %s", strings[1]);
free (strings);
#else
snprintf (msg, MSGSIZ, "begin %lx", (unsigned long) this_fn);
#endif
(void) GPTLprint_memusage (msg);
}
(void) GPTLstart_instr (this_fn);
}

void __cyg_profile_func_exit (void *this_fn,
void *call_site)
{
#ifdef HAVE_BACKTRACE
void *buffer[2];
int nptrs;
char **strings;
#endif
char msg[MSGSIZ];

(void) GPTLstop_instr (this_fn);

if (dopr_memusage) {
#ifdef HAVE_BACKTRACE
nptrs = backtrace (buffer, 2);
strings = backtrace_symbols (buffer, nptrs);
snprintf (msg, MSGSIZ, "end %s", (char *) strings[1]);
free (strings);
#else
snprintf (msg, MSGSIZ, "end %lx", (unsigned long) this_fn);
#endif
(void) GPTLprint_memusage (msg);
}
}
#endif

Expand Down
1 change: 1 addition & 0 deletions gptl.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ typedef enum {
GPTLdopr_threadsort = 13, /* Print sorted thread stats (true) */
GPTLdopr_multparent = 14, /* Print multiple parent info (true) */
GPTLdopr_collision = 15, /* Print hastable collision info (true) */
GPTLdopr_memusage = 27, /* Call GPTLprint_memusage when auto-instrumented */
GPTLprint_method = 16, /* Tree print method: first parent, last parent
most frequent, or full tree (most frequent) */
GPTLtablesize = 50, /* per-thread size of hash table */
Expand Down
1 change: 1 addition & 0 deletions gptl.h.template
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ typedef enum {
GPTLdopr_threadsort = #GPTLdopr_threadsort, /* Print sorted thread stats (true) */
GPTLdopr_multparent = #GPTLdopr_multparent, /* Print multiple parent info (true) */
GPTLdopr_collision = #GPTLdopr_collision, /* Print hastable collision info (true) */
GPTLdopr_memusage = #GPTLdopr_memusage, /* Call GPTLprint_memusage when auto-instrumented */
GPTLprint_method = #GPTLprint_method, /* Tree print method: first parent, last parent
most frequent, or full tree (most frequent) */
GPTLtablesize = #GPTLtablesize, /* per-thread size of hash table */
Expand Down
2 changes: 2 additions & 0 deletions gptl.inc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
integer GPTLdopr_threadsort
integer GPTLdopr_multparent
integer GPTLdopr_collision
integer GPTLdopr_memusage
integer GPTLprint_method
integer GPTLtablesize
integer GPTLmaxthreads
Expand Down Expand Up @@ -65,6 +66,7 @@
parameter (GPTLdopr_threadsort= 13)
parameter (GPTLdopr_multparent= 14)
parameter (GPTLdopr_collision = 15)
parameter (GPTLdopr_memusage = 27)
parameter (GPTLprint_method = 16)
parameter (GPTLtablesize = 50)
parameter (GPTLmaxthreads = 51)
Expand Down
2 changes: 2 additions & 0 deletions gptl.inc.template
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
integer GPTLdopr_threadsort
integer GPTLdopr_multparent
integer GPTLdopr_collision
integer GPTLdopr_memusage
integer GPTLprint_method
integer GPTLtablesize
integer GPTLmaxthreads
Expand Down Expand Up @@ -65,6 +66,7 @@
parameter (GPTLdopr_threadsort= #GPTLdopr_threadsort)
parameter (GPTLdopr_multparent= #GPTLdopr_multparent)
parameter (GPTLdopr_collision = #GPTLdopr_collision)
parameter (GPTLdopr_memusage = #GPTLdopr_memusage)
parameter (GPTLprint_method = #GPTLprint_method)
parameter (GPTLtablesize = #GPTLtablesize)
parameter (GPTLmaxthreads = #GPTLmaxthreads)
Expand Down
1 change: 1 addition & 0 deletions gptlf.F90
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module gptl
integer, parameter :: GPTLdopr_threadsort= 13
integer, parameter :: GPTLdopr_multparent= 14
integer, parameter :: GPTLdopr_collision = 15
integer, parameter :: GPTLdopr_memusage = 27
integer, parameter :: GPTLprint_method = 16
integer, parameter :: GPTLtablesize = 50
integer, parameter :: GPTLmaxthreads = 51
Expand Down
1 change: 1 addition & 0 deletions gptlf.F90.template
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module gptl
integer, parameter :: GPTLdopr_threadsort= #GPTLdopr_threadsort
integer, parameter :: GPTLdopr_multparent= #GPTLdopr_multparent
integer, parameter :: GPTLdopr_collision = #GPTLdopr_collision
integer, parameter :: GPTLdopr_memusage = #GPTLdopr_memusage
integer, parameter :: GPTLprint_method = #GPTLprint_method
integer, parameter :: GPTLtablesize = #GPTLtablesize
integer, parameter :: GPTLmaxthreads = #GPTLmaxthreads
Expand Down
10 changes: 10 additions & 0 deletions macros.make.jet
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,13 @@ ifeq ($(HAVE_MPI),yes)
HAVE_IARGCGETARG = no
endif
endif

# Whether system functions backtrace() and backtrace_symbols() exist. Setting HAVE_BACKTRACE=yes
# will enable auto-generation of function name when auto-profiling and GPTLdopr_memusage has been
# enabled at run-time. If HAVE_BACKTRACE=no, function address will be printed instead.
# GNU compilers: compile application code with -finstrument-functions -rdynamic
# Intel compilers: compile application code with -finstrument-functions -rdynamic -g
HAVE_BACKTRACE = yes
ifeq ($(HAVE_BACKTRACE),yes)
CFLAGS += -DHAVE_BACKTRACE
endif
10 changes: 10 additions & 0 deletions macros.make.jet.nompi
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,13 @@ ifeq ($(HAVE_MPI),yes)
HAVE_IARGCGETARG = no
endif
endif

# Whether system functions backtrace() and backtrace_symbols() exist. Setting HAVE_BACKTRACE=yes
# will enable auto-generation of function name when auto-profiling and GPTLdopr_memusage has been
# enabled at run-time. If HAVE_BACKTRACE=no, function address will be printed instead.
# GNU compilers: compile application code with -finstrument-functions -rdynamic
# Intel compilers: compile application code with -finstrument-functions -rdynamic -g
HAVE_BACKTRACE = yes
ifeq ($(HAVE_BACKTRACE),yes)
CFLAGS += -DHAVE_BACKTRACE
endif
10 changes: 10 additions & 0 deletions macros.make.lahey
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,13 @@ ifeq ($(HAVE_MPI),yes)
HAVE_IARGCGETARG = no
endif
endif

# Whether system functions backtrace() and backtrace_symbols() exist. Setting HAVE_BACKTRACE=yes
# will enable auto-generation of function name when auto-profiling and GPTLdopr_memusage has been
# enabled at run-time. If HAVE_BACKTRACE=no, function address will be printed instead.
# GNU compilers: compile application code with -finstrument-functions -rdynamic
# Intel compilers: compile application code with -finstrument-functions -rdynamic -g
HAVE_BACKTRACE = no
ifeq ($(HAVE_BACKTRACE),yes)
CFLAGS += -DHAVE_BACKTRACE
endif
12 changes: 11 additions & 1 deletion macros.make.linux
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ HAVE_TIMES = yes
HAVE_GETTIMEOFDAY = yes

# Whether to test auto-profiling (adds 2 tests to "make test"). If compiler is gcc or
# pathscale, set INSTRFLAG to -finstrument-functions. PGI 8.0.2 and later provide
# pathscale or intel, set INSTRFLAG to -finstrument-functions. PGI 8.0.2 and later provide
# -Minstrument:functions.
TEST_AUTOPROFILE = yes
ifeq ($(TEST_AUTOPROFILE),yes)
Expand All @@ -141,3 +141,13 @@ ifeq ($(HAVE_MPI),yes)
HAVE_IARGCGETARG = no
endif
endif

# Whether system functions backtrace() and backtrace_symbols() exist. Setting HAVE_BACKTRACE=yes
# will enable auto-generation of function name when auto-profiling and GPTLdopr_memusage has been
# enabled at run-time. If HAVE_BACKTRACE=no, function address will be printed instead.
# GNU compilers: compile application code with -finstrument-functions -rdynamic
# Intel compilers: compile application code with -finstrument-functions -rdynamic -g
HAVE_BACKTRACE = yes
ifeq ($(HAVE_BACKTRACE),yes)
CFLAGS += -DHAVE_BACKTRACE
endif
10 changes: 10 additions & 0 deletions macros.make.macos
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,13 @@ ifeq ($(HAVE_MPI),yes)
HAVE_IARGCGETARG = no
endif
endif

# Whether system functions backtrace() and backtrace_symbols() exist. Setting HAVE_BACKTRACE=yes
# will enable auto-generation of function name when auto-profiling and GPTLdopr_memusage has been
# enabled at run-time. If HAVE_BACKTRACE=no, function address will be printed instead.
# GNU compilers: compile application code with -finstrument-functions -rdynamic
# Intel compilers: compile application code with -finstrument-functions -rdynamic -g
HAVE_BACKTRACE = yes
ifeq ($(HAVE_BACKTRACE),yes)
CFLAGS += -DHAVE_BACKTRACE
endif
10 changes: 10 additions & 0 deletions macros.make.ornlintel
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,13 @@ ifeq ($(HAVE_MPI),yes)
HAVE_IARGCGETARG = no
endif
endif

# Whether system functions backtrace() and backtrace_symbols() exist. Setting HAVE_BACKTRACE=yes
# will enable auto-generation of function name when auto-profiling and GPTLdopr_memusage has been
# enabled at run-time. If HAVE_BACKTRACE=no, function address will be printed instead.
# GNU compilers: compile application code with -finstrument-functions -rdynamic
# Intel compilers: compile application code with -finstrument-functions -rdynamic -g
HAVE_BACKTRACE = yes
ifeq ($(HAVE_BACKTRACE),yes)
CFLAGS += -DHAVE_BACKTRACE
endif
10 changes: 10 additions & 0 deletions macros.make.pgi
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,13 @@ ifeq ($(HAVE_MPI),yes)
HAVE_IARGCGETARG = no
endif
endif

# Whether system functions backtrace() and backtrace_symbols() exist. Setting HAVE_BACKTRACE=yes
# will enable auto-generation of function name when auto-profiling and GPTLdopr_memusage has been
# enabled at run-time. If HAVE_BACKTRACE=no, function address will be printed instead.
# GNU compilers: compile application code with -finstrument-functions -rdynamic
# Intel compilers: compile application code with -finstrument-functions -rdynamic -g
HAVE_BACKTRACE = no
ifeq ($(HAVE_BACKTRACE),yes)
CFLAGS += -DHAVE_BACKTRACE
endif
Loading

0 comments on commit 2710da5

Please sign in to comment.