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博客


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

相关推荐
执尺量北斗1 小时前
[特殊字符] 基于 Qt + OpenGL 实现的入门级打砖块游戏
开发语言·qt·游戏
夏子曦1 小时前
C#内存管理深度解析:从栈堆原理到高性能编程实践
开发语言·c#
Q741_1471 小时前
C++ 模拟题 力扣495. 提莫攻击 题解 每日一题
c++·算法·leetcode·模拟
青岛少儿编程-王老师2 小时前
CCF编程能力等级认证GESP—C++7级—20250927
数据结构·c++·算法
Miki Makimura2 小时前
Reactor 模式实现:从 epoll 到高并发调试
运维·服务器·c++·学习
jiajixi3 小时前
Go 异步编程
开发语言·后端·golang
QX_hao3 小时前
【Go】--strings包
开发语言·后端·golang
计算机毕业设计木哥3 小时前
计算机毕设选题推荐:基于Hadoop和Python的游戏销售大数据可视化分析系统
大数据·开发语言·hadoop·python·信息可视化·spark·课程设计
秦禹辰3 小时前
venv与conda:Python虚拟环境深度解析助力构建稳定高效的开发工作流
开发语言·后端·golang
cooldream20093 小时前
深入解析 Conda、Anaconda 与 Miniconda:Python 环境管理的完整指南
开发语言·python·conda