summaryrefslogtreecommitdiff
path: root/cmds/dumpstate/dumpstate.cpp
diff options
context:
space:
mode:
author Steven Moreland <smoreland@google.com> 2025-01-10 22:24:57 +0000
committer Steven Moreland <smoreland@google.com> 2025-01-10 14:28:44 -0800
commit0d564d5f773989a3d90c186ac6278655c17d8906 (patch)
tree8cd43a6612ed4361981481a9b4cb859e928ca71f /cmds/dumpstate/dumpstate.cpp
parent33a6e89aa8ebde305ea3bc408d3b5b96756cacd6 (diff)
dumpstate: notes on usage
This is what a few old maintainers of dumpstate told me when I made changes to it back ~2016 or so: always exec stuff, never link it. Well, there have been quite a few divergences from this, and it's come up in a couple of reviews I've seen here. So, I've added notes on this into the readme and comments on some of the worst offender. For instance, we could have probably avoided a lot of this async/exec logic for these custom cases if we used the standard run command with timeout stuff. Bug: N/A Test: N/A Change-Id: I4c33f3042ca16d4433082b8d78ebdd29cb75f0b3
Diffstat (limited to 'cmds/dumpstate/dumpstate.cpp')
-rw-r--r--cmds/dumpstate/dumpstate.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp
index bb0ffe650b..c24bee12be 100644
--- a/cmds/dumpstate/dumpstate.cpp
+++ b/cmds/dumpstate/dumpstate.cpp
@@ -128,6 +128,9 @@ using android::os::dumpstate::PropertiesHelper;
using android::os::dumpstate::TaskQueue;
using android::os::dumpstate::WaitForTask;
+// BAD - See README.md: "Dumpstate philosophy: exec not link"
+// Do not add more complicated variables here, prefer to execute only. Don't link more code here.
+
// Keep in sync with
// frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java
static const int TRACE_DUMP_TIMEOUT_MS = 10000; // 10 seconds
@@ -1266,6 +1269,8 @@ static void DumpKernelMemoryAllocations() {
}
}
+// BAD - See README.md: "Dumpstate philosophy: exec not link"
+// This should all be moved into a separate binary rather than have complex logic here.
static Dumpstate::RunStatus RunDumpsysTextByPriority(const std::string& title, int priority,
std::chrono::milliseconds timeout,
std::chrono::milliseconds service_timeout) {
@@ -1346,6 +1351,8 @@ static Dumpstate::RunStatus RunDumpsysTextNormalPriority(const std::string& titl
service_timeout);
}
+// BAD - See README.md: "Dumpstate philosophy: exec not link"
+// This should all be moved into a separate binary rather than have complex logic here.
static Dumpstate::RunStatus RunDumpsysProto(const std::string& title, int priority,
std::chrono::milliseconds timeout,
std::chrono::milliseconds service_timeout) {
@@ -1427,6 +1434,8 @@ static Dumpstate::RunStatus RunDumpsysNormal() {
* Dumpstate can pick up later and output to the bugreport. Using STDOUT_FILENO
* if it's not running in the parallel task.
*/
+// BAD - See README.md: "Dumpstate philosophy: exec not link"
+// This should all be moved into a separate binary rather than have complex logic here.
static void DumpHals(int out_fd = STDOUT_FILENO) {
RunCommand("HARDWARE HALS", {"lshal", "--all", "--types=all"},
CommandOptions::WithTimeout(10).AsRootIfAvailable().Build(),
@@ -1483,6 +1492,9 @@ static void DumpHals(int out_fd = STDOUT_FILENO) {
}
}
+// BAD - See README.md: "Dumpstate philosophy: exec not link"
+// This should all be moved into a separate binary rather than have complex logic here.
+//
// Dump all of the files that make up the vendor interface.
// See the files listed in dumpFileList() for the latest list of files.
static void DumpVintf() {
@@ -1512,6 +1524,8 @@ static void DumpExternalFragmentationInfo() {
printf("------ EXTERNAL FRAGMENTATION INFO ------\n");
std::ifstream ifs("/proc/buddyinfo");
auto unusable_index_regex = std::regex{"Node\\s+([0-9]+),\\s+zone\\s+(\\S+)\\s+(.*)"};
+ // BAD - See README.md: "Dumpstate philosophy: exec not link"
+ // This should all be moved into a separate binary rather than have complex logic here.
for (std::string line; std::getline(ifs, line);) {
std::smatch match_results;
if (std::regex_match(line, match_results, unusable_index_regex)) {
@@ -2452,6 +2466,8 @@ static dumpstate_hal_aidl::IDumpstateDevice::DumpstateMode GetDumpstateHalModeAi
return dumpstate_hal_aidl::IDumpstateDevice::DumpstateMode::DEFAULT;
}
+// BAD - See README.md: "Dumpstate philosophy: exec not link"
+// This should all be moved into a separate binary rather than have complex logic here.
static void DoDumpstateBoardHidl(
const sp<dumpstate_hal_hidl_1_0::IDumpstateDevice> dumpstate_hal_1_0,
const std::vector<::ndk::ScopedFileDescriptor>& dumpstate_fds,