Skip to content

Commit

Permalink
Check logging verbosity before evaluating format parameters
Browse files Browse the repository at this point in the history
Vast majority of diagnostic logging from mce is not emitted to journal
on default verbosity. Spending cpu time evaluating format parameters
and pushing them to stack just to be discarded makes no sense.

Now verbosity level is checked 1st and potentially time consuming
parameter evaluation is done only if the message is going to be
emitted to the journal.

[mce] Check logging verbosity before evaluating format parameters. Fixes JB#22310
  • Loading branch information
spiiroin committed Aug 26, 2014
1 parent 20477bd commit 37b4453
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
7 changes: 6 additions & 1 deletion mce-log.h
Expand Up @@ -54,7 +54,12 @@ void mce_log_file(loglevel_t loglevel, const char *const file,
const char *const function, const char *const fmt, ...)
__attribute__((format(printf, 4, 5)));
#define mce_log_raw(__loglevel, __fmt, __args...) mce_log_file(__loglevel, NULL, NULL, __fmt , ## __args)
#define mce_log(__loglevel, __fmt, __args...) mce_log_file(__loglevel, __FILE__, __FUNCTION__, __fmt , ## __args)
#define mce_log(__loglevel, __fmt, __args...) \
do {\
if( mce_log_p(__loglevel) )\
mce_log_file(__loglevel, __FILE__, __FUNCTION__, __fmt , ## __args); \
} while(0)

void mce_log_set_verbosity(const int verbosity);
void mce_log_open(const char *const name, const int facility, const int type);
void mce_log_close(void);
Expand Down
12 changes: 12 additions & 0 deletions tools/evdev_trace.c
Expand Up @@ -228,6 +228,18 @@ mce_log_file(loglevel_t loglevel,
free(msg);
}

/** Stub for compatibility with mce-log.h
*/
int mce_log_p_(const loglevel_t loglevel,
const char *const file,
const char *const func)
{
(void)loglevel;
(void)file;
(void)func;

return true;
}
/** Provide runtime usage information
*/
static void usage(void)
Expand Down

0 comments on commit 37b4453

Please sign in to comment.