blob: cdbfe6480d915fd6ec7419c8b59acef7e7a5bc05 [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) {
47 if (!access(file, R_OK)) {
48 return false;
49 }
50 return true;
51}
52bool isUserBuild() {
53 return ::android::os::dumpstate::PropertiesHelper::IsUserBuild();
54}
55int getFilesInDir(const char *directory, std::vector<std::string> *files) {
56 std::string content;
57 struct dirent *entry;
58 DIR *dir = opendir(directory);
59 if (dir == NULL)
60 return -1;
61 files->clear();
62 while ((entry = readdir(dir)) != NULL)
63 files->push_back(entry->d_name);
64 closedir(dir);
65 sort(files->begin(), files->end());
66 return 0;
67}
68void dumpPowerStatsTimes() {
69 const char *title = "Power Stats Times";
70 char rBuff[128];
71 struct timespec rTs;
72 struct sysinfo info;
73 int ret;
74 printTitle(title);
75 sysinfo(&info);
76 const time_t boottime = time(NULL) - info.uptime;
77 ret = clock_gettime(CLOCK_REALTIME, &rTs);
78 if (ret)
79 return;
80 struct tm *nowTime = std::localtime(&rTs.tv_sec);
81 std::strftime(rBuff, sizeof(rBuff), "%m/%d/%Y %H:%M:%S", nowTime);
82 printf("Boot: %s", ctime(&boottime));
83 printf("Now: %s\n", rBuff);
84}
85int readContentsOfDir(const char* title, const char* directory, const char* strMatch,
86 bool useStrMatch = false, bool printDirectory = false) {
87 std::vector<std::string> files;
88 std::string content;
89 std::string fileLocation;
90 int ret;
91 ret = getFilesInDir(directory, &files);
92 if (ret < 0)
93 return ret;
94 printTitle(title);
95 for (auto &file : files) {
96 if (useStrMatch && std::string::npos == std::string(file).find(strMatch)) {
97 continue;
98 }
99 fileLocation = std::string(directory) + std::string(file);
100 if (!android::base::ReadFileToString(fileLocation, &content)) {
101 continue;
102 }
103 if (printDirectory) {
104 printf("\n\n%s\n", fileLocation.c_str());
105 }
106 if (content.back() == '\n')
107 content.pop_back();
108 printf("%s\n", content.c_str());
109 }
110 return 0;
111}
112void dumpAcpmStats() {
113 const char* acpmDir = "/sys/devices/platform/acpm_stats/";
114 const char* statsSubStr = "_stats";
115 const char* acpmTitle = "ACPM stats";
116 readContentsOfDir(acpmTitle, acpmDir, statsSubStr, true, true);
117}
118void dumpPowerSupplyStats() {
119 const char* dumpList[][2] = {
120 {"CPU PM stats", "/sys/devices/system/cpu/cpupm/cpupm/time_in_state"},
121 {"GENPD summary", "/d/pm_genpd/pm_genpd_summary"},
122 {"Power supply property battery", "/sys/class/power_supply/battery/uevent"},
123 {"Power supply property dc", "/sys/class/power_supply/dc/uevent"},
124 {"Power supply property gcpm", "/sys/class/power_supply/gcpm/uevent"},
125 {"Power supply property gcpm_pps", "/sys/class/power_supply/gcpm_pps/uevent"},
126 {"Power supply property main-charger", "/sys/class/power_supply/main-charger/uevent"},
127 {"Power supply property dc-mains", "/sys/class/power_supply/dc-mains/uevent"},
128 {"Power supply property tcpm", "/sys/class/power_supply/tcpm-source-psy-8-0025/uevent"},
129 {"Power supply property usb", "/sys/class/power_supply/usb/uevent"},
130 {"Power supply property wireless", "/sys/class/power_supply/wireless/uevent"},
131 };
132 for (const auto &row : dumpList) {
133 dumpFileContent(row[0], row[1]);
134 }
135}
136void dumpMaxFg() {
137 const char *maxfgLoc = "/sys/class/power_supply/maxfg";
138 const char *maxfg [][2] = {
139 {"Power supply property maxfg", "/sys/class/power_supply/maxfg/uevent"},
140 {"m5_state", "/sys/class/power_supply/maxfg/m5_model_state"},
141 {"maxfg", "/dev/logbuffer_maxfg"},
142 {"maxfg", "/dev/logbuffer_maxfg_monitor"},
143 };
144 const char *maxfgFlip [][2] = {
145 {"Power supply property maxfg_base", "/sys/class/power_supply/maxfg_base/uevent"},
146 {"Power supply property maxfg_flip", "/sys/class/power_supply/maxfg_flip/uevent"},
147 {"m5_state", "/sys/class/power_supply/maxfg_base/m5_model_state"},
148 {"maxfg_base", "/dev/logbuffer_maxfg_base"},
149 {"maxfg_flip", "/dev/logbuffer_maxfg_flip"},
150 {"maxfg_base", "/dev/logbuffer_maxfg_base_monitor"},
151 {"maxfg_flip", "/dev/logbuffer_maxfg_flip_monitor"},
152 };
153 const char *maxfgHistoryName = "Maxim FG History";
154 const char *maxfgHistoryDir = "/dev/maxfg_history";
155 std::string content;
156 if (isValidFile(maxfgLoc)) {
157 for (const auto &row : maxfg) {
158 dumpFileContent(row[0], row[1]);
159 }
160 } else {
161 for (const auto &row : maxfgFlip) {
162 dumpFileContent(row[0], row[1]);
163 }
164 }
165 if (isValidFile(maxfgHistoryDir)) {
166 dumpFileContent(maxfgHistoryName, maxfgHistoryDir);
167 }
168}
169void dumpPowerSupplyDock() {
170 const char* powerSupplyPropertyDockTitle = "Power supply property dock";
171 const char* powerSupplyPropertyDockFile = "/sys/class/power_supply/dock/uevent";
172 dumpFileContent(powerSupplyPropertyDockTitle, powerSupplyPropertyDockFile);
173}
174void dumpLogBufferTcpm() {
175 const char* logbufferTcpmTitle = "Logbuffer TCPM";
176 const char* logbufferTcpmFile = "/dev/logbuffer_tcpm";
177 const char* debugTcpmFile = "/sys/kernel/debug/tcpm";
178 const char* tcpmLogTitle = "TCPM logs";
179 const char* tcpmFile = "/sys/kernel/debug/tcpm";
180 const char* tcpmFileAlt = "/sys/kernel/debug/usb/tcpm";
181 int retCode;
182 dumpFileContent(logbufferTcpmTitle, logbufferTcpmFile);
183 retCode = readContentsOfDir(tcpmLogTitle, isValidFile(debugTcpmFile) ? tcpmFile : tcpmFileAlt,
184 NULL);
185 if (retCode < 0)
186 printTitle(tcpmLogTitle);
187}
188void dumpTcpc() {
189 int ret;
190 const char* max77759TcpcHead = "TCPC";
191 const char* i2cSubDirMatch = "i2c-";
192 const char* directory = "/sys/devices/platform/10d60000.hsi2c/";
193 const char* max77759Tcpc [][2] {
194 {"registers:", "/i2c-max77759tcpc/registers"},
195 {"frs:", "/i2c-max77759tcpc/frs"},
196 {"auto_discharge:", "/i2c-max77759tcpc/auto_discharge"},
197 {"bcl2_enabled:", "/i2c-max77759tcpc/bcl2_enabled"},
198 {"cc_toggle_enable:", "/i2c-max77759tcpc/cc_toggle_enable"},
199 {"containment_detection:", "/i2c-max77759tcpc/containment_detection"},
200 {"containment_detection_status:", "/i2c-max77759tcpc/containment_detection_status"},
201 };
202 std::vector<std::string> files;
203 std::string content;
204 printTitle(max77759TcpcHead);
205 ret = getFilesInDir(directory, &files);
206 if (ret < 0) {
207 for (auto &tcpcVal : max77759Tcpc)
208 printf("%s\n", tcpcVal[0]);
209 return;
210 }
211 for (auto &file : files) {
212 for (auto &tcpcVal : max77759Tcpc) {
213 printf("%s ", tcpcVal[0]);
214 if (std::string::npos == std::string(file).find(i2cSubDirMatch)) {
215 continue;
216 }
217 std::string fileName = directory + file + "/" + std::string(tcpcVal[1]);
218 if (!android::base::ReadFileToString(fileName, &content)) {
219 continue;
220 }
221 printf("%s\n", content.c_str());
222 }
223 }
224}
225void dumpPdEngine() {
226 const char* pdEngine [][2] {
227 {"PD Engine", "/dev/logbuffer_usbpd"},
228 {"PPS-google_cpm", "/dev/logbuffer_cpm"},
229 {"PPS-dc", "/dev/logbuffer_pca9468"},
230 };
231 for (const auto &row : pdEngine) {
232 dumpFileContent(row[0], row[1]);
233 }
234}
235void dumpWc68() {
236 const char* wc68Title = "WC68";
237 const char* wc68File = "/dev/logbuffer_wc68";
238 dumpFileContent(wc68Title, wc68File);
239}
240void dumpLn8411() {
241 const char* ln8411Title = "LN8411";
242 const char* ln8411File = "/dev/logbuffer_ln8411";
243 dumpFileContent(ln8411Title, ln8411File);
244}
245void dumpBatteryHealth() {
246 const char* batteryHealth [][2] {
247 {"Battery Health", "/sys/class/power_supply/battery/health_index_stats"},
248 {"BMS", "/dev/logbuffer_ssoc"},
249 {"TTF", "/dev/logbuffer_ttf"},
250 {"TTF details", "/sys/class/power_supply/battery/ttf_details"},
251 {"TTF stats", "/sys/class/power_supply/battery/ttf_stats"},
252 {"aacr_state", "/sys/class/power_supply/battery/aacr_state"},
253 {"maxq", "/dev/logbuffer_maxq"},
254 {"TEMP/DOCK-DEFEND", "/dev/logbuffer_bd"},
255 };
256 for (const auto &row : batteryHealth) {
257 dumpFileContent(row[0], row[1]);
258 }
259}
260void dumpBatteryDefend() {
261 const char* defendConfig [][3] {
262 {"TRICKLE-DEFEND Config",
263 "/sys/devices/platform/google,battery/power_supply/battery/", "bd_"},
264 {"DWELL-DEFEND Config", "/sys/devices/platform/google,charger/", "charge_s"},
265 {"TEMP-DEFEND Config", "/sys/devices/platform/google,charger/", "bd_"},
266 };
267 std::vector<std::string> files;
268 struct dirent *entry;
269 std::string content;
270 std::string fileLocation;
271 for (auto &config : defendConfig) {
272 DIR *dir = opendir(config[1]);
273 if (dir == NULL)
274 continue;
275 printTitle(config[0]);
276 while ((entry = readdir(dir)) != NULL) {
277 if (std::string(entry->d_name).find(config[2]) != std::string::npos &&
278 strncmp(config[2], entry->d_name, strlen(config[2])) == 0) {
279 files.push_back(entry->d_name);
280 }
281 }
282 closedir(dir);
283 sort(files.begin(), files.end());
284 for (auto &file : files) {
285 fileLocation = std::string(config[1]) + std::string(file);
286 if (!android::base::ReadFileToString(fileLocation, &content)) {
287 content = "\n";
288 }
289 printf("%s: %s", file.c_str(), content.c_str());
290 if (content.back() != '\n')
291 printf("\n");
292 }
293 files.clear();
294 }
295}
296void dumpChgUserDebug() {
297 std::vector<std::string> files;
298 struct dirent *entry;
299 std::string content;
300 const char *chgUserDebug [][2] {
301 {"DC_registers dump", "/sys/class/power_supply/dc-mains/device/registers_dump"},
302 {"max77759_chg registers dump", "/d/max77759_chg/registers"},
303 {"max77729_pmic registers dump", "/d/max77729_pmic/registers"},
304 {"Charging table dump", "/d/google_battery/chg_raw_profile"},
305 };
306 const std::string debugfs = "/d/";
307 const char *maxFgStrMatch = "maxfg";
308 const char *fgInfo [][2] {
309 {"fg_model", "fg_model"},
310 {"fg_alo_ver", "algo_ver"},
311 {"fg_model_ok", "model_ok"},
312 {"fg registers", "registers"},
313 {"Maxim FG NV RAM", "nv_registers"},
314 };
315 if (!isUserBuild())
316 return;
317 for (auto &row : chgUserDebug) {
318 dumpFileContent(row[0], row[1]);
319 }
320 for (auto &info : fgInfo) {
321 DIR *dir = opendir(debugfs.c_str());
322 if (dir == NULL)
323 return;
324 printTitle(info[0]);
325 while ((entry = readdir(dir)) != NULL)
326 if (std::string(entry->d_name).find(maxFgStrMatch) != std::string::npos)
327 files.push_back(entry->d_name);
328 closedir(dir);
329 sort(files.begin(), files.end());
330 for (auto &file : files) {
331 std::string fileDirectory = debugfs + file;
332 std::string fileLocation = fileDirectory + "/" + std::string(info[1]);
333 if (!android::base::ReadFileToString(fileLocation, &content)) {
334 content = "\n";
335 }
336 printf("%s:\n%s", fileDirectory.c_str(), content.c_str());
337 if (content.back() != '\n')
338 printf("\n");
339 }
340 files.clear();
341 }
342}
343void dumpBatteryEeprom() {
344 const char *title = "Battery EEPROM";
345 const char *files[] {
346 "/sys/devices/platform/10970000.hsi2c/i2c-4/4-0050/eeprom",
347 "/sys/devices/platform/10970000.hsi2c/i2c-5/5-0050/eeprom",
348 "/sys/devices/platform/10da0000.hsi2c/i2c-6/6-0050/eeprom",
349 "/sys/devices/platform/10da0000.hsi2c/i2c-7/7-0050/eeprom",
350 "/sys/devices/platform/10c90000.hsi2c/i2c-7/7-0050/eeprom",
351 "/sys/devices/platform/10c90000.hsi2c/i2c-6/6-0050/eeprom",
352 };
353 std::string result;
354 std::string xxdCmd;
355 printTitle(title);
356 for (auto &file : files) {
357 if (!isValidFile(file))
358 continue;
359 xxdCmd = "xxd " + std::string(file);
360 int ret = getCommandOutput(xxdCmd.c_str(), &result);
361 if (ret < 0)
362 return;
363 printf("%s\n", result.c_str());
364 }
365}
366void dumpChargerStats() {
367 const char *chgStatsTitle = "Charger Stats";
368 const char *chgStatsLocation = "/sys/class/power_supply/battery/charge_details";
369 const char *chargerStats [][3] {
370 {"Google Charger", "/sys/kernel/debug/google_charger/", "pps_"},
371 {"Google Battery", "/sys/kernel/debug/google_battery/", "ssoc_"},
372 };
373 std::vector<std::string> files;
374 std::string content;
375 struct dirent *entry;
376 dumpFileContent(chgStatsTitle, chgStatsLocation);
377 if (!isUserBuild())
378 return;
379 for (auto &stat : chargerStats) {
380 DIR *dir = opendir(stat[1]);
381 if (dir == NULL)
382 return;
383 printTitle(stat[0]);
384 while ((entry = readdir(dir)) != NULL)
385 if (std::string(entry->d_name).find(stat[2]) != std::string::npos)
386 files.push_back(entry->d_name);
387 closedir(dir);
388 sort(files.begin(), files.end());
389 for (auto &file : files) {
390 std::string fileLocation = std::string(stat[1]) + file;
391 if (!android::base::ReadFileToString(fileLocation, &content)) {
392 content = "\n";
393 }
394 printf("%s: %s", file.c_str(), content.c_str());
395 if (content.back() != '\n')
396 printf("\n");
397 }
398 files.clear();
399 }
400}
401void dumpWlcLogs() {
402 const char *dumpWlcList [][2] {
403 {"WLC Logs", "/dev/logbuffer_wireless"},
404 {"WLC VER", "/sys/class/power_supply/wireless/device/version"},
405 {"WLC STATUS", "/sys/class/power_supply/wireless/device/status"},
406 {"WLC FW Version", "/sys/class/power_supply/wireless/device/fw_rev"},
407 {"RTX", "/dev/logbuffer_rtx"},
408 };
409 for (auto &row : dumpWlcList) {
410 if (!isValidFile(row[1]))
411 printTitle(row[0]);
412 dumpFileContent(row[0], row[1]);
413 }
414}
415void dumpGvoteables() {
416 const char *directory = "/sys/kernel/debug/gvotables/";
417 const char *statusName = "/status";
418 const char *title = "gvotables";
419 std::string content;
420 std::vector<std::string> files;
421 int ret;
422 if (!isUserBuild())
423 return;
424 ret = getFilesInDir(directory, &files);
425 if (ret < 0)
426 return;
427 printTitle(title);
428 for (auto &file : files) {
429 std::string fileLocation = std::string(directory) + file + std::string(statusName);
430 if (!android::base::ReadFileToString(fileLocation, &content)) {
431 continue;
432 }
433 printf("%s: %s", file.c_str(), content.c_str());
434 if (content.back() != '\n')
435 printf("\n");
436 }
437 files.clear();
438}
439void dumpMitigation() {
440 const char *mitigationList [][2] {
441 {"Lastmeal" , "/data/vendor/mitigation/lastmeal.txt"},
442 {"Thismeal" , "/data/vendor/mitigation/thismeal.txt"},
443 };
444 for (auto &row : mitigationList) {
445 if (!isValidFile(row[1]))
446 printTitle(row[0]);
447 dumpFileContent(row[0], row[1]);
448 }
449}
450void dumpMitigationStats() {
451 int ret;
452 const char *directory = "/sys/devices/virtual/pmic/mitigation/last_triggered_count/";
453 const char *capacityDirectory = "/sys/devices/virtual/pmic/mitigation/last_triggered_capacity/";
454 const char *timestampDirectory =
455 "/sys/devices/virtual/pmic/mitigation/last_triggered_timestamp/";
456 const char *voltageDirectory = "/sys/devices/virtual/pmic/mitigation/last_triggered_voltage/";
457 const char *capacitySuffix = "_cap";
458 const char *timeSuffix = "_time";
459 const char *voltageSuffix = "_volt";
460 const char *countSuffix = "_count";
461 const char *title = "Mitigation Stats";
462 std::vector<std::string> files;
463 std::string content;
464 std::string fileLocation;
465 std::string source;
466 std::string subModuleName;
467 int count;
468 int soc;
469 int time;
470 int voltage;
471 ret = getFilesInDir(directory, &files);
472 if (ret < 0)
473 return;
474 printTitle(title);
475 printf("Source\t\tCount\tSOC\tTime\tVoltage\n");
476 for (auto &file : files) {
477 fileLocation = std::string(directory) + std::string(file);
478 if (!android::base::ReadFileToString(fileLocation, &content)) {
479 continue;
480 }
481 ret = atoi(android::base::Trim(content).c_str());
482 if (ret == -1)
483 continue;
484 count = ret;
485 subModuleName = std::string(file);
486 subModuleName.erase(subModuleName.find(countSuffix), strlen(countSuffix));
487 fileLocation = std::string(capacityDirectory) + std::string(subModuleName) +
488 std::string(capacitySuffix);
489 if (!android::base::ReadFileToString(fileLocation, &content)) {
490 continue;
491 }
492 ret = atoi(android::base::Trim(content).c_str());
493 if (ret == -1)
494 continue;
495 soc = ret;
496 fileLocation = std::string(timestampDirectory) + std::string(subModuleName) +
497 std::string(timeSuffix);
498 if (!android::base::ReadFileToString(fileLocation, &content)) {
499 continue;
500 }
501 ret = atoi(android::base::Trim(content).c_str());
502 if (ret == -1)
503 continue;
504 time = ret;
505 fileLocation = std::string(voltageDirectory) + std::string(subModuleName) +
506 std::string(voltageSuffix);
507 if (!android::base::ReadFileToString(fileLocation, &content)) {
508 continue;
509 }
510 ret = atoi(android::base::Trim(content).c_str());
511 if (ret == -1)
512 continue;
513 voltage = ret;
514 printf("%s \t%i\t%i\t%i\t%i\n", subModuleName.c_str(), count, soc, time, voltage);
515 }
516}
517void dumpMitigationDirs() {
518 const int paramCount = 4;
519 const char *titles[] = {
520 "Clock Divider Ratio",
521 "Clock Stats",
522 "Triggered Level",
523 "Instruction",
524 };
525 const char *directories[] = {
526 "/sys/devices/virtual/pmic/mitigation/clock_ratio/",
527 "/sys/devices/virtual/pmic/mitigation/clock_stats/",
528 "/sys/devices/virtual/pmic/mitigation/triggered_lvl/",
529 "/sys/devices/virtual/pmic/mitigation/instruction/",
530 };
531 const char *paramSuffix[] = {"_ratio", "_stats", "_lvl", ""};
532 const char *titleRowVal[] = {
533 "Source\t\tRatio",
534 "Source\t\tStats",
535 "Source\t\tLevel",
536 "",
537 };
538 const int eraseCnt[] = {6, 6, 4, 0};
539 const bool useTitleRow[] = {true, true, true, false};
540 std::vector<std::string> files;
541 std::string content;
542 std::string fileLocation;
543 std::string source;
544 std::string subModuleName;
545 std::string readout;
546 for (int i = 0; i < paramCount; i++) {
547 printTitle(titles[i]);
548 if (useTitleRow[i]) {
549 printf("%s\n", titleRowVal[i]);
550 }
551 getFilesInDir(directories[i], &files);
552 for (auto &file : files) {
553 fileLocation = std::string(directories[i]) + std::string(file);
554 if (!android::base::ReadFileToString(fileLocation, &content)) {
555 continue;
556 }
557 readout = android::base::Trim(content);
558 subModuleName = std::string(file);
559 subModuleName.erase(subModuleName.find(paramSuffix[i]), eraseCnt[i]);
560 if (useTitleRow[i]) {
561 printf("%s \t%s\n", subModuleName.c_str(), readout.c_str());
562 } else {
563 printf("%s=%s\n", subModuleName.c_str(), readout.c_str());
564 }
565 }
566 }
567}
568void dumpIrqDurationCounts() {
569 const char *title = "IRQ Duration Counts";
570 const char *colNames = "Source\t\t\t\tlt_5ms_cnt\tbt_5ms_to_10ms_cnt\tgt_10ms_cnt\tCode"
571 "\tCurrent Threshold (uA)\tCurrent Reading (uA)\n";
572 const int nonOdpmChannelCnt = 9;
573 const int odpmChCnt = 12;
574 enum Duration {
575 LT_5MS,
576 BT_5MS_10MS,
577 GT_10MS,
578 DUR_MAX,
579 };
580 const char *irqDurDirectories[] = {
581 "/sys/devices/virtual/pmic/mitigation/irq_dur_cnt/less_than_5ms_count",
582 "/sys/devices/virtual/pmic/mitigation/irq_dur_cnt/between_5ms_to_10ms_count",
583 "/sys/devices/virtual/pmic/mitigation/irq_dur_cnt/greater_than_10ms_count",
584 };
585 enum PowerWarn {
586 MAIN,
587 SUB,
588 PWRWARN_MAX,
589 };
590 const char *pwrwarnDirectories[] = {
591 "/sys/devices/virtual/pmic/mitigation/main_pwrwarn/",
592 "/sys/devices/virtual/pmic/mitigation/sub_pwrwarn/",
593 };
594 const char *lpfCurrentDirs[] = {
595 "/sys/devices/platform/acpm_mfd_bus@15500000/i2c-1/1-001f/s2mpg14-meter/"
596 "s2mpg14-odpm/iio:device1/lpf_current",
597 "/sys/devices/platform/acpm_mfd_bus@15510000/i2c-0/0-002f/s2mpg15-meter/"
598 "s2mpg15-odpm/iio:device0/lpf_current",
599 };
600 bool titlesInitialized = false;
601 std::vector<std::string> channelNames;
602 std::vector<std::string> channelData[DUR_MAX];
603 std::vector<std::string> pwrwarnThreshold[PWRWARN_MAX];
604 std::vector<std::string> pwrwarnCode[PWRWARN_MAX];
605 std::vector<std::string> lpfCurrentVals[PWRWARN_MAX];
606 std::vector<std::string> files;
607 std::string content;
608 std::string token;
609 std::string tokenCh;
610 std::string fileLocation;
611 for (int i = 0; i < DUR_MAX; i++) {
612 if (!android::base::ReadFileToString(irqDurDirectories[i], &content)) {
613 return;
614 }
615 std::istringstream tokenStream(content);
616 while (std::getline(tokenStream, token, '\n')) {
617 if (!titlesInitialized) {
618 tokenCh = token;
619 tokenCh.erase(tokenCh.find(':'), tokenCh.length());
620 channelNames.push_back(tokenCh);
621 }
622 // there is a space after the ':' which needs to be removed
623 token.erase(0, token.find(':') + 1);
624 channelData[i].push_back(token);
625 }
626 if (!titlesInitialized)
627 titlesInitialized = true;
628 }
629 for (int i = 0; i < PWRWARN_MAX; i++) {
630 getFilesInDir(pwrwarnDirectories[i], &files);
631 for (auto &file : files) {
632 fileLocation = std::string(pwrwarnDirectories[i]) + std::string(file);
633 if (!android::base::ReadFileToString(fileLocation, &content)) {
634 continue;
635 }
636 std::string readout;
637 readout = android::base::Trim(content);
638 std::string readoutThreshold = readout;
639 readoutThreshold.erase(0, readoutThreshold.find('=') + 1);
640 std::string readoutCode = readout;
641 readoutCode.erase(readoutCode.find('='), readoutCode.length());
642 pwrwarnThreshold[i].push_back(readoutThreshold);
643 pwrwarnCode[i].push_back(readoutCode);
644 }
645 }
646 for (int i = 0; i < PWRWARN_MAX; i++) {
647 if (!android::base::ReadFileToString(lpfCurrentDirs[i], &content)) {
648 continue;
649 }
650 std::istringstream tokenStream(content);
651 bool first = true;
652 while (std::getline(tokenStream, token, '\n')) {
653 token.erase(0, token.find(' '));
654 if (first) {
655 first = false;
656 continue;
657 }
658 lpfCurrentVals[i].push_back(token);
659 }
660 }
661 printTitle(title);
662 printf("%s", colNames);
663 for (uint i = 0; i < channelNames.size(); i++) {
664 std::string code = "";
665 std::string threshold = "";
666 std::string current = "";
667 std::string ltDataMsg = "";
668 std::string btDataMsg = "";
669 std::string gtDataMsg = "";
670 int pmicSel = 0;
671 int offset = 0;
672 std::string channelNameSuffix = " \t";
673 if (i >= nonOdpmChannelCnt) {
674 offset = nonOdpmChannelCnt;
675 if (i >= (odpmChCnt + nonOdpmChannelCnt)) {
676 pmicSel = 1;
677 offset = odpmChCnt + nonOdpmChannelCnt;
678 }
679 channelNameSuffix = "";
680 code = pwrwarnCode[pmicSel][i - offset];
681 threshold = pwrwarnThreshold[pmicSel][i - offset];
682 current = lpfCurrentVals[pmicSel][i - offset];
683 }
684 if (i < channelData[0].size())
685 ltDataMsg = channelData[0][i];
686 if (i < channelData[1].size())
687 btDataMsg = channelData[1][i];
688 if (i < channelData[2].size())
689 gtDataMsg = channelData[2][i];
690 std::string adjustedChannelName = channelNames[i] + channelNameSuffix;
691 printf("%s \t%s\t\t%s\t\t\t%s\t\t%s \t%s \t\t%s\n",
692 adjustedChannelName.c_str(),
693 ltDataMsg.c_str(),
694 btDataMsg.c_str(),
695 gtDataMsg.c_str(),
696 code.c_str(),
697 threshold.c_str(),
698 current.c_str());
699 }
700}
701int main() {
702 dumpPowerStatsTimes();
703 dumpAcpmStats();
704 dumpPowerSupplyStats();
705 dumpMaxFg();
706 dumpPowerSupplyDock();
707 dumpLogBufferTcpm();
708 dumpTcpc();
709 dumpPdEngine();
710 dumpWc68();
711 dumpLn8411();
712 dumpBatteryHealth();
713 dumpBatteryDefend();
714 dumpChgUserDebug();
715 dumpBatteryEeprom();
716 dumpChargerStats();
717 dumpWlcLogs();
718 dumpGvoteables();
719 dumpMitigation();
720 dumpMitigationStats();
721 dumpMitigationDirs();
722 dumpIrqDurationCounts();
723}