diff --git a/soc/Android.bp b/soc/Android.bp index fdef92c..9600855 100644 --- a/soc/Android.bp +++ b/soc/Android.bp @@ -13,6 +13,7 @@ cc_binary { shared_libs: [ "libbase", "libdump", + "liblog", ], vendor: true, relative_install_path: "dump", diff --git a/soc/dump_soc.cpp b/soc/dump_soc.cpp index bc08689..4c34349 100644 --- a/soc/dump_soc.cpp +++ b/soc/dump_soc.cpp @@ -14,6 +14,19 @@ * limitations under the License. */ #include +#include +#include +#include +#include +#include + +std::string readFile(const std::string& file_path) { + std::string content; + if(android::base::ReadFileToString(file_path.c_str(), &content)) { + return std::regex_replace(content, std::regex("\\r\\n|\\r|\\n"),""); + } + return content; +} // Dump chip ID. int main() { @@ -23,5 +36,48 @@ int main() { dumpFileContent("PRODUCT ID", "/sys/devices/system/chip-id/product_id"); dumpFileContent("REVISION", "/sys/devices/system/chip-id/revision"); dumpFileContent("RAW STR", "/sys/devices/system/chip-id/raw_str"); + dumpFileContent("CPU present", "/sys/devices/system/cpu/present"); + dumpFileContent("CPU online", "/sys/devices/system/cpu/online"); + + printf("------ CPU time-in-state ------\n"); + std::string states; + std::unique_ptr cpudir(opendir("/sys/devices/system/cpu/"), closedir); + if (!cpudir) { + ALOGE("Fail To Open Dir /sys/devices/system/cpu/"); + return 0; + } + dirent *entry; + while ((entry = readdir(cpudir.get())) != nullptr) { + std::string core(entry->d_name); + if (core.find("cpu") != std::string::npos) { + std::string path("/sys/devices/system/cpu/" + core + "/cpufreq/stats/time_in_state"); + if(!access(path.c_str(), R_OK)){ + dumpFileContent(path.c_str(), path.c_str()); + } + } + std::string cpu_idle_path("/sys/devices/system/cpu/" + core + "/cpuidle"); + std::unique_ptr statedir(opendir(cpu_idle_path.c_str()), closedir); + if (!statedir) { + continue; + } + dirent *state_entry; + while ((state_entry = readdir(statedir.get())) != nullptr) { + std::string cpu_idle_state_path(state_entry->d_name); + std::string full_state_path; + full_state_path += cpu_idle_path; + full_state_path += "/"; + full_state_path += cpu_idle_state_path; + if (cpu_idle_state_path.find("state") != std::string::npos) { + std::string name(full_state_path + "/name"); + std::string desc(full_state_path + "/desc"); + std::string time(full_state_path + "/time"); + std::string usage(full_state_path + "/usage"); + states += full_state_path+": "+readFile(name)+" "+readFile(desc)+" "+readFile(time)+" "+readFile(usage)+"\n"; + } + } + } + printf("------ CPU cpuidle ------\n%s\n", states.c_str()); + + dumpFileContent("INTERRUPTS", "/proc/interrupts"); return 0; }