Merge "Change bash script to C++ implementation" into main

This commit is contained in:
Adam Shih 2023-07-19 07:02:38 +00:00 committed by Android (Google) Code Review
commit 58f00fd6f2
5 changed files with 107 additions and 52 deletions

View File

@ -2,11 +2,21 @@ package {
default_applicable_licenses: ["Android-Apache-2.0"],
}
sh_binary {
name: "dump_memory.sh",
src: "dump_memory.sh",
cc_binary {
name: "dump_memory",
srcs: ["dump_memory.cpp"],
cflags: [
"-Wall",
"-Wextra",
"-Werror",
],
shared_libs: [
"libbase",
"libdump",
"liblog",
],
vendor: true,
sub_dir: "dump",
relative_install_path: "dump",
}
cc_binary {

91
soc/dump_memory.cpp Normal file
View File

@ -0,0 +1,91 @@
/*
* 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 <stdio.h>
#include <log/log.h>
char* concat(char* result, const char* one, const char* two){
strcpy(result, one);
strcat(result, two);
return result;
}
void iterate(const char* path){
dirent *entry, *entry2;
char result[100], base[100];
std::unique_ptr<DIR, decltype(&closedir)> ion(opendir(path), closedir);
if (!ion) {
ALOGE("Fail To Open Dir %s", path);
return;
}
while ((entry = readdir(ion.get())) != nullptr) {
if(entry->d_name[0] == '.') {
continue;
}
strcpy(base, path);
strcat(base, entry->d_name);
strcat(base, "/");
std::unique_ptr<DIR, decltype(&closedir)> ion2(opendir(base), closedir);
if (!ion2) {
ALOGE("Fail To Open Dir %s\n", base);
return;
}
while ((entry2 = readdir(ion2.get())) != nullptr) {
if(entry2->d_name[0] == '.') {
continue;
}
dumpFileContent(entry2->d_name, concat(result, base, entry2->d_name));
}
}
return;
}
// Dump memory.
int main() {
dirent *entry;
char result[100];
printf("------ ION HEAPS ------\n");
iterate("/d/ion/");
dumpFileContent("dmabuf info", "/d/dma_buf/bufinfo");
dumpFileContent("Page Pinner - longterm pin", "/sys/kernel/debug/page_pinner/buffer");
printf("------ CMA info ------\n");
std::unique_ptr<DIR, decltype(&closedir)> cmadebug(opendir("/sys/kernel/debug/cma/"), closedir);
if (!cmadebug) {
ALOGE("Fail To Open Dir /sys/kernel/debug/cma/");
} else {
while ((entry = readdir(cmadebug.get())) != nullptr) {
if(entry->d_name[0] == '.') {
continue;
}
dumpFileContent("count", concat(result, concat(result, "/sys/kernel/debug/cma/", entry->d_name), "/count"));
dumpFileContent("used", concat(result, concat(result, "/sys/kernel/debug/cma/", entry->d_name), "/used"));
dumpFileContent("bitmap", concat(result, concat(result, "/sys/kernel/debug/cma/", entry->d_name), "/bitmap"));
}
}
printf("------ Pixel CMA stat ------\n");
iterate("/sys/kernel/pixel_stat/mm/cma/");
dumpFileContent("Pixel Trace", "/sys/kernel/tracing/instances/pixel/trace");
return 0;
}

View File

@ -1,46 +0,0 @@
#!/vendor/bin/sh
echo "------ ION HEAPS ------"
for d in $(ls -d /d/ion/*)
do
if [ -f $d ]; then
echo --- $d
cat $d
else
for f in $(ls $d)
do
echo --- $d/$f
cat $d/$f
done
fi
done
echo "------ dmabuf info ------"
cat "/d/dma_buf/bufinfo"
echo "------ Page Pinner - longterm pin ------"
cat "/sys/kernel/debug/page_pinner/buffer"
echo "------ CMA info ------"
for d in $(ls -d /sys/kernel/debug/cma/*)
do
echo --- $d
echo --- count; cat $d/count;
echo --- used; cat $d/used;
echo --- bitmap; cat $d/bitmap;
done
echo "------ Pixel CMA stat ------"
for d in $(ls -d /sys/kernel/pixel_stat/mm/cma/*); do
if [ -f $d ]; then
echo --- $d
cat $d
else
for f in $(ls $d); do
echo --- $d/$f
cat $d/$f
done
fi
done
echo "------ Pixel Trace ------"
cat "/sys/kernel/tracing/instances/pixel/trace"

View File

@ -1,3 +1,3 @@
/vendor/bin/dump/dump_soc u:object_r:dump_soc_exec:s0
/vendor/bin/dump/dump_memory\.sh u:object_r:dump_memory_exec:s0
/vendor/bin/dump/dump_memory u:object_r:dump_memory_exec:s0

View File

@ -1,5 +1,5 @@
BOARD_VENDOR_SEPOLICY_DIRS += device/google/gs-common/soc/sepolicy/soc
PRODUCT_PACKAGES += dump_soc
PRODUCT_PACKAGES_DEBUG += dump_memory.sh
PRODUCT_PACKAGES_DEBUG += dump_memory