C++ exe程序内存占用分析

编译
bash 复制代码
$ git clone https://github.com/google/bloaty
$ cd bloaty
$ cmake -B build -G Ninja -S .
$ cmake --build build
$ cmake --build build --target install
命令
bash 复制代码
bloaty.exe	--list-sources

rmembers       the .o files in a .a file
compileunits    source file for the .o file (translation unit). requires debug info.
inputfiles      the filename specified on the Bloaty command-line
inlines         source line/file where inlined code came from.  requires debug info.
sections        object file section
segments        load commands in the binary
symbols         symbols from symbol table (configure demangling with --demangle)
rawsymbols      unmangled symbols
fullsymbols     full demangled symbols
shortsymbols    short demangled symbols
bash 复制代码
bloaty.exe	--help

USAGE: bloaty [OPTION]... FILE... [-- BASE_FILE...]

Options:

  --csv              Output in CSV format instead of human-readable.
  --tsv              Output in TSV format instead of human-readable.
  -c FILE            Load configuration from <file>.
  -d SOURCE,SOURCE   Comma-separated list of sources to scan.
  --debug-file=FILE  Use this file for debug symbols and/or symbol table.
  -C MODE            How to demangle symbols.  Possible values are:
  --demangle=MODE      --demangle=none   no demangling, print raw symbols
                       --demangle=short  demangle, but omit arg/return types
                       --demangle=full   print full demangled type
                     The default is --demangle=short.
  --disassemble=FUNCTION
                     Disassemble this function (EXPERIMENTAL)
  --domain=DOMAIN    Which domains to show.  Possible values are:
                       --domain=vm
                       --domain=file
                       --domain=both (the default)
  -n NUM             How many rows to show per level before collapsing
                     other keys into '[Other]'.  Set to '0' for unlimited.
                     Defaults to 20.
  -s SORTBY          Whether to sort by VM or File size.  Possible values
                     are:
                       -s vm
                       -s file
                       -s both (the default: sorts by max(vm, file)).
  -w                 Wide output; don't truncate long labels.
  --help             Display this message and exit.
  --list-sources     Show a list of available sources and exit.
  --source-filter=PATTERN
                     Only show keys with names matching this pattern.

Options for debugging Bloaty:

  --debug-vmaddr=ADDR
  --debug-fileoff=OFF
                     Print extended debugging information for the given
                     VM address and/or file offset.
  -v                 Verbose output.  Dumps warnings encountered during
                     processing and full VM/file maps at the end.
                     Add more v's (-vv, -vvv) for even more.
测试
cpp 复制代码
#include <iostream>

const char* data = "而此时是ii四十九而此时是ii四十九而此时是ii四十九而此时是ii四十九而此时是ii四十九而此时是ii四十九而此时是ii四十九而此时是ii四十九而此时是ii四十九而此时是ii四十九";

int main() {
	printf("test main\n");
}
bash 复制代码
g++ -g main.cpp -o  my_program.exe
bloaty   my_program.exe
配置
bash 复制代码
bloaty -c bloaty_package.bloaty my_program.exe

bloaty_package.bloaty

html 复制代码
custom_data_source: {
  name: "bloaty_package"
  base_data_source: "compileunits"

  rewrite: {
    pattern: "^(\\.\\./)?src"
    replacement: "src"
  }
  rewrite: {
    pattern: "^(\\.\\./)?(third_party/\\w+)"
    replacement: "\\2"
  }
}
参考

GitHub - google/bloaty: Bloaty: a size profiler for binaries

C/C++ Native 包大小测量_bloaty-CSDN博客


创作不易,小小的支持一下吧!

相关推荐
gCode Teacher 格码致知2 小时前
Javascript提高:自定义的占位符替换-由Deepseek产生
开发语言·javascript·ecmascript
王老师青少年编程2 小时前
csp信奥赛C++高频考点专项训练之贪心算法 --【跳跃与过河问题】:过河问题
c++·算法·贪心·csp·信奥赛·跳跃与过河问题·过河问题
是个西兰花2 小时前
C++11:智能指针
开发语言·c++·智能指针·rall
摇滚侠2 小时前
Java 零基础全套视频教程,面向对象(高级),笔记 105-120
java·开发语言·笔记
CN-Dust3 小时前
【C++专题】输出cout例题
开发语言·c++
时空系3 小时前
第6篇:多维数据盒——管理大量数据 python中文编程
开发语言·python·ai编程
charlie1145141913 小时前
嵌入式Linux驱动开发(7) 从虚拟设备到真实硬件 —— LED驱动硬件基础
linux·开发语言·驱动开发·内核·c
小短腿的代码世界3 小时前
QCefView深度解析:Qt应用中嵌入Chromium浏览器的终极方案
开发语言·qt
沉默-_-3 小时前
备战蓝桥杯-哈希
c++·学习·算法·蓝桥杯·哈希算法
Reese_Cool3 小时前
【STL】蓝桥杯/天梯赛终极杀器!10个C++字符串核心技巧,暴力破解高频考点
开发语言·c++·蓝桥杯·stl