| Adam Shih | cf72660 | 2022-10-04 13:09:00 +0800 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright 2022 The Android Open Source Project | 
|  | 3 | * | 
|  | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | * you may not use this file except in compliance with the License. | 
|  | 6 | * You may obtain a copy of the License at | 
|  | 7 | * | 
|  | 8 | *      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | * | 
|  | 10 | * Unless required by applicable law or agreed to in writing, software | 
|  | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | * See the License for the specific language governing permissions and | 
|  | 14 | * limitations under the License. | 
|  | 15 | */ | 
| Adam Shih | 4b68f5f | 2022-10-18 11:45:37 +0800 | [diff] [blame] | 16 | #include <dump/pixel_dump.h> | 
| Adam Shih | 7fbb67d | 2022-12-07 15:40:40 +0800 | [diff] [blame] | 17 | #include <android-base/file.h> | 
|  | 18 | #include <string.h> | 
|  | 19 | #include <stdio.h> | 
|  | 20 | #include <log/log.h> | 
|  | 21 | #include <regex> | 
|  | 22 |  | 
|  | 23 | std::string readFile(const std::string& file_path) { | 
|  | 24 | std::string content; | 
|  | 25 | if(android::base::ReadFileToString(file_path.c_str(), &content)) { | 
|  | 26 | return std::regex_replace(content, std::regex("\\r\\n|\\r|\\n"),""); | 
|  | 27 | } | 
|  | 28 | return content; | 
|  | 29 | } | 
| Adam Shih | cf72660 | 2022-10-04 13:09:00 +0800 | [diff] [blame] | 30 |  | 
|  | 31 | // Dump chip ID. | 
|  | 32 | int main() { | 
|  | 33 | dumpFileContent("AP HW TUNE", "/sys/devices/system/chip-id/ap_hw_tune_str"); | 
|  | 34 | dumpFileContent("EVT VERSION", "/sys/devices/system/chip-id/evt_ver"); | 
|  | 35 | dumpFileContent("LOT ID", "/sys/devices/system/chip-id/lot_id"); | 
|  | 36 | dumpFileContent("PRODUCT ID", "/sys/devices/system/chip-id/product_id"); | 
|  | 37 | dumpFileContent("REVISION", "/sys/devices/system/chip-id/revision"); | 
|  | 38 | dumpFileContent("RAW STR", "/sys/devices/system/chip-id/raw_str"); | 
| Adam Shih | 7fbb67d | 2022-12-07 15:40:40 +0800 | [diff] [blame] | 39 | dumpFileContent("CPU present", "/sys/devices/system/cpu/present"); | 
|  | 40 | dumpFileContent("CPU online", "/sys/devices/system/cpu/online"); | 
|  | 41 |  | 
|  | 42 | printf("------ CPU time-in-state ------\n"); | 
|  | 43 | std::string states; | 
|  | 44 | std::unique_ptr<DIR, decltype(&closedir)> cpudir(opendir("/sys/devices/system/cpu/"), closedir); | 
|  | 45 | if (!cpudir) { | 
|  | 46 | ALOGE("Fail To Open Dir /sys/devices/system/cpu/"); | 
|  | 47 | return 0; | 
|  | 48 | } | 
|  | 49 | dirent *entry; | 
|  | 50 | while ((entry = readdir(cpudir.get())) != nullptr) { | 
|  | 51 | std::string core(entry->d_name); | 
|  | 52 | if (core.find("cpu") != std::string::npos) { | 
|  | 53 | std::string path("/sys/devices/system/cpu/" + core + "/cpufreq/stats/time_in_state"); | 
|  | 54 | if(!access(path.c_str(), R_OK)){ | 
|  | 55 | dumpFileContent(path.c_str(), path.c_str()); | 
|  | 56 | } | 
|  | 57 | } | 
|  | 58 | std::string cpu_idle_path("/sys/devices/system/cpu/" + core + "/cpuidle"); | 
|  | 59 | std::unique_ptr<DIR, decltype(&closedir)> statedir(opendir(cpu_idle_path.c_str()), closedir); | 
|  | 60 | if (!statedir) { | 
|  | 61 | continue; | 
|  | 62 | } | 
|  | 63 | dirent *state_entry; | 
|  | 64 | while ((state_entry = readdir(statedir.get())) != nullptr) { | 
|  | 65 | std::string cpu_idle_state_path(state_entry->d_name); | 
|  | 66 | std::string full_state_path; | 
|  | 67 | full_state_path += cpu_idle_path; | 
|  | 68 | full_state_path += "/"; | 
|  | 69 | full_state_path += cpu_idle_state_path; | 
|  | 70 | if (cpu_idle_state_path.find("state") != std::string::npos) { | 
|  | 71 | std::string name(full_state_path + "/name"); | 
|  | 72 | std::string desc(full_state_path + "/desc"); | 
|  | 73 | std::string time(full_state_path + "/time"); | 
|  | 74 | std::string usage(full_state_path + "/usage"); | 
|  | 75 | states += full_state_path+": "+readFile(name)+" "+readFile(desc)+" "+readFile(time)+" "+readFile(usage)+"\n"; | 
|  | 76 | } | 
|  | 77 | } | 
|  | 78 | } | 
|  | 79 | printf("------ CPU cpuidle ------\n%s\n", states.c_str()); | 
|  | 80 |  | 
|  | 81 | dumpFileContent("INTERRUPTS", "/proc/interrupts"); | 
| Adam Shih | cf72660 | 2022-10-04 13:09:00 +0800 | [diff] [blame] | 82 | return 0; | 
|  | 83 | } |