Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce Log-levels in DART (2) #316

Merged
merged 10 commits into from
Mar 9, 2017
46 changes: 38 additions & 8 deletions dart-if/include/dash/dart/if/dart.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,17 @@
*
* In this release, most of DART's functionality cannot be called from within
* multiple threads in parallel. This is especially true for
* \ref DartGroupTeam "group and team management" and \ref DartGlobMem "global memory management"
* functionality as well as \ref DartCommunication "communication operations".
* All exceptions from this rule have been marked accordingly in the documentation.
* Improvements to thread-safety of DART are scheduled for the next release.
*
* Note that this also affects global operations in DASH as they rely on DART functionality.
* However, all operations on local data can be considered thread-safe, e.g., `Container.local` or
* `Container.lbegin`. The local access operators adhere to the C++ STL thread-safety
* \ref DartGroupTeam "group and team management" and \ref DartGlobMem "global
* memory management" functionality as well as \ref DartCommunication
* "communication operations".
* All exceptions from this rule have been marked accordingly in the
* documentation. Improvements to thread-safety of DART are scheduled for the
* next release.
*
* Note that this also affects global operations in DASH as they rely on DART
* functionality. However, all operations on local data can be considered
* thread-safe, e.g., `Container.local` or `Container.lbegin`.
* The local access operators adhere to the C++ STL thread-safety
* rules (see http://en.cppreference.com/w/cpp/container for details).
* Thus, the following code is valid:
*
Expand All @@ -98,6 +101,33 @@ for( auto i=0; i<arr.local.size(); i++ ) [
arr.local[i]=foo(i);
}
* \endcode
*
*
* Logging
* -------
*
* DART can be configured to produce log output with different log levels, a
* feature that is mainly meant for debugging purposes. To enable general
* logging output, the parameter \c -DENABLE_DART_LOGGING=ON should be
* passed to CMake when building DART/DASH. Alternatively, the pre-compiler
* macro \c DART_ENABLE_LOGGING can be defined manually. Please note that the
* additional log output may cause notable performance overhead and should
* not be enabled for production runs.
*
* The verbosity of the log output can be controlled at runtime through
* the environment variable DART_LOG_LEVEL, whose value (if set) controls
* the maximum log level. Possible values are:
* - \c DART_LOGLEVEL_ERROR: Emit only messages on errors that are fatal
* (similar to having logging disabled).
* - \c DART_LOGLEVEL_WARN: Emit error messages and non-fatal warnings.
* - \c DART_LOGLEVEL_INFO: In addition to errors and warnings, emit
* additional information on the execution
* of the DART library.
* - \c DART_LOGLEVEL_DEBUG: Issue detailed debugging output on (mostly)
* all DART methods executed.
* - \c DART_LOGLEVEL_TRACE: In addition to the above, also output
* information on the internal state of DART.
*
*/
#ifdef __cplusplus
extern "C" {
Expand Down
1 change: 1 addition & 0 deletions dart-impl/base/include/dash/dart/base/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#ifndef DASH_DART_BASE_ATOMIC_H_
#define DASH_DART_BASE_ATOMIC_H_

#include <stdint.h>

#if DART_HAVE_SYNC_BUILTINS

Expand Down
195 changes: 49 additions & 146 deletions dart-impl/base/include/dash/dart/base/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,8 @@
#ifndef DART__BASE__LOGGING_H__
#define DART__BASE__LOGGING_H__

#include <dash/dart/base/config.h>
#if defined(DART__PLATFORM__LINUX) && !defined(_GNU_SOURCE)
# define _GNU_SOURCE
#endif
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>

#include <dash/dart/if/dart_types.h>
#include <dash/dart/if/dart_config.h>
#include <dash/dart/if/dart_team_group.h>

#ifdef DART_ENABLE_ASSERTIONS
#include <assert.h>
#endif


/* Width of unit id field in log messages in number of characters */
#define DASH__DART_LOGGING__UNIT__WIDTH 4
/* Width of process id field in log messages in number of characters */
#define DASH__DART_LOGGING__PROC__WIDTH 5
/* Width of file name field in log messages in number of characters */
#define DASH__DART_LOGGING__FILE__WIDTH 25
/* Width of line number field in log messages in number of characters */
#define DASH__DART_LOGGING__LINE__WIDTH 4
/* Maximum length of a single log message in number of characters */
#define DASH__DART_LOGGING__MAX_MESSAGE_LENGTH 256;
#include <string.h>

#ifdef DART_LOG_OUTPUT_STDOUT
#define DART_LOG_OUTPUT_TARGET stdout
Expand Down Expand Up @@ -65,139 +39,68 @@ const int dart__base__unit_term_colors[DART_LOG_TCOL_NUM_CODES-1];
} /* extern "C" */
#endif

/* GNU variant of basename.3 */
inline char * dart_base_logging_basename(char *path) {
char *base = strrchr(path, '/');
return base ? base+1 : path;
}

enum dart__base__logging_loglevel{
DART_LOGLEVEL_ERROR = 0,
DART_LOGLEVEL_WARN,
DART_LOGLEVEL_INFO,
DART_LOGLEVEL_DEBUG,
DART_LOGLEVEL_TRACE,
DART_LOGLEVEL_NUM_LEVEL
};

void
dart__base__log_message(
const char *filename,
int line,
int level,
const char *format,
...
) __attribute__((format(printf, 4, 5)));

//
// Always log error messages and warnings:
//
#define DART_LOG_ERROR(...) \
do { \
const int maxlen = DASH__DART_LOGGING__MAX_MESSAGE_LENGTH; \
int sn_ret; \
char msg_buf[maxlen]; \
pid_t pid = getpid(); \
sn_ret = snprintf(msg_buf, maxlen, __VA_ARGS__); \
if (sn_ret < 0 || sn_ret >= maxlen) { \
break; \
} \
dart_global_unit_t unit_id; \
dart_myid(&unit_id); \
fprintf(DART_LOG_OUTPUT_TARGET, \
"[ %*d ERROR ] [ %*d ] %-*s:%-*d !!! DART: %s\n", \
DASH__DART_LOGGING__UNIT__WIDTH, unit_id.id, \
DASH__DART_LOGGING__PROC__WIDTH, pid, \
DASH__DART_LOGGING__FILE__WIDTH, dart_base_logging_basename(__FILE__), \
DASH__DART_LOGGING__LINE__WIDTH, __LINE__, \
msg_buf); \
} while (0)

#define DART_LOG_WARN(...) \
do { \
const int maxlen = DASH__DART_LOGGING__MAX_MESSAGE_LENGTH; \
int sn_ret; \
char msg_buf[maxlen]; \
pid_t pid = getpid(); \
sn_ret = snprintf(msg_buf, maxlen, __VA_ARGS__); \
if (sn_ret < 0 || sn_ret >= maxlen) { \
break; \
} \
dart_global_unit_t unit_id; \
dart_myid(&unit_id); \
fprintf(DART_LOG_OUTPUT_TARGET, \
"[ %*d WARN ] [ %*d ] %-*s:%-*d !!! DART: %s\n", \
DASH__DART_LOGGING__UNIT__WIDTH, unit_id.id, \
DASH__DART_LOGGING__PROC__WIDTH, pid, \
DASH__DART_LOGGING__FILE__WIDTH, dart_base_logging_basename(__FILE__), \
DASH__DART_LOGGING__LINE__WIDTH, __LINE__, \
msg_buf); \
} while (0)
dart__base__log_message( \
__FILE__, \
__LINE__, \
DART_LOGLEVEL_ERROR, \
__VA_ARGS__);

#define DART_LOG_WARN(...) \
dart__base__log_message( \
__FILE__, \
__LINE__, \
DART_LOGLEVEL_WARN, \
__VA_ARGS__);

//
// Debug, Info, and Trace log messages:
//
#ifdef DART_ENABLE_LOGGING

#define DART_LOG_TRACE(...) \
do { \
dart_config_t * dart_cfg; \
dart_config(&dart_cfg); \
if (!dart_cfg->log_enabled) { \
break; \
} \
const int maxlen = DASH__DART_LOGGING__MAX_MESSAGE_LENGTH; \
int sn_ret; \
char msg_buf[maxlen]; \
pid_t pid = getpid(); \
sn_ret = snprintf(msg_buf, maxlen, __VA_ARGS__); \
if (sn_ret < 0 || sn_ret >= maxlen) { \
break; \
} \
dart_global_unit_t unit_id; \
dart_myid(&unit_id); \
fprintf(DART_LOG_OUTPUT_TARGET, \
"[ %*d TRACE ] [ %*d ] %-*s:%-*d : DART: %s\n", \
DASH__DART_LOGGING__UNIT__WIDTH, unit_id.id, \
DASH__DART_LOGGING__PROC__WIDTH, pid, \
DASH__DART_LOGGING__FILE__WIDTH, dart_base_logging_basename(__FILE__), \
DASH__DART_LOGGING__LINE__WIDTH, __LINE__, \
msg_buf); \
} while (0)
dart__base__log_message( \
__FILE__, \
__LINE__, \
DART_LOGLEVEL_TRACE, \
__VA_ARGS__);

#define DART_LOG_DEBUG(...) \
do { \
dart_config_t * dart_cfg; \
dart_config(&dart_cfg); \
if (!dart_cfg->log_enabled) { \
break; \
} \
const int maxlen = DASH__DART_LOGGING__MAX_MESSAGE_LENGTH; \
int sn_ret; \
char msg_buf[maxlen]; \
pid_t pid = getpid(); \
sn_ret = snprintf(msg_buf, maxlen, __VA_ARGS__); \
if (sn_ret < 0 || sn_ret >= maxlen) { \
break; \
} \
dart_global_unit_t unit_id; \
dart_myid(&unit_id); \
fprintf(DART_LOG_OUTPUT_TARGET, \
"[ %*d DEBUG ] [ %*d ] %-*s:%-*d : DART: %s\n", \
DASH__DART_LOGGING__UNIT__WIDTH, unit_id.id, \
DASH__DART_LOGGING__PROC__WIDTH, pid, \
DASH__DART_LOGGING__FILE__WIDTH, dart_base_logging_basename(__FILE__), \
DASH__DART_LOGGING__LINE__WIDTH, __LINE__, \
msg_buf); \
} while (0)

#define DART_LOG_INFO(...) \
do { \
dart_config_t * dart_cfg; \
dart_config(&dart_cfg); \
if (!dart_cfg->log_enabled) { \
break; \
} \
const int maxlen = DASH__DART_LOGGING__MAX_MESSAGE_LENGTH; \
int sn_ret; \
char msg_buf[maxlen]; \
pid_t pid = getpid(); \
sn_ret = snprintf(msg_buf, maxlen, __VA_ARGS__); \
if (sn_ret < 0 || sn_ret >= maxlen) { \
break; \
} \
dart_global_unit_t unit_id; \
dart_myid(&unit_id); \
fprintf(DART_LOG_OUTPUT_TARGET, \
"[ %*d INFO ] [ %*d ] %-*s:%-*d : DART: %s\n", \
DASH__DART_LOGGING__UNIT__WIDTH, unit_id.id, \
DASH__DART_LOGGING__PROC__WIDTH, pid, \
DASH__DART_LOGGING__FILE__WIDTH, dart_base_logging_basename(__FILE__), \
DASH__DART_LOGGING__LINE__WIDTH, __LINE__, \
msg_buf); \
} while (0)
dart__base__log_message( \
__FILE__, \
__LINE__, \
DART_LOGLEVEL_DEBUG, \
__VA_ARGS__);

#define DART_LOG_INFO(...) \
dart__base__log_message( \
__FILE__, \
__LINE__, \
DART_LOGLEVEL_INFO, \
__VA_ARGS__ \
);

#define DART_LOG_TRACE_ARRAY(context, fmt, array, nelem) \
do { \
Expand Down
18 changes: 13 additions & 5 deletions dart-impl/base/include/dash/dart/base/mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
#include <pthread.h>
#endif


#ifdef DART_HAVE_PTHREADS
#define DART_MUTEX_INITIALIZER { PTHREAD_MUTEX_INITIALIZER }
#else
#define DART_MUTEX_INITIALIZER { 0 }
#endif


typedef struct dart_mutex {
#ifdef DART_HAVE_PTHREADS
pthread_mutex_t mutex;
Expand All @@ -27,7 +35,7 @@ char __dummy;

static inline
dart_ret_t
dart_mutex_init(dart_mutex_t *mutex)
dart__base__mutex_init(dart_mutex_t *mutex)
{
#ifdef DART_HAVE_PTHREADS
pthread_mutex_init(&mutex->mutex, NULL);
Expand All @@ -39,7 +47,7 @@ dart_mutex_init(dart_mutex_t *mutex)

static inline
dart_ret_t
dart_mutex_lock(dart_mutex_t *mutex)
dart__base__mutex_lock(dart_mutex_t *mutex)
{
#ifdef DART_HAVE_PTHREADS
pthread_mutex_lock(&mutex->mutex);
Expand All @@ -51,7 +59,7 @@ dart_mutex_lock(dart_mutex_t *mutex)

static inline
dart_ret_t
dart_mutex_unlock(dart_mutex_t *mutex)
dart__base__mutex_unlock(dart_mutex_t *mutex)
{
#ifdef DART_HAVE_PTHREADS
pthread_mutex_unlock(&mutex->mutex);
Expand All @@ -63,7 +71,7 @@ dart_mutex_unlock(dart_mutex_t *mutex)

static inline
dart_ret_t
dart_mutex_trylock(dart_mutex_t *mutex)
dart__base__mutex_trylock(dart_mutex_t *mutex)
{
#ifdef DART_HAVE_PTHREADS
pthread_mutex_trylock(&mutex->mutex);
Expand All @@ -76,7 +84,7 @@ dart_mutex_trylock(dart_mutex_t *mutex)

static inline
dart_ret_t
dart_mutex_destroy(dart_mutex_t *mutex)
dart__base__mutex_destroy(dart_mutex_t *mutex)
{
#ifdef DART_HAVE_PTHREADS
pthread_mutex_destroy(&mutex->mutex);
Expand Down
5 changes: 3 additions & 2 deletions dart-impl/base/src/internal/domain_locality.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <dash/dart/if/dart_types.h>
#include <dash/dart/if/dart_locality.h>
#include <dash/dart/if/dart_team_group.h>

#include <inttypes.h>
#include <string.h>
Expand Down Expand Up @@ -552,8 +553,8 @@ dart_ret_t dart__base__locality__domain__filter_subdomains(
if (domain->num_domains != subdomain_idx) {
if (subdomain_idx > domain->num_domains) {
DART_LOG_WARN("dart__base__locality__domain__filter_subdomains: "
"number of subdomains increased from",
domain->num_domains, "to", subdomain_idx, "in",
"number of subdomains increased from %d to %d in %s",
domain->num_domains, subdomain_idx,
domain->domain_tag);
// Filtering should never increase number of subdomains:
DART_ASSERT(subdomain_idx <= domain->num_domains);
Expand Down
1 change: 1 addition & 0 deletions dart-impl/base/src/internal/unit_locality.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <dash/dart/if/dart_types.h>
#include <dash/dart/if/dart_locality.h>
#include <dash/dart/if/dart_communication.h>
#include <dash/dart/if/dart_team_group.h>

#include <unistd.h>
#include <inttypes.h>
Expand Down
1 change: 1 addition & 0 deletions dart-impl/base/src/locality.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <dash/dart/if/dart_types.h>
#include <dash/dart/if/dart_locality.h>
#include <dash/dart/if/dart_communication.h>
#include <dash/dart/if/dart_team_group.h>

/* ====================================================================== *
* Private Data *
Expand Down
Loading