blob: e8e4a38a2df59bb57d3589a4125d4fe953d31957 [file] [log] [blame]
samou6c250222024-07-16 07:40:36 +00001
2/*
3 * Copyright 2023 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17#include <cstring>
18#include <dirent.h>
19#include <dump/pixel_dump.h>
20#include <fstream>
21#include <stdio.h>
22#include <stdlib.h>
23#include <sys/sysinfo.h>
24#include <time.h>
25#include <vector>
26#include <android-base/file.h>
27#include <android-base/strings.h>
28#include "DumpstateUtil.h"
29void printTitle(const char *msg) {
30 printf("\n------ %s ------\n", msg);
31}
32int getCommandOutput(const char *cmd, std::string *output) {
33 char buffer[1024];
34 FILE *pipe = popen(cmd, "r");
35 if (!pipe) {
36 return -1;
37 }
38 while (fgets(buffer, sizeof buffer, pipe) != NULL) {
39 *output += buffer;
40 }
41 pclose(pipe);
42 if (output->back() == '\n')
43 output->pop_back();
44 return 0;
45}
46bool isValidFile(const char *file) {
Spade Lee7bbc59e2024-10-29 16:07:29 +000047 FILE *fp = fopen(file, "r");
48 if (fp != NULL) {
49 fclose(fp);
50 return true;
samou6c250222024-07-16 07:40:36 +000051 }
Spade Lee7bbc59e2024-10-29 16:07:29 +000052 return false;
53}
54bool isValidDir(const char *directory) {
55 DIR *dir = opendir(directory);
56 if (dir == NULL)
57 return false;
58
59 closedir(dir);
samou6c250222024-07-16 07:40:36 +000060 return true;
61}
62bool isUserBuild() {
63 return ::android::os::dumpstate::PropertiesHelper::IsUserBuild();
64}
65int getFilesInDir(const char *directory, std::vector<std::string> *files) {
66 std::string content;
67 struct dirent *entry;
68 DIR *dir = opendir(directory);
69 if (dir == NULL)
70 return -1;
71 files->clear();
72 while ((entry = readdir(dir)) != NULL)
73 files->push_back(entry->d_name);
74 closedir(dir);
75 sort(files->begin(), files->end());
76 return 0;
77}
78void dumpPowerStatsTimes() {
79 const char *title = "Power Stats Times";
80 char rBuff[128];
81 struct timespec rTs;
82 struct sysinfo info;
83 int ret;
84 printTitle(title);
85 sysinfo(&info);
86 const time_t boottime = time(NULL) - info.uptime;
87 ret = clock_gettime(CLOCK_REALTIME, &rTs);
88 if (ret)
89 return;
90 struct tm *nowTime = std::localtime(&rTs.tv_sec);
91 std::strftime(rBuff, sizeof(rBuff), "%m/%d/%Y %H:%M:%S", nowTime);
92 printf("Boot: %s", ctime(&boottime));
93 printf("Now: %s\n", rBuff);
94}
95int readContentsOfDir(const char* title, const char* directory, const char* strMatch,
96 bool useStrMatch = false, bool printDirectory = false) {
97 std::vector<std::string> files;
98 std::string content;
99 std::string fileLocation;
100 int ret;
101 ret = getFilesInDir(directory, &files);
102 if (ret < 0)
103 return ret;
104 printTitle(title);
105 for (auto &file : files) {
106 if (useStrMatch && std::string::npos == std::string(file).find(strMatch)) {
107 continue;
108 }
109 fileLocation = std::string(directory) + std::string(file);
110 if (!android::base::ReadFileToString(fileLocation, &content)) {
111 continue;
112 }
113 if (printDirectory) {
114 printf("\n\n%s\n", fileLocation.c_str());
115 }
116 if (content.back() == '\n')
117 content.pop_back();
118 printf("%s\n", content.c_str());
119 }
120 return 0;
121}
122void dumpAcpmStats() {
123 const char* acpmDir = "/sys/devices/platform/acpm_stats/";
124 const char* statsSubStr = "_stats";
125 const char* acpmTitle = "ACPM stats";
126 readContentsOfDir(acpmTitle, acpmDir, statsSubStr, true, true);
127}
128void dumpPowerSupplyStats() {
129 const char* dumpList[][2] = {
130 {"CPU PM stats", "/sys/devices/system/cpu/cpupm/cpupm/time_in_state"},
samou6c250222024-07-16 07:40:36 +0000131 {"Power supply property battery", "/sys/class/power_supply/battery/uevent"},
132 {"Power supply property dc", "/sys/class/power_supply/dc/uevent"},
133 {"Power supply property gcpm", "/sys/class/power_supply/gcpm/uevent"},
134 {"Power supply property gcpm_pps", "/sys/class/power_supply/gcpm_pps/uevent"},
135 {"Power supply property main-charger", "/sys/class/power_supply/main-charger/uevent"},
Spade Leedf3964b2024-11-07 17:22:50 +0000136 {"Power supply property pca9468-mains", "/sys/class/power_supply/pca9468-mains/uevent"},
Spade Lee7bbc59e2024-10-29 16:07:29 +0000137 {"Power supply property tcpm", "/sys/class/power_supply/tcpm-source-psy-i2c-max77759tcpc/uevent"},
samou6c250222024-07-16 07:40:36 +0000138 {"Power supply property usb", "/sys/class/power_supply/usb/uevent"},
139 {"Power supply property wireless", "/sys/class/power_supply/wireless/uevent"},
140 };
141 for (const auto &row : dumpList) {
142 dumpFileContent(row[0], row[1]);
143 }
144}
145void dumpMaxFg() {
146 const char *maxfgLoc = "/sys/class/power_supply/maxfg";
147 const char *maxfg [][2] = {
148 {"Power supply property maxfg", "/sys/class/power_supply/maxfg/uevent"},
149 {"m5_state", "/sys/class/power_supply/maxfg/m5_model_state"},
Spade Lee7bbc59e2024-10-29 16:07:29 +0000150 {"maxfg registers", "/sys/class/power_supply/maxfg/registers_dump"},
Spade Leedf3964b2024-11-07 17:22:50 +0000151 {"maxfg logbuffer", "/dev/logbuffer_maxfg"},
152 {"maxfg_monitor logbuffer", "/dev/logbuffer_maxfg_monitor"},
samou6c250222024-07-16 07:40:36 +0000153 };
samou6c250222024-07-16 07:40:36 +0000154 std::string content;
Spade Lee7bbc59e2024-10-29 16:07:29 +0000155 if (isValidDir(maxfgLoc)) {
samou6c250222024-07-16 07:40:36 +0000156 for (const auto &row : maxfg) {
157 dumpFileContent(row[0], row[1]);
158 }
samou6c250222024-07-16 07:40:36 +0000159 }
160}
161void dumpPowerSupplyDock() {
162 const char* powerSupplyPropertyDockTitle = "Power supply property dock";
163 const char* powerSupplyPropertyDockFile = "/sys/class/power_supply/dock/uevent";
164 dumpFileContent(powerSupplyPropertyDockTitle, powerSupplyPropertyDockFile);
165}
166void dumpLogBufferTcpm() {
167 const char* logbufferTcpmTitle = "Logbuffer TCPM";
168 const char* logbufferTcpmFile = "/dev/logbuffer_tcpm";
169 const char* debugTcpmFile = "/sys/kernel/debug/tcpm";
170 const char* tcpmLogTitle = "TCPM logs";
171 const char* tcpmFile = "/sys/kernel/debug/tcpm";
172 const char* tcpmFileAlt = "/sys/kernel/debug/usb/tcpm";
173 int retCode;
174 dumpFileContent(logbufferTcpmTitle, logbufferTcpmFile);
175 retCode = readContentsOfDir(tcpmLogTitle, isValidFile(debugTcpmFile) ? tcpmFile : tcpmFileAlt,
176 NULL);
177 if (retCode < 0)
178 printTitle(tcpmLogTitle);
179}
180void dumpTcpc() {
181 int ret;
182 const char* max77759TcpcHead = "TCPC";
183 const char* i2cSubDirMatch = "i2c-";
184 const char* directory = "/sys/devices/platform/10d60000.hsi2c/";
185 const char* max77759Tcpc [][2] {
186 {"registers:", "/i2c-max77759tcpc/registers"},
187 {"frs:", "/i2c-max77759tcpc/frs"},
188 {"auto_discharge:", "/i2c-max77759tcpc/auto_discharge"},
189 {"bcl2_enabled:", "/i2c-max77759tcpc/bcl2_enabled"},
190 {"cc_toggle_enable:", "/i2c-max77759tcpc/cc_toggle_enable"},
191 {"containment_detection:", "/i2c-max77759tcpc/containment_detection"},
192 {"containment_detection_status:", "/i2c-max77759tcpc/containment_detection_status"},
193 };
194 std::vector<std::string> files;
195 std::string content;
196 printTitle(max77759TcpcHead);
197 ret = getFilesInDir(directory, &files);
198 if (ret < 0) {
199 for (auto &tcpcVal : max77759Tcpc)
200 printf("%s\n", tcpcVal[0]);
201 return;
202 }
203 for (auto &file : files) {
204 for (auto &tcpcVal : max77759Tcpc) {
205 printf("%s ", tcpcVal[0]);
206 if (std::string::npos == std::string(file).find(i2cSubDirMatch)) {
207 continue;
208 }
209 std::string fileName = directory + file + "/" + std::string(tcpcVal[1]);
210 if (!android::base::ReadFileToString(fileName, &content)) {
211 continue;
212 }
213 printf("%s\n", content.c_str());
214 }
215 }
216}
217void dumpPdEngine() {
218 const char* pdEngine [][2] {
219 {"PD Engine", "/dev/logbuffer_usbpd"},
Spade Leedf3964b2024-11-07 17:22:50 +0000220 {"PPS-google_cpm logbuffer", "/dev/logbuffer_cpm"},
221 {"PPS-pca9468 logbuffer", "/dev/logbuffer_pca9468"},
samou6c250222024-07-16 07:40:36 +0000222 };
223 for (const auto &row : pdEngine) {
224 dumpFileContent(row[0], row[1]);
225 }
226}
samou6c250222024-07-16 07:40:36 +0000227void dumpBatteryHealth() {
228 const char* batteryHealth [][2] {
229 {"Battery Health", "/sys/class/power_supply/battery/health_index_stats"},
Spade Lee7bbc59e2024-10-29 16:07:29 +0000230 {"Battery Health SoC Residency", "/sys/class/power_supply/battery/swelling_data"},
samou6c250222024-07-16 07:40:36 +0000231 {"BMS", "/dev/logbuffer_ssoc"},
232 {"TTF", "/dev/logbuffer_ttf"},
233 {"TTF details", "/sys/class/power_supply/battery/ttf_details"},
234 {"TTF stats", "/sys/class/power_supply/battery/ttf_stats"},
235 {"aacr_state", "/sys/class/power_supply/battery/aacr_state"},
236 {"maxq", "/dev/logbuffer_maxq"},
237 {"TEMP/DOCK-DEFEND", "/dev/logbuffer_bd"},
238 };
239 for (const auto &row : batteryHealth) {
240 dumpFileContent(row[0], row[1]);
241 }
242}
243void dumpBatteryDefend() {
244 const char* defendConfig [][3] {
245 {"TRICKLE-DEFEND Config",
246 "/sys/devices/platform/google,battery/power_supply/battery/", "bd_"},
247 {"DWELL-DEFEND Config", "/sys/devices/platform/google,charger/", "charge_s"},
248 {"TEMP-DEFEND Config", "/sys/devices/platform/google,charger/", "bd_"},
249 };
250 std::vector<std::string> files;
251 struct dirent *entry;
252 std::string content;
253 std::string fileLocation;
254 for (auto &config : defendConfig) {
255 DIR *dir = opendir(config[1]);
256 if (dir == NULL)
257 continue;
258 printTitle(config[0]);
259 while ((entry = readdir(dir)) != NULL) {
260 if (std::string(entry->d_name).find(config[2]) != std::string::npos &&
261 strncmp(config[2], entry->d_name, strlen(config[2])) == 0) {
262 files.push_back(entry->d_name);
263 }
264 }
265 closedir(dir);
266 sort(files.begin(), files.end());
267 for (auto &file : files) {
268 fileLocation = std::string(config[1]) + std::string(file);
Spade Lee7bbc59e2024-10-29 16:07:29 +0000269 if (!android::base::ReadFileToString(fileLocation, &content) || content.empty()) {
samou6c250222024-07-16 07:40:36 +0000270 content = "\n";
271 }
272 printf("%s: %s", file.c_str(), content.c_str());
273 if (content.back() != '\n')
274 printf("\n");
275 }
276 files.clear();
277 }
278}
Spade Lee7bbc59e2024-10-29 16:07:29 +0000279void printValuesOfDirectory(const char *directory, std::string debugfs, const char *strMatch) {
280 std::vector<std::string> files;
281 auto info = directory;
282 std::string content;
283 struct dirent *entry;
284 DIR *dir = opendir(debugfs.c_str());
285 if (dir == NULL)
286 return;
287
288 printTitle((debugfs + std::string(strMatch) + "/" + std::string(info)).c_str());
289 while ((entry = readdir(dir)) != NULL)
290 if (std::string(entry->d_name).find(strMatch) != std::string::npos)
291 files.push_back(entry->d_name);
292 closedir(dir);
293
294 sort(files.begin(), files.end());
295
296 for (auto &file : files) {
297 std::string fileDirectory = debugfs + file;
298 std::string fileLocation = fileDirectory + "/" + std::string(info);
299 if (!android::base::ReadFileToString(fileLocation, &content)) {
300 content = "\n";
301 }
302
303 printf("%s:\n%s", fileDirectory.c_str(), content.c_str());
304
305 if (content.back() != '\n')
306 printf("\n");
307 }
308 files.clear();
309}
310void dumpChg() {
Spade Leedf3964b2024-11-07 17:22:50 +0000311 const std::string pmic_bus = "/sys/devices/platform/10d50000.hsi2c/i2c-12/12-0066";
Spade Lee7bbc59e2024-10-29 16:07:29 +0000312 const char* chg_reg_dump_file = "/sys/class/power_supply/main-charger/device/registers_dump";
313 const std::string chg_name_cmd = "/sys/class/power_supply/main-charger/device/name";
314 const std::string pmic_name_cmd = pmic_bus + "/name";
315 const std::string pmic_reg_dump_file = pmic_bus + "/registers_dump";
316 const std::string reg_dump_str = " registers dump";
317 const char* chgConfig [][2] {
318 {"DC_registers dump", "/sys/class/power_supply/pca9468-mains/device/registers_dump"},
319 };
320 std::string chg_name;
321 std::string pmic_name;
322
323 printf("\n");
324
325 int ret = android::base::ReadFileToString(chg_name_cmd, &chg_name);
326 if (ret && !chg_name.empty()) {
327 chg_name.erase(chg_name.length() - 1); // remove new line
328 const std::string chg_reg_dump_title = chg_name + reg_dump_str;
329
330 /* CHG reg dump */
331 dumpFileContent(chg_reg_dump_title.c_str(), chg_reg_dump_file);
332 }
333
334 ret = android::base::ReadFileToString(pmic_name_cmd, &pmic_name);
335 if (ret && !pmic_name.empty()) {
336 pmic_name.erase(pmic_name.length() - 1); // remove new line
337 const std::string pmic_reg_dump_title = pmic_name + reg_dump_str;
338
339 /* PMIC reg dump */
340 dumpFileContent(pmic_reg_dump_title.c_str(), pmic_reg_dump_file.c_str());
341 }
342
343 for (auto &config : chgConfig) {
344 dumpFileContent(config[0], config[1]);
345 }
346}
347void dumpChgUserDebug() {
348 const std::string debugfs = "/d/";
349 const char *maxFgDir = "/d/maxfg";
350 const char *maxFgStrMatch = "maxfg";
Spade Lee7bbc59e2024-10-29 16:07:29 +0000351 const char *chgTblName = "Charging table dump";
352 const char *chgTblDir = "/d/google_battery/chg_raw_profile";
353
354 const char *maxFgInfo [] {
355 "fg_model",
356 "algo_ver",
357 "model_ok",
358 };
359
Spade Lee7bbc59e2024-10-29 16:07:29 +0000360 if (isUserBuild())
361 return;
362
363 dumpFileContent(chgTblName, chgTblDir);
364
365 if (isValidDir(maxFgDir)) {
366 for (auto & directory : maxFgInfo) {
367 printValuesOfDirectory(directory, debugfs, maxFgStrMatch);
368 }
Spade Lee7bbc59e2024-10-29 16:07:29 +0000369 }
370}
samou6c250222024-07-16 07:40:36 +0000371void dumpBatteryEeprom() {
372 const char *title = "Battery EEPROM";
373 const char *files[] {
Spade Lee7bbc59e2024-10-29 16:07:29 +0000374 "/sys/devices/platform/10970000.hsi2c/i2c-8/8-0050/eeprom",
samou6c250222024-07-16 07:40:36 +0000375 };
376 std::string result;
377 std::string xxdCmd;
378 printTitle(title);
379 for (auto &file : files) {
380 if (!isValidFile(file))
381 continue;
382 xxdCmd = "xxd " + std::string(file);
383 int ret = getCommandOutput(xxdCmd.c_str(), &result);
384 if (ret < 0)
385 return;
386 printf("%s\n", result.c_str());
387 }
388}
389void dumpChargerStats() {
390 const char *chgStatsTitle = "Charger Stats";
391 const char *chgStatsLocation = "/sys/class/power_supply/battery/charge_details";
392 const char *chargerStats [][3] {
393 {"Google Charger", "/sys/kernel/debug/google_charger/", "pps_"},
394 {"Google Battery", "/sys/kernel/debug/google_battery/", "ssoc_"},
395 };
396 std::vector<std::string> files;
397 std::string content;
398 struct dirent *entry;
399 dumpFileContent(chgStatsTitle, chgStatsLocation);
Spade Lee7bbc59e2024-10-29 16:07:29 +0000400 if (isUserBuild())
samou6c250222024-07-16 07:40:36 +0000401 return;
402 for (auto &stat : chargerStats) {
403 DIR *dir = opendir(stat[1]);
404 if (dir == NULL)
405 return;
406 printTitle(stat[0]);
407 while ((entry = readdir(dir)) != NULL)
408 if (std::string(entry->d_name).find(stat[2]) != std::string::npos)
409 files.push_back(entry->d_name);
410 closedir(dir);
411 sort(files.begin(), files.end());
412 for (auto &file : files) {
413 std::string fileLocation = std::string(stat[1]) + file;
414 if (!android::base::ReadFileToString(fileLocation, &content)) {
415 content = "\n";
416 }
417 printf("%s: %s", file.c_str(), content.c_str());
418 if (content.back() != '\n')
419 printf("\n");
420 }
421 files.clear();
422 }
423}
424void dumpWlcLogs() {
425 const char *dumpWlcList [][2] {
426 {"WLC Logs", "/dev/logbuffer_wireless"},
427 {"WLC VER", "/sys/class/power_supply/wireless/device/version"},
428 {"WLC STATUS", "/sys/class/power_supply/wireless/device/status"},
429 {"WLC FW Version", "/sys/class/power_supply/wireless/device/fw_rev"},
430 {"RTX", "/dev/logbuffer_rtx"},
431 };
432 for (auto &row : dumpWlcList) {
433 if (!isValidFile(row[1]))
434 printTitle(row[0]);
435 dumpFileContent(row[0], row[1]);
436 }
437}
438void dumpGvoteables() {
439 const char *directory = "/sys/kernel/debug/gvotables/";
440 const char *statusName = "/status";
441 const char *title = "gvotables";
442 std::string content;
443 std::vector<std::string> files;
444 int ret;
Spade Lee7bbc59e2024-10-29 16:07:29 +0000445 if (isUserBuild())
samou6c250222024-07-16 07:40:36 +0000446 return;
447 ret = getFilesInDir(directory, &files);
448 if (ret < 0)
449 return;
450 printTitle(title);
451 for (auto &file : files) {
452 std::string fileLocation = std::string(directory) + file + std::string(statusName);
453 if (!android::base::ReadFileToString(fileLocation, &content)) {
454 continue;
455 }
456 printf("%s: %s", file.c_str(), content.c_str());
457 if (content.back() != '\n')
458 printf("\n");
459 }
460 files.clear();
461}
462void dumpMitigation() {
463 const char *mitigationList [][2] {
464 {"Lastmeal" , "/data/vendor/mitigation/lastmeal.txt"},
465 {"Thismeal" , "/data/vendor/mitigation/thismeal.txt"},
466 };
467 for (auto &row : mitigationList) {
468 if (!isValidFile(row[1]))
469 printTitle(row[0]);
470 dumpFileContent(row[0], row[1]);
471 }
472}
473void dumpMitigationStats() {
474 int ret;
475 const char *directory = "/sys/devices/virtual/pmic/mitigation/last_triggered_count/";
476 const char *capacityDirectory = "/sys/devices/virtual/pmic/mitigation/last_triggered_capacity/";
477 const char *timestampDirectory =
478 "/sys/devices/virtual/pmic/mitigation/last_triggered_timestamp/";
479 const char *voltageDirectory = "/sys/devices/virtual/pmic/mitigation/last_triggered_voltage/";
480 const char *capacitySuffix = "_cap";
481 const char *timeSuffix = "_time";
482 const char *voltageSuffix = "_volt";
483 const char *countSuffix = "_count";
484 const char *title = "Mitigation Stats";
485 std::vector<std::string> files;
486 std::string content;
487 std::string fileLocation;
488 std::string source;
489 std::string subModuleName;
490 int count;
491 int soc;
492 int time;
493 int voltage;
494 ret = getFilesInDir(directory, &files);
495 if (ret < 0)
496 return;
497 printTitle(title);
498 printf("Source\t\tCount\tSOC\tTime\tVoltage\n");
499 for (auto &file : files) {
500 fileLocation = std::string(directory) + std::string(file);
501 if (!android::base::ReadFileToString(fileLocation, &content)) {
502 continue;
503 }
504 ret = atoi(android::base::Trim(content).c_str());
505 if (ret == -1)
506 continue;
507 count = ret;
508 subModuleName = std::string(file);
509 subModuleName.erase(subModuleName.find(countSuffix), strlen(countSuffix));
510 fileLocation = std::string(capacityDirectory) + std::string(subModuleName) +
511 std::string(capacitySuffix);
512 if (!android::base::ReadFileToString(fileLocation, &content)) {
513 continue;
514 }
515 ret = atoi(android::base::Trim(content).c_str());
516 if (ret == -1)
517 continue;
518 soc = ret;
519 fileLocation = std::string(timestampDirectory) + std::string(subModuleName) +
520 std::string(timeSuffix);
521 if (!android::base::ReadFileToString(fileLocation, &content)) {
522 continue;
523 }
524 ret = atoi(android::base::Trim(content).c_str());
525 if (ret == -1)
526 continue;
527 time = ret;
528 fileLocation = std::string(voltageDirectory) + std::string(subModuleName) +
529 std::string(voltageSuffix);
530 if (!android::base::ReadFileToString(fileLocation, &content)) {
531 continue;
532 }
533 ret = atoi(android::base::Trim(content).c_str());
534 if (ret == -1)
535 continue;
536 voltage = ret;
537 printf("%s \t%i\t%i\t%i\t%i\n", subModuleName.c_str(), count, soc, time, voltage);
538 }
539}
540void dumpMitigationDirs() {
541 const int paramCount = 4;
542 const char *titles[] = {
543 "Clock Divider Ratio",
544 "Clock Stats",
545 "Triggered Level",
546 "Instruction",
547 };
548 const char *directories[] = {
549 "/sys/devices/virtual/pmic/mitigation/clock_ratio/",
550 "/sys/devices/virtual/pmic/mitigation/clock_stats/",
551 "/sys/devices/virtual/pmic/mitigation/triggered_lvl/",
552 "/sys/devices/virtual/pmic/mitigation/instruction/",
553 };
554 const char *paramSuffix[] = {"_ratio", "_stats", "_lvl", ""};
555 const char *titleRowVal[] = {
556 "Source\t\tRatio",
557 "Source\t\tStats",
558 "Source\t\tLevel",
559 "",
560 };
561 const int eraseCnt[] = {6, 6, 4, 0};
562 const bool useTitleRow[] = {true, true, true, false};
563 std::vector<std::string> files;
564 std::string content;
565 std::string fileLocation;
566 std::string source;
567 std::string subModuleName;
568 std::string readout;
569 for (int i = 0; i < paramCount; i++) {
570 printTitle(titles[i]);
571 if (useTitleRow[i]) {
572 printf("%s\n", titleRowVal[i]);
573 }
574 getFilesInDir(directories[i], &files);
575 for (auto &file : files) {
576 fileLocation = std::string(directories[i]) + std::string(file);
577 if (!android::base::ReadFileToString(fileLocation, &content)) {
578 continue;
579 }
580 readout = android::base::Trim(content);
581 subModuleName = std::string(file);
582 subModuleName.erase(subModuleName.find(paramSuffix[i]), eraseCnt[i]);
583 if (useTitleRow[i]) {
584 printf("%s \t%s\n", subModuleName.c_str(), readout.c_str());
585 } else {
586 printf("%s=%s\n", subModuleName.c_str(), readout.c_str());
587 }
588 }
589 }
590}
591void dumpIrqDurationCounts() {
592 const char *title = "IRQ Duration Counts";
593 const char *colNames = "Source\t\t\t\tlt_5ms_cnt\tbt_5ms_to_10ms_cnt\tgt_10ms_cnt\tCode"
594 "\tCurrent Threshold (uA)\tCurrent Reading (uA)\n";
595 const int nonOdpmChannelCnt = 9;
596 const int odpmChCnt = 12;
597 enum Duration {
598 LT_5MS,
599 BT_5MS_10MS,
600 GT_10MS,
601 DUR_MAX,
602 };
603 const char *irqDurDirectories[] = {
604 "/sys/devices/virtual/pmic/mitigation/irq_dur_cnt/less_than_5ms_count",
605 "/sys/devices/virtual/pmic/mitigation/irq_dur_cnt/between_5ms_to_10ms_count",
606 "/sys/devices/virtual/pmic/mitigation/irq_dur_cnt/greater_than_10ms_count",
607 };
608 enum PowerWarn {
609 MAIN,
610 SUB,
611 PWRWARN_MAX,
612 };
613 const char *pwrwarnDirectories[] = {
614 "/sys/devices/virtual/pmic/mitigation/main_pwrwarn/",
615 "/sys/devices/virtual/pmic/mitigation/sub_pwrwarn/",
616 };
617 const char *lpfCurrentDirs[] = {
618 "/sys/devices/platform/acpm_mfd_bus@15500000/i2c-1/1-001f/s2mpg14-meter/"
619 "s2mpg14-odpm/iio:device1/lpf_current",
620 "/sys/devices/platform/acpm_mfd_bus@15510000/i2c-0/0-002f/s2mpg15-meter/"
621 "s2mpg15-odpm/iio:device0/lpf_current",
622 };
623 bool titlesInitialized = false;
624 std::vector<std::string> channelNames;
625 std::vector<std::string> channelData[DUR_MAX];
626 std::vector<std::string> pwrwarnThreshold[PWRWARN_MAX];
627 std::vector<std::string> pwrwarnCode[PWRWARN_MAX];
628 std::vector<std::string> lpfCurrentVals[PWRWARN_MAX];
629 std::vector<std::string> files;
630 std::string content;
631 std::string token;
632 std::string tokenCh;
633 std::string fileLocation;
634 for (int i = 0; i < DUR_MAX; i++) {
635 if (!android::base::ReadFileToString(irqDurDirectories[i], &content)) {
636 return;
637 }
638 std::istringstream tokenStream(content);
639 while (std::getline(tokenStream, token, '\n')) {
640 if (!titlesInitialized) {
641 tokenCh = token;
642 tokenCh.erase(tokenCh.find(':'), tokenCh.length());
643 channelNames.push_back(tokenCh);
644 }
645 // there is a space after the ':' which needs to be removed
646 token.erase(0, token.find(':') + 1);
647 channelData[i].push_back(token);
648 }
649 if (!titlesInitialized)
650 titlesInitialized = true;
651 }
652 for (int i = 0; i < PWRWARN_MAX; i++) {
653 getFilesInDir(pwrwarnDirectories[i], &files);
654 for (auto &file : files) {
655 fileLocation = std::string(pwrwarnDirectories[i]) + std::string(file);
656 if (!android::base::ReadFileToString(fileLocation, &content)) {
657 continue;
658 }
659 std::string readout;
660 readout = android::base::Trim(content);
661 std::string readoutThreshold = readout;
662 readoutThreshold.erase(0, readoutThreshold.find('=') + 1);
663 std::string readoutCode = readout;
664 readoutCode.erase(readoutCode.find('='), readoutCode.length());
665 pwrwarnThreshold[i].push_back(readoutThreshold);
666 pwrwarnCode[i].push_back(readoutCode);
667 }
668 }
669 for (int i = 0; i < PWRWARN_MAX; i++) {
670 if (!android::base::ReadFileToString(lpfCurrentDirs[i], &content)) {
671 continue;
672 }
673 std::istringstream tokenStream(content);
674 bool first = true;
675 while (std::getline(tokenStream, token, '\n')) {
676 token.erase(0, token.find(' '));
677 if (first) {
678 first = false;
679 continue;
680 }
681 lpfCurrentVals[i].push_back(token);
682 }
683 }
684 printTitle(title);
685 printf("%s", colNames);
686 for (uint i = 0; i < channelNames.size(); i++) {
687 std::string code = "";
688 std::string threshold = "";
689 std::string current = "";
690 std::string ltDataMsg = "";
691 std::string btDataMsg = "";
692 std::string gtDataMsg = "";
693 int pmicSel = 0;
694 int offset = 0;
695 std::string channelNameSuffix = " \t";
696 if (i >= nonOdpmChannelCnt) {
697 offset = nonOdpmChannelCnt;
698 if (i >= (odpmChCnt + nonOdpmChannelCnt)) {
699 pmicSel = 1;
700 offset = odpmChCnt + nonOdpmChannelCnt;
701 }
702 channelNameSuffix = "";
703 code = pwrwarnCode[pmicSel][i - offset];
704 threshold = pwrwarnThreshold[pmicSel][i - offset];
705 current = lpfCurrentVals[pmicSel][i - offset];
706 }
707 if (i < channelData[0].size())
708 ltDataMsg = channelData[0][i];
709 if (i < channelData[1].size())
710 btDataMsg = channelData[1][i];
711 if (i < channelData[2].size())
712 gtDataMsg = channelData[2][i];
713 std::string adjustedChannelName = channelNames[i] + channelNameSuffix;
714 printf("%s \t%s\t\t%s\t\t\t%s\t\t%s \t%s \t\t%s\n",
715 adjustedChannelName.c_str(),
716 ltDataMsg.c_str(),
717 btDataMsg.c_str(),
718 gtDataMsg.c_str(),
719 code.c_str(),
720 threshold.c_str(),
721 current.c_str());
722 }
723}
724int main() {
725 dumpPowerStatsTimes();
726 dumpAcpmStats();
727 dumpPowerSupplyStats();
728 dumpMaxFg();
729 dumpPowerSupplyDock();
730 dumpLogBufferTcpm();
731 dumpTcpc();
732 dumpPdEngine();
samou6c250222024-07-16 07:40:36 +0000733 dumpBatteryHealth();
734 dumpBatteryDefend();
Spade Lee7bbc59e2024-10-29 16:07:29 +0000735 dumpChg();
736 dumpChgUserDebug();
samou6c250222024-07-16 07:40:36 +0000737 dumpBatteryEeprom();
738 dumpChargerStats();
739 dumpWlcLogs();
740 dumpGvoteables();
741 dumpMitigation();
742 dumpMitigationStats();
743 dumpMitigationDirs();
744 dumpIrqDurationCounts();
745}