Merge "modem: Migrate dump_modem.sh to rust" into main
This commit is contained in:
commit
eea858c900
5 changed files with 121 additions and 53 deletions
|
@ -2,11 +2,11 @@ package {
|
|||
default_applicable_licenses: ["Android-Apache-2.0"],
|
||||
}
|
||||
|
||||
sh_binary {
|
||||
name: "dump_modem.sh",
|
||||
src: "dump_modem.sh",
|
||||
rust_binary {
|
||||
name: "dump_modem",
|
||||
srcs: ["dump_modem.rs"],
|
||||
vendor: true,
|
||||
sub_dir: "dump",
|
||||
relative_install_path: "dump",
|
||||
}
|
||||
|
||||
// Modem Log Dumper
|
||||
|
|
109
modem/dump_modemlog/dump_modem.rs
Normal file
109
modem/dump_modemlog/dump_modem.rs
Normal file
|
@ -0,0 +1,109 @@
|
|||
// Copyright 2024 Google LLC
|
||||
|
||||
//! The dump_modem binary is used to capture kernel/userspace logs in bugreport
|
||||
|
||||
use std::fs;
|
||||
|
||||
const MODEM_STAT: &str = "/data/vendor/modem_stat/debug.txt";
|
||||
const SSRDUMP_DIR: &str = "/data/vendor/ssrdump";
|
||||
const RFSD_ERR_LOG_DIR: &str = "/data/vendor/log/rfsd";
|
||||
const WAKEUP_EVENTS: &str = "/sys/devices/platform/cpif/wakeup_events";
|
||||
const CPIF_LOGBUFFER: &str = "/dev/logbuffer_cpif";
|
||||
const PCIE_EVENT_STATS: &str = "/sys/devices/platform/cpif/modem/pcie_event_stats";
|
||||
|
||||
fn handle_io_error(file: &str, err: std::io::Error) {
|
||||
match err.kind() {
|
||||
std::io::ErrorKind::NotFound => println!("{file} not found!"),
|
||||
std::io::ErrorKind::PermissionDenied => println!("Permission denied to access {file}"),
|
||||
_ => println!("I/O error accessing {file}: {err}"),
|
||||
}
|
||||
}
|
||||
|
||||
fn print_file(file: &str) -> Result<(), std::io::Error> {
|
||||
fs::metadata(file)?;
|
||||
|
||||
let data = fs::read_to_string(file)?;
|
||||
|
||||
if data.is_empty() {
|
||||
println!("{file} is empty");
|
||||
} else {
|
||||
print!("{data}");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn print_file_and_handle_error(file: &str) {
|
||||
if let Err(err) = print_file(file) {
|
||||
handle_io_error(file, err);
|
||||
}
|
||||
}
|
||||
|
||||
fn print_matching_files_in_dir(dir: &str, filename: &str) {
|
||||
let Ok(entries) = fs::read_dir(dir) else {
|
||||
return println!("Cannot open directory {dir}");
|
||||
};
|
||||
|
||||
for entry in entries {
|
||||
let Ok(entry) = entry else {
|
||||
continue;
|
||||
};
|
||||
if entry.path().is_file() && entry.file_name().to_string_lossy().starts_with(filename) {
|
||||
if let Some(path_str) = entry.path().to_str() {
|
||||
println!("{}", path_str);
|
||||
print_file_and_handle_error(path_str);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Capture modem stat log if it exists
|
||||
fn modem_stat() {
|
||||
println!("------ Modem Stat ------");
|
||||
print_file_and_handle_error(MODEM_STAT);
|
||||
println!();
|
||||
}
|
||||
|
||||
// Capture crash signatures from all modem crashes
|
||||
fn modem_ssr_history() {
|
||||
println!("------ Modem SSR history ------");
|
||||
print_matching_files_in_dir(SSRDUMP_DIR, "crashinfo_modem");
|
||||
println!();
|
||||
}
|
||||
|
||||
// Capture rfsd error logs from all existing log files
|
||||
fn rfsd_error_log() {
|
||||
println!("------ RFSD error log ------");
|
||||
print_matching_files_in_dir(RFSD_ERR_LOG_DIR, "rfslog");
|
||||
println!();
|
||||
}
|
||||
|
||||
// Capture modem wakeup events if the sysfs attribute exists
|
||||
fn wakeup_events() {
|
||||
println!("------ Wakeup event counts ------");
|
||||
print_file_and_handle_error(WAKEUP_EVENTS);
|
||||
println!();
|
||||
}
|
||||
|
||||
// Capture kernel driver logbuffer if it exists
|
||||
fn cpif_logbuffer() {
|
||||
println!("------ CPIF Logbuffer ------");
|
||||
print_file_and_handle_error(CPIF_LOGBUFFER);
|
||||
println!();
|
||||
}
|
||||
|
||||
// Capture modem pcie stats if the sysfs attribute exists
|
||||
fn pcie_event_stats() {
|
||||
println!("------ PCIe event stats ------");
|
||||
print_file_and_handle_error(PCIE_EVENT_STATS);
|
||||
println!();
|
||||
}
|
||||
|
||||
fn main() {
|
||||
modem_stat();
|
||||
modem_ssr_history();
|
||||
rfsd_error_log();
|
||||
wakeup_events();
|
||||
cpif_logbuffer();
|
||||
pcie_event_stats();
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
#!/vendor/bin/sh
|
||||
|
||||
WAKEUP_EVENTS_FILE=/sys/devices/platform/cpif/wakeup_events
|
||||
CPIF_LOGBUFFER=/dev/logbuffer_cpif
|
||||
PCIE_EVENT_STATS=/sys/devices/platform/cpif/modem/pcie_event_stats
|
||||
|
||||
echo "------ Modem Stat ------"
|
||||
cat /data/vendor/modem_stat/debug.txt
|
||||
|
||||
echo "\n------ Modem SSR history ------"
|
||||
for f in $(ls /data/vendor/ssrdump/crashinfo_modem*); do
|
||||
echo $f
|
||||
cat $f
|
||||
done
|
||||
|
||||
echo "\n------ RFSD error log ------"
|
||||
for f in $(ls /data/vendor/log/rfsd/rfslog_*); do
|
||||
echo $f
|
||||
cat $f
|
||||
done
|
||||
|
||||
if [ -e $WAKEUP_EVENTS_FILE ]
|
||||
then
|
||||
echo "\n------ Wakeup event counts ------"
|
||||
echo $WAKEUP_EVENTS_FILE
|
||||
cat $WAKEUP_EVENTS_FILE
|
||||
fi
|
||||
|
||||
if [ -e $CPIF_LOGBUFFER ]
|
||||
then
|
||||
echo "\n------ CPIF Logbuffer ------"
|
||||
echo $CPIF_LOGBUFFER
|
||||
cat $CPIF_LOGBUFFER
|
||||
fi
|
||||
|
||||
if [ -e $PCIE_EVENT_STATS ]
|
||||
then
|
||||
echo "\n------ PCIe event stats ------"
|
||||
echo $PCIE_EVENT_STATS
|
||||
cat $PCIE_EVENT_STATS
|
||||
fi
|
|
@ -1,5 +1,5 @@
|
|||
BOARD_VENDOR_SEPOLICY_DIRS += device/google/gs-common/modem/dump_modemlog/sepolicy
|
||||
|
||||
PRODUCT_PACKAGES += dump_modem.sh
|
||||
PRODUCT_PACKAGES += dump_modem
|
||||
PRODUCT_PACKAGES += dump_modemlog
|
||||
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
/vendor/bin/dump/dump_modem\.sh u:object_r:dump_modem_exec:s0
|
||||
/vendor/bin/dump/dump_modem u:object_r:dump_modem_exec:s0
|
||||
/vendor/bin/dump/dump_modemlog u:object_r:dump_modemlog_exec:s0
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue