1 /*
2 * Copyright 2016 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
17 #include <dumpstate.h>
18 #include <stdlib.h>
19 #include <string>
20 #include <cutils/properties.h>
21
22 #define LOG_TAG "dumpstate"
23 #include <cutils/log.h>
24
25 #define MODEM_LOG_PREFIX_PROPERTY "ro.radio.log_prefix"
26 #define MODEM_LOGGING_SWITCH "persist.radio.smlog_switch"
27
28 static std::vector<std::string> ril_and_netmgr_logs
29 {
30 "/data/misc/radio/ril_log",
31 "/data/misc/radio/ril_log_old",
32 "/data/misc/netmgr/netmgr_log",
33 "/data/misc/netmgr/netmgr_log_old"
34 };
35 static std::string modem_log_folder_name = "modem_log";
36
get_property_value(const std::string & property_name)37 static std::string get_property_value (const std::string& property_name) {
38
39 char property[PROPERTY_VALUE_MAX];
40 property_get (property_name.c_str(), property, "");
41
42 return property;
43 }
44
45 /*
46 * Returns true if the system property `key` has the value "1", "y", "yes",
47 * "on", or "true", false for "0", "n", "no", "off", or "false",
48 * or `default_value` otherwise.
49 */
get_bool_property_value(const std::string & property_name,bool default_value)50 static bool get_bool_property_value (const std::string& property_name,
51 bool default_value) {
52 std::string value = get_property_value(property_name);
53 if (value == "1" || value == "y" || value == "yes" || value == "on" || value == "true") {
54 return true;
55 } else if (value == "0" || value == "n" || value == "no" || value == "off" || value == "false") {
56 return false;
57 }
58 return default_value;
59 }
60
dumpstate_board()61 void dumpstate_board()
62 {
63 /* Check if smlog_dump tool exist */
64 if (!is_user_build() && !access("/system/bin/smlog_dump", F_OK)) {
65 bool modem_logging_enabled = get_bool_property_value (MODEM_LOGGING_SWITCH, false);
66
67 /* Execute SMLOG DUMP if SMLOG is enabled */
68 if (modem_logging_enabled && !bugreport_dir.empty()) {
69 std::string modem_log_dir = bugreport_dir + "/" + modem_log_folder_name;
70 std::string modem_log_mkdir_cmd= "/system/bin/mkdir " + modem_log_dir;
71 run_command("MKDIR MODEM LOG", 5, SU_PATH, "root", "/system/bin/sh", "-c",
72 modem_log_mkdir_cmd.c_str(), NULL);
73 run_command("SMLOG DUMP", 120, SU_PATH, "root", "smlog_dump", "-d",
74 "-o", modem_log_dir.c_str(), NULL);
75 for(unsigned int i = 0; i < ril_and_netmgr_logs.size(); i++)
76 {
77 std::string copy_cmd= "/system/bin/cp " + ril_and_netmgr_logs[i] + " " + modem_log_dir;
78 run_command("MV RIL LOG", 20, SU_PATH, "root", "/system/bin/sh", "-c", copy_cmd.c_str(), NULL);
79 }
80 // Remove smlogs older than 10 days
81 std::string file_prefix = get_property_value (MODEM_LOG_PREFIX_PROPERTY);
82 if (!file_prefix.empty()) {
83 std::string remove_command = "/system/bin/find " +
84 bugreport_dir + "/" + file_prefix + "* -mtime +10 -delete";
85 MYLOGD("Removing old logs using command %s\n", remove_command.c_str());
86 run_command("RM OLD SMLOG", 5, SU_PATH,
87 "root", "/system/bin/sh", "-c", remove_command.c_str(), NULL);
88 }
89 std::string modem_log_combined = bugreport_dir + "/" + file_prefix + "all.tar.gz";
90 std::string modem_log_gzip_cmd= "/system/bin/tar czvf " + modem_log_combined + " -C" + modem_log_dir + " .";
91 run_command("GZIP LOG", 5, SU_PATH, "root", "/system/bin/sh", "-c",
92 modem_log_gzip_cmd.c_str(), NULL);
93 std::string modem_log_perm_cmd= "/system/bin/chmod a+rw " + modem_log_combined;
94 run_command("CHG PERM", 5, SU_PATH, "root", "/system/bin/sh", "-c",
95 modem_log_perm_cmd.c_str(), NULL);
96 std::string modem_log_clear_cmd= "/system/bin/rm -r " + modem_log_dir;
97 run_command("RM MODEM DIR", 5, SU_PATH, "root", "/system/bin/sh", "-c",
98 modem_log_clear_cmd.c_str(), NULL);
99 }
100 run_command("RM OLD SMLOG", 5, SU_PATH, "root", "/system/bin/sh", "-c",
101 "/system/bin/find /data/smlog_* -delete", NULL);
102 }
103
104 dump_file("CPU present", "/sys/devices/system/cpu/present");
105 dump_file("CPU online", "/sys/devices/system/cpu/online");
106 dump_file("RPM Stats", "/d/rpm_stats");
107 dump_file("Power Management Stats", "/d/rpm_master_stats");
108 dump_file("SMD Log", "/d/ipc_logging/smd/log");
109 run_command("ION HEAPS", 5, SU_PATH, "root", "/system/bin/sh", "-c", "for d in $(ls -d /d/ion/*); do for f in $(ls $d); do echo --- $d/$f; cat $d/$f; done; done", NULL);
110 dump_file("dmabuf info", "/d/dma_buf/bufinfo");
111 run_command("Temperatures", 5, SU_PATH, "root", "/system/bin/sh", "-c", "for f in `ls /sys/class/thermal` ; do type=`cat /sys/class/thermal/$f/type` ; temp=`cat /sys/class/thermal/$f/temp` ; echo \"$type: $temp\" ; done", NULL);
112 dump_file("cpu0-1 time-in-state", "/sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state");
113 run_command("cpu0-1 cpuidle", 5, SU_PATH, "root", "/system/bin/sh", "-c", "for d in $(ls -d /sys/devices/system/cpu/cpu0/cpuidle/state*); do echo \"$d: `cat $d/name` `cat $d/desc` `cat $d/time` `cat $d/usage`\"; done", NULL);
114 dump_file("cpu2-3 time-in-state", "/sys/devices/system/cpu/cpu2/cpufreq/stats/time_in_state");
115 run_command("cpu2-3 cpuidle", 5, SU_PATH, "root", "/system/bin/sh", "-c", "for d in $(ls -d /sys/devices/system/cpu/cpu2/cpuidle/state*); do echo \"$d: `cat $d/name` `cat $d/desc` `cat $d/time` `cat $d/usage`\"; done", NULL);
116 dump_file("MDP xlogs", "/d/mdp/xlog/dump");
117
118 /* Check if qsee_logger tool exists */
119 if (!access("/system/bin/qsee_logger", F_OK)) {
120 run_command("FP LOGS", 10, "qsee_logger", "-d", NULL);
121 }
122 };
123