Files
systemd/src/analyze/analyze-malloc.c
T
Luca Boccassi f50535afad analyze: add 'malloc' verb to dump malloc_info()
Gets the memory state of the manager:

root@image:~# systemd-analyze malloc
<malloc version=1>
<heap nr=0>
<sizes>
  <size from=33 to=33 total=396 count=12/>
  <unsorted from=20385 to=20385 total=20385 count=1/>
</sizes>
<total type=fast count=0 size=0/>
<total type=rest count=14 size=36589/>
<system type=current size=1691648/>
<system type=max size=1839104/>
<aspace type=total size=1691648/>
<aspace type=mprotect size=1691648/>
</heap>
<total type=fast count=0 size=0/>
<total type=rest count=14 size=36589/>
<total type=mmap count=0 size=0/>
<system type=current size=1691648/>
<system type=max size=1839104/>
<aspace type=total size=1691648/>
<aspace type=mprotect size=1691648/>
</malloc>
2023-02-23 18:59:06 +00:00

64 lines
2.2 KiB
C

/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include "sd-bus.h"
#include "analyze-malloc.h"
#include "analyze.h"
#include "bus-error.h"
#include "bus-internal.h"
static int dump_malloc_info(sd_bus *bus, char *service) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
int r;
assert(bus);
assert(service);
r = sd_bus_call_method(bus,
service,
"/org/freedesktop/MemoryAllocation1",
"org.freedesktop.MemoryAllocation1",
"GetMallocInfo",
&error,
&reply,
NULL);
if (r < 0)
return log_error_errno(r, "Failed to call GetMallocInfo on '%s': %s", service, bus_error_message(&error, r));
return dump_fd_reply(reply);
}
int verb_malloc(int argc, char *argv[], void *userdata) {
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
char **services = STRV_MAKE("org.freedesktop.systemd1");
int r;
if (!strv_isempty(strv_skip(argv, 1))) {
services = strv_skip(argv, 1);
STRV_FOREACH(service, services)
if (!service_name_is_valid(*service))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "D-Bus service name '%s' is not valid.", *service);
}
r = acquire_bus(&bus, NULL);
if (r < 0)
return bus_log_connect_error(r, arg_transport);
r = sd_bus_can_send(bus, SD_BUS_TYPE_UNIX_FD);
if (r < 0)
return log_error_errno(r, "Unable to determine if bus connection supports fd passing: %m");
if (r == 0)
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "Unable to receive FDs over D-Bus.");
pager_open(arg_pager_flags);
STRV_FOREACH(service, services) {
r = dump_malloc_info(bus, *service);
if (r < 0)
return r;
}
return EXIT_SUCCESS;
}