如何分析一个C程序的内存占用 [英] How to profile memory usage of a C program

查看:308
本文介绍了如何分析一个C程序的内存占用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要弄清楚,我运行,走的是多少(按百分比或绝对)内存一个Linux程序的哪一部分。我需要创建多个此类项目的一个配置文件,这样我就可以找出一些较大的消费者的记忆在我的code,看看我是否能够优化他们少用。
我需要它在MIPS平台上,不幸的是,Valgrind的不能在MIPS工作。

I need to figure out which part of a linux program that I am running, is taking how much (either percentage, or absolute) memory. I need to create a profile of multiple such programs, so that I can identify some of the bigger consumers of memory in my code, and see if I can optimize them to use less. I need it on MIPS platform, and unfortunately, Valgrind doesn't work on MIPS.

任何帮助/指针将大大AP preciated。

Any help/pointers would be greatly appreciated.

推荐答案

您可以换到免费的malloc 用自己的功能,其中还提供例如在哪个文件以及在什么行号每次分配完成。从这些信息可以很容易地看到的是正在使用的内存中。

You could wrap all your calls to free and malloc with your own functions in which you also supply for instance in which file and at what line number each allocation is done. From this information it's easy to see what memory is being used where.

这篇关于如何分析一个C程序的内存占用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆