Skip to content

Commit c09f9fa

Browse files
Treehugger Robotandroid-build-merge-worker-robot
authored andcommitted
Merge "dumpstate: notes on usage" into main am: cbd1764 am: 77f0c55
Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/3446594 Change-Id: I64d356bbfc983ec1ac2cbf93bb01f6a62637bfad Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2 parents f9fc9e7 + 77f0c55 commit c09f9fa

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
@@ -1273,6 +1276,8 @@ static void DumpKernelMemoryAllocations() {
12731276
}
12741277
}
12751278

1279+
// BAD - See README.md: "Dumpstate philosophy: exec not link"
1280+
// This should all be moved into a separate binary rather than have complex logic here.
12761281
static Dumpstate::RunStatus RunDumpsysTextByPriority(const std::string& title, int priority,
12771282
std::chrono::milliseconds timeout,
12781283
std::chrono::milliseconds service_timeout) {
@@ -1353,6 +1358,8 @@ static Dumpstate::RunStatus RunDumpsysTextNormalPriority(const std::string& titl
13531358
service_timeout);
13541359
}
13551360

1361+
// BAD - See README.md: "Dumpstate philosophy: exec not link"
1362+
// This should all be moved into a separate binary rather than have complex logic here.
13561363
static Dumpstate::RunStatus RunDumpsysProto(const std::string& title, int priority,
13571364
std::chrono::milliseconds timeout,
13581365
std::chrono::milliseconds service_timeout) {
@@ -1434,6 +1441,8 @@ static Dumpstate::RunStatus RunDumpsysNormal() {
14341441
* Dumpstate can pick up later and output to the bugreport. Using STDOUT_FILENO
14351442
* if it's not running in the parallel task.
14361443
*/
1444+
// BAD - See README.md: "Dumpstate philosophy: exec not link"
1445+
// This should all be moved into a separate binary rather than have complex logic here.
14371446
static void DumpHals(int out_fd = STDOUT_FILENO) {
14381447
RunCommand("HARDWARE HALS", {"lshal", "--all", "--types=all"},
14391448
CommandOptions::WithTimeout(10).AsRootIfAvailable().Build(),
@@ -1490,6 +1499,9 @@ static void DumpHals(int out_fd = STDOUT_FILENO) {
14901499
}
14911500
}
14921501

1502+
// BAD - See README.md: "Dumpstate philosophy: exec not link"
1503+
// This should all be moved into a separate binary rather than have complex logic here.
1504+
//
14931505
// Dump all of the files that make up the vendor interface.
14941506
// See the files listed in dumpFileList() for the latest list of files.
14951507
static void DumpVintf() {
@@ -1519,6 +1531,8 @@ static void DumpExternalFragmentationInfo() {
15191531
printf("------ EXTERNAL FRAGMENTATION INFO ------\n");
15201532
std::ifstream ifs("/proc/buddyinfo");
15211533
auto unusable_index_regex = std::regex{"Node\\s+([0-9]+),\\s+zone\\s+(\\S+)\\s+(.*)"};
1534+
// BAD - See README.md: "Dumpstate philosophy: exec not link"
1535+
// This should all be moved into a separate binary rather than have complex logic here.
15221536
for (std::string line; std::getline(ifs, line);) {
15231537
std::smatch match_results;
15241538
if (std::regex_match(line, match_results, unusable_index_regex)) {
@@ -2464,6 +2478,8 @@ static dumpstate_hal_aidl::IDumpstateDevice::DumpstateMode GetDumpstateHalModeAi
24642478
return dumpstate_hal_aidl::IDumpstateDevice::DumpstateMode::DEFAULT;
24652479
}
24662480

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

0 commit comments

Comments
 (0)