【问题标题】:How to find out the memory usage of particular function in a process (C Program) in linux?如何在linux中找出进程(C程序)中特定函数的内存使用情况?
【发布时间】:2015-09-25 11:34:31
【问题描述】:
I would like to find out the memory consumed by particular function in linux.   

如何在进程(C 程序)中找出 function_net() 的确切内存使用情况?

linux中是否有任何系统调用来找出相同的?

For example:

/* How to find out the memory usage of this function */

**void function_net()
{
   int *a = (int *)malloc(200);
}**

 #include<stdio.h>
int main()
{
   function_net();
}

【问题讨论】:

  • 一旦代码被编译,生成的代码中实际上并没有任何“函数”,这与最初的 C 函数概念不同。你所拥有的只是代码不同部分之间的跳转,Linux 内核不知道某些分配来自什么“功能”。有一些工具可以帮助您,例如strace 跟踪系统调用(如 malloc)、分析器和调试器,它们基本上都需要您运行调试构建以获取任何有意义的信息。
  • 感谢您的回复。是否可以使用 pmap 进行检查?

标签: c linux operating-system


【解决方案1】:

您可以让编译器在编译阶段将程序集源输出生成为单独的文件,或者让链接器在构建的链接阶段输出映射文件。然而,它可能会被优化出来

【讨论】:

    猜你喜欢
    • 2021-09-25
    • 1970-01-01
    • 1970-01-01
    • 2014-04-11
    • 2013-05-11
    • 2010-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多