summaryrefslogtreecommitdiff
path: root/soc/dump_soc.cpp
blob: 4c343494022adc0c1d1612082a30d6a340763eaf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
 * Copyright 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include <dump/pixel_dump.h>
#include <android-base/file.h>
#include <string.h>
#include <stdio.h>
#include <log/log.h>
#include <regex>

std::string readFile(const std::string& file_path) {
    std::string content;
    if(android::base::ReadFileToString(file_path.c_str(), &content)) {
        return std::regex_replace(content, std::regex("\\r\\n|\\r|\\n"),"");
    }
    return content;
}

// Dump chip ID.
int main() {
    dumpFileContent("AP HW TUNE", "/sys/devices/system/chip-id/ap_hw_tune_str");
    dumpFileContent("EVT VERSION", "/sys/devices/system/chip-id/evt_ver");
    dumpFileContent("LOT ID", "/sys/devices/system/chip-id/lot_id");
    dumpFileContent("PRODUCT ID", "/sys/devices/system/chip-id/product_id");
    dumpFileContent("REVISION", "/sys/devices/system/chip-id/revision");
    dumpFileContent("RAW STR", "/sys/devices/system/chip-id/raw_str");
    dumpFileContent("CPU present", "/sys/devices/system/cpu/present");
    dumpFileContent("CPU online", "/sys/devices/system/cpu/online");

    printf("------ CPU time-in-state ------\n");
    std::string states;
    std::unique_ptr<DIR, decltype(&closedir)> cpudir(opendir("/sys/devices/system/cpu/"), closedir);
    if (!cpudir) {
        ALOGE("Fail To Open Dir /sys/devices/system/cpu/");
        return 0;
    }
    dirent *entry;
    while ((entry = readdir(cpudir.get())) != nullptr) {
        std::string core(entry->d_name);
        if (core.find("cpu") != std::string::npos) {
            std::string path("/sys/devices/system/cpu/" + core + "/cpufreq/stats/time_in_state");
            if(!access(path.c_str(), R_OK)){
                dumpFileContent(path.c_str(), path.c_str());
            }
        }
        std::string cpu_idle_path("/sys/devices/system/cpu/" + core + "/cpuidle");
        std::unique_ptr<DIR, decltype(&closedir)> statedir(opendir(cpu_idle_path.c_str()), closedir);
        if (!statedir) {
            continue;
        }
        dirent *state_entry;
        while ((state_entry = readdir(statedir.get())) != nullptr) {
            std::string cpu_idle_state_path(state_entry->d_name);
            std::string full_state_path;
            full_state_path += cpu_idle_path;
            full_state_path += "/";
            full_state_path += cpu_idle_state_path;
            if (cpu_idle_state_path.find("state") != std::string::npos) {
                std::string name(full_state_path + "/name");
                std::string desc(full_state_path + "/desc");
                std::string time(full_state_path + "/time");
                std::string usage(full_state_path + "/usage");
                states += full_state_path+": "+readFile(name)+" "+readFile(desc)+" "+readFile(time)+" "+readFile(usage)+"\n";
            }
        }
    }
    printf("------ CPU cpuidle ------\n%s\n", states.c_str());

    dumpFileContent("INTERRUPTS", "/proc/interrupts");
    return 0;
}