Skip to content

Commit 0d564d5

Browse files
author
Steven Moreland
committed
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
1 parent 33a6e89 commit 0d564d5

3 files changed

Lines changed: 35 additions & 5 deletions

File tree

cmds/dumpstate/Android.bp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,26 +83,28 @@ cc_defaults {
8383
"aconfig_lib_cc_static_link.defaults",
8484
"dumpstate_cflag_defaults",
8585
],
86+
// See README.md: "Dumpstate philosophy: exec not link"
87+
// Do not add things here - keep dumpstate as simple as possible and exec where possible.
8688
shared_libs: [
8789
"android.hardware.dumpstate@1.0",
8890
"android.hardware.dumpstate@1.1",
8991
"android.hardware.dumpstate-V1-ndk",
9092
"libziparchive",
9193
"libbase",
92-
"libbinder",
93-
"libbinder_ndk",
94+
"libbinder", // BAD: dumpstate should not link code directly, should only exec binaries
95+
"libbinder_ndk", // BAD: dumpstate should not link code directly, should only exec binaries
9496
"libcrypto",
9597
"libcutils",
9698
"libdebuggerd_client",
9799
"libdumpstateaidl",
98100
"libdumpstateutil",
99101
"libdumputils",
100102
"libhardware_legacy",
101-
"libhidlbase",
103+
"libhidlbase", // BAD: dumpstate should not link code directly, should only exec binaries
102104
"liblog",
103105
"libutils",
104-
"libvintf",
105-
"libbinderdebug",
106+
"libvintf", // BAD: dumpstate should not link code directly, should only exec binaries
107+
"libbinderdebug", // BAD: dumpstate should not link code directly, should only exec binaries
106108
"packagemanager_aidl-cpp",
107109
"server_configurable_flags",
108110
"device_policy_aconfig_flags_c_lib",

cmds/dumpstate/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ Example:
2121
mmm -j frameworks/native/cmds/dumpstate device/acme/secret_device/dumpstate/ hardware/interfaces/dumpstate
2222
```
2323

24+
## Dumpstate philosophy: exec not link
25+
26+
Never link code directly into dumpstate. Dumpstate should execute many
27+
binaries and collect the results. In general, code should fail hard fail fast,
28+
but dumpstate is the last to solve many Android bugs. Oftentimes, failures
29+
in core Android infrastructure or tools are issues that cause problems in
30+
bugreport directly, so bugreport should not rely on these tools working.
31+
We want dumpstate to have as minimal of code loaded in process so that
32+
only that core subset needs to be bugfree for bugreport to work. Even if
33+
many pieces of Android break, that should not prevent dumpstate from
34+
working.
35+
2436
## To build, deploy, and take a bugreport
2537

2638
```

cmds/dumpstate/dumpstate.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ using android::os::dumpstate::PropertiesHelper;
128128
using android::os::dumpstate::TaskQueue;
129129
using android::os::dumpstate::WaitForTask;
130130

131+
// BAD - See README.md: "Dumpstate philosophy: exec not link"
132+
// Do not add more complicated variables here, prefer to execute only. Don't link more code here.
133+
131134
// Keep in sync with
132135
// frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java
133136
static const int TRACE_DUMP_TIMEOUT_MS = 10000; // 10 seconds
@@ -1266,6 +1269,8 @@ static void DumpKernelMemoryAllocations() {
12661269
}
12671270
}
12681271

1272+
// BAD - See README.md: "Dumpstate philosophy: exec not link"
1273+
// This should all be moved into a separate binary rather than have complex logic here.
12691274
static Dumpstate::RunStatus RunDumpsysTextByPriority(const std::string& title, int priority,
12701275
std::chrono::milliseconds timeout,
12711276
std::chrono::milliseconds service_timeout) {
@@ -1346,6 +1351,8 @@ static Dumpstate::RunStatus RunDumpsysTextNormalPriority(const std::string& titl
13461351
service_timeout);
13471352
}
13481353

1354+
// BAD - See README.md: "Dumpstate philosophy: exec not link"
1355+
// This should all be moved into a separate binary rather than have complex logic here.
13491356
static Dumpstate::RunStatus RunDumpsysProto(const std::string& title, int priority,
13501357
std::chrono::milliseconds timeout,
13511358
std::chrono::milliseconds service_timeout) {
@@ -1427,6 +1434,8 @@ static Dumpstate::RunStatus RunDumpsysNormal() {
14271434
* Dumpstate can pick up later and output to the bugreport. Using STDOUT_FILENO
14281435
* if it's not running in the parallel task.
14291436
*/
1437+
// BAD - See README.md: "Dumpstate philosophy: exec not link"
1438+
// This should all be moved into a separate binary rather than have complex logic here.
14301439
static void DumpHals(int out_fd = STDOUT_FILENO) {
14311440
RunCommand("HARDWARE HALS", {"lshal", "--all", "--types=all"},
14321441
CommandOptions::WithTimeout(10).AsRootIfAvailable().Build(),
@@ -1483,6 +1492,9 @@ static void DumpHals(int out_fd = STDOUT_FILENO) {
14831492
}
14841493
}
14851494

1495+
// BAD - See README.md: "Dumpstate philosophy: exec not link"
1496+
// This should all be moved into a separate binary rather than have complex logic here.
1497+
//
14861498
// Dump all of the files that make up the vendor interface.
14871499
// See the files listed in dumpFileList() for the latest list of files.
14881500
static void DumpVintf() {
@@ -1512,6 +1524,8 @@ static void DumpExternalFragmentationInfo() {
15121524
printf("------ EXTERNAL FRAGMENTATION INFO ------\n");
15131525
std::ifstream ifs("/proc/buddyinfo");
15141526
auto unusable_index_regex = std::regex{"Node\\s+([0-9]+),\\s+zone\\s+(\\S+)\\s+(.*)"};
1527+
// BAD - See README.md: "Dumpstate philosophy: exec not link"
1528+
// This should all be moved into a separate binary rather than have complex logic here.
15151529
for (std::string line; std::getline(ifs, line);) {
15161530
std::smatch match_results;
15171531
if (std::regex_match(line, match_results, unusable_index_regex)) {
@@ -2452,6 +2466,8 @@ static dumpstate_hal_aidl::IDumpstateDevice::DumpstateMode GetDumpstateHalModeAi
24522466
return dumpstate_hal_aidl::IDumpstateDevice::DumpstateMode::DEFAULT;
24532467
}
24542468

2469+
// BAD - See README.md: "Dumpstate philosophy: exec not link"
2470+
// This should all be moved into a separate binary rather than have complex logic here.
24552471
static void DoDumpstateBoardHidl(
24562472
const sp<dumpstate_hal_hidl_1_0::IDumpstateDevice> dumpstate_hal_1_0,
24572473
const std::vector<::ndk::ScopedFileDescriptor>& dumpstate_fds,

0 commit comments

Comments
 (0)