summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Alessio Balsini <balsini@google.com> 2024-12-10 15:31:57 +0000
committer Alessio Balsini <balsini@google.com> 2024-12-27 18:28:58 +0000
commit9e332a7f3c80166e612f86a3ed99174ea3486728 (patch)
tree1709a23f406de8f74df525927100e4ad61efd8d3
parentf408a472018aa3549d4dbf8f5aba06988b599d30 (diff)
Add kernel memory allocations to bugreport
Add the contents of /proc/allocinfo to the bugreport. This file shows the current snapshot of all the memory allocated and the number of allocations associated with kernel code locations. The collection and processing of /proc/allocinfo is done by calling the alloctop tool, to return the top entries that allocated most memory. The kernel memory allocations entry is added to the bugreport only if the /proc/allocinfo file exists. As shown below, a rough measurement of the execution time of this command on Cuttlefish shows an average of ~43 ms. On the same device, the total number of characters generated by the command is 6704, so ~6.6 KiB uncompressed. ``` vsoc_x86_64:/ # time for i in $(seq 1 1000); do alloctop --once --sort s --min 1 --lines 100 > /dev/null done 0m42.25s real 0m00.17s user 0m03.63s system vsoc_x86_64:/ # alloctop --once --sort s --min 1 --lines 100 | wc -c 6704 ``` Bug: 384777823 Test: adb shell dumpstate Change-Id: Ib8f7eeebe5ad88fc608e2d84582ad32e1b069985 Signed-off-by: Alessio Balsini <balsini@google.com>
-rw-r--r--cmds/dumpstate/Android.bp1
-rw-r--r--cmds/dumpstate/dumpstate.cpp11
2 files changed, 12 insertions, 0 deletions
diff --git a/cmds/dumpstate/Android.bp b/cmds/dumpstate/Android.bp
index b22cc2a508..be96306f55 100644
--- a/cmds/dumpstate/Android.bp
+++ b/cmds/dumpstate/Android.bp
@@ -128,6 +128,7 @@ cc_binary {
"main.cpp",
],
required: [
+ "alloctop",
"atrace",
"bugreport_procdump",
"dmabuf_dump",
diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp
index 5e83e3337f..bb0ffe650b 100644
--- a/cmds/dumpstate/dumpstate.cpp
+++ b/cmds/dumpstate/dumpstate.cpp
@@ -1257,6 +1257,15 @@ static void DumpIpAddrAndRules() {
RunCommand("IP RULES v6", {"ip", "-6", "rule", "show"});
}
+static void DumpKernelMemoryAllocations() {
+ if (!access("/proc/allocinfo", F_OK)) {
+ // Print the top 100 biggest memory allocations of at least one byte.
+ // The output is sorted by size, descending.
+ RunCommand("KERNEL MEMORY ALLOCATIONS",
+ {"alloctop", "--once", "--sort", "s", "--min", "1", "--lines", "100"});
+ }
+}
+
static Dumpstate::RunStatus RunDumpsysTextByPriority(const std::string& title, int priority,
std::chrono::milliseconds timeout,
std::chrono::milliseconds service_timeout) {
@@ -1766,6 +1775,8 @@ Dumpstate::RunStatus Dumpstate::dumpstate() {
DoKmsg();
+ DumpKernelMemoryAllocations();
+
DumpShutdownCheckpoints();
DumpIpAddrAndRules();