summaryrefslogtreecommitdiff
path: root/src/core/dbus-unit.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-01-23 02:58:02 +0100
committerLennart Poettering <lennart@poettering.net>2015-01-23 03:00:15 +0100
commit934277fe6a26ff2a4da37059c70d84ab6a700781 (patch)
tree5fbd09d8a0933a565a6c3d393f74897afad49a9a /src/core/dbus-unit.c
parentda41abc52ca1f5965a22cc481a720328b987b335 (diff)
core: add a property that shows the current memory usage of a unit
This is exposed the memory.usage_in_bytes cgroup property on the bus, and makes "systemctl status" show it in its default output.
Diffstat (limited to 'src/core/dbus-unit.c')
-rw-r--r--src/core/dbus-unit.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c
index b968009938..fe876b3ffe 100644
--- a/src/core/dbus-unit.c
+++ b/src/core/dbus-unit.c
@@ -638,10 +638,46 @@ static int property_get_slice(
return sd_bus_message_append(reply, "s", unit_slice_name(u));
}
+static int property_get_current_memory(
+ sd_bus *bus,
+ const char *path,
+ const char *interface,
+ const char *property,
+ sd_bus_message *reply,
+ void *userdata,
+ sd_bus_error *error) {
+
+ Unit *u = userdata;
+ uint64_t sz = (uint64_t) -1;
+ int r;
+
+ assert(bus);
+ assert(reply);
+ assert(u);
+
+ if (u->cgroup_path &&
+ (u->cgroup_realized_mask & CGROUP_MEMORY)) {
+ _cleanup_free_ char *v = NULL;
+
+ r = cg_get_attribute("memory", u->cgroup_path, "memory.usage_in_bytes", &v);
+ if (r < 0 && r != -ENOENT)
+ log_unit_warning_errno(u->id, r, "Couldn't read memory.usage_in_bytes attribute: %m");
+
+ if (v) {
+ r = safe_atou64(v, &sz);
+ if (r < 0)
+ log_unit_warning_errno(u->id, r, "Failed to parse memory.usage_in_bytes attribute: %m");
+ }
+ }
+
+ return sd_bus_message_append(reply, "t", sz);
+}
+
const sd_bus_vtable bus_unit_cgroup_vtable[] = {
SD_BUS_VTABLE_START(0),
SD_BUS_PROPERTY("Slice", "s", property_get_slice, 0, 0),
SD_BUS_PROPERTY("ControlGroup", "s", NULL, offsetof(Unit, cgroup_path), 0),
+ SD_BUS_PROPERTY("MemoryCurrent", "t", property_get_current_memory, 0, 0),
SD_BUS_VTABLE_END
};