~lttng/lttng-ust/lttng-ust

« back to all changes in this revision

Viewing changes to src/common/logging.h

  • Committer: Mathieu Desnoyers
  • Author(s): Michael Jeanson
  • Date: 2021-05-14 21:02:43 UTC
  • Revision ID: git-v1:9ff107a9504abe331c714a0301f0f4726f01cf41
Add critical log level

Rename the unused BUG() macro to CRIT() to signify an error that can't
be recovered from. Add a new environment variable
LTTNG_UST_ABORT_ON_CRITICAL that when set will abort() on a critical log
statement.

Change-Id: Ib3384a66b7efa4004677b3c153f86cb97b06a091
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
        LTTNG_UST_LOG_LEVEL_DEBUG,
30
30
};
31
31
 
 
32
enum lttng_ust_log_critical_action {
 
33
        LTTNG_UST_LOG_CRITICAL_ACTION_UNKNOWN = 0,
 
34
        LTTNG_UST_LOG_CRITICAL_ACTION_NONE,
 
35
        LTTNG_UST_LOG_CRITICAL_ACTION_ABORT,
 
36
};
 
37
 
32
38
extern int lttng_ust_log_level                  /* enum lttng_ust_log_level */
33
39
        __attribute__((visibility("hidden")));
34
40
 
 
41
extern int lttng_ust_log_critical_action                /* enum lttng_ust_log_critical_action */
 
42
        __attribute__((visibility("hidden")));
 
43
 
35
44
/*
36
45
 * Initialize the global log level from the "LTTNG_UST_DEBUG" environment
37
 
 * variable.
 
46
 * variable and the global log critical action from "LTTNG_UST_ABORT_ON_CRITICAL".
38
47
 *
39
48
 * This could end up being called concurrently by multiple threads but doesn't
40
49
 * require a mutex since the input is invariant across threads and the result
41
50
 * will be the same.
42
 
 *
43
 
 * Return the current log level to save the caller a second read of the global
44
 
 * log level.
45
51
 */
46
 
int lttng_ust_logging_init(void)
 
52
void lttng_ust_logging_init(void)
47
53
        __attribute__((visibility("hidden")));
48
54
 
49
55
#ifdef LTTNG_UST_DEBUG
61
67
        current_log_level = CMM_LOAD_SHARED(lttng_ust_log_level);
62
68
 
63
69
        /* If the global log level is unknown, lazy-initialize it. */
64
 
        if (caa_unlikely(current_log_level == LTTNG_UST_LOG_LEVEL_UNKNOWN))
65
 
                current_log_level = lttng_ust_logging_init();
 
70
        if (caa_unlikely(current_log_level == LTTNG_UST_LOG_LEVEL_UNKNOWN)) {
 
71
                lttng_ust_logging_init();
 
72
                current_log_level = CMM_LOAD_SHARED(lttng_ust_log_level);
 
73
        }
66
74
 
67
75
        return current_log_level == LTTNG_UST_LOG_LEVEL_DEBUG;
68
76
}
69
77
#endif /* #ifdef LTTNG_UST_DEBUG */
70
78
 
 
79
#ifdef LTTNG_UST_ABORT_ON_CRITICAL
 
80
static inline
 
81
bool lttng_ust_logging_abort_on_critical_enabled(void)
 
82
{
 
83
        return true;
 
84
}
 
85
#else /* #ifdef LTTNG_UST_ABORT_ON_CRITICAL */
 
86
static inline
 
87
bool lttng_ust_logging_abort_on_critical_enabled(void)
 
88
{
 
89
        int current_log_critical_action;
 
90
 
 
91
        current_log_critical_action = CMM_LOAD_SHARED(lttng_ust_log_critical_action);
 
92
 
 
93
        /* If the global log critical action is unknown, lazy-initialize it. */
 
94
        if (caa_unlikely(current_log_critical_action == LTTNG_UST_LOG_CRITICAL_ACTION_UNKNOWN)) {
 
95
                lttng_ust_logging_init();
 
96
                current_log_critical_action = CMM_LOAD_SHARED(lttng_ust_log_critical_action);
 
97
        }
 
98
 
 
99
        return current_log_critical_action == LTTNG_UST_LOG_CRITICAL_ACTION_ABORT;
 
100
}
 
101
#endif /* #ifdef LTTNG_UST_ABORT_ON_CRITICAL */
 
102
 
71
103
/*
72
 
 * The default component for error messages.
 
104
 * The default component for log statements.
73
105
 */
74
106
#ifndef UST_COMPONENT
75
107
#define UST_COMPONENT libust
113
145
#define DBG_raw(fmt, args...)   sigsafe_print_err(fmt, ## args)
114
146
#define WARN(fmt, args...)      ERRMSG("Warning: " fmt, ## args)
115
147
#define ERR(fmt, args...)       ERRMSG("Error: " fmt, ## args)
116
 
#define BUG(fmt, args...)       ERRMSG("BUG: " fmt, ## args)
 
148
#define CRIT(fmt, args...)                                              \
 
149
        do {                                                            \
 
150
                ERRMSG("Critical: " fmt, ## args);                      \
 
151
                if (lttng_ust_logging_abort_on_critical_enabled()) {    \
 
152
                        abort();                                        \
 
153
                }                                                       \
 
154
        } while(0)
117
155
 
118
156
#if !defined(__GLIBC__) || ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !defined(_GNU_SOURCE))
119
157
/*