device_google_gs-common/storage/dump_storage.cpp
Michael Bestas 50929e081f aml_tz6_351400020 (13155446,com.google.android.go.tzdata6,com.google.android.tzdata6)
-----BEGIN PGP SIGNATURE-----
 
 iF0EABECAB0WIQRDQNE1cO+UXoOBCWTorT+BmrEOeAUCZ9i73wAKCRDorT+BmrEO
 eCi5AKCHAzJVFdsm++eJGXcPb6LbaKIGTQCcDiWODLyLOWCK64nt7tfCwTgUFCE=
 =3OQU
 -----END PGP SIGNATURE-----
gpgsig -----BEGIN SSH SIGNATURE-----
 U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAgPpdpjxPACTIhnlvYz0GM4BR7FJ
 +rYv3jMbfxNKD3JvcAAAADZ2l0AAAAAAAAAAZzaGE1MTIAAABTAAAAC3NzaC1lZDI1NTE5
 AAAAQGzx1CwS4pcfih6dNJzdvsHLng+4M9qD8N/OatGRRJF0ck6x3Qwifdp45ItOlU7d0T
 52HZvmRrb/FCpQQR9Z/QE=
 -----END SSH SIGNATURE-----

Merge tag 'aml_tz6_351400020' into staging/lineage-23.0_merge-aml_tz6_351400020

aml_tz6_351400020 (13155446,com.google.android.go.tzdata6,com.google.android.tzdata6)

# -----BEGIN PGP SIGNATURE-----
#
# iF0EABECAB0WIQRDQNE1cO+UXoOBCWTorT+BmrEOeAUCZ9i73wAKCRDorT+BmrEO
# eCi5AKCHAzJVFdsm++eJGXcPb6LbaKIGTQCcDiWODLyLOWCK64nt7tfCwTgUFCE=
# =3OQU
# -----END PGP SIGNATURE-----
# gpg: Signature made Tue Mar 18 02:18:39 2025 EET
# gpg:                using DSA key 4340D13570EF945E83810964E8AD3F819AB10E78
# gpg: Good signature from "The Android Open Source Project <initial-contribution@android.com>" [ultimate]

# By Jaegeuk Kim (6) and others
# Via Android (Google) Code Review (55) and others
* tag 'aml_tz6_351400020': (74 commits)
  Fix comment
  Adjust the version set in manifest xml and matrix xml
  Add astd sepolicy to gs-common for P26 factory builds
  Allow tachyon service to make binder calls to gca
  display: add drm_atomic_state to debug-build bugreport
  init.pixel-perf.rc: Setup default rampup multiplier and util_est
  Allow write for restorecon
  Dump F2FS disk_map and UFS phy version
  Fix UFS err_stats
  Fix selinux permission denials
  move common init perf settings to gs_common
  Revert "Set up access control rule for aocxd"
  16KB: Move CopyEfsTest to device/google/gs-common
  Revert^2 "Add Bluetooth extension HAL - CCO"
  gs-common: wlc: add tx update permission for hal_googlebattery
  Revert "Add Bluetooth extension HAL - CCO"
  storage: fix userdata_exp.ai partition selinux error
  Revert "move common init perf settings to gs_common"
  insmod-sh: Allow writing to kmsg
  RamdumpService: Fix the SELinux errors from introducing Firebase Analytics.
  ...

 Conflicts:
	display/dump_pixel_display.mk

Change-Id: Iaa05ef7e62a7b8320f320ad4db482998863fe136
2025-06-23 05:14:52 +03:00

258 lines
11 KiB
C++

/*
* Copyright 2023 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 <android-base/stringprintf.h>
#include <android-base/properties.h>
#include <string.h>
#include <stdio.h>
#include <log/log.h>
#include <regex>
#include <fstream>
#include <map>
#define F2FS_FSCK_TIME_PROPERTY "ro.boottime.init.fsck.data"
#define F2FS_MNT_TIME_PROPERTY "ro.boottime.init.mount.data"
#define BUILD_TYPE_PROPERTY "ro.build.type"
void read_buffer(int buf_id, int total_len, const char* path)
{
int i, len;
system("mkdir -m 0770 -p /data/vendor/storage/");
auto cmd = android::base::StringPrintf("rm -f /data/vendor/storage/%s\n", path);
system(cmd.c_str());
for (i=0;i<=total_len;i+=524288) {
if (total_len-i < 524288) {
len = total_len-i;
printf("/vendor/bin/sg_read_buffer -m 0x1c -i %d -l %d -o %d -r /dev/sg3 >> /data/vendor/storage/%s\n",
buf_id, len, i, path);
auto cmd = android::base::StringPrintf(
"/vendor/bin/sg_read_buffer -m 0x1c -i %d -l %d -o %d -r /dev/sg3 >> /data/vendor/storage/%s\n",
buf_id, len, i, path);
system(cmd.c_str());
break;
}
len = 524288;
printf("/vendor/bin/sg_read_buffer -m 0x1c -i %d -l %d -o %d -r /dev/sg3 >> /data/vendor/storage/%s\n",
buf_id, len, i, path);
auto cmd = android::base::StringPrintf(
"/vendor/bin/sg_read_buffer -m 0x1c -i %d -l %d -o %d -r /dev/sg3 >> /data/vendor/storage/%s\n",
buf_id, len, i, path);
system(cmd.c_str());
}
}
int main() {
//F2FS
dumpFileContent("F2FS status", "/sys/kernel/debug/f2fs/status");
dumpFileContent("F2FS fsck", "/dev/fscklogs/fsck");
int fsck_time = android::base::GetIntProperty(F2FS_FSCK_TIME_PROPERTY, 0);
printf("--- F2FS - fsck time (ms) ---\n%d\n\n", fsck_time);
int mnt_time = android::base::GetIntProperty(F2FS_MNT_TIME_PROPERTY, 0);
printf("--- F2FS - checkpoint=disable time (ms) ---\n%d\n\n", mnt_time);
const std::string f2fs_proc_path("/proc/fs/f2fs/");
std::unique_ptr<DIR, decltype(&closedir)> procdir(
opendir(f2fs_proc_path.c_str()), closedir);
if (procdir) {
dirent *proc_entry;
while ((proc_entry = readdir(procdir.get())) != nullptr) {
std::string proc_name(proc_entry->d_name);
if (proc_name == "." || proc_name == ".." ||
strncmp(proc_name.c_str(), "dm-", 3))
continue;
dumpFileContent(("F2FS - " + proc_name).c_str(),
(f2fs_proc_path + proc_name + "/disk_map").c_str());
}
}
//UFS
dumpFileContent("UFS model", "/sys/block/sda/device/model");
dumpFileContent("UFS rev", "/sys/block/sda/device/rev");
dumpFileContent("UFS size", "/sys/block/sda/size");
dumpFileContent("UFS phy version",
"/dev/sys/block/bootdevice/pixel/phy_version");
dumpFileContent("UFS phy release_date",
"/dev/sys/block/bootdevice/pixel/phy_release_date");
dumpFileContent("UFS Slow IO Read",
"/dev/sys/block/bootdevice/slowio_read_cnt");
dumpFileContent("UFS Slow IO Write",
"/dev/sys/block/bootdevice/slowio_write_cnt");
dumpFileContent("UFS Slow IO Unmap",
"/dev/sys/block/bootdevice/slowio_unmap_cnt");
dumpFileContent("UFS Slow IO Sync",
"/dev/sys/block/bootdevice/slowio_sync_cnt");
printf("------ UFS err_stats ------\n");
const std::string ufs_err_stats_path(
"/dev/sys/block/bootdevice/err_stats/");
std::unique_ptr<DIR, decltype(&closedir)> statdir(
opendir(ufs_err_stats_path.c_str()), closedir);
if (statdir) {
dirent *stat_entry;
while ((stat_entry = readdir(statdir.get())) != nullptr) {
std::string stat_name(stat_entry->d_name);
if (stat_name == "." || stat_name == "..") continue;
dumpFileContent(stat_name.c_str(),
(ufs_err_stats_path + stat_name).c_str());
}
}
printf("\n------ UFS io_stats ------\n");
printf("\t\t%-12s %-12s %-12s %-12s %-12s %-12s\n", "ReadCnt", "ReadBytes",
"WriteCnt", "WriteBytes", "RWCnt", "RWBytes");
const std::string ufs_io_stats = "/dev/sys/block/bootdevice/io_stats/";
const std::string iostats_seq[3] = {"_start", "_complete", "_maxdiff"};
const std::string iostats[6] = {"rcnt", "rbyte", "wcnt", "wbyte", "rwcnt",
"rwbyte"};
for (int i = 0; i < 3; i++) {
const std::string header[3] = {"Started: \t", "Completed: \t",
"MaxDiff: \t"};
printf("%s", header[i].c_str());
for (int j = 0; j < 6; j++) {
std::string iostat_path = ufs_io_stats.c_str();
iostat_path.append(iostats[j].c_str());
iostat_path.append(iostats_seq[i].c_str());
std::ifstream io_stats_file(iostat_path.c_str());
unsigned long io_stat_atom = 0;
if (io_stats_file.is_open()) {
io_stats_file >> io_stat_atom;
printf("%-12lu ", io_stat_atom);
io_stats_file.close();
}
}
printf("\n");
}
printf("\n------ UFS req_stats ------\n");
printf("\t%-12s %-12s %-12s %-12s %-12s %-12s\n", "All", "Write", "Read",
"Security", "Flush", "Discard");
const std::string ufs_req_stats = "/dev/sys/block/bootdevice/req_stats/";
const std::string reqstats_seq[4] = {"_min", "_max", "_avg", "_sum"};
const std::string reqstats[6] = {"all", "write", "read", "security",
"flush", "discard"};
for (int i = 0; i < 4; i++) {
const std::string header[4] = {"Min:\t", "Max: \t", "Avg: \t",
"Count: \t"};
printf("%s", header[i].c_str());
for (int j = 0; j < 6; j++) {
std::string reqstat_path = ufs_req_stats.c_str();
reqstat_path.append(reqstats[j].c_str());
reqstat_path.append(reqstats_seq[i].c_str());
std::ifstream req_stats_file(reqstat_path.c_str());
unsigned long req_stat_atom = 0;
if (req_stats_file.is_open()) {
req_stats_file >> req_stat_atom;
printf("%-12lu ", req_stat_atom);
req_stats_file.close();
}
}
printf("\n");
}
printf("\n------ UFS health ------\n");
dumpFileContent(
"",
"/dev/sys/block/bootdevice/health_descriptor/life_time_estimation_a");
dumpFileContent(
"",
"/dev/sys/block/bootdevice/health_descriptor/life_time_estimation_b");
dumpFileContent("", "/dev/sys/block/bootdevice/health_descriptor/eol_info");
dumpFileContent(
"",
"/dev/sys/block/bootdevice/health_descriptor/life_time_estimation_c");
printf("\n------ UFS error history ------\n");
std::string build_type = android::base::GetProperty(BUILD_TYPE_PROPERTY, "");
if (build_type == "eng") {
std::string sg_read_buffer = "/vendor/bin/sg_read_buffer";
std::ifstream sg_read_buffer_file(sg_read_buffer.c_str());
if (sg_read_buffer_file.is_open()) {
const std::string ufs_ver_path(
"/dev/sys/block/bootdevice/device_descriptor/specification_version");
std::ifstream ufs_ver_file(ufs_ver_path);
std::string ufs_ver;
if (ufs_ver_file.is_open()) {
ufs_ver_file >> ufs_ver;
ufs_ver_file.close();
}
if (strcmp(ufs_ver.c_str(), "0x0210")) {
const std::string ufs_brand_path("/sys/block/sda/device/vendor");
std::ifstream ufs_brand_file(ufs_brand_path);
std::string ufs_brand;
if (ufs_brand_file.is_open()) {
ufs_brand_file >> ufs_brand;
ufs_brand_file.close();
}
std::map<std::string, int> const table =
{
{"MICRON", 0x12C},
{"KIOXIA", 0x198},
{"SKhynix", 0x1AD},
{"SAMSUNG", 0x1CE}
};
auto ufs_vendor_id = table.find(ufs_brand);
if (ufs_vendor_id != table.end()) {
switch(ufs_vendor_id->second){
case 0x12C: //MICRON
read_buffer(16, 2097152, "micron_10_ufs_err_history.dat");
read_buffer(18, 10485760, "micron_12_ufs_err_history.dat");
read_buffer(19, 10485760, "micron_13_ufs_err_history.dat");
break;
case 0x198: //KIOXIA
read_buffer(16, 16773120, "kioxia_10_ufs_err_history.dat");
read_buffer(17, 2097152, "kioxia_11_ufs_err_history.dat");
read_buffer(18, 131072, "kioxia_12_ufs_err_history.dat");
break;
case 0x1AD: //SKhynix
if (!strcmp(ufs_ver.c_str(), "0x0310")) {
read_buffer(0, 4096, "skhynix_00_ufs_err_history.dat");
read_buffer(16, 131072, "skhynix_10_ufs_err_history.dat");
read_buffer(17, 131072, "skhynix_11_ufs_err_history.dat");
read_buffer(18, 131072, "skhynix_12_ufs_err_history.dat");
read_buffer(19, 131072, "skhynix_13_ufs_err_history.dat");
} else {
read_buffer(0, 4096, "skhynix_00_ufs_err_history.dat");
read_buffer(16, 8388608, "skhynix_10_ufs_err_history.dat");
read_buffer(17, 8388608, "skhynix_11_ufs_err_history.dat");
}
break;
case 0x1CE: //SAMSUNG
if (!strcmp(ufs_ver.c_str(), "0x0310"))
read_buffer(16, 8404992, "samsung_10_ufs_err_history.dat");
else
read_buffer(16, 12599296, "samsung_10_ufs_err_history.dat");
break;
default:
break;
}
}
sg_read_buffer_file.close();
}
} else
printf("sg_read_buffer does not exist\n");
}
return 0;
}