mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-29 17:22:56 +08:00
add stack_usage_report generate py script
This commit is contained in:
parent
0285c19abd
commit
001efd5946
@ -18,6 +18,8 @@ project(pikascript VERSION 0.1.0)
|
||||
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage")
|
||||
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage")
|
||||
SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage -lgcov")
|
||||
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fstack-usage")
|
||||
|
||||
|
||||
include_directories(package/pikascript/pikascript-core)
|
||||
include_directories(package/pikascript/pikascript-api)
|
||||
|
49
port/linux/generate_stack_usage_report.py
Normal file
49
port/linux/generate_stack_usage_report.py
Normal file
@ -0,0 +1,49 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def collect_stack_usage_info():
|
||||
stack_usage_data = []
|
||||
|
||||
for root, _, files in os.walk("./build/package/pikascript/CMakeFiles/pikascript-core.dir/pikascript-core"):
|
||||
for file in files:
|
||||
if file.endswith(".su"):
|
||||
su_path = Path(root) / file
|
||||
# print(f"Processing file: {su_path}")
|
||||
with open(su_path) as f:
|
||||
for line in f.readlines():
|
||||
# '/root/pikascript/port/linux/package/pikascript/pikascript-lib/pika_libc/pika_vsnprintf.c:184:38:get_bit_access'
|
||||
items = line.strip().split()
|
||||
if len(items) == 3:
|
||||
location, stack_size, storage_type = items[0], items[1], items[2]
|
||||
location_items = location.split(":")
|
||||
if len(location_items) == 4:
|
||||
file_name, line_number, column_number, function = location_items
|
||||
else:
|
||||
print(
|
||||
f"Skipping line due to incorrect format: {line.strip()}")
|
||||
continue
|
||||
stack_usage_data.append(
|
||||
(file_name, function, int(stack_size), storage_type))
|
||||
|
||||
return stack_usage_data
|
||||
|
||||
|
||||
def generate_report(stack_usage_data):
|
||||
sorted_data = sorted(stack_usage_data, key=lambda x: x[2], reverse=True)
|
||||
|
||||
report = "Stack usage report (sorted by stack size):\n\n"
|
||||
report += "{:<10} {:<40} {:<15}\n".format(
|
||||
"Stack Size", "Function", "File")
|
||||
report += "-" * 75 + "\n"
|
||||
|
||||
for file_name, function, stack_size, storage_type in sorted_data:
|
||||
report += "{:<10} {:<40} {:<15}\n".format(
|
||||
stack_size, function, os.path.basename(file_name))
|
||||
|
||||
return report
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
stack_usage_data = collect_stack_usage_info()
|
||||
report = generate_report(stack_usage_data)
|
@ -1,2 +1,3 @@
|
||||
cd build && rm ./test/pikascript_test -f && ninja
|
||||
cd .. && cp ./build/boot/demo06-pikamain/pikascript_demo06-pikamain package/pikascript/pika
|
||||
python3 generate_stack_usage_report.py
|
@ -1,9 +1,34 @@
|
||||
#!/bin/sh
|
||||
sh only_make.sh
|
||||
if [ $# == 0 ] ; then
|
||||
valgrind -s --track-origins=yes --leak-check=full --show-leak-kinds=all --exit-on-first-error=yes --error-exitcode=1 --num-callers=50 build/test/pikascript_test
|
||||
|
||||
# 初始化参数变量
|
||||
tool_option=""
|
||||
valgrind_common_options=""
|
||||
gtest_filter=""
|
||||
massif=false
|
||||
|
||||
# 处理命令行参数
|
||||
for arg in "$@"
|
||||
do
|
||||
case $arg in
|
||||
--massif)
|
||||
tool_option="--tool=massif --stacks=yes"
|
||||
massif=true
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
gtest_filter="--gtest_filter=$arg"
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# 设置 valgrind 命令的公共参数
|
||||
if [ "$massif" = true ]; then
|
||||
valgrind_common_options=""
|
||||
else
|
||||
valgrind_common_options="-s --track-origins=yes --leak-check=full --show-leak-kinds=all --exit-on-first-error=yes --error-exitcode=1 --num-callers=50"
|
||||
fi
|
||||
|
||||
if [ $# == 1 ] ; then
|
||||
filter=$1
|
||||
valgrind -s --track-origins=yes --leak-check=full --show-leak-kinds=all --exit-on-first-error=yes --error-exitcode=1 --num-callers=50 build/test/pikascript_test --gtest_filter=$filter
|
||||
fi
|
||||
# 执行 valgrind 命令
|
||||
valgrind $tool_option $valgrind_common_options build/test/pikascript_test $gtest_filter
|
||||
|
Loading…
x
Reference in New Issue
Block a user