• 请不要在回答技术问题时复制粘贴 AI 生成的内容
lookingmoon
V2EX  ›  程序员

求助 怎么排查 c++程序的内存占用

  •  
  •   lookingmoon · Dec 2, 2022 · 2814 views
    This topic created in 1434 days ago, the information mentioned may be changed or developed.
    大概有 600w 的业务订单数据
    服务启动后内存一直在增加,最终服务器上能占用 120G 。之后就稳定下来了
    通过 valgrind 跑的话没发现内存泄漏的问题,但是最终占用也基本是 120 多 G 是一样的。
    有没有什么办法 能分析到究竟是程序哪里开辟和占用的过高呢?
    9 replies  •  2022-12-05 10:57:17 +08:00
    lookingmoon
    lookingmoon
    OP
    Dec 2, 2022
    1
    求大佬们指点指点 help~
    imggyyll
    imggyyll
    Dec 2, 2022
    2
    jemalloc 或者 tcmalloc 的 profile 功能,也可以看看 /proc/pid/smaps
    jones2000
    jones2000
    Dec 2, 2022
    3
    使用自己的内存池, 所有内存分配都走自己的内存池。内存池里面的内存块头上加点信息,好定位内存使用的地方,然后就打印信息,慢慢找了。
    litmxs
    litmxs
    Dec 2, 2022 via Android
    4
    Google Perf Tools
    litmxs
    litmxs
    Dec 2, 2022 via Android
    5
    这么大的内存不知道 profile 工具能不能跑起来,最好能定位到小点的模块后单独抽出来做 profile
    noErr
    noErr
    Dec 2, 2022
    6
    能调试的话,就很方便了,运行一会,diff 一下内存
    lookingmoon
    lookingmoon
    OP
    Dec 2, 2022
    7
    @noErr 可以 gdb diff 内存怎么操作 我是菜鸡……
    Nemodontcry
    Nemodontcry
    Dec 3, 2022
    8
    hook 一下 malloc
    theniupa
    theniupa
    Dec 5, 2022
    9
    linux 环境?试试 malloc_trim?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   5827 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 43ms · UTC 03:04 · PVG 11:04 · LAX 19:04 · JFK 22:04
    ♥ Do have faith in what you're doing.