mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-22 13:33:56 +03:00
pid1: use LOG_DEBUG/INFO/NOTICE for unit resource consumption message
We now log at LOG_INFO for any unit. Let's vary the log level a bit, so that for normal short lived-units (less than 1 sec CPU), we only log if debugging is enabled.
This commit is contained in:
parent
49139a5d92
commit
37109b856a
@ -57,6 +57,16 @@
|
||||
#include "user-util.h"
|
||||
#include "virt.h"
|
||||
|
||||
/* Thresholds for logging at INFO level about resource consumption */
|
||||
#define MENTIONWORTHY_CPU_NSEC (1 * NSEC_PER_SEC)
|
||||
#define MENTIONWORTHY_IO_BYTES (1024 * 1024ULL)
|
||||
#define MENTIONWORTHY_IP_BYTES (0ULL)
|
||||
|
||||
/* Thresholds for logging at INFO level about resource consumption */
|
||||
#define NOTICEWORTHY_CPU_NSEC (10*60 * NSEC_PER_SEC) /* 10 minutes */
|
||||
#define NOTICEWORTHY_IO_BYTES (10 * 1024 * 1024ULL) /* 10 MB */
|
||||
#define NOTICEWORTHY_IP_BYTES (128 * 1024 * 1024ULL) /* 128 MB */
|
||||
|
||||
const UnitVTable * const unit_vtable[_UNIT_TYPE_MAX] = {
|
||||
[UNIT_SERVICE] = &service_vtable,
|
||||
[UNIT_SOCKET] = &socket_vtable,
|
||||
@ -2138,10 +2148,19 @@ void unit_trigger_notify(Unit *u) {
|
||||
UNIT_VTABLE(other)->trigger_notify(other, u);
|
||||
}
|
||||
|
||||
static int raise_level(int log_level, bool condition_info, bool condition_notice) {
|
||||
if (condition_notice && log_level > LOG_NOTICE)
|
||||
return LOG_NOTICE;
|
||||
if (condition_info && log_level > LOG_INFO)
|
||||
return LOG_INFO;
|
||||
return log_level;
|
||||
}
|
||||
|
||||
static int unit_log_resources(Unit *u) {
|
||||
struct iovec iovec[1 + _CGROUP_IP_ACCOUNTING_METRIC_MAX + _CGROUP_IO_ACCOUNTING_METRIC_MAX + 4];
|
||||
bool any_traffic = false, have_ip_accounting = false, any_io = false, have_io_accounting = false;
|
||||
_cleanup_free_ char *igress = NULL, *egress = NULL, *rr = NULL, *wr = NULL;
|
||||
int log_level = LOG_DEBUG; /* May be raised if resources consumed over a treshold */
|
||||
size_t n_message_parts = 0, n_iovec = 0;
|
||||
char* message_parts[1 + 2 + 2 + 1], *t;
|
||||
nsec_t nsec = NSEC_INFINITY;
|
||||
@ -2187,6 +2206,10 @@ static int unit_log_resources(Unit *u) {
|
||||
}
|
||||
|
||||
message_parts[n_message_parts++] = t;
|
||||
|
||||
log_level = raise_level(log_level,
|
||||
nsec > NOTICEWORTHY_CPU_NSEC,
|
||||
nsec > MENTIONWORTHY_CPU_NSEC);
|
||||
}
|
||||
|
||||
for (CGroupIOAccountingMetric k = 0; k < _CGROUP_IO_ACCOUNTING_METRIC_MAX; k++) {
|
||||
@ -2227,6 +2250,11 @@ static int unit_log_resources(Unit *u) {
|
||||
goto finish;
|
||||
}
|
||||
}
|
||||
|
||||
if (IN_SET(k, CGROUP_IO_READ_BYTES, CGROUP_IO_WRITE_BYTES))
|
||||
log_level = raise_level(log_level,
|
||||
value > MENTIONWORTHY_IO_BYTES,
|
||||
value > NOTICEWORTHY_IO_BYTES);
|
||||
}
|
||||
|
||||
if (have_io_accounting) {
|
||||
@ -2287,6 +2315,11 @@ static int unit_log_resources(Unit *u) {
|
||||
goto finish;
|
||||
}
|
||||
}
|
||||
|
||||
if (IN_SET(m, CGROUP_IP_INGRESS_BYTES, CGROUP_IP_EGRESS_BYTES))
|
||||
log_level = raise_level(log_level,
|
||||
value > MENTIONWORTHY_IP_BYTES,
|
||||
value > NOTICEWORTHY_IP_BYTES);
|
||||
}
|
||||
|
||||
if (have_ip_accounting) {
|
||||
@ -2343,7 +2376,7 @@ static int unit_log_resources(Unit *u) {
|
||||
t = strjoina(u->manager->invocation_log_field, u->invocation_id_string);
|
||||
iovec[n_iovec + 3] = IOVEC_MAKE_STRING(t);
|
||||
|
||||
log_struct_iovec(LOG_INFO, iovec, n_iovec + 4);
|
||||
log_struct_iovec(log_level, iovec, n_iovec + 4);
|
||||
r = 0;
|
||||
|
||||
finish:
|
||||
|
Loading…
Reference in New Issue
Block a user