Debug message types
Former-commit-id: 666a031026a363b15c01ca8cdc174fbf152dee8e
This commit is contained in:
parent
eddb8558d8
commit
652ab6f3ba
22
qpms/error.c
22
qpms/error.c
|
@ -3,6 +3,16 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
qpms_dbgmsg_flags qpms_dbgmsg_enabled = QPMS_DBGMSG_MISC;
|
||||
|
||||
qpms_dbgmsg_flags qpms_dbgmsg_enable(qpms_dbgmsg_flags types) {
|
||||
return (qpms_dbgmsg_enabled |= types);
|
||||
}
|
||||
|
||||
qpms_dbgmsg_flags qpms_dbgmsg_disable(qpms_dbgmsg_flags types) {
|
||||
return (qpms_dbgmsg_enabled &= ~types);
|
||||
}
|
||||
|
||||
void qpms_pr_error(const char *fmt, ...) {
|
||||
fflush(stdout);
|
||||
va_list ap;
|
||||
|
@ -68,6 +78,18 @@ void qpms_pr_debug_at_flf(const char *filename, unsigned int linenum,
|
|||
fflush(stderr);
|
||||
}
|
||||
|
||||
void qpms_debug_at_flf(const char *filename, unsigned int linenum,
|
||||
const char *func, qpms_dbgmsg_flags type,
|
||||
const char *fmt, ...) {
|
||||
if (!(type & qpms_dbgmsg_enabled)) return;
|
||||
fprintf(stderr, "%s:%u, %s: ", filename, linenum, func);
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
vfprintf(stderr, fmt, ap);
|
||||
va_end(ap);
|
||||
fputc('\n', stderr);
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
//void qpms_error_at_line(const char *filename, unsigned int linenum,
|
||||
// const char *fmt, ...);
|
||||
|
|
|
@ -34,6 +34,27 @@ class VSWFNorm(enum.IntEnum):
|
|||
TAYLOR = QPMS_NORMALISATION_TAYLOR
|
||||
TAYLOR_CS = QPMS_NORMALISATION_TAYLOR_CS
|
||||
|
||||
try:
|
||||
class DebugFlags(enum.IntFlag): # Should be IntFlag if python version >= 3.6
|
||||
MISC = QPMS_DBGMSG_MISC
|
||||
THREADS = QPMS_DBGMSG_THREADS
|
||||
has_IntFlag = True
|
||||
except AttributeError: # For old versions of enum, use IntEnum instead
|
||||
class DebugFlags(enum.IntEnum):
|
||||
MISC = QPMS_DBGMSG_MISC
|
||||
THREADS = QPMS_DBGMSG_THREADS
|
||||
has_IntFlag = False
|
||||
|
||||
def dbgmsg_enable(qpms_dbgmsg_flags types):
|
||||
flags = qpms_dbgmsg_enable(types)
|
||||
return DebugFlags(flags) if has_IntFlag else flags
|
||||
def dbgmsg_disable(qpms_dbgmsg_flags types):
|
||||
flags = qpms_dbgmsg_disable(types)
|
||||
return DebugFlags(flags) if has_IntFlag else flags
|
||||
def dbgmsg_active():
|
||||
flags = qpms_dbgmsg_enable(<qpms_dbgmsg_flags>0)
|
||||
return DebugFlags(flags) if has_IntFlag else flags
|
||||
|
||||
import math # for copysign in crep methods
|
||||
#import re # TODO for crep methods?
|
||||
|
||||
|
|
|
@ -87,6 +87,14 @@ cdef extern from "qpms_types.h":
|
|||
bint owns_m # FIXME in fact bool
|
||||
# maybe more if needed
|
||||
|
||||
cdef extern from "qpms_error.h":
|
||||
ctypedef enum qpms_dbgmsg_flags:
|
||||
QPMS_DBGMSG_MISC
|
||||
QPMS_DBGMSG_THREADS
|
||||
qpms_dbgmsg_flags qpms_dbgmsg_enable(qpms_dbgmsg_flags types)
|
||||
qpms_dbgmsg_flags qpms_dbgmsg_disable(qpms_dbgmsg_flags types)
|
||||
|
||||
|
||||
cdef extern from "indexing.h":
|
||||
qpms_uvswfi_t qpms_tmn2uvswfi(qpms_vswf_type_t t, qpms_m_t m, qpms_l_t n)
|
||||
qpms_errno_t qpms_uvswfi2tmn(qpms_uvswfi_t u, qpms_vswf_type_t* t, qpms_m_t* m, qpms_l_t* n)
|
||||
|
|
|
@ -25,9 +25,26 @@ void qpms_pr_debug_at_flf(const char *filename, unsigned int linenum,
|
|||
// const char *fmt, ...);
|
||||
|
||||
|
||||
typedef enum {
|
||||
QPMS_DBGMSG_MISC = 1,
|
||||
QPMS_DBGMSG_THREADS = 2 // Multithreading-related debug messages.
|
||||
} qpms_dbgmsg_flags;
|
||||
|
||||
void qpms_debug_at_flf(const char *filename, unsigned int linenum,
|
||||
const char *func,
|
||||
qpms_dbgmsg_flags type,
|
||||
const char *fmt, ...);
|
||||
|
||||
extern qpms_dbgmsg_flags qpms_dbgmsg_enabled;
|
||||
|
||||
qpms_dbgmsg_flags qpms_dbgmsg_disable(qpms_dbgmsg_flags types);
|
||||
qpms_dbgmsg_flags qpms_dbgmsg_enable(qpms_dbgmsg_flags types);
|
||||
|
||||
|
||||
|
||||
#define QPMS_WARN(msg, ...) qpms_warn_at_flf(__FILE__,__LINE__,__func__,msg, ##__VA_ARGS__)
|
||||
|
||||
#define QPMS_DEBUG(msg, ...) qpms_pr_debug_at_flf(__FILE__,__LINE__,__func__,msg, ##__VA_ARGS__)
|
||||
#define QPMS_DEBUG(type, msg, ...) qpms_debug_at_flf(__FILE__,__LINE__,__func__,type,msg, ##__VA_ARGS__)
|
||||
|
||||
#define QPMS_CRASHING_MALLOC(pointer, size) {(pointer) = malloc(size); if(!pointer && (size)) qpms_pr_debug_at_flf(__FILE__,__LINE__,__func__, "Allocation of %zd bytes for " #pointer " failed.", (size_t) (size));}
|
||||
|
||||
|
|
|
@ -1427,16 +1427,16 @@ complex double *qpms_scatsys_build_modeproblem_matrix_irrep_packed_parallelR(
|
|||
long nthreads;
|
||||
if (qpms_scatsystem_nthreads_override > 0) {
|
||||
nthreads = qpms_scatsystem_nthreads_override;
|
||||
QPMS_WARN("Using overriding value of %ld thread(s).",
|
||||
QPMS_DEBUG(QPMS_DBGMSG_THREADS, "Using overriding value of %ld thread(s).",
|
||||
nthreads);
|
||||
} else {
|
||||
nthreads = sysconf(_SC_NPROCESSORS_ONLN);
|
||||
if (nthreads < 1) {
|
||||
QPMS_WARN("_SC_NPROCESSORS_ONLN returned %ld, using %ld thread(s) instead.",
|
||||
QPMS_DEBUG(QPMS_DBGMSG_THREADS, "_SC_NPROCESSORS_ONLN returned %ld, using %ld thread(s) instead.",
|
||||
nthreads, qpms_scatsystem_nthreads_default);
|
||||
nthreads = qpms_scatsystem_nthreads_default;
|
||||
} else {
|
||||
QPMS_DEBUG("_SC_NRPOCESSORS_ONLN returned %ld.", nthreads);
|
||||
QPMS_DEBUG(QPMS_DBGMSG_THREADS, "_SC_NRPOCESSORS_ONLN returned %ld.", nthreads);
|
||||
}
|
||||
}
|
||||
pthread_t thread_ids[nthreads];
|
||||
|
|
Loading…
Reference in New Issue