File: debug.h

package info (click to toggle)
mpich 4.3.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 101,184 kB
  • sloc: ansic: 1,040,629; cpp: 82,270; javascript: 40,763; perl: 27,933; python: 16,041; sh: 14,676; xml: 14,418; f90: 12,916; makefile: 9,270; fortran: 8,046; java: 4,635; asm: 324; ruby: 103; awk: 27; lisp: 19; php: 8; sed: 4
file content (95 lines) | stat: -rw-r--r-- 2,354 bytes parent folder | download | duplicates (20)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
 * Copyright © 2009 CNRS
 * Copyright © 2009-2020 Inria.  All rights reserved.
 * Copyright © 2009, 2011 Université Bordeaux
 * Copyright © 2011 Cisco Systems, Inc.  All rights reserved.
 * See COPYING in top-level directory.
 */

/* The configuration file */

#ifndef HWLOC_DEBUG_H
#define HWLOC_DEBUG_H

#include "private/autogen/config.h"
#include "private/misc.h"

#ifdef HWLOC_DEBUG
#include <stdarg.h>
#include <stdio.h>
#endif

#ifdef ANDROID
extern void JNIDebug(char *text);
#endif

/* Compile-time assertion */
#define HWLOC_BUILD_ASSERT(condition) ((void)sizeof(char[1 - 2*!(condition)]))

#ifdef HWLOC_DEBUG
static __hwloc_inline int hwloc_debug_enabled(void)
{
  static int checked = 0;
  static int enabled = 1;
  if (!checked) {
    const char *env = getenv("HWLOC_DEBUG_VERBOSE");
    if (env)
      enabled = atoi(env);
    if (enabled)
      fprintf(stderr, "hwloc verbose debug enabled, may be disabled with HWLOC_DEBUG_VERBOSE=0 in the environment.\n");
    checked = 1;
  }
  return enabled;
}
#endif

static __hwloc_inline void hwloc_debug(const char *s __hwloc_attribute_unused, ...) __hwloc_attribute_format(printf, 1, 2);
static __hwloc_inline void hwloc_debug(const char *s __hwloc_attribute_unused, ...)
{
#ifdef HWLOC_DEBUG
  if (hwloc_debug_enabled()) {
#ifdef ANDROID
    char buffer[256];
#endif
    va_list ap;
    va_start(ap, s);
#ifdef ANDROID
    vsprintf(buffer, s, ap);
    JNIDebug(buffer);
#else
    vfprintf(stderr, s, ap);
#endif
    va_end(ap);
  }
#endif
}

#ifdef HWLOC_DEBUG
#define hwloc_debug_bitmap(fmt, bitmap) do { \
if (hwloc_debug_enabled()) { \
  char *s; \
  hwloc_bitmap_asprintf(&s, bitmap); \
  hwloc_debug(fmt, s); \
  free(s); \
} } while (0)
#define hwloc_debug_1arg_bitmap(fmt, arg1, bitmap) do { \
if (hwloc_debug_enabled()) { \
  char *s; \
  hwloc_bitmap_asprintf(&s, bitmap); \
  hwloc_debug(fmt, arg1, s); \
  free(s); \
} } while (0)
#define hwloc_debug_2args_bitmap(fmt, arg1, arg2, bitmap) do { \
if (hwloc_debug_enabled()) { \
  char *s; \
  hwloc_bitmap_asprintf(&s, bitmap); \
  hwloc_debug(fmt, arg1, arg2, s); \
  free(s); \
} } while (0)
#else
#define hwloc_debug_bitmap(s, bitmap) do { } while(0)
#define hwloc_debug_1arg_bitmap(s, arg1, bitmap) do { } while(0)
#define hwloc_debug_2args_bitmap(s, arg1, arg2, bitmap) do { } while(0)
#endif

#endif /* HWLOC_DEBUG_H */