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