dump_power: fix the problem of not being able to dump properties

Bug: 309011602
Test: adb bugreport and check dumpstate_board.txt
Change-Id: I8a6251e03bcf16b2c1f4242a724f1949dab75759
Signed-off-by: Jack Wu <wjack@google.com>
This commit is contained in:
Jack Wu 2023-11-03 11:37:37 +08:00
parent 73d96fb40f
commit 5f6d9cc357

View file

@ -52,9 +52,20 @@ int getCommandOutput(const char *cmd, std::string *output) {
} }
bool isValidFile(const char *file) { bool isValidFile(const char *file) {
if (!access(file, R_OK)) { FILE *fp = fopen(file, "r");
return false; if (fp != NULL) {
fclose(fp);
return true;
} }
return false;
}
bool isValidDir(const char *directory) {
DIR *dir = opendir(directory);
if (dir == NULL)
return false;
closedir(dir);
return true; return true;
} }
@ -167,8 +178,8 @@ void dumpMaxFg() {
const char *maxfg [][2] = { const char *maxfg [][2] = {
{"Power supply property maxfg", "/sys/class/power_supply/maxfg/uevent"}, {"Power supply property maxfg", "/sys/class/power_supply/maxfg/uevent"},
{"m5_state", "/sys/class/power_supply/maxfg/m5_model_state"}, {"m5_state", "/sys/class/power_supply/maxfg/m5_model_state"},
{"maxfg", "/dev/logbuffer_maxfg"}, {"maxfg logbuffer", "/dev/logbuffer_maxfg"},
{"maxfg", "/dev/logbuffer_maxfg_monitor"}, {"maxfg_monitor logbuffer", "/dev/logbuffer_maxfg_monitor"},
}; };
const char *maxfgFlip [][2] = { const char *maxfgFlip [][2] = {
@ -187,7 +198,7 @@ void dumpMaxFg() {
std::string content; std::string content;
if (isValidFile(maxfgLoc)) { if (isValidDir(maxfgLoc)) {
for (const auto &row : maxfg) { for (const auto &row : maxfg) {
dumpFileContent(row[0], row[1]); dumpFileContent(row[0], row[1]);
} }
@ -205,7 +216,9 @@ void dumpMaxFg() {
void dumpPowerSupplyDock() { void dumpPowerSupplyDock() {
const char* powerSupplyPropertyDockTitle = "Power supply property dock"; const char* powerSupplyPropertyDockTitle = "Power supply property dock";
const char* powerSupplyPropertyDockFile = "/sys/class/power_supply/dock/uevent"; const char* powerSupplyPropertyDockFile = "/sys/class/power_supply/dock/uevent";
dumpFileContent(powerSupplyPropertyDockTitle, powerSupplyPropertyDockFile); if (isValidFile(powerSupplyPropertyDockFile)) {
dumpFileContent(powerSupplyPropertyDockTitle, powerSupplyPropertyDockFile);
}
} }
void dumpLogBufferTcpm() { void dumpLogBufferTcpm() {
@ -286,14 +299,18 @@ void dumpWc68() {
const char* wc68Title = "WC68"; const char* wc68Title = "WC68";
const char* wc68File = "/dev/logbuffer_wc68"; const char* wc68File = "/dev/logbuffer_wc68";
dumpFileContent(wc68Title, wc68File); if (isValidFile(wc68File)) {
dumpFileContent(wc68Title, wc68File);
}
} }
void dumpLn8411() { void dumpLn8411() {
const char* ln8411Title = "LN8411"; const char* ln8411Title = "LN8411";
const char* ln8411File = "/dev/logbuffer_ln8411"; const char* ln8411File = "/dev/logbuffer_ln8411";
dumpFileContent(ln8411Title, ln8411File); if (isValidFile(ln8411File)) {
dumpFileContent(ln8411Title, ln8411File);
}
} }
void dumpBatteryHealth() { void dumpBatteryHealth() {
@ -359,62 +376,102 @@ void dumpBatteryDefend() {
} }
} }
void dumpChgUserDebug() { void printValuesOfDirectory(const char *directory, std::string debugfs, const char *strMatch) {
std::vector<std::string> files; std::vector<std::string> files;
struct dirent *entry; auto info = directory;
std::string content; std::string content;
struct dirent *entry;
DIR *dir = opendir(debugfs.c_str());
if (dir == NULL)
return;
const char *chgUserDebug [][2] { printTitle((debugfs + std::string(strMatch) + "/" + std::string(info)).c_str());
{"DC_registers dump", "/sys/class/power_supply/dc-mains/device/registers_dump"}, while ((entry = readdir(dir)) != NULL)
if (std::string(entry->d_name).find(strMatch) != std::string::npos)
files.push_back(entry->d_name);
closedir(dir);
sort(files.begin(), files.end());
for (auto &file : files) {
std::string fileDirectory = debugfs + file;
std::string fileLocation = fileDirectory + "/" + std::string(info);
if (!android::base::ReadFileToString(fileLocation, &content)) {
content = "\n";
}
printf("%s:\n%s", fileDirectory.c_str(), content.c_str());
if (content.back() != '\n')
printf("\n");
}
files.clear();
}
void dumpChgUserDebug() {
const char *chgDebugMax77759 [][2] {
{"max77759_chg registers dump", "/d/max77759_chg/registers"}, {"max77759_chg registers dump", "/d/max77759_chg/registers"},
{"max77729_pmic registers dump", "/d/max77729_pmic/registers"}, {"max77729_pmic registers dump", "/d/max77729_pmic/registers"},
{"Charging table dump", "/d/google_battery/chg_raw_profile"}, };
const char *chgDebugMax77779 [][2] {
{"max77779_chg registers dump", "/d/max77779_chg/registers"},
{"max77779_pmic registers dump", "/d/max77779_pmic/registers"},
}; };
const std::string debugfs = "/d/"; const std::string debugfs = "/d/";
const char *maxFgStrMatch = "maxfg";
const char *fgInfo [][2] { const char *maxFgDir = "/d/maxfg";
{"fg_model", "fg_model"}, const char *maxFgStrMatch = "maxfg";
{"fg_alo_ver", "algo_ver"}, const char *maxFg77779StrMatch = "max77779fg";
{"fg_model_ok", "model_ok"}, const char *baseChgDir = "/d/max77759_chg";
{"fg registers", "registers"}, const char *dcRegName = "DC_registers dump";
{"Maxim FG NV RAM", "nv_registers"}, const char *dcRegDir = "/sys/class/power_supply/dc-mains/device/registers_dump";
const char *chgTblName = "Charging table dump";
const char *chgTblDir = "/d/google_battery/chg_raw_profile";
const char *maxFgInfo [] {
"fg_model",
"algo_ver",
"model_ok",
"registers",
"nv_registers",
}; };
if (!isUserBuild()) const char *max77779FgInfo [] {
"fg_model",
"algo_ver",
"model_ok",
"registers",
"debug_registers",
};
if (isUserBuild())
return; return;
for (auto &row : chgUserDebug) { if (isValidFile(dcRegDir)) {
dumpFileContent(row[0], row[1]); dumpFileContent(dcRegName, dcRegDir);
} }
for (auto &info : fgInfo) { if (isValidDir(baseChgDir)) {
DIR *dir = opendir(debugfs.c_str()); for (auto &row : chgDebugMax77759) {
if (dir == NULL) dumpFileContent(row[0], row[1]);
return; }
} else {
printTitle(info[0]); for (auto &row : chgDebugMax77779) {
while ((entry = readdir(dir)) != NULL) dumpFileContent(row[0], row[1]);
if (std::string(entry->d_name).find(maxFgStrMatch) != std::string::npos) }
files.push_back(entry->d_name); }
closedir(dir);
dumpFileContent(chgTblName, chgTblDir);
sort(files.begin(), files.end());
if (isValidDir(maxFgDir)) {
for (auto &file : files) { for (auto & directory : maxFgInfo) {
std::string fileDirectory = debugfs + file; printValuesOfDirectory(directory, debugfs, maxFgStrMatch);
std::string fileLocation = fileDirectory + "/" + std::string(info[1]); }
if (!android::base::ReadFileToString(fileLocation, &content)) { } else {
content = "\n"; for (auto & directory : max77779FgInfo) {
} printValuesOfDirectory(directory, debugfs, maxFg77779StrMatch);
printf("%s:\n%s", fileDirectory.c_str(), content.c_str());
if (content.back() != '\n')
printf("\n");
} }
files.clear();
} }
} }
@ -454,7 +511,7 @@ void dumpChargerStats() {
dumpFileContent(chgStatsTitle, chgStatsLocation); dumpFileContent(chgStatsTitle, chgStatsLocation);
if (!isUserBuild()) if (isUserBuild())
return; return;
for (auto &stat : chargerStats) { for (auto &stat : chargerStats) {
@ -509,7 +566,7 @@ void dumpGvoteables() {
std::vector<std::string> files; std::vector<std::string> files;
int ret; int ret;
if (!isUserBuild()) if (isUserBuild())
return; return;
ret = getFilesInDir(directory, &files); ret = getFilesInDir(directory, &files);