• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  */
16 #include <dump/pixel_dump.h>
17 #include <android-base/file.h>
18 #include <string.h>
19 #include <stdio.h>
20 #include <log/log.h>
21 #include <regex>
22 
readFile(const std::string & file_path)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 }
30 
31 // Dump chip ID.
main()32 int main() {
33     dumpFileContent("AP HW TUNE", "/sys/devices/system/chip-id/ap_hw_tune_str");
34     dumpFileContent("DVFS VERSION", "/sys/devices/system/chip-id/dvfs_version");
35     dumpFileContent("EVT VERSION", "/sys/devices/system/chip-id/evt_ver");
36     dumpFileContent("LOT ID", "/sys/devices/system/chip-id/lot_id");
37     dumpFileContent("PACKAGE", "/sys/devices/system/chip-id/pkg_revision");
38     dumpFileContent("PRODUCT ID", "/sys/devices/system/chip-id/product_id");
39     dumpFileContent("REVISION", "/sys/devices/system/chip-id/revision");
40     dumpFileContent("RAW STR", "/sys/devices/system/chip-id/raw_str");
41     dumpFileContent("CPU present", "/sys/devices/system/cpu/present");
42     dumpFileContent("CPU online", "/sys/devices/system/cpu/online");
43 
44     printf("------ CPU time-in-state ------\n");
45     std::string states;
46     std::unique_ptr<DIR, decltype(&closedir)> cpudir(opendir("/sys/devices/system/cpu/"), closedir);
47     if (!cpudir) {
48         ALOGE("Fail To Open Dir /sys/devices/system/cpu/");
49         return 0;
50     }
51     dirent *entry;
52     while ((entry = readdir(cpudir.get())) != nullptr) {
53         std::string core(entry->d_name);
54         if (core.find("cpu") != std::string::npos) {
55             std::string path("/sys/devices/system/cpu/" + core + "/cpufreq/stats/time_in_state");
56             if(!access(path.c_str(), R_OK)){
57                 dumpFileContent(path.c_str(), path.c_str());
58             }
59         }
60         std::string cpu_idle_path("/sys/devices/system/cpu/" + core + "/cpuidle");
61         std::unique_ptr<DIR, decltype(&closedir)> statedir(opendir(cpu_idle_path.c_str()), closedir);
62         if (!statedir) {
63             continue;
64         }
65         dirent *state_entry;
66         while ((state_entry = readdir(statedir.get())) != nullptr) {
67             std::string cpu_idle_state_path(state_entry->d_name);
68             std::string full_state_path;
69             full_state_path += cpu_idle_path;
70             full_state_path += "/";
71             full_state_path += cpu_idle_state_path;
72             if (cpu_idle_state_path.find("state") != std::string::npos) {
73                 std::string name(full_state_path + "/name");
74                 std::string desc(full_state_path + "/desc");
75                 std::string time(full_state_path + "/time");
76                 std::string usage(full_state_path + "/usage");
77                 states += full_state_path+": "+readFile(name)+" "+readFile(desc)+" "+readFile(time)+" "+readFile(usage)+"\n";
78             }
79         }
80     }
81     printf("------ CPU cpuidle ------\n%s\n", states.c_str());
82 
83     dumpFileContent("INTERRUPTS", "/proc/interrupts");
84     return 0;
85 }
86