diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-02-17 00:07:36 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-02-17 00:07:36 +0000 |
commit | d977a6e45040efa70ade7638a72278ae418d9be2 (patch) | |
tree | 8db1a9ebe52a8f79ea4db5564e28c84679e99b68 | |
parent | b5def80d061510a0b64e0f56529194f55017786f (diff) | |
parent | 9393f25d2c530de5e536783d715b040043737dd5 (diff) | |
download | native-d977a6e45040efa70ade7638a72278ae418d9be2.tar.gz |
Snap for 8191458 from 9393f25d2c530de5e536783d715b040043737dd5 to sc-qpr3-release
Change-Id: Ib0b0f14676cf4f56cd93c7f7bfc45f7d2400e67e
-rw-r--r-- | cmds/dumpstate/dumpstate.cpp | 61 | ||||
-rw-r--r-- | cmds/dumpstate/dumpstate.h | 3 |
2 files changed, 62 insertions, 2 deletions
diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp index 2d11b908c2..30ef4b9f55 100644 --- a/cmds/dumpstate/dumpstate.cpp +++ b/cmds/dumpstate/dumpstate.cpp @@ -1793,8 +1793,8 @@ static Dumpstate::RunStatus dumpstate() { // Add linker configuration directory ds.AddDir(LINKERCONFIG_DIR, true); - /* Dump cgroupfs */ - ds.AddDir(CGROUPFS_DIR, true); + /* Dump frozen cgroupfs */ + dump_frozen_cgroupfs(); if (ds.dump_pool_) { WAIT_TASK_WITH_CONSENT_CHECK(DUMP_INCIDENT_REPORT_TASK, ds.dump_pool_); @@ -4007,6 +4007,63 @@ void dump_route_tables() { fclose(fp); } +void dump_frozen_cgroupfs(const char *dir, int level, + int (*dump_from_fd)(const char* title, const char* path, int fd)) { + DIR *dirp; + struct dirent *d; + char *newpath = nullptr; + + dirp = opendir(dir); + if (dirp == nullptr) { + MYLOGE("%s: %s\n", dir, strerror(errno)); + return; + } + + for (; ((d = readdir(dirp))); free(newpath), newpath = nullptr) { + if ((d->d_name[0] == '.') + && (((d->d_name[1] == '.') && (d->d_name[2] == '\0')) + || (d->d_name[1] == '\0'))) { + continue; + } + if (d->d_type == DT_DIR) { + asprintf(&newpath, "%s/%s/", dir, d->d_name); + if (!newpath) { + continue; + } + if (level == 0 && !strncmp(d->d_name, "uid_", 4)) { + dump_frozen_cgroupfs(newpath, 1, dump_from_fd); + } else if (level == 1 && !strncmp(d->d_name, "pid_", 4)) { + char *freezer = nullptr; + asprintf(&freezer, "%s/%s", newpath, "cgroup.freeze"); + if (freezer) { + FILE* fp = fopen(freezer, "r"); + if (fp != NULL) { + int frozen; + fscanf(fp, "%d", &frozen); + if (frozen > 0) { + dump_files("", newpath, skip_none, dump_from_fd); + } + fclose(fp); + } + free(freezer); + } + } + } + } + closedir(dirp); +} + +void dump_frozen_cgroupfs() { + if (!ds.IsZipping()) { + MYLOGD("Not adding cgroupfs because it's not a zipped bugreport\n"); + return; + } + MYLOGD("Adding frozen processes from %s\n", CGROUPFS_DIR); + DurationReporter duration_reporter("FROZEN CGROUPFS"); + if (PropertiesHelper::IsDryRun()) return; + dump_frozen_cgroupfs(CGROUPFS_DIR, 0, _add_file_from_fd); +} + void Dumpstate::UpdateProgress(int32_t delta_sec) { if (progress_ == nullptr) { MYLOGE("UpdateProgress: progress_ not set\n"); diff --git a/cmds/dumpstate/dumpstate.h b/cmds/dumpstate/dumpstate.h index 83e6787ebf..34280d01e8 100644 --- a/cmds/dumpstate/dumpstate.h +++ b/cmds/dumpstate/dumpstate.h @@ -642,6 +642,9 @@ void do_dmesg(); /* Prints the contents of all the routing tables, both IPv4 and IPv6. */ void dump_route_tables(); +/* Dump subdirectories of cgroupfs if the corresponding process is frozen */ +void dump_frozen_cgroupfs(); + /* Play a sound via Stagefright */ void play_sound(const char *path); |