summaryrefslogtreecommitdiff
path: root/src/core/dbus-unit.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-03-01 16:24:19 +0100
committerLennart Poettering <lennart@poettering.net>2015-03-02 12:15:25 +0100
commit5ad096b3f1331b175340129a8c9a5a9d711e5415 (patch)
tree41896760dde9b0ca2d45d04484c4a2308a600b0e /src/core/dbus-unit.c
parent606303a93ea52a70ebba55bb3152820e630f2164 (diff)
core: expose consumed CPU time per unit
This adds support for showing the accumulated consumed CPU time per-unit in the "systemctl status" output. The property is also readable via the bus.
Diffstat (limited to 'src/core/dbus-unit.c')
-rw-r--r--src/core/dbus-unit.c42
1 files changed, 28 insertions, 14 deletions
diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c
index 0ff9a01e11..af7dc26241 100644
--- a/src/core/dbus-unit.c
+++ b/src/core/dbus-unit.c
@@ -661,30 +661,43 @@ static int property_get_current_memory(
void *userdata,
sd_bus_error *error) {
- Unit *u = userdata;
uint64_t sz = (uint64_t) -1;
+ Unit *u = userdata;
int r;
assert(bus);
assert(reply);
assert(u);
- if (u->cgroup_path &&
- (u->cgroup_realized_mask & CGROUP_MEMORY)) {
- _cleanup_free_ char *v = NULL;
+ r = unit_get_memory_current(u, &sz);
+ if (r < 0 && r != -ENODATA)
+ log_unit_warning_errno(u->id, r, "Failed to get memory.usage_in_bytes attribute: %m");
- 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");
+ return sd_bus_message_append(reply, "t", sz);
+}
- 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");
- }
- }
+static int property_get_cpu_usage(
+ sd_bus *bus,
+ const char *path,
+ const char *interface,
+ const char *property,
+ sd_bus_message *reply,
+ void *userdata,
+ sd_bus_error *error) {
- return sd_bus_message_append(reply, "t", sz);
+ nsec_t ns = (nsec_t) -1;
+ Unit *u = userdata;
+ int r;
+
+ assert(bus);
+ assert(reply);
+ assert(u);
+
+ r = unit_get_cpu_usage(u, &ns);
+ if (r < 0 && r != -ENODATA)
+ log_unit_warning_errno(u->id, r, "Failed to get cpuacct.usage attribute: %m");
+
+ return sd_bus_message_append(reply, "t", ns);
}
const sd_bus_vtable bus_unit_cgroup_vtable[] = {
@@ -692,6 +705,7 @@ const sd_bus_vtable bus_unit_cgroup_vtable[] = {
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_PROPERTY("CPUUsageNSec", "t", property_get_cpu_usage, 0, 0),
SD_BUS_VTABLE_END
};