V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
lookingmoon
V2EX  ›  程序员

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

  •  
  •   lookingmoon · Dec 2, 2022 · 2297 views
    This topic created in 1250 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
        1
    lookingmoon  
    OP
       Dec 2, 2022
    求大佬们指点指点 help~
    imggyyll
        2
    imggyyll  
       Dec 2, 2022
    jemalloc 或者 tcmalloc 的 profile 功能,也可以看看 /proc/pid/smaps
    jones2000
        3
    jones2000  
       Dec 2, 2022
    使用自己的内存池, 所有内存分配都走自己的内存池。内存池里面的内存块头上加点信息,好定位内存使用的地方,然后就打印信息,慢慢找了。
    litmxs
        4
    litmxs  
       Dec 2, 2022 via Android
    Google Perf Tools
    litmxs
        5
    litmxs  
       Dec 2, 2022 via Android
    这么大的内存不知道 profile 工具能不能跑起来,最好能定位到小点的模块后单独抽出来做 profile
    noErr
        6
    noErr  
       Dec 2, 2022
    能调试的话,就很方便了,运行一会,diff 一下内存
    lookingmoon
        7
    lookingmoon  
    OP
       Dec 2, 2022
    @noErr 可以 gdb diff 内存怎么操作 我是菜鸡……
    Nemodontcry
        8
    Nemodontcry  
       Dec 3, 2022
    hook 一下 malloc
    theniupa
        9
    theniupa  
       Dec 5, 2022
    linux 环境?试试 malloc_trim?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2797 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 46ms · UTC 09:39 · PVG 17:39 · LAX 02:39 · JFK 05:39
    ♥ Do have faith in what you're doing.