Flip bugreport version to 2.0

- Adds support for proto dumps
- Adds support for priority service dumps
- Change order of arguments when dumping Normal priority services
- Adds a new DEFAULT priority for services which is treated the same as NORMAL priority but dumpsys does not send "--dump-priority" arguments to the service.
Bug: 67716082, 27429130
Test: Manually generate bugreport (default version) and check for any issues
Test: Load bugreport on ABT
Test: mmm -j56 frameworks/native/cmds/dumpstate && \
      adb sync data && adb shell /data/nativetest/dumpstate_test/dumpstate_test && \
      adb shell /data/nativetest64/dumpstate_test/dumpstate_test && \
      adb shell /data/nativetest64/dumpstate_smoke_test/dumpstate_smoke_test && \
      adb shell /data/nativetest/dumpsys_test/dumpsys_test && \
      adb shell /data/nativetest64/dumpsys_test/dumpsys_test && \
      printf "\n\n#### ALL TESTS PASSED ####\n"

Change-Id: Ie8761a2dd0425574b0d905752e1562196a1f7426
This commit is contained in:
Vishnu Nair 2018-02-01 15:29:34 -08:00
parent 0fea11479e
commit 64afc024d7
8 changed files with 165 additions and 84 deletions

View file

@ -59,18 +59,35 @@ files upon the end users request:
On _Android O (Oreo)_, the following changes were made:
- The ANR traces are added to the `FS` folder, typically under `FS/data/anr` (version `2.0-dev-split-anr`).
## Android P versions
On _Android P (PleaseMightyAndroidWhatsYourNextReleaseName?)_, the following changes were made:
- Dumpsys sections are dumped by priority (version `2.0-dev-priority-dumps`).
Supported priorities can be specified when registering framework services. Section headers are
changed to contain priority info.
`DUMPSYS` -> `DUMPSYS CRITICAL/HIGH/NORMAL`
`DUMP OF SERVICE <servicename>` -> `DUMP OF SERVICE CRITICAL/HIGH/NORMAL <servicename>`
Supported Priorities:
## Version 2.0 (Android P)
On _Android P_, the following changes were made:
- Framework services are dumped by priority. Supported priorities can be specified
when registering the service. If a service does not specify its priority, its
assumed to be NORMAL.
Supported priorities:
- CRITICAL - services that must dump first, and fast (under 100ms). Ex: cpuinfo.
- HIGH - services that also must dump first, but can take longer (under 250ms) to dump. Ex: meminfo.
- HIGH - services that also must dump first, but can take longer (under 250ms)
to dump. Ex: meminfo.
- NORMAL - services that have no rush to dump and can take a long time (under 10s).
Format changes:
- Two additional dumpsys sections are generated. The two new sections can be
identified by their HEADER `DUMPSYS CRITICAL` and `DUMPSYS HIGH`.
- Services in the new sections will have a new header containing the
priority.
`DUMP OF SERVICE CRITICAL <servicename>` and
`DUMP OF SERVICE HIGH <servicename>`.
For example, cpuinfo will now move to `DUMPSYS CRITICAL` and will have a
header `DUMP OF SERVICE CRITICAL CPUINFO`.
- Bug report will contain proto dumps from all supporting services. Support can be
specified when registering framework services.
Format changes:
- All protos will be generated into separate files per service, per priority. The files
will be stored in `proto/<servicename>(_CRITICAL|_HIGH|).proto`
- ANR trace feature has been pushed to version `3.0-dev-split-anr`
## Intermediate versions
During development, the versions will be suffixed with _-devX_ or
_-devX-EXPERIMENTAL_FEATURE_, where _X_ is a number that increases as the

View file

@ -1110,20 +1110,14 @@ static void DumpIpAddrAndRules() {
RunCommand("IP RULES v6", {"ip", "-6", "rule", "show"});
}
void RunDumpsysText(const std::string& title, int priority, std::chrono::milliseconds timeout,
std::chrono::milliseconds service_timeout) {
static void RunDumpsysTextByPriority(const std::string& title, int priority,
std::chrono::milliseconds timeout,
std::chrono::milliseconds service_timeout) {
auto start = std::chrono::steady_clock::now();
sp<android::IServiceManager> sm = defaultServiceManager();
Dumpsys dumpsys(sm.get());
DurationReporter duration_reporter(title);
Vector<String16> args;
Dumpsys::setServiceArgs(args, /* asProto = */ false, priority);
if (!title.empty()) {
dprintf(STDOUT_FILENO, "------ %s (%s) ------\n", title.c_str(), "/system/bin/dumpsys");
fsync(STDOUT_FILENO);
}
auto start = std::chrono::steady_clock::now();
Vector<String16> services = dumpsys.listServices(priority, /* supports_proto = */ false);
for (const String16& service : services) {
std::string path(title);
@ -1153,8 +1147,31 @@ void RunDumpsysText(const std::string& title, int priority, std::chrono::millise
}
}
void RunDumpsysProto(const std::string& title, int priority, std::chrono::milliseconds timeout,
std::chrono::milliseconds service_timeout) {
static void RunDumpsysText(const std::string& title, int priority,
std::chrono::milliseconds timeout,
std::chrono::milliseconds service_timeout) {
DurationReporter duration_reporter(title);
dprintf(STDOUT_FILENO, "------ %s (/system/bin/dumpsys) ------\n", title.c_str());
fsync(STDOUT_FILENO);
RunDumpsysTextByPriority(title, priority, timeout, service_timeout);
}
/* Dump all services registered with Normal or Default priority. */
static void RunDumpsysTextNormalPriority(const std::string& title,
std::chrono::milliseconds timeout,
std::chrono::milliseconds service_timeout) {
DurationReporter duration_reporter(title);
dprintf(STDOUT_FILENO, "------ %s (/system/bin/dumpsys) ------\n", title.c_str());
fsync(STDOUT_FILENO);
RunDumpsysTextByPriority(title, IServiceManager::DUMP_FLAG_PRIORITY_NORMAL, timeout,
service_timeout);
RunDumpsysTextByPriority(title, IServiceManager::DUMP_FLAG_PRIORITY_DEFAULT, timeout,
service_timeout);
}
static void RunDumpsysProto(const std::string& title, int priority,
std::chrono::milliseconds timeout,
std::chrono::milliseconds service_timeout) {
sp<android::IServiceManager> sm = defaultServiceManager();
Dumpsys dumpsys(sm.get());
Vector<String16> args;
@ -1196,45 +1213,28 @@ void RunDumpsysProto(const std::string& title, int priority, std::chrono::millis
// Runs dumpsys on services that must dump first and and will take less than 100ms to dump.
static void RunDumpsysCritical() {
if (ds.CurrentVersionSupportsPriorityDumps()) {
RunDumpsysText("DUMPSYS CRITICAL", IServiceManager::DUMP_FLAG_PRIORITY_CRITICAL,
/* timeout= */ 5s, /* service_timeout= */ 500ms);
RunDumpsysProto("DUMPSYS CRITICAL PROTO", IServiceManager::DUMP_FLAG_PRIORITY_CRITICAL,
/* timeout= */ 5s, /* service_timeout= */ 500ms);
} else {
RunDumpsys("DUMPSYS MEMINFO", {"meminfo", "-a"},
CommandOptions::WithTimeout(90).DropRoot().Build());
RunDumpsys("DUMPSYS CPUINFO", {"cpuinfo", "-a"},
CommandOptions::WithTimeout(10).DropRoot().Build());
}
RunDumpsysText("DUMPSYS CRITICAL", IServiceManager::DUMP_FLAG_PRIORITY_CRITICAL,
/* timeout= */ 5s, /* service_timeout= */ 500ms);
RunDumpsysProto("DUMPSYS CRITICAL PROTO", IServiceManager::DUMP_FLAG_PRIORITY_CRITICAL,
/* timeout= */ 5s, /* service_timeout= */ 500ms);
}
// Runs dumpsys on services that must dump first but can take up to 250ms to dump.
static void RunDumpsysHigh() {
if (ds.CurrentVersionSupportsPriorityDumps()) {
// TODO meminfo takes ~10s, connectivity takes ~5sec to dump. They are both
// high priority. Reduce timeout once they are able to dump in a shorter time or
// moved to a parallel task.
RunDumpsysText("DUMPSYS HIGH", IServiceManager::DUMP_FLAG_PRIORITY_HIGH,
/* timeout= */ 90s, /* service_timeout= */ 30s);
RunDumpsysProto("DUMPSYS HIGH PROTO", IServiceManager::DUMP_FLAG_PRIORITY_HIGH,
/* timeout= */ 5s, /* service_timeout= */ 1s);
} else {
RunDumpsys("NETWORK DIAGNOSTICS", {"connectivity", "--diag"});
}
// TODO meminfo takes ~10s, connectivity takes ~5sec to dump. They are both
// high priority. Reduce timeout once they are able to dump in a shorter time or
// moved to a parallel task.
RunDumpsysText("DUMPSYS HIGH", IServiceManager::DUMP_FLAG_PRIORITY_HIGH,
/* timeout= */ 90s, /* service_timeout= */ 30s);
RunDumpsysProto("DUMPSYS HIGH PROTO", IServiceManager::DUMP_FLAG_PRIORITY_HIGH,
/* timeout= */ 5s, /* service_timeout= */ 1s);
}
// Runs dumpsys on services that must dump but can take up to 10s to dump.
static void RunDumpsysNormal() {
if (ds.CurrentVersionSupportsPriorityDumps()) {
RunDumpsysText("DUMPSYS", IServiceManager::DUMP_FLAG_PRIORITY_NORMAL,
/* timeout= */ 90s, /* service_timeout= */ 10s);
RunDumpsysProto("DUMPSYS PROTO", IServiceManager::DUMP_FLAG_PRIORITY_NORMAL,
/* timeout= */ 90s, /* service_timeout= */ 10s);
} else {
RunDumpsys("DUMPSYS", {"--skip", "meminfo", "cpuinfo"},
CommandOptions::WithTimeout(90).Build(), SEC_TO_MSEC(10));
}
RunDumpsysTextNormalPriority("DUMPSYS", /* timeout= */ 90s, /* service_timeout= */ 10s);
RunDumpsysProto("DUMPSYS PROTO", IServiceManager::DUMP_FLAG_PRIORITY_NORMAL,
/* timeout= */ 90s, /* service_timeout= */ 10s);
}
static void DumpHals() {
@ -1893,12 +1893,10 @@ int run_main(int argc, char* argv[]) {
ds.version_ = VERSION_CURRENT;
}
if (ds.version_ != VERSION_CURRENT && ds.version_ != VERSION_SPLIT_ANR &&
ds.version_ != VERSION_PRIORITY_DUMPS) {
MYLOGE(
"invalid version requested ('%s'); suppported values are: ('%s', '%s', '%s', '%s')\n",
ds.version_.c_str(), VERSION_DEFAULT.c_str(), VERSION_CURRENT.c_str(),
VERSION_SPLIT_ANR.c_str(), VERSION_PRIORITY_DUMPS.c_str());
if (ds.version_ != VERSION_CURRENT && ds.version_ != VERSION_SPLIT_ANR) {
MYLOGE("invalid version requested ('%s'); suppported values are: ('%s', '%s', '%s')\n",
ds.version_.c_str(), VERSION_DEFAULT.c_str(), VERSION_CURRENT.c_str(),
VERSION_SPLIT_ANR.c_str());
exit(1);
}

View file

@ -145,19 +145,13 @@ class Progress {
*
* See bugreport-format.md for more info.
*/
static std::string VERSION_CURRENT = "1.0";
static std::string VERSION_CURRENT = "2.0";
/*
* Temporary version that adds a anr-traces.txt entry. Once tools support it, the current version
* will be bumped to 2.0.
* will be bumped to 3.0.
*/
static std::string VERSION_SPLIT_ANR = "2.0-dev-split-anr";
/*
* Temporary version that adds priority based dumps. Once tools support it, the current version
* will be bumped to 2.0.
*/
static std::string VERSION_PRIORITY_DUMPS = "2.0-dev-priority-dumps";
static std::string VERSION_SPLIT_ANR = "3.0-dev-split-anr";
/*
* "Alias" for the current version.

View file

@ -259,10 +259,6 @@ std::string Dumpstate::GetPath(const std::string& suffix) const {
name_.c_str(), suffix.c_str());
}
bool Dumpstate::CurrentVersionSupportsPriorityDumps() const {
return (version_ == VERSION_PRIORITY_DUMPS);
}
void Dumpstate::SetProgress(std::unique_ptr<Progress> progress) {
progress_ = std::move(progress);
}

View file

@ -284,14 +284,23 @@ Vector<String16> Dumpsys::listServices(int priorityFilterFlags, bool filterByPro
}
void Dumpsys::setServiceArgs(Vector<String16>& args, bool asProto, int priorityFlags) {
if ((priorityFlags == IServiceManager::DUMP_FLAG_PRIORITY_ALL) ||
(priorityFlags == IServiceManager::DUMP_FLAG_PRIORITY_NORMAL)) {
args.add(String16("-a"));
}
// Add proto flag if dumping service as proto.
if (asProto) {
args.insertAt(String16(PriorityDumper::PROTO_ARG), 0);
}
if (priorityFlags != IServiceManager::DUMP_FLAG_PRIORITY_ALL) {
// Add -a (dump all) flag if dumping all services, dumping normal services or
// services not explicitly registered to a priority bucket (default services).
if ((priorityFlags == IServiceManager::DUMP_FLAG_PRIORITY_ALL) ||
(priorityFlags == IServiceManager::DUMP_FLAG_PRIORITY_NORMAL) ||
(priorityFlags == IServiceManager::DUMP_FLAG_PRIORITY_DEFAULT)) {
args.insertAt(String16("-a"), 0);
}
// Add priority flags when dumping services registered to a specific priority bucket.
if ((priorityFlags == IServiceManager::DUMP_FLAG_PRIORITY_CRITICAL) ||
(priorityFlags == IServiceManager::DUMP_FLAG_PRIORITY_HIGH) ||
(priorityFlags == IServiceManager::DUMP_FLAG_PRIORITY_NORMAL)) {
String16 priorityType = ConvertBitmaskToPriorityType(priorityFlags);
args.insertAt(String16(PriorityDumper::PRIORITY_ARG), 0);
args.insertAt(priorityType, 1);
@ -349,7 +358,8 @@ void Dumpsys::writeDumpHeader(int fd, const String16& serviceName, int priorityF
"----------------------------------------"
"---------------------------------------\n");
if (priorityFlags == IServiceManager::DUMP_FLAG_PRIORITY_ALL ||
priorityFlags == IServiceManager::DUMP_FLAG_PRIORITY_NORMAL) {
priorityFlags == IServiceManager::DUMP_FLAG_PRIORITY_NORMAL ||
priorityFlags == IServiceManager::DUMP_FLAG_PRIORITY_DEFAULT) {
StringAppendF(&msg, "DUMP OF SERVICE %s:\n", String8(serviceName).c_str());
} else {
String16 priorityType = ConvertBitmaskToPriorityType(priorityFlags);

View file

@ -351,6 +351,65 @@ TEST_F(DumpsysTest, DumpWithArgsRunningService) {
AssertOutput("I DO!");
}
// Tests dumpsys passes the -a flag when called on all services
TEST_F(DumpsysTest, PassAllFlagsToServices) {
ExpectListServices({"Locksmith", "Valet"});
ExpectCheckService("Locksmith");
ExpectCheckService("Valet");
ExpectDumpWithArgs("Locksmith", {"-a"}, "dumped1");
ExpectDumpWithArgs("Valet", {"-a"}, "dumped2");
CallMain({"-T", "500"});
AssertDumped("Locksmith", "dumped1");
AssertDumped("Valet", "dumped2");
}
// Tests dumpsys passes the -a flag when called on NORMAL priority services
TEST_F(DumpsysTest, PassAllFlagsToNormalServices) {
ExpectListServicesWithPriority({"Locksmith", "Valet"},
IServiceManager::DUMP_FLAG_PRIORITY_NORMAL);
ExpectCheckService("Locksmith");
ExpectCheckService("Valet");
ExpectDumpWithArgs("Locksmith", {"-a", "--dump-priority", "NORMAL"}, "dump1");
ExpectDumpWithArgs("Valet", {"-a", "--dump-priority", "NORMAL"}, "dump2");
CallMain({"--priority", "NORMAL"});
AssertDumped("Locksmith", "dump1");
AssertDumped("Valet", "dump2");
}
// Tests dumpsys passes only priority flags when called on CRITICAL priority services
TEST_F(DumpsysTest, PassPriorityFlagsToCriticalServices) {
ExpectListServicesWithPriority({"Locksmith", "Valet"},
IServiceManager::DUMP_FLAG_PRIORITY_CRITICAL);
ExpectCheckService("Locksmith");
ExpectCheckService("Valet");
ExpectDumpWithArgs("Locksmith", {"--dump-priority", "CRITICAL"}, "dump1");
ExpectDumpWithArgs("Valet", {"--dump-priority", "CRITICAL"}, "dump2");
CallMain({"--priority", "CRITICAL"});
AssertDumpedWithPriority("Locksmith", "dump1", PriorityDumper::PRIORITY_ARG_CRITICAL);
AssertDumpedWithPriority("Valet", "dump2", PriorityDumper::PRIORITY_ARG_CRITICAL);
}
// Tests dumpsys passes only priority flags when called on HIGH priority services
TEST_F(DumpsysTest, PassPriorityFlagsToHighServices) {
ExpectListServicesWithPriority({"Locksmith", "Valet"},
IServiceManager::DUMP_FLAG_PRIORITY_HIGH);
ExpectCheckService("Locksmith");
ExpectCheckService("Valet");
ExpectDumpWithArgs("Locksmith", {"--dump-priority", "HIGH"}, "dump1");
ExpectDumpWithArgs("Valet", {"--dump-priority", "HIGH"}, "dump2");
CallMain({"--priority", "HIGH"});
AssertDumpedWithPriority("Locksmith", "dump1", PriorityDumper::PRIORITY_ARG_HIGH);
AssertDumpedWithPriority("Valet", "dump2", PriorityDumper::PRIORITY_ARG_HIGH);
}
// Tests 'dumpsys' with no arguments
TEST_F(DumpsysTest, DumpMultipleServices) {
ExpectListServices({"running1", "stopped2", "running3"});

View file

@ -35,7 +35,7 @@ class BinderService
{
public:
static status_t publish(bool allowIsolated = false,
int dumpFlags = IServiceManager::DUMP_FLAG_PRIORITY_NORMAL) {
int dumpFlags = IServiceManager::DUMP_FLAG_PRIORITY_DEFAULT) {
sp<IServiceManager> sm(defaultServiceManager());
return sm->addService(String16(SERVICE::getServiceName()), new SERVICE(), allowIsolated,
dumpFlags);
@ -43,7 +43,7 @@ public:
static void publishAndJoinThreadPool(
bool allowIsolated = false,
int dumpFlags = IServiceManager::DUMP_FLAG_PRIORITY_NORMAL) {
int dumpFlags = IServiceManager::DUMP_FLAG_PRIORITY_DEFAULT) {
publish(allowIsolated, dumpFlags);
joinThreadPool();
}

View file

@ -31,15 +31,22 @@ class IServiceManager : public IInterface
{
public:
DECLARE_META_INTERFACE(ServiceManager)
/*
/**
* Must match values in IServiceManager.java
*/
/* Allows services to dump sections according to priorities. */
static const int DUMP_FLAG_PRIORITY_CRITICAL = 1 << 0;
static const int DUMP_FLAG_PRIORITY_HIGH = 1 << 1;
static const int DUMP_FLAG_PRIORITY_NORMAL = 1 << 2;
static const int DUMP_FLAG_PRIORITY_ALL =
DUMP_FLAG_PRIORITY_CRITICAL | DUMP_FLAG_PRIORITY_HIGH | DUMP_FLAG_PRIORITY_NORMAL;
static const int DUMP_FLAG_PROTO = 1 << 3;
/**
* Services are by default registered with a DEFAULT dump priority. DEFAULT priority has the
* same priority as NORMAL priority but the services are not called with dump priority
* arguments.
*/
static const int DUMP_FLAG_PRIORITY_DEFAULT = 1 << 3;
static const int DUMP_FLAG_PRIORITY_ALL = DUMP_FLAG_PRIORITY_CRITICAL |
DUMP_FLAG_PRIORITY_HIGH | DUMP_FLAG_PRIORITY_NORMAL | DUMP_FLAG_PRIORITY_DEFAULT;
static const int DUMP_FLAG_PROTO = 1 << 4;
/**
* Retrieve an existing service, blocking for a few seconds
@ -57,7 +64,7 @@ public:
*/
virtual status_t addService(const String16& name, const sp<IBinder>& service,
bool allowIsolated = false,
int dumpsysFlags = DUMP_FLAG_PRIORITY_NORMAL) = 0;
int dumpsysFlags = DUMP_FLAG_PRIORITY_DEFAULT) = 0;
/**
* Return list of all existing services.