]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: add log_get_max_level check optimization in log_unit_full
authorLuca Boccassi <luca.boccassi@microsoft.com>
Tue, 21 Apr 2020 16:23:21 +0000 (17:23 +0100)
committerLuca Boccassi <luca.boccassi@microsoft.com>
Tue, 21 Apr 2020 17:05:24 +0000 (18:05 +0100)
Just as log_full already does, check if the log level would result in
logging immediately in the macro in order to avoid doing
unnecessary work that adds up in hot spots.

src/core/unit.h

index 2e103f7ab294d07fa5e5aad9dbccd1ffe9f74bc1..e38871a97c0d02599b3e2bd55304f15f43a992a9 100644 (file)
@@ -883,8 +883,9 @@ int unit_can_clean(Unit *u, ExecCleanMask *ret_mask);
 #define log_unit_full(unit, level, error, ...)                          \
         ({                                                              \
                 const Unit *_u = (unit);                                \
-                _u ? log_object_internal(level, error, PROJECT_FILE, __LINE__, __func__, _u->manager->unit_log_field, _u->id, _u->manager->invocation_log_field, _u->invocation_id_string, ##__VA_ARGS__) : \
-                        log_internal(level, error, PROJECT_FILE, __LINE__, __func__, ##__VA_ARGS__); \
+                (log_get_max_level() < LOG_PRI(level)) ? -ERRNO_VALUE(error) : \
+                        _u ? log_object_internal(level, error, PROJECT_FILE, __LINE__, __func__, _u->manager->unit_log_field, _u->id, _u->manager->invocation_log_field, _u->invocation_id_string, ##__VA_ARGS__) : \
+                                log_internal(level, error, PROJECT_FILE, __LINE__, __func__, ##__VA_ARGS__); \
         })
 
 #define log_unit_debug(unit, ...)   log_unit_full(unit, LOG_DEBUG, 0, ##__VA_ARGS__)