代码拉取完成,页面将自动刷新
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)
with open("stack_usage_report.txt", "w") as f:
f.write(report)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。