Commit aa47ee26 authored by Peter W. Draper's avatar Peter W. Draper
Browse files

Make the memuse reports a no-op configure option and put back the

more detailed file:function:line output foe debugging.
parent a3f75b90
......@@ -275,6 +275,18 @@ elif test "$no_gravity_below_id" != "no"; then
AC_DEFINE_UNQUOTED([SWIFT_NO_GRAVITY_BELOW_ID], [$enableval] ,[Particles with smaller ID than this will have zero gravity forces])
fi
# See if we want memuse reporting.
AC_ARG_ENABLE([memuse-reports],
[AS_HELP_STRING([--enable-memuse-reports],
[Output reports about significant memory allocations@<:@yes/no@:>@]
)],
[enable_memuse_reports="$enableval"],
[enable_memuse_reports="no"]
)
if test "$enable_memuse_reports" = "yes"; then
AC_DEFINE([SWIFT_MEMUSE_REPORTS],1,[Enable memory usage reports])
fi
# Define HAVE_POSIX_MEMALIGN if it works.
AX_FUNC_POSIX_MEMALIGN
......
......@@ -31,51 +31,61 @@
#include <sys/types.h>
#include <unistd.h>
/* Local defines. */
#include "memuse.h"
/* Local includes. */
#include "clocks.h"
#include "engine.h"
/* Local macros to report output. */
#ifdef WITH_MPI
#ifdef SWIFT_MEMUSE_REPORTS
/* For output messages. */
extern int engine_rank;
extern int engine_cstep;
#define memuse_output(what, memuse) \
({ \
printf("[%04i] %s :memuse: %i:%s %s\n", \
engine_rank, clocks_get_timesincestart(), engine_cstep, \
what, memuse); \
})
#else
#define memuse_output(what, memuse) \
({ \
printf("%s :memuse: %i:%s %s\n", \
clocks_get_timesincestart(), engine_cstep, what, memuse); \
})
#endif
/**
* @brief Report a memory allocation or use in bytes.
*
* @param what a name for the report, "parts", "gparts" etc.
* @param file caller code file name
* @param function caller code function.
* @param line caller code file line no.
* @param bytes the number of bytes that have been allocated
*/
void memuse_report(const char *what, size_t bytes) {
void memuse_report__(const char *what, const char *file, const char *function,
int line, size_t bytes) {
char buffer[32];
sprintf(buffer, "%zd", bytes/1024);
memuse_output(what, buffer);
memuse_report_str__(what, file, function, line, buffer);
}
/**
* @brief Report a memory allocation or use formatted description.
*
* @param what a name for the report, "parts", "gparts" etc.
* @param file caller code file name
* @param function caller code function.
* @param line caller code file line no.
* @param description the report, values should be in KB, the
* result of memuse_process() is suitable.
*/
void memuse_report_str(const char *what, const char *description) {
memuse_output(what, description);
void memuse_report_str__(const char *what, const char *file,
const char *function, int line,
const char *description) {
#ifdef WITH_MPI
printf("[%04i] %s :memuse: %i:%s %s:%s:%i %s\n",
engine_rank, clocks_get_timesincestart(), engine_cstep, what,
file, function, line, description);
#else
printf("%s :memuse: %i:%s %s:%s:%i %s\n",
clocks_get_timesincestart(), engine_cstep, what, file, function,
line, description);
#endif
}
#endif /* SWIFT_MEMUSE_REPORTS */
/**
* @brief parse the process /proc/self/statm file to get the process
* memory use (in KB). Top field in ().
......@@ -133,7 +143,7 @@ void memuse_use(long *size, long *resident, long *share, long *trs,
* @result the memory use of the process, note make a copy if not used
* immediately.
*/
char *memuse_process() {
const char *memuse_process() {
static char buffer[256];
long size;
long resident;
......
......@@ -22,10 +22,25 @@
/* Config parameters. */
#include "../config.h"
void memuse_report(const char *what, size_t bytes);
void memuse_report_str(const char *what, const char *description);
/* Public API. */
void memuse_use(long *size, long *resident, long *share, long *trs,
long *lrs, long *drs, long *dt);
const char *memuse_process();
/* Reports are a no-op unless wanted. */
#ifdef SWIFT_MEMUSE_REPORTS
void memuse_report__(const char *what, const char *file, const char *function,
int line, size_t bytes);
void memuse_report_str__(const char *what, const char *file,
const char *function, int line, const char *description);
#define memuse_report(what, size) \
memuse_report__(what, __FILE__, __FUNCTION__, __LINE__, size)
#define memuse_report_str(what, description) \
memuse_report_str__(what, __FILE__, __FUNCTION__, __LINE__, description)
#else
#define memuse_report(what, size)
#define memuse_report_str(what, description)
#endif
#endif /* SWIFT_MEMUSE_H */
......@@ -398,7 +398,7 @@ void runner_do_sort(struct runner *r, struct cell *c, int flags, int cleanup,
allocated += sizeof(struct entry) * (count + 1);
}
}
memuse_report("c->sort[*]", allocated);
memuse_report("cell_sorts", allocated);
/* Does this cell have any progeny? */
if (c->split) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment